0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 05:33:02 -05:00

component set (#128)

This commit is contained in:
Alex Sánchez 2024-05-31 13:32:59 +02:00 committed by GitHub
parent 79f6ce80d2
commit f8e6b6ecd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 14 additions and 11 deletions

View file

@ -0,0 +1,5 @@
---
"penpot-exporter": minor
---
Component set

View file

@ -22,7 +22,7 @@ export const transformComponentNode = async (
componentsLibrary.register(node.id, { componentsLibrary.register(node.id, {
type: 'component', type: 'component',
name: node.name, name: node.name,
path: '', path: node.parent?.type === 'COMPONENT_SET' ? node.parent.name : '',
...transformFigmaIds(node), ...transformFigmaIds(node),
...(await transformFills(node)), ...(await transformFills(node)),
...transformEffects(node), ...transformEffects(node),

View file

@ -13,12 +13,12 @@ import {
import { FrameShape } from '@ui/lib/types/shapes/frameShape'; import { FrameShape } from '@ui/lib/types/shapes/frameShape';
const isSectionNode = (node: FrameNode | SectionNode): node is SectionNode => { const isSectionNode = (node: FrameNode | SectionNode | ComponentSetNode): node is SectionNode => {
return node.type === 'SECTION'; return node.type === 'SECTION';
}; };
export const transformFrameNode = async ( export const transformFrameNode = async (
node: FrameNode | SectionNode, node: FrameNode | SectionNode | ComponentSetNode,
baseX: number, baseX: number,
baseY: number baseY: number
): Promise<FrameShape> => { ): Promise<FrameShape> => {

View file

@ -25,18 +25,14 @@ export const transformInstanceNode = async (
* *
* 1. If the component does not have a main component. * 1. If the component does not have a main component.
* 2. If the component does not have parent (it comes from an external design system). * 2. If the component does not have parent (it comes from an external design system).
* 3. If the component is inside a component set, (it is a variant component).
*/ */
if ( if (!mainComponent || mainComponent.parent === null) {
!mainComponent ||
mainComponent.parent === null ||
mainComponent.parent.type === 'COMPONENT_SET'
) {
return; return;
} }
return { return {
type: 'instance', type: 'instance',
name: node.name,
mainComponentFigmaId: mainComponent.id, mainComponentFigmaId: mainComponent.id,
isComponentRoot: isComponentRoot(node), isComponentRoot: isComponentRoot(node),
...transformFigmaIds(node), ...transformFigmaIds(node),

View file

@ -34,6 +34,7 @@ export const transformSceneNode = async (
break; break;
case 'SECTION': case 'SECTION':
case 'FRAME': case 'FRAME':
case 'COMPONENT_SET':
penpotNode = await transformFrameNode(node, baseX, baseY); penpotNode = await transformFrameNode(node, baseX, baseY);
break; break;
case 'GROUP': case 'GROUP':

View file

@ -18,7 +18,7 @@ export type ComponentShape = ShapeBaseAttributes &
export type ComponentAttributes = { export type ComponentAttributes = {
type?: 'component'; type?: 'component';
name: string; name: string;
path: ''; path: string;
mainInstanceId?: Uuid; mainInstanceId?: Uuid;
mainInstancePage?: Uuid; mainInstancePage?: Uuid;
}; };

View file

@ -1,5 +1,5 @@
import { LayoutAttributes, LayoutChildAttributes } from '@ui/lib/types/shapes/layout'; import { LayoutAttributes, LayoutChildAttributes } from '@ui/lib/types/shapes/layout';
import { ShapeGeomAttributes } from '@ui/lib/types/shapes/shape'; import { ShapeAttributes, ShapeGeomAttributes } from '@ui/lib/types/shapes/shape';
import { Children } from '@ui/lib/types/utils/children'; import { Children } from '@ui/lib/types/utils/children';
export type ComponentRoot = { export type ComponentRoot = {
@ -8,6 +8,7 @@ export type ComponentRoot = {
}; };
export type ComponentInstance = ShapeGeomAttributes & export type ComponentInstance = ShapeGeomAttributes &
ShapeAttributes &
LayoutAttributes & LayoutAttributes &
LayoutChildAttributes & LayoutChildAttributes &
Children & { Children & {