Skip to content

Instantly share code, notes, and snippets.

@ryonakae
Created February 7, 2022 07:38
Show Gist options
  • Save ryonakae/54b063b9732532d78bd07716ef395beb to your computer and use it in GitHub Desktop.
Save ryonakae/54b063b9732532d78bd07716ef395beb to your computer and use it in GitHub Desktop.
Apply auto-layout for multiple frames on Figma
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