Skip to content

Commit

Permalink
Fix hug in frames (#174)
Browse files Browse the repository at this point in the history
* fix hug in frames

* changeset

* fixes
  • Loading branch information
Cenadros authored Jun 18, 2024
1 parent 738ebfe commit beb3caa
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-baboons-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": patch
---

Fix Hug in Frames
5 changes: 3 additions & 2 deletions plugin-src/transformers/partials/transformLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const transformAutoLayout = (node: BaseFrameMixin): LayoutAttributes => {
};

export const transformLayoutAttributes = (
node: LayoutMixin
node: LayoutMixin,
isFrame: boolean = false
): Pick<
LayoutChildAttributes,
| 'layoutItemH-Sizing'
Expand All @@ -43,7 +44,7 @@ export const transformLayoutAttributes = (
| 'layoutItemMinW'
> => {
return {
'layoutItemH-Sizing': translateLayoutSizing(node.layoutSizingHorizontal),
'layoutItemH-Sizing': translateLayoutSizing(node.layoutSizingHorizontal, isFrame),
'layoutItemV-Sizing': translateLayoutSizing(node.layoutSizingVertical),
'layoutItemAbsolute': node.layoutPositioning === 'ABSOLUTE',
'layoutItemMaxH': node.maxHeight ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformComponentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const transformComponentNode = async (
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node),
...transformLayoutAttributes(node),
...transformLayoutAttributes(node, true),
...transformCornerRadius(node),
...(await transformChildren(node, node.rotation + baseRotation)),
...transformDimension(node),
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformFrameNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const transformFrameNode = async (
// @see: https://forum.figma.com/t/add-a-blendmode-property-for-sectionnode/58560
...transformBlend(node),
...transformProportion(node),
...transformLayoutAttributes(node),
...transformLayoutAttributes(node, true),
...transformCornerRadius(node),
...transformEffects(node),
...transformConstraints(node),
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformInstanceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const transformInstanceNode = async (
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node),
...transformLayoutAttributes(node),
...transformLayoutAttributes(node, true),
...transformCornerRadius(node),
...transformDimension(node),
...transformRotationAndPosition(node, baseRotation),
Expand Down
7 changes: 5 additions & 2 deletions plugin-src/translators/translateLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ export const translateLayoutAlignItems = (node: BaseFrameMixin): JustifyAlignIte
}
};

export const translateLayoutSizing = (sizing: FigmaLayoutSizing): LayoutSizing => {
export const translateLayoutSizing = (
sizing: FigmaLayoutSizing,
isFrame: boolean = false
): LayoutSizing => {
switch (sizing) {
case 'FIXED':
return 'fix';
case 'HUG':
return 'auto';
return isFrame ? 'fix' : 'auto'; // @TODO: Penpot does not handle hug in frames as figma does
case 'FILL':
return 'fill';
}
Expand Down

0 comments on commit beb3caa

Please sign in to comment.