-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1102 from openameba/chore/code-connect
Initial Setup for Figma Connect
- Loading branch information
Showing
18 changed files
with
3,483 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Publish Figma Code Connect | ||
|
||
on: | ||
push: | ||
paths: | ||
- packages/spindle-ui/src/**/*.figma.tsx | ||
branches: | ||
- main | ||
|
||
jobs: | ||
code-connect: | ||
name: Code Connect | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm i -g @figma/code-connect | ||
- run: figma connect publish | ||
env: | ||
FIGMA_ACCESS_TOKEN: ${{ secrets.FIGMA_TOKEN_CODE_CONNECT }} | ||
working-directory: packages/spindle-ui |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ regconfig.json | |
tsconfig.json | ||
design-doc.md | ||
setup-tests.ts | ||
*.figma.tsx |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"codeConnect": { | ||
"parser": "react", | ||
"include": ["src/**/*.tsx"] | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import fs from 'fs'; | ||
import * as Figma from 'figma-api'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
if (!process.env.FIGMA_ACCESS_TOKEN) { | ||
throw new Error( | ||
'Figma personal token should be set as an environment variable "FIGMA_ACCESS_TOKEN".', | ||
); | ||
} | ||
|
||
export const figma = new Figma.Api({ | ||
personalAccessToken: process.env.FIGMA_ACCESS_TOKEN, | ||
}); | ||
|
||
const fileKey = 'G445fTskctZn7y3gkmSp8xaT'; | ||
const nodeId = '991-0'; | ||
const fileName = 'icon'; | ||
|
||
async function connectIcons() { | ||
const result = await figma.getFileNodes(fileKey, [nodeId]); | ||
const components = Object.entries( | ||
result.nodes[nodeId.replace('-', ':')]?.components || {}, | ||
).map(([key, value]) => { | ||
return { | ||
// Convert snake_case to PascalCase | ||
name: value.name | ||
.split('_') | ||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(''), | ||
figmaUrl: `https://www.figma.com/design/${fileKey}/${fileName}?node-id=${key.replace( | ||
':', | ||
'-', | ||
)}`, | ||
}; | ||
}); | ||
|
||
const uniqueNames = new Set([...components.map((c) => c.name)]); | ||
|
||
fs.writeFileSync( | ||
'src/icons.figma.tsx', | ||
`\ | ||
import figma from '@figma/code-connect' | ||
import { | ||
${Array.from(uniqueNames) | ||
.map((iconName) => `${iconName},`) | ||
.join('\n')} | ||
} from './Icon' | ||
${components | ||
.map( | ||
(c) => | ||
`figma.connect(${c.name}, '${c.figmaUrl}', { imports: ["import { ${c.name} } from '@openameba/spindle-ui/Icon';"] })`, | ||
) | ||
.join('\n')} | ||
`, | ||
); | ||
} | ||
|
||
connectIcons(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import { Button } from './Button'; | ||
import figma from '@figma/code-connect'; | ||
|
||
figma.connect( | ||
Button, | ||
'https://www.figma.com/design/FSgvRthUiMMXWgrSE4RUgr/Spindle-UI?node-id=1789-29120&t=5pAze6eM9wAFTPFz-0', | ||
{ | ||
imports: ["import { Button } from '@openameba/spindle-ui';"], | ||
props: { | ||
size: figma.enum('size', { | ||
large: 'large', | ||
medium: 'medium', | ||
small: 'small', | ||
}), | ||
variant: figma.enum('variant', { | ||
contained: 'contained', | ||
outlined: 'outlined', | ||
neutral: 'neutral', | ||
lighted: 'lighted', | ||
danger: 'danger', | ||
}), | ||
layout: figma.enum('layout', { | ||
intrinsic: 'intrinsic', | ||
fullWidth: 'fullWidth', | ||
}), | ||
disabled: figma.boolean('disabled'), | ||
content: figma.nestedProps('Instance / Content', { | ||
iconPosition: figma.enum('iconPosition', { | ||
start: 'start', | ||
end: 'end', | ||
}), | ||
icon: figma.boolean('icon', { | ||
true: figma.instance('└ iconName'), | ||
false: undefined, | ||
}), | ||
label: figma.textContent('btn_txt'), | ||
}), | ||
}, | ||
example: ({ size, variant, layout, disabled, content }) => ( | ||
<Button | ||
size={size} | ||
variant={variant} | ||
layout={layout} | ||
disabled={disabled} | ||
icon={content.icon} | ||
iconPosition={content.iconPosition} | ||
> | ||
{content.label} | ||
</Button> | ||
), | ||
}, | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { Dialog } from './Dialog'; | ||
import figma from '@figma/code-connect'; | ||
import { SubtleButton } from 'src/SubtleButton'; | ||
import { Button } from 'src/Button'; | ||
|
||
figma.connect( | ||
Dialog, | ||
'https://www.figma.com/design/FSgvRthUiMMXWgrSE4RUgr/Spindle-UI?node-id=452-38043', | ||
{ | ||
imports: ["import { Dialog } from '@openameba/spindle-ui';"], | ||
props: { | ||
title: figma.boolean('Title', { | ||
true: <Dialog.Title></Dialog.Title>, | ||
false: undefined, | ||
}), | ||
description: figma.boolean('Description', { | ||
true: <Dialog.Body></Dialog.Body>, | ||
false: undefined, | ||
}), | ||
closeButton: figma.boolean('Close Button', { | ||
true: <SubtleButton size="medium">とじる</SubtleButton>, | ||
false: undefined, | ||
}), | ||
content: figma.nestedProps('Button Layout', { | ||
layout: figma.enum('Layout', { | ||
Vertical: 'column', | ||
Horizontal: 'row', | ||
}), | ||
secondaryButton: figma.boolean('Secondary Button2', { | ||
true: <Button layout="fullWidth" size="medium"></Button>, | ||
false: undefined, | ||
}), | ||
}), | ||
}, | ||
example: ({ title, description, closeButton, content }) => ( | ||
<Dialog.Frame> | ||
{title} | ||
{description} | ||
<Dialog.ButtonGroup direction={content.layout}> | ||
<Button layout="fullWidth" size="medium" autoFocus></Button> | ||
{content.secondaryButton} | ||
{closeButton} | ||
</Dialog.ButtonGroup> | ||
</Dialog.Frame> | ||
), | ||
}, | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { Checkbox } from './Checkbox'; | ||
import figma from '@figma/code-connect'; | ||
|
||
figma.connect( | ||
Checkbox, | ||
'https://www.figma.com/design/FSgvRthUiMMXWgrSE4RUgr/Spindle-UI?node-id=473-33059&t=BiQUBKKifVQV5TbP-0', | ||
{ | ||
imports: ["import { Checkbox } from '@openameba/spindle-ui/Form';"], | ||
props: { | ||
active: figma.boolean('Active'), | ||
hover: figma.boolean('Focus Ring'), | ||
label: figma.string('Label'), | ||
name: figma.string('Name'), | ||
id: figma.string('id'), | ||
value: figma.string('value'), | ||
}, | ||
example: ({ active, label, name, id, value }) => ( | ||
<Checkbox | ||
id={id} | ||
name={name} | ||
value={value} | ||
aria-label={label} | ||
checked={active} | ||
></Checkbox> | ||
), | ||
}, | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { Radio } from './Radio'; | ||
import figma from '@figma/code-connect'; | ||
|
||
figma.connect( | ||
Radio, | ||
'https://www.figma.com/design/FSgvRthUiMMXWgrSE4RUgr/Spindle-UI?node-id=473-33051&t=BiQUBKKifVQV5TbP-0', | ||
{ | ||
imports: ["import { Radio } from '@openameba/spindle-ui/Form';"], | ||
props: { | ||
active: figma.boolean('Active'), | ||
hover: figma.boolean('Focus Ring'), | ||
label: figma.string('Label'), | ||
name: figma.string('Name'), | ||
id: figma.string('id'), | ||
}, | ||
example: ({ active, label, name, id }) => ( | ||
<Radio id={id} name={name} aria-label={label} checked={active}></Radio> | ||
), | ||
}, | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { ToggleSwitch } from './ToggleSwitch'; | ||
import figma from '@figma/code-connect'; | ||
|
||
figma.connect( | ||
ToggleSwitch, | ||
'https://www.figma.com/design/FSgvRthUiMMXWgrSE4RUgr/Spindle-UI?node-id=473-33067&t=BiQUBKKifVQV5TbP-0', | ||
{ | ||
imports: ["import { ToggleSwitch } from '@openameba/spindle-ui/Form';"], | ||
props: { | ||
active: figma.boolean('Active'), | ||
id: figma.string('id'), | ||
label: figma.string('label'), | ||
}, | ||
example: ({ active, id, label }) => ( | ||
<ToggleSwitch id={id} aria-label={label} checked={active}></ToggleSwitch> | ||
), | ||
}, | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { IconButton } from './IconButton'; | ||
import figma from '@figma/code-connect'; | ||
|
||
figma.connect( | ||
IconButton, | ||
'https://www.figma.com/design/FSgvRthUiMMXWgrSE4RUgr/Spindle-UI?node-id=4042-25426&t=R8kIhRlvP5CmX9Qn-0', | ||
{ | ||
imports: ["import { IconButton } from '@openameba/spindle-ui';"], | ||
props: { | ||
size: figma.enum('Size', { | ||
Large: 'large', | ||
Medium: 'medium', | ||
Small: 'small', | ||
'Ex Small': 'exSmall', | ||
}), | ||
style: figma.enum('Style', { | ||
Contained: 'contained', | ||
Outlined: 'outlined', | ||
Neutral: 'neutral', | ||
Lighted: 'lighted', | ||
}), | ||
disabled: figma.boolean('Disabled'), | ||
children: figma.children('*'), | ||
label: figma.string('Label'), | ||
}, | ||
example: ({ size, style, disabled, children, label }) => ( | ||
<IconButton | ||
size={size} | ||
variant={style} | ||
disabled={disabled} | ||
aria-label={label} | ||
> | ||
{children} | ||
</IconButton> | ||
), | ||
}, | ||
); |
Oops, something went wrong.