Skip to content

Commit

Permalink
component set (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros authored May 31, 2024
1 parent 79f6ce8 commit f8e6b6e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-months-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": minor
---

Component set
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformComponentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const transformComponentNode = async (
componentsLibrary.register(node.id, {
type: 'component',
name: node.name,
path: '',
path: node.parent?.type === 'COMPONENT_SET' ? node.parent.name : '',
...transformFigmaIds(node),
...(await transformFills(node)),
...transformEffects(node),
Expand Down
4 changes: 2 additions & 2 deletions plugin-src/transformers/transformFrameNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {

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';
};

export const transformFrameNode = async (
node: FrameNode | SectionNode,
node: FrameNode | SectionNode | ComponentSetNode,
baseX: number,
baseY: number
): Promise<FrameShape> => {
Expand Down
8 changes: 2 additions & 6 deletions plugin-src/transformers/transformInstanceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ export const transformInstanceNode = async (
*
* 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).
* 3. If the component is inside a component set, (it is a variant component).
*/
if (
!mainComponent ||
mainComponent.parent === null ||
mainComponent.parent.type === 'COMPONENT_SET'
) {
if (!mainComponent || mainComponent.parent === null) {
return;
}

return {
type: 'instance',
name: node.name,
mainComponentFigmaId: mainComponent.id,
isComponentRoot: isComponentRoot(node),
...transformFigmaIds(node),
Expand Down
1 change: 1 addition & 0 deletions plugin-src/transformers/transformSceneNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const transformSceneNode = async (
break;
case 'SECTION':
case 'FRAME':
case 'COMPONENT_SET':
penpotNode = await transformFrameNode(node, baseX, baseY);
break;
case 'GROUP':
Expand Down
2 changes: 1 addition & 1 deletion ui-src/lib/types/shapes/componentShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ComponentShape = ShapeBaseAttributes &
export type ComponentAttributes = {
type?: 'component';
name: string;
path: '';
path: string;
mainInstanceId?: Uuid;
mainInstancePage?: Uuid;
};
3 changes: 2 additions & 1 deletion ui-src/types/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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';

export type ComponentRoot = {
Expand All @@ -8,6 +8,7 @@ export type ComponentRoot = {
};

export type ComponentInstance = ShapeGeomAttributes &
ShapeAttributes &
LayoutAttributes &
LayoutChildAttributes &
Children & {
Expand Down

0 comments on commit f8e6b6e

Please sign in to comment.