Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional layout properties #190

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-teachers-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": patch
---

Add additional layout properties
5 changes: 5 additions & 0 deletions plugin-src/transformers/partials/transformLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {
translateLayoutAlignItems,
translateLayoutFlexDir,
translateLayoutGap,
translateLayoutItemAlignSelf,
translateLayoutJustifyContent,
translateLayoutJustifyItems,
translateLayoutPadding,
translateLayoutPaddingType,
translateLayoutSizing,
translateLayoutWrapType
} from '@plugin/translators';
Expand All @@ -23,6 +25,7 @@ export const transformAutoLayout = (node: BaseFrameMixin): LayoutAttributes => {
),
layoutWrapType: translateLayoutWrapType(node.layoutWrap),
layoutPadding: translateLayoutPadding(node),
layoutPaddingType: translateLayoutPaddingType(node),
layoutJustifyContent: translateLayoutJustifyContent(node),
layoutJustifyItems: translateLayoutJustifyItems(node),
layoutAlignContent: translateLayoutAlignContent(node),
Expand All @@ -37,6 +40,7 @@ export const transformLayoutAttributes = (
LayoutChildAttributes,
| 'layoutItemH-Sizing'
| 'layoutItemV-Sizing'
| 'layoutItemAlignSelf'
| 'layoutItemAbsolute'
| 'layoutItemMaxH'
| 'layoutItemMinH'
Expand All @@ -46,6 +50,7 @@ export const transformLayoutAttributes = (
return {
'layoutItemH-Sizing': translateLayoutSizing(node.layoutSizingHorizontal, isFrame),
'layoutItemV-Sizing': translateLayoutSizing(node.layoutSizingVertical, isFrame),
'layoutItemAlignSelf': translateLayoutItemAlignSelf(node.layoutAlign),
'layoutItemAbsolute': node.layoutPositioning === 'ABSOLUTE',
'layoutItemMaxH': node.maxHeight ?? undefined,
'layoutItemMinH': node.minHeight ?? undefined,
Expand Down
24 changes: 24 additions & 0 deletions plugin-src/translators/translateLayout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
JustifyAlignContent,
JustifyAlignItems,
LayoutAlignSelf,
LayoutFlexDir,
LayoutGap,
LayoutPadding,
Expand All @@ -14,6 +15,8 @@ type FigmaWrap = 'NO_WRAP' | 'WRAP';

type FigmaLayoutSizing = 'FIXED' | 'HUG' | 'FILL';

type FigmaLayoutAlign = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'INHERIT';

export const translateLayoutFlexDir = (layoutMode: FigmaLayoutMode): LayoutFlexDir | undefined => {
switch (layoutMode) {
case 'HORIZONTAL':
Expand Down Expand Up @@ -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 => {
switch (node.primaryAxisAlignItems) {
case 'MIN':
Expand Down Expand Up @@ -128,3 +139,16 @@ export const translateLayoutSizing = (
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';
}
};
4 changes: 3 additions & 1 deletion ui-src/lib/types/shapes/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Uuid } from '@ui/lib/types/utils/uuid';

export type LayoutSizing = 'fill' | 'fix' | 'auto';

export type LayoutAlignSelf = 'start' | 'end' | 'center' | 'stretch';

export type LayoutChildAttributes = {
'layoutItemMarginType'?: 'simple' | 'multiple';
'layoutItemMargin'?: {
Expand All @@ -16,7 +18,7 @@ export type LayoutChildAttributes = {
'layoutItemMinW'?: number;
'layoutItemH-Sizing'?: LayoutSizing;
'layoutItemV-Sizing'?: LayoutSizing;
'layoutItemAlignSelf'?: 'start' | 'end' | 'center' | 'stretch';
'layoutItemAlignSelf'?: LayoutAlignSelf;
'layoutItemAbsolute'?: boolean;
'layoutItemZIndex'?: number;
};
Expand Down