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:
parent
79f6ce80d2
commit
f8e6b6ecd9
7 changed files with 14 additions and 11 deletions
5
.changeset/sixty-months-wink.md
Normal file
5
.changeset/sixty-months-wink.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"penpot-exporter": minor
|
||||
---
|
||||
|
||||
Component set
|
|
@ -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),
|
||||
|
|
|
@ -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> => {
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -18,7 +18,7 @@ export type ComponentShape = ShapeBaseAttributes &
|
|||
export type ComponentAttributes = {
|
||||
type?: 'component';
|
||||
name: string;
|
||||
path: '';
|
||||
path: string;
|
||||
mainInstanceId?: Uuid;
|
||||
mainInstancePage?: Uuid;
|
||||
};
|
||||
|
|
|
@ -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 = {
|
||||
|
@ -8,6 +8,7 @@ export type ComponentRoot = {
|
|||
};
|
||||
|
||||
export type ComponentInstance = ShapeGeomAttributes &
|
||||
ShapeAttributes &
|
||||
LayoutAttributes &
|
||||
LayoutChildAttributes &
|
||||
Children & {
|
||||
|
|
Loading…
Reference in a new issue