0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/ui-src/parser/creators/createComponent.ts
Alex Sánchez 7b3192936e
Component Instances (#124)
* wip

* wip

* wipo

* more structure

* wip

* id library wip

* wip

* main instance working

* improvements

* fix node order

* refactor

* remove not used method

* refactor

* fix component set translation

* refactor

* add changelog

* penpot lib update

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-05-30 17:54:37 +02:00

38 lines
946 B
TypeScript

import { componentsLibrary } from '@plugin/ComponentLibrary';
import { PenpotFile } from '@ui/lib/types/penpotFile';
import { uiComponents } from '@ui/parser/libraries';
import { ComponentRoot } from '@ui/types';
import { createArtboard } from '.';
export const createComponent = (file: PenpotFile, { figmaId }: ComponentRoot) => {
const component = componentsLibrary.get(figmaId);
if (!component) {
return;
}
const uiComponent = uiComponents.get(figmaId);
const componentId = uiComponent?.componentId ?? file.newId();
const frameId = createArtboard(file, {
...component,
showContent: true,
componentFile: file.getId(),
componentId,
componentRoot: true,
mainInstance: true,
type: 'frame'
});
if (!frameId) {
return;
}
uiComponents.register(figmaId, {
componentId,
mainInstancePage: file.getCurrentPageId(),
componentFigmaId: figmaId,
mainInstanceId: frameId
});
};