Created
February 7, 2022 07:38
-
-
Save ryonakae/54b063b9732532d78bd07716ef395beb to your computer and use it in GitHub Desktop.
Apply auto-layout for multiple frames on Figma
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const layoutMode = 'HORIZONTAL' // 'HORIZONTAL' or 'VERTICAL' | |
figma.currentPage.selection.forEach(node => { | |
if (node.type === 'FRAME') { | |
const firstItemPosition = layoutMode === 'HORIZONTAL' ? node.children[0].x : node.children[0].y | |
const firstItemSize = layoutMode === 'HORIZONTAL' ? node.children[0].width : node.children[0].height | |
const secondItemPosition = layoutMode === 'HORIZONTAL' ? node.children[1].x : node.children[1].y | |
const itemSpacing = secondItemPosition - (firstItemPosition + firstItemSize) | |
node.layoutMode = layoutMode | |
node.itemSpacing = itemSpacing | |
if (layoutMode === 'HORIZONTAL') { | |
node.paddingLeft = firstItemPosition | |
node.paddingRight = firstItemPosition | |
} else { | |
node.paddingTop = firstItemPosition | |
node.paddingTop = firstItemPosition | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment