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 be5ff3be8e
Remote components (External design systems) (#140)
* remote components processing

* changeset

* fixes

* fixes

* fixes

* fixes

* fix everything

* revert for now

* fixes

* change delete nodes flag

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-06-06 09:37:35 +02:00

37 lines
923 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,
componentFile: file.getId(),
componentId,
componentRoot: true,
mainInstance: true,
type: 'frame'
});
if (!frameId) {
return;
}
uiComponents.register(figmaId, {
componentId,
mainInstancePage: file.getCurrentPageId(),
componentFigmaId: figmaId,
mainInstanceId: frameId
});
};