-
Notifications
You must be signed in to change notification settings - Fork 23
docs: add Figma design links and real Badges to Storybook toolbar #1076
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1aa0595
feat: add Figma design-link toolbar tool
frankieyan 3f4653f
chore: add Figma parameter to plop story template
frankieyan 11910f9
docs: link Figma designs from component stories
frankieyan 9f4372a
refactor(storybook): render a11y badges with Reactist Badge
frankieyan 2f4cbcd
refactor(storybook): rename figma label to path
frankieyan 69595fc
refactor(storybook): drop the figma link string shorthand
frankieyan 517cf27
build(storybook): type-check the figma and badges tools
frankieyan a74d315
refactor(storybook): guard badge tones against type drift
frankieyan bec3922
feat(storybook): support figma:false to hide the figma tool
frankieyan 2a63b20
docs: opt non-design pages out of the figma tool
frankieyan a3dd4b2
build(storybook): add manager-api path for react18 type-check
frankieyan 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
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import { useParameter } from 'storybook/manager-api' | ||
|
|
||
| import { Badge } from '../../src/badge/badge' | ||
| import { Inline } from '../../src/inline' | ||
|
|
||
| import { resolveBadges } from './badges' | ||
| import { BADGES_CONFIG_PARAMETER, BADGES_PARAMETER } from './constants' | ||
|
|
||
| const emptyBadges: unknown[] = [] | ||
| const emptyBadgesConfig: Record<string, unknown> = {} | ||
|
|
||
| export const BadgesTool = React.memo(function BadgesTool() { | ||
| const badgesParameter = useParameter(BADGES_PARAMETER, emptyBadges) | ||
| const badgesConfigParameter = useParameter(BADGES_CONFIG_PARAMETER, emptyBadgesConfig) | ||
|
|
||
| const badges = React.useMemo( | ||
| () => resolveBadges(badgesParameter, badgesConfigParameter), | ||
| [badgesParameter, badgesConfigParameter], | ||
| ) | ||
|
|
||
| if (badges.length === 0) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <Inline space="xsmall"> | ||
| {badges.map(({ id, title, tone }) => ( | ||
| <Badge key={id} tone={tone} label={title} /> | ||
| ))} | ||
| </Inline> | ||
| ) | ||
| }) |
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
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| export { BadgesTool } from './BadgesTool' | ||
| export { BadgesTool } from './badges-tool' | ||
| export { ADDON_ID, TOOL_ID } from './constants' |
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,3 @@ | ||
| export const ADDON_ID = 'reactist/figma' | ||
| export const TOOL_ID = `${ADDON_ID}/tool` | ||
| export const FIGMA_PARAMETER = '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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import * as React from 'react' | ||
|
|
||
| // https://www.figma.com/using-the-figma-brand/ | ||
| export function FigmaIcon() { | ||
| return ( | ||
| <svg width="11" height="16" viewBox="0 0 38 57" fill="none" aria-hidden="true"> | ||
| <path d="M19 28.5a9.5 9.5 0 1 1 19 0 9.5 9.5 0 0 1-19 0Z" fill="#1ABCFE" /> | ||
| <path d="M0 47.5A9.5 9.5 0 0 1 9.5 38H19v9.5a9.5 9.5 0 1 1-19 0Z" fill="#0ACF83" /> | ||
| <path d="M19 0v19h9.5a9.5 9.5 0 1 0 0-19H19Z" fill="#FF7262" /> | ||
| <path d="M0 9.5A9.5 9.5 0 0 0 9.5 19H19V0H9.5A9.5 9.5 0 0 0 0 9.5Z" fill="#F24E1E" /> | ||
| <path d="M0 28.5A9.5 9.5 0 0 0 9.5 38H19V19H9.5A9.5 9.5 0 0 0 0 28.5Z" fill="#A259FF" /> | ||
| </svg> | ||
| ) | ||
| } |
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,39 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import { useParameter } from 'storybook/manager-api' | ||
|
|
||
| import { Badge } from '../../src/badge/badge' | ||
| import { IconButton } from '../../src/button/button' | ||
| import { Inline } from '../../src/inline' | ||
|
|
||
| import { FIGMA_PARAMETER } from './constants' | ||
| import { resolveFigmaLinks } from './figma' | ||
| import { FigmaIcon } from './figma-icon' | ||
|
|
||
| export const FigmaTool = React.memo(function FigmaTool() { | ||
| const figmaParameter = useParameter(FIGMA_PARAMETER, undefined) | ||
| const links = React.useMemo(() => resolveFigmaLinks(figmaParameter), [figmaParameter]) | ||
|
|
||
| if (figmaParameter === false) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <Inline space="xsmall"> | ||
| {links.length === 0 ? ( | ||
| <Badge tone="info" label="No Figma link" /> | ||
| ) : ( | ||
| links.map((link) => ( | ||
| <IconButton | ||
| key={link.url} | ||
| variant="quaternary" | ||
| icon={<FigmaIcon />} | ||
| aria-label={`View in Figma: ${link.path}`} | ||
| tooltip={link.path} | ||
| render={<a href={link.url} target="_blank" rel="noopener noreferrer" />} | ||
| /> | ||
| )) | ||
| )} | ||
| </Inline> | ||
| ) | ||
| }) | ||
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,47 @@ | ||
| import { resolveFigmaLinks } from './figma' | ||
|
|
||
| describe('resolveFigmaLinks', () => { | ||
| it('resolves an object with path and url', () => { | ||
| expect( | ||
| resolveFigmaLinks({ | ||
| path: 'Web › Buttons › Button', | ||
| url: 'https://figma.com/design/abc?node-id=1-2', | ||
| }), | ||
| ).toEqual([ | ||
| { | ||
| path: 'Web › Buttons › Button', | ||
| url: 'https://figma.com/design/abc?node-id=1-2', | ||
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('falls back to the url as path when path is missing', () => { | ||
| expect(resolveFigmaLinks({ url: 'https://figma.com/design/abc' })).toEqual([ | ||
| { path: 'https://figma.com/design/abc', url: 'https://figma.com/design/abc' }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('resolves an array, dropping malformed entries', () => { | ||
| expect( | ||
| resolveFigmaLinks([ | ||
| { path: 'B', url: 'https://figma.com/b' }, | ||
| { path: 'C' }, | ||
| { url: 42 }, | ||
| '', | ||
| null, | ||
| ]), | ||
| ).toEqual([{ path: 'B', url: 'https://figma.com/b' }]) | ||
| }) | ||
|
|
||
| it('treats malformed and empty params as no links', () => { | ||
| expect(resolveFigmaLinks(undefined)).toEqual([]) | ||
| expect(resolveFigmaLinks(null)).toEqual([]) | ||
| expect(resolveFigmaLinks(false)).toEqual([]) | ||
| expect(resolveFigmaLinks('https://figma.com/x')).toEqual([]) | ||
| expect(resolveFigmaLinks('')).toEqual([]) | ||
| expect(resolveFigmaLinks({})).toEqual([]) | ||
| expect(resolveFigmaLinks({ path: 'no url' })).toEqual([]) | ||
| expect(resolveFigmaLinks({ url: 42 })).toEqual([]) | ||
| expect(resolveFigmaLinks([])).toEqual([]) | ||
| }) | ||
| }) |
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,29 @@ | ||
| type ResolvedFigmaLink = { | ||
| path: string | ||
| url: string | ||
| } | ||
|
|
||
| function isRecord(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === 'object' && value !== null && !Array.isArray(value) | ||
| } | ||
|
|
||
| function resolveEntry(entry: unknown): ResolvedFigmaLink[] { | ||
| if (isRecord(entry) && typeof entry.url === 'string' && entry.url.length > 0) { | ||
| const path = | ||
| typeof entry.path === 'string' && entry.path.length > 0 ? entry.path : entry.url | ||
| return [{ path, url: entry.url }] | ||
| } | ||
|
|
||
| return [] | ||
| } | ||
|
|
||
| function resolveFigmaLinks(param: unknown): ResolvedFigmaLink[] { | ||
| if (Array.isArray(param)) { | ||
| return param.flatMap(resolveEntry) | ||
| } | ||
|
|
||
| return resolveEntry(param) | ||
| } | ||
|
|
||
| export { resolveFigmaLinks } | ||
| export type { ResolvedFigmaLink } |
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,2 @@ | ||
| export { FigmaTool } from './figma-tool' | ||
| export { ADDON_ID, TOOL_ID } from './constants' |
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.
Uh oh!
There was an error while loading. Please reload this page.