-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Dialog, Card & Button have Figma code connect files for v1 testing #35327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
miceclavea
wants to merge
1
commit into
microsoft:master
Choose a base branch
from
miceclavea:codeConnectDemo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,302
−17
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"codeConnect": { | ||
"include": [ | ||
"packages/react-components/*/stories/**/*.figma.{ts,tsx}", | ||
"packages/react-components/*/stories/**/*.stories.{ts,tsx}" | ||
], | ||
"exclude": ["node_modules/**", "dist/**", "build/**"], | ||
"parser": "react", | ||
"docs": { | ||
"storybookUrl": "http://localhost:3000" | ||
} | ||
} | ||
} |
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
178 changes: 178 additions & 0 deletions
178
packages/react-components/react-button/stories/FIGMA_CODE_CONNECT.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
# Figma Code Connect Integration for Button Component | ||
|
||
This document explains how to use the Figma Code Connect integration that has been added to the Button component in Fluent UI. | ||
|
||
## Overview | ||
|
||
Figma Code Connect allows developers and designers to link Figma components directly to their code implementation, providing a seamless design-to-development workflow. This integration shows the actual React code for components when inspecting them in Figma's Dev Mode. | ||
|
||
## What's Been Added | ||
|
||
### 1. Dependencies | ||
|
||
- `@figma/code-connect` package has been added to the workspace | ||
|
||
### 2. Configuration Files | ||
|
||
- `Button.figma.tsx` - Maps Figma Button properties to React props | ||
- `figma.config.json` - Project-wide Figma Code Connect configuration | ||
- Updated `index.stories.tsx` - Added Figma metadata to Button stories | ||
|
||
### 3. Scripts | ||
|
||
- `yarn figma:connect` - Publish Code Connect mappings to Figma | ||
- `yarn figma:connect:dev` - Run development server for Code Connect | ||
|
||
## How It Works | ||
|
||
### Property Mapping | ||
|
||
The `Button.figma.tsx` file maps Figma design properties to React component props: | ||
|
||
```typescript | ||
figma.connect(Button, 'FIGMA_NODE_URL', { | ||
props: { | ||
children: figma.textContent('Button Text'), | ||
appearance: figma.enum('Appearance', { | ||
Primary: 'primary', | ||
Secondary: 'secondary', | ||
// ... other mappings | ||
}), | ||
size: figma.enum('Size', { | ||
Small: 'small', | ||
Medium: 'medium', | ||
Large: 'large', | ||
}), | ||
// ... other props | ||
}, | ||
example: ({ children, appearance, size, shape, disabled }) => ( | ||
<Button appearance={appearance} size={size} shape={shape} disabled={disabled}> | ||
{children} | ||
</Button> | ||
), | ||
}); | ||
``` | ||
|
||
### Storybook Integration | ||
|
||
The Button stories now include Figma metadata in the `parameters` object: | ||
|
||
```typescript | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/design/yourfile/yournode', | ||
}, | ||
figmaConnect: { | ||
componentId: 'Button', | ||
variantProps: ['appearance', 'size', 'shape', 'disabled'], | ||
}, | ||
} | ||
``` | ||
|
||
## Setup Instructions | ||
|
||
### For Developers | ||
|
||
1. **Get Figma Access Token** | ||
|
||
- Visit [Figma Personal Access Tokens](https://help.figma.com/hc/en-us/articles/8085703771159-Manage-personal-access-tokens) | ||
- Create a token with "File Content" and "Code Connect Write" scopes | ||
- Set the token in your environment or provide it when prompted | ||
|
||
2. **Update Figma URLs** | ||
|
||
- Replace placeholder URLs in `Button.figma.tsx` with actual Figma component URLs | ||
- Update the design URL in `index.stories.tsx` | ||
|
||
3. **Run Code Connect Development Server** | ||
|
||
```bash | ||
yarn figma:connect:dev | ||
``` | ||
|
||
4. **Publish to Figma** (when ready) | ||
```bash | ||
yarn figma:connect | ||
``` | ||
|
||
### For Designers | ||
|
||
1. **Open Figma Dev Mode** | ||
|
||
- Select the Button component in your Figma file | ||
- Switch to Dev Mode | ||
- You should see the React code examples linked to your component | ||
|
||
2. **View Component Code** | ||
- The actual React implementation will be displayed | ||
- Property mappings will show how design tokens translate to code props | ||
- Live examples demonstrate component usage | ||
|
||
## File Structure | ||
|
||
``` | ||
packages/react-components/react-button/stories/src/Button/ | ||
├── Button.figma.tsx # Code Connect configuration | ||
├── index.stories.tsx # Updated with Figma metadata | ||
├── ButtonDefault.stories.tsx # Updated with Figma metadata | ||
└── ...other story files | ||
|
||
figma.config.json # Project-wide configuration | ||
``` | ||
|
||
## Benefits | ||
|
||
1. **Design-Code Consistency** - Ensures design components match code implementation | ||
2. **Developer Handoff** - Developers can see exact code while inspecting designs | ||
3. **Documentation** - Living documentation that stays up-to-date with code changes | ||
4. **Efficiency** - Reduces back-and-forth between designers and developers | ||
|
||
## Next Steps | ||
|
||
1. **Connect Real Figma Components** | ||
|
||
- Get the actual Figma file URLs for Button components | ||
- Update the placeholder URLs in the configuration files | ||
|
||
2. **Expand to Other Components** | ||
|
||
- Follow the same pattern for other Fluent UI components | ||
- Create `.figma.tsx` files for each component that needs Code Connect | ||
|
||
3. **Set Up CI/CD Integration** | ||
- Automate publishing of Code Connect mappings | ||
- Integrate with your build process | ||
|
||
## Troubleshooting | ||
|
||
### Common Issues | ||
|
||
1. **TypeScript Errors** | ||
|
||
- Ensure React is imported as `import * as React from 'react'` | ||
- Check that all prop mappings match actual component props | ||
|
||
2. **Access Token Issues** | ||
|
||
- Verify token has correct scopes | ||
- Check token hasn't expired | ||
|
||
3. **Missing Components in Figma** | ||
- Ensure Figma URLs point to correct components | ||
- Verify component is published in Figma | ||
|
||
### Resources | ||
|
||
- [Figma Code Connect Documentation](https://www.figma.com/developers/code-connect) | ||
- [Code Connect GitHub Repository](https://github.com/figma/code-connect) | ||
- [Fluent UI Button Documentation](https://react.fluentui.dev/?path=/docs/components-button-button--docs) | ||
|
||
## Contributing | ||
|
||
When adding new components or updating existing ones: | ||
|
||
1. Create a corresponding `.figma.tsx` file | ||
2. Update the component's stories with Figma metadata | ||
3. Test the integration locally with `yarn figma:connect:dev` | ||
4. Document any new property mappings |
74 changes: 74 additions & 0 deletions
74
packages/react-components/react-button/stories/src/Button/Button.figma.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as React from 'react'; | ||
import { Button } from '@fluentui/react-components'; | ||
import { figma } from '@figma/code-connect'; | ||
|
||
/** | ||
* Figma Code Connect configuration for Button component | ||
* This connects the Figma Button component to the React implementation | ||
*/ | ||
figma.connect( | ||
Button, | ||
'https://www.figma.com/design/Z9KRuq4Dca3xEuC0BAt0YY/Design-Systems-Connect--Demo-?node-id=10-1271&m=dev', // Replace with actual Figma file URL | ||
{ | ||
props: { | ||
// Map Figma properties to React props | ||
children: figma.textContent('Button Text'), | ||
appearance: figma.enum('Appearance', { | ||
Secondary: 'secondary', // Default | ||
Primary: 'primary', | ||
Outline: 'outline', | ||
Subtle: 'subtle', | ||
Transparent: 'transparent', | ||
}), | ||
size: figma.enum('Size', { | ||
Small: 'small', | ||
Medium: 'medium', // Default | ||
Large: 'large', | ||
}), | ||
shape: figma.enum('Shape', { | ||
Rounded: 'rounded', // Default | ||
Circular: 'circular', | ||
Square: 'square', | ||
}), | ||
disabled: figma.boolean('Disabled'), | ||
disabledFocusable: figma.boolean('Disabled Focusable'), | ||
// Icon mapping - assuming there's an icon variant | ||
icon: figma.instance('Icon'), | ||
iconPosition: figma.enum('Icon Position', { | ||
Before: 'before', // Default | ||
After: 'after', | ||
}), | ||
}, | ||
example: ({ | ||
children, | ||
appearance, | ||
size, | ||
shape, | ||
disabled, | ||
disabledFocusable, | ||
icon, | ||
iconPosition, | ||
}: { | ||
children: any; | ||
appearance: any; | ||
size: any; | ||
shape: any; | ||
disabled: any; | ||
disabledFocusable: any; | ||
icon: any; | ||
iconPosition: any; | ||
}) => ( | ||
<Button | ||
appearance={appearance} | ||
size={size} | ||
shape={shape} | ||
disabled={disabled} | ||
disabledFocusable={disabledFocusable} | ||
icon={icon} | ||
iconPosition={iconPosition} | ||
> | ||
{children} | ||
</Button> | ||
), | ||
}, | ||
); |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/Drawer 1 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/Skeleton converged 1 screenshots
vr-tests-react-components/TagPicker 2 screenshots
vr-tests-web-components/Avatar 1 screenshots
vr-tests-web-components/Badge 1 screenshots
vr-tests-web-components/MenuList 1 screenshots
vr-tests/Callout 11 screenshots
vr-tests/Coachmark 1 screenshots
vr-tests/Keytip 1 screenshots
vr-tests/react-charting-LineChart 2 screenshots
vr-tests/react-charting-MultiStackBarChart 4 screenshots
vr-tests/react-charting-VerticalBarChart 1 screenshots
There were 4 duplicate changes discarded. Check the build logs for more information.