mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 13:43:03 -05:00
Additional layout properties (#190)
* additional layout properties * changeset
This commit is contained in:
parent
aee78de8ac
commit
511b842b12
4 changed files with 37 additions and 1 deletions
5
.changeset/five-teachers-cheat.md
Normal file
5
.changeset/five-teachers-cheat.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"penpot-exporter": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add additional layout properties
|
|
@ -3,9 +3,11 @@ import {
|
||||||
translateLayoutAlignItems,
|
translateLayoutAlignItems,
|
||||||
translateLayoutFlexDir,
|
translateLayoutFlexDir,
|
||||||
translateLayoutGap,
|
translateLayoutGap,
|
||||||
|
translateLayoutItemAlignSelf,
|
||||||
translateLayoutJustifyContent,
|
translateLayoutJustifyContent,
|
||||||
translateLayoutJustifyItems,
|
translateLayoutJustifyItems,
|
||||||
translateLayoutPadding,
|
translateLayoutPadding,
|
||||||
|
translateLayoutPaddingType,
|
||||||
translateLayoutSizing,
|
translateLayoutSizing,
|
||||||
translateLayoutWrapType
|
translateLayoutWrapType
|
||||||
} from '@plugin/translators';
|
} from '@plugin/translators';
|
||||||
|
@ -23,6 +25,7 @@ export const transformAutoLayout = (node: BaseFrameMixin): LayoutAttributes => {
|
||||||
),
|
),
|
||||||
layoutWrapType: translateLayoutWrapType(node.layoutWrap),
|
layoutWrapType: translateLayoutWrapType(node.layoutWrap),
|
||||||
layoutPadding: translateLayoutPadding(node),
|
layoutPadding: translateLayoutPadding(node),
|
||||||
|
layoutPaddingType: translateLayoutPaddingType(node),
|
||||||
layoutJustifyContent: translateLayoutJustifyContent(node),
|
layoutJustifyContent: translateLayoutJustifyContent(node),
|
||||||
layoutJustifyItems: translateLayoutJustifyItems(node),
|
layoutJustifyItems: translateLayoutJustifyItems(node),
|
||||||
layoutAlignContent: translateLayoutAlignContent(node),
|
layoutAlignContent: translateLayoutAlignContent(node),
|
||||||
|
@ -37,6 +40,7 @@ export const transformLayoutAttributes = (
|
||||||
LayoutChildAttributes,
|
LayoutChildAttributes,
|
||||||
| 'layoutItemH-Sizing'
|
| 'layoutItemH-Sizing'
|
||||||
| 'layoutItemV-Sizing'
|
| 'layoutItemV-Sizing'
|
||||||
|
| 'layoutItemAlignSelf'
|
||||||
| 'layoutItemAbsolute'
|
| 'layoutItemAbsolute'
|
||||||
| 'layoutItemMaxH'
|
| 'layoutItemMaxH'
|
||||||
| 'layoutItemMinH'
|
| 'layoutItemMinH'
|
||||||
|
@ -46,6 +50,7 @@ export const transformLayoutAttributes = (
|
||||||
return {
|
return {
|
||||||
'layoutItemH-Sizing': translateLayoutSizing(node.layoutSizingHorizontal, isFrame),
|
'layoutItemH-Sizing': translateLayoutSizing(node.layoutSizingHorizontal, isFrame),
|
||||||
'layoutItemV-Sizing': translateLayoutSizing(node.layoutSizingVertical, isFrame),
|
'layoutItemV-Sizing': translateLayoutSizing(node.layoutSizingVertical, isFrame),
|
||||||
|
'layoutItemAlignSelf': translateLayoutItemAlignSelf(node.layoutAlign),
|
||||||
'layoutItemAbsolute': node.layoutPositioning === 'ABSOLUTE',
|
'layoutItemAbsolute': node.layoutPositioning === 'ABSOLUTE',
|
||||||
'layoutItemMaxH': node.maxHeight ?? undefined,
|
'layoutItemMaxH': node.maxHeight ?? undefined,
|
||||||
'layoutItemMinH': node.minHeight ?? undefined,
|
'layoutItemMinH': node.minHeight ?? undefined,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
JustifyAlignContent,
|
JustifyAlignContent,
|
||||||
JustifyAlignItems,
|
JustifyAlignItems,
|
||||||
|
LayoutAlignSelf,
|
||||||
LayoutFlexDir,
|
LayoutFlexDir,
|
||||||
LayoutGap,
|
LayoutGap,
|
||||||
LayoutPadding,
|
LayoutPadding,
|
||||||
|
@ -14,6 +15,8 @@ type FigmaWrap = 'NO_WRAP' | 'WRAP';
|
||||||
|
|
||||||
type FigmaLayoutSizing = 'FIXED' | 'HUG' | 'FILL';
|
type FigmaLayoutSizing = 'FIXED' | 'HUG' | 'FILL';
|
||||||
|
|
||||||
|
type FigmaLayoutAlign = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'INHERIT';
|
||||||
|
|
||||||
export const translateLayoutFlexDir = (layoutMode: FigmaLayoutMode): LayoutFlexDir | undefined => {
|
export const translateLayoutFlexDir = (layoutMode: FigmaLayoutMode): LayoutFlexDir | undefined => {
|
||||||
switch (layoutMode) {
|
switch (layoutMode) {
|
||||||
case 'HORIZONTAL':
|
case 'HORIZONTAL':
|
||||||
|
@ -61,6 +64,14 @@ export const translateLayoutPadding = (node: BaseFrameMixin): LayoutPadding => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const translateLayoutPaddingType = (node: BaseFrameMixin): 'simple' | 'multiple' => {
|
||||||
|
if (node.paddingTop === node.paddingBottom && node.paddingRight === node.paddingLeft) {
|
||||||
|
return 'simple';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'multiple';
|
||||||
|
};
|
||||||
|
|
||||||
export const translateLayoutJustifyContent = (node: BaseFrameMixin): JustifyAlignContent => {
|
export const translateLayoutJustifyContent = (node: BaseFrameMixin): JustifyAlignContent => {
|
||||||
switch (node.primaryAxisAlignItems) {
|
switch (node.primaryAxisAlignItems) {
|
||||||
case 'MIN':
|
case 'MIN':
|
||||||
|
@ -128,3 +139,16 @@ export const translateLayoutSizing = (
|
||||||
return isFrame ? 'fix' : 'fill'; // @TODO: Penpot does not handle fill in frames as figma does
|
return isFrame ? 'fix' : 'fill'; // @TODO: Penpot does not handle fill in frames as figma does
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const translateLayoutItemAlignSelf = (align: FigmaLayoutAlign): LayoutAlignSelf => {
|
||||||
|
switch (align) {
|
||||||
|
case 'MIN':
|
||||||
|
return 'start';
|
||||||
|
case 'CENTER':
|
||||||
|
return 'center';
|
||||||
|
case 'MAX':
|
||||||
|
return 'end';
|
||||||
|
default:
|
||||||
|
return 'stretch';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -2,6 +2,8 @@ import { Uuid } from '@ui/lib/types/utils/uuid';
|
||||||
|
|
||||||
export type LayoutSizing = 'fill' | 'fix' | 'auto';
|
export type LayoutSizing = 'fill' | 'fix' | 'auto';
|
||||||
|
|
||||||
|
export type LayoutAlignSelf = 'start' | 'end' | 'center' | 'stretch';
|
||||||
|
|
||||||
export type LayoutChildAttributes = {
|
export type LayoutChildAttributes = {
|
||||||
'layoutItemMarginType'?: 'simple' | 'multiple';
|
'layoutItemMarginType'?: 'simple' | 'multiple';
|
||||||
'layoutItemMargin'?: {
|
'layoutItemMargin'?: {
|
||||||
|
@ -16,7 +18,7 @@ export type LayoutChildAttributes = {
|
||||||
'layoutItemMinW'?: number;
|
'layoutItemMinW'?: number;
|
||||||
'layoutItemH-Sizing'?: LayoutSizing;
|
'layoutItemH-Sizing'?: LayoutSizing;
|
||||||
'layoutItemV-Sizing'?: LayoutSizing;
|
'layoutItemV-Sizing'?: LayoutSizing;
|
||||||
'layoutItemAlignSelf'?: 'start' | 'end' | 'center' | 'stretch';
|
'layoutItemAlignSelf'?: LayoutAlignSelf;
|
||||||
'layoutItemAbsolute'?: boolean;
|
'layoutItemAbsolute'?: boolean;
|
||||||
'layoutItemZIndex'?: number;
|
'layoutItemZIndex'?: number;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue