Skip to content

Commit 63ce121

Browse files
committed
make playground story editable with controls
1 parent b46bc0d commit 63ce121

File tree

2 files changed

+68
-71
lines changed

2 files changed

+68
-71
lines changed
Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,15 @@
1-
// import type {Meta} from '@storybook/react-vite'
2-
31
import {Avatar} from '@primer/react'
4-
5-
export default () => <Avatar alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
6-
7-
// const DEFAULT_AVATAR_SIZE = 20
8-
9-
// export default {
10-
// title: 'Components/Avatar',
11-
// component: Avatar,
12-
// }
13-
14-
// type Args = {
15-
// size?: number
16-
// sizeAtNarrow?: number
17-
// sizeAtRegular?: number
18-
// sizeAtWide?: number
19-
// } & Omit<AvatarProps, 'size'>
20-
21-
// export const Playground: StoryFn<Args> = args => {
22-
// return (
23-
// <Avatar
24-
// size={DEFAULT_AVATAR_SIZE}
25-
// square={args.square}
26-
// src="https://avatars.githubusercontent.com/u/7143434?v=4"
27-
// alt="mona"
28-
// />
29-
// )
30-
// }
31-
32-
// Playground.args = {
33-
// size: DEFAULT_AVATAR_SIZE,
34-
// }
35-
36-
// Playground.argTypes = {
37-
// size: {
38-
// control: {
39-
// type: 'number',
40-
// },
41-
// },
42-
// sizeAtNarrow: {
43-
// name: 'size.narrow',
44-
// control: {
45-
// type: 'number',
46-
// },
47-
// },
48-
// sizeAtRegular: {
49-
// name: 'size.regular',
50-
// control: {
51-
// type: 'number',
52-
// },
53-
// },
54-
// sizeAtWide: {
55-
// name: 'size.wide',
56-
// control: {
57-
// type: 'number',
58-
// },
59-
// },
60-
// alt: {
61-
// controls: false,
62-
// table: {
63-
// disable: true,
64-
// },
65-
// },
66-
// }
2+
import {parseSizeFromArgs} from 'storyHelpers'
3+
4+
const Playground = args => {
5+
return (
6+
<Avatar
7+
size={parseSizeFromArgs(args)}
8+
square={args.square}
9+
src="https://avatars.githubusercontent.com/u/7143434?v=4"
10+
alt="mona"
11+
/>
12+
)
13+
}
14+
15+
export default Playground
Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,70 @@
11
import * as PrimerReactLibrary from '../index'
2+
import * as storyHelpers from './storyHelpers'
23
import {makeLiveEditStory} from 'storybook-addon-code-editor'
34
import type {Meta, StoryObj} from '@storybook/react'
45
import storyCode from './Avatar.source.tsx?raw'
6+
import {Avatar} from '../index'
57

6-
const meta = {
8+
const meta: Meta<typeof PrimerReactLibrary.Avatar> = {
79
// Story defaults
810
title: 'Components/Avatar',
9-
} satisfies Meta<typeof PrimerReactLibrary.Avatar>
11+
component: PrimerReactLibrary.Avatar,
12+
} as Meta<typeof PrimerReactLibrary.Avatar>
13+
14+
export const Default = () => <Avatar alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
1015

1116
export default meta
1217

13-
type Story = StoryObj<typeof meta>
18+
const DEFAULT_AVATAR_SIZE = 20
19+
20+
type Args = {
21+
size?: number
22+
sizeAtNarrow?: number
23+
sizeAtRegular?: number
24+
sizeAtWide?: number
25+
} & Omit<PrimerReactLibrary.AvatarProps, 'size'>
26+
27+
type Story = StoryObj<Args>
1428

15-
export const Default: Story = {
29+
export const Playground: Story = {
1630
// Story config
31+
args: {
32+
size: DEFAULT_AVATAR_SIZE,
33+
},
34+
argTypes: {
35+
size: {
36+
control: {
37+
type: 'number',
38+
},
39+
},
40+
sizeAtNarrow: {
41+
name: 'size.narrow',
42+
control: {
43+
type: 'number',
44+
},
45+
},
46+
sizeAtRegular: {
47+
name: 'size.regular',
48+
control: {
49+
type: 'number',
50+
},
51+
},
52+
sizeAtWide: {
53+
name: 'size.wide',
54+
control: {
55+
type: 'number',
56+
},
57+
},
58+
alt: {
59+
controls: false,
60+
table: {
61+
disable: true,
62+
},
63+
},
64+
},
1765
}
1866

19-
makeLiveEditStory(Default, {
20-
availableImports: {'@primer/react': PrimerReactLibrary},
67+
makeLiveEditStory(Playground, {
68+
availableImports: {'@primer/react': PrimerReactLibrary, storyHelpers},
2169
code: storyCode,
2270
})

0 commit comments

Comments
 (0)