|
| 1 | +import figma from '@figma/code-connect' |
| 2 | +import { Button } from './Button' |
| 3 | + |
| 4 | +/** |
| 5 | + * Code Connect mapping for Button component. |
| 6 | + * |
| 7 | + * Maps Figma design variants to React component props. |
| 8 | + * Run `npx figma connect publish` from packages/eds-core-react/ to publish. |
| 9 | + * |
| 10 | + * Figma component structure: |
| 11 | + * - Button [EDS] (18:1193) → .Geometry Options → ⌘ Button |
| 12 | + * - Icon Button [EDS] (18:1373) → .Geometry Options → ⌘ Icon Button |
| 13 | + */ |
| 14 | + |
| 15 | +// ============================================ |
| 16 | +// Connection 1: Button [EDS] (18:1193) |
| 17 | +// Top-level wrapper with Tone + nested geometry + nested button |
| 18 | +// ============================================ |
| 19 | + |
| 20 | +figma.connect( |
| 21 | + Button, |
| 22 | + 'https://www.figma.com/design/dz0XQdc5j7AAtjXr1gTfVR/EDS-Core-Components?node-id=18-1193', |
| 23 | + { |
| 24 | + props: { |
| 25 | + tone: figma.enum('Tone', { |
| 26 | + Accent: 'accent', |
| 27 | + Neutral: 'neutral', |
| 28 | + Danger: 'danger', |
| 29 | + }), |
| 30 | + geometry: figma.nestedProps('.Geometry Options', { |
| 31 | + size: figma.enum('Size', { |
| 32 | + Large: 'large', |
| 33 | + Default: 'default', |
| 34 | + Small: 'small', |
| 35 | + }), |
| 36 | + }), |
| 37 | + inner: figma.nestedProps('⌘ Button', { |
| 38 | + variant: figma.enum('Variant', { |
| 39 | + Primary: 'primary', |
| 40 | + Outline: 'secondary', |
| 41 | + Ghost: 'ghost', |
| 42 | + }), |
| 43 | + disabled: figma.enum('State', { |
| 44 | + Disabled: true, |
| 45 | + }), |
| 46 | + leadingIcon: figma.boolean('Show Leading Icon', { |
| 47 | + true: figma.instance('Leading Icon Item'), |
| 48 | + false: undefined, |
| 49 | + }), |
| 50 | + trailingIcon: figma.boolean('Show Trailing Icon', { |
| 51 | + true: figma.instance('Trailing Icon Item'), |
| 52 | + false: undefined, |
| 53 | + }), |
| 54 | + label: figma.string('Label'), |
| 55 | + }), |
| 56 | + }, |
| 57 | + example: ({ tone, geometry, inner }) => ( |
| 58 | + <Button |
| 59 | + variant={inner.variant} |
| 60 | + size={geometry.size} |
| 61 | + tone={tone} |
| 62 | + disabled={inner.disabled} |
| 63 | + > |
| 64 | + {/* TODO: Replace with actual icon components, when Icon component is |
| 65 | + available in Code Connect */} |
| 66 | + {inner.leadingIcon} |
| 67 | + {inner.label} |
| 68 | + {inner.trailingIcon} |
| 69 | + </Button> |
| 70 | + ), |
| 71 | + }, |
| 72 | +) |
| 73 | + |
| 74 | +// ============================================ |
| 75 | +// Connection 2: Icon Button [EDS] (18:1373) |
| 76 | +// Top-level wrapper with Tone + nested geometry (includes Round) + nested icon button |
| 77 | +// ============================================ |
| 78 | + |
| 79 | +figma.connect( |
| 80 | + Button, |
| 81 | + 'https://www.figma.com/design/dz0XQdc5j7AAtjXr1gTfVR/EDS-Core-Components?node-id=18-1373', |
| 82 | + { |
| 83 | + props: { |
| 84 | + tone: figma.enum('Tone', { |
| 85 | + Accent: 'accent', |
| 86 | + Neutral: 'neutral', |
| 87 | + Danger: 'danger', |
| 88 | + }), |
| 89 | + geometry: figma.nestedProps('.Geometry Options', { |
| 90 | + size: figma.enum('Size', { |
| 91 | + Large: 'large', |
| 92 | + Default: 'default', |
| 93 | + Small: 'small', |
| 94 | + }), |
| 95 | + round: figma.boolean('Round'), |
| 96 | + }), |
| 97 | + // @ts-expect-error - Code Connect's ConnectedComponent type doesn't match ReactElement |
| 98 | + inner: figma.nestedProps('⌘ Icon Button', { |
| 99 | + variant: figma.enum('Variant', { |
| 100 | + Primary: 'primary', |
| 101 | + Outline: 'secondary', |
| 102 | + Ghost: 'ghost', |
| 103 | + }), |
| 104 | + disabled: figma.enum('State', { |
| 105 | + Disabled: true, |
| 106 | + }), |
| 107 | + iconContent: figma.instance('icon'), |
| 108 | + }), |
| 109 | + }, |
| 110 | + example: ({ tone, geometry, inner }) => ( |
| 111 | + <Button |
| 112 | + icon |
| 113 | + variant={inner.variant} |
| 114 | + size={geometry.size} |
| 115 | + tone={tone} |
| 116 | + round={geometry.round} |
| 117 | + disabled={inner.disabled} |
| 118 | + /* Remember to describe the action of the icon button for accessibility */ |
| 119 | + aria-label="[Describe action]" |
| 120 | + > |
| 121 | + {inner.iconContent} |
| 122 | + </Button> |
| 123 | + ), |
| 124 | + }, |
| 125 | +) |
0 commit comments