Skip to content

Commit f7c44c3

Browse files
langermankjonrohan
andauthored
Storybook: add Label stories (#1708)
* add label stories * playgrounds * add features * Create dirty-pillows-drop.md Co-authored-by: Jon Rohan <yes@jonrohan.codes>
1 parent bc50203 commit f7c44c3

File tree

10 files changed

+515
-0
lines changed

10 files changed

+515
-0
lines changed

.changeset/dirty-pillows-drop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": patch
3+
---
4+
5+
Storybook: add Label stories
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"story-template": {
3+
"prefix": "story-template",
4+
"body": [
5+
"import React from 'react'",
6+
"import clsx from 'clsx'",
7+
"// import { StoryTemplateName } from './OtherStoryFile.stories' // import stories for component compositions",
8+
"",
9+
"export default {",
10+
" title: 'Components/ComponentName',",
11+
" excludeStories: ['ComponentTemplateName'],",
12+
" argTypes: {",
13+
" booleanExample: {",
14+
" control: { type: 'boolean' },",
15+
" description: 'true/false toggle to controls',",
16+
" table: {",
17+
" category: 'Pick one: CSS, HTML, Interactive'",
18+
" }",
19+
" },",
20+
" selectExample: {",
21+
" options: [0, 1, 2, 3], // iterator",
22+
" mapping: ['string1', 'string2', 'string3', 'string4'], // values",
23+
" control: {",
24+
" type: 'select',",
25+
" labels: ['string1-label', 'string2-label', 'string3-label', 'string4-label'] // public labels",
26+
" },",
27+
" description: 'select menu mapping to strings (example: use for variant class names)',",
28+
" table: {",
29+
" category: 'Pick one: CSS, HTML, Interactive'",
30+
" }",
31+
" },",
32+
" stringExample: {",
33+
" name: 'stringExample',",
34+
" type: 'string',",
35+
" description: 'text box control',",
36+
" table: {",
37+
" category: 'Pick one: CSS, HTML, Interactive'",
38+
" }",
39+
" },",
40+
" children: {",
41+
" description: 'creates a slot for children',",
42+
" table: {",
43+
" category: 'HTML'",
44+
" }",
45+
" },",
46+
" }",
47+
"}",
48+
"",
49+
"// build every component case here in the template (private api)",
50+
"export const ComponentTemplateName = ({ booleanExample, selectExample, stringExample, children }) => (",
51+
" <div",
52+
" // use clsx for multiple classnames",
53+
" className={clsx('defaultClass', selectExample && `${selectExample}`, booleanExample && 'defaultClass--modifier')}",
54+
" // use undefined for values that shouldn't be set if false",
55+
" aria-hidden={booleanExample ? 'true' : undefined}",
56+
" >",
57+
" {/* use {children} for wrapper component templates */}",
58+
" <>",
59+
" {stringExample}",
60+
" {children}",
61+
" </>",
62+
" </div>",
63+
")",
64+
"",
65+
"// create a \"playground\" demo page that may set some defaults and allow story to access component controls",
66+
"export const Playground = ComponentTemplateName.bind({})",
67+
"Playground.args = {",
68+
" stringExample: 'Default text',",
69+
" booleanExample: false,",
70+
" children: (",
71+
" <>",
72+
" <StoryTemplateName someProp=\"Use props from other stories\" />",
73+
" </>",
74+
" )",
75+
"}",
76+
""
77+
],
78+
"description": "Basic component story jsx template"
79+
}
80+
}
File renamed without changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React from 'react'
2+
import clsx from 'clsx'
3+
4+
export default {
5+
title: 'Components/Label/IssueLabel',
6+
excludeStories: ['IssueLabelTemplate'],
7+
argTypes: {
8+
variant: {
9+
options: [0, 1, 2, 3], // iterator
10+
mapping: [
11+
'color-bg-accent-emphasis',
12+
'color-bg-danger-emphasis',
13+
'color-bg-success-emphasis',
14+
'color-bg-attention-emphasis'
15+
], // values
16+
control: {
17+
type: 'select',
18+
labels: ['accent', 'danger', 'success', 'attention'] // public labels
19+
},
20+
description: 'Colors',
21+
table: {
22+
category: 'CSS'
23+
}
24+
},
25+
size: {
26+
options: [0, 1], // iterator
27+
mapping: ['', 'IssueLabel--big'], // values
28+
control: {
29+
type: 'select',
30+
labels: ['default', 'big'] // public labels
31+
},
32+
description: 'Size',
33+
table: {
34+
category: 'CSS'
35+
}
36+
},
37+
text: {
38+
name: 'stringExample',
39+
type: 'string',
40+
description: 'Label text',
41+
table: {
42+
category: 'HTML'
43+
}
44+
}
45+
}
46+
}
47+
48+
// build every component case here in the template (private api)
49+
export const IssueLabelTemplate = ({variant, size, text}) => (
50+
<span className={clsx('IssueLabel', 'color-fg-on-emphasis', variant && `${variant}`, size && `${size}`)}>{text}</span>
51+
)
52+
53+
// create a "playground" demo page that may set some defaults and allow story to access component controls
54+
export const Playground = IssueLabelTemplate.bind({})
55+
Playground.args = {
56+
text: 'bug 🐛',
57+
variant: 'color-bg-accent-emphasis'
58+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react'
2+
import clsx from 'clsx'
3+
4+
export default {
5+
title: 'Components/Label/Label',
6+
excludeStories: ['LabelTemplate'],
7+
argTypes: {
8+
inline: {
9+
control: {type: 'boolean'},
10+
description: 'Display label inline',
11+
table: {
12+
category: 'CSS'
13+
}
14+
},
15+
variant: {
16+
options: [0, 1, 2, 3, 4, 5], // iterator
17+
mapping: [
18+
'',
19+
'Label--primary',
20+
'Label--secondary',
21+
'Label--info',
22+
'Label--success',
23+
'Label--warning',
24+
'Label--danger'
25+
], // values
26+
control: {
27+
type: 'select',
28+
labels: ['default', 'primary', 'secondary', 'info', 'success', 'warning', 'danger']
29+
},
30+
description: 'Colors',
31+
table: {
32+
category: 'HTML'
33+
}
34+
},
35+
size: {
36+
options: [0, 1], // iterator
37+
mapping: ['', 'Label--large'], // values
38+
control: {
39+
type: 'select',
40+
labels: ['default', 'large'] // public labels
41+
},
42+
description: 'Colors',
43+
table: {
44+
category: 'CSS'
45+
}
46+
},
47+
text: {
48+
name: 'text',
49+
type: 'string',
50+
description: 'Label text',
51+
table: {
52+
category: 'HTML'
53+
}
54+
}
55+
}
56+
}
57+
58+
export const LabelTemplate = ({inline, variant, size, text}) => (
59+
<span className={clsx('Label', variant && `${variant}`, size && `${size}`, inline && 'Label--inline')}>{text}</span>
60+
)
61+
62+
export const Playground = LabelTemplate.bind({})
63+
Playground.args = {
64+
text: 'Label text',
65+
inline: false,
66+
variant: 'Label--primary'
67+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React from 'react'
2+
import clsx from 'clsx'
3+
4+
export default {
5+
title: 'Components/Label/Counter',
6+
excludeStories: ['LabelCounterTemplate'],
7+
argTypes: {
8+
variant: {
9+
options: [0, 1, 2], // iterator
10+
mapping: ['', 'Counter--primary', 'Counter--secondary'], // values
11+
control: {
12+
type: 'select',
13+
labels: ['default', 'primary', 'secondary'] // public labels
14+
},
15+
table: {
16+
category: 'CSS'
17+
}
18+
},
19+
text: {
20+
name: 'text',
21+
type: 'string',
22+
description: 'Label text',
23+
table: {
24+
category: 'HTML'
25+
}
26+
},
27+
icon: {
28+
defaultValue: '',
29+
name: 'icon',
30+
type: 'string',
31+
description: 'Paste [Octicon](https://primer.style/octicons/) in control field',
32+
table: {
33+
category: 'HTML'
34+
}
35+
}
36+
}
37+
}
38+
39+
// build every component case here in the template (private api)
40+
export const LabelCounterTemplate = ({variant, text, icon}) => (
41+
<span className={clsx('Counter', variant && `${variant}`)}>
42+
<>
43+
{icon && icon}
44+
{text}
45+
</>
46+
</span>
47+
)
48+
49+
// create a "playground" demo page that may set some defaults and allow story to access component controls
50+
export const Playground = LabelCounterTemplate.bind({})
51+
Playground.args = {
52+
text: '23',
53+
variant: 'Counter--primary'
54+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
3+
export default {
4+
title: 'Components/Label/Diffstat',
5+
excludeStories: ['LabelDiffstatTemplate'],
6+
argTypes: {
7+
diffValueIntent: {
8+
options: [0, 1, 2], // iterator
9+
mapping: ['', 'color-fg-success', 'color-fg-danger'], // values
10+
control: {
11+
type: 'select',
12+
labels: ['default', 'success', 'danger'] // public labels
13+
},
14+
table: {
15+
category: 'CSS'
16+
}
17+
},
18+
diffValue: {
19+
name: 'diffValue',
20+
type: 'string',
21+
description: '7',
22+
table: {
23+
category: 'HTML'
24+
}
25+
}
26+
}
27+
}
28+
29+
// build every component case here in the template (private api)
30+
export const LabelDiffstatTemplate = ({diffValue, diffValueIntent}) => (
31+
<span class="diffstat tooltipped tooltipped-e" aria-label="6 changes: 3 additions &amp; 3 deletions">
32+
{diffValueIntent === 'color-fg-success' && <span class="color-fg-success">+{diffValue}</span>}
33+
{diffValueIntent === 'color-fg-danger' && <span class="color-fg-danger">-{diffValue}</span>}
34+
{diffValueIntent === '' && diffValue} <span class="diffstat-block-added"></span>
35+
<span class="diffstat-block-added"></span>
36+
<span class="diffstat-block-deleted"></span>
37+
<span class="diffstat-block-deleted"></span>
38+
<span class="diffstat-block-neutral"></span>
39+
</span>
40+
)
41+
42+
// create a "playground" demo page that may set some defaults and allow story to access component controls
43+
export const Playground = LabelDiffstatTemplate.bind({})
44+
Playground.args = {
45+
diffValue: '7',
46+
diffValueIntent: ''
47+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react'
2+
import {LabelTemplate} from './Label.stories' // import stories for component compositions
3+
4+
export default {
5+
title: 'Components/Label/Label/Features'
6+
}
7+
8+
export const VariantDefault = LabelTemplate.bind({})
9+
VariantDefault.storyName = '[Variant] Default'
10+
VariantDefault.args = {
11+
text: 'Label text',
12+
inline: false,
13+
variant: 'Label--default'
14+
}
15+
16+
export const VariantPrimary = LabelTemplate.bind({})
17+
VariantPrimary.storyName = '[Variant] Primary'
18+
VariantPrimary.args = {
19+
text: 'Label text',
20+
inline: false,
21+
variant: 'Label--primary'
22+
}
23+
24+
export const VariantInfo = LabelTemplate.bind({})
25+
VariantInfo.storyName = '[Variant] Info'
26+
VariantInfo.args = {
27+
text: 'Label text',
28+
inline: false,
29+
variant: 'Label--info'
30+
}
31+
32+
export const VariantSuccess = LabelTemplate.bind({})
33+
VariantSuccess.storyName = '[Variant] Success'
34+
VariantSuccess.args = {
35+
text: 'Label text',
36+
inline: false,
37+
variant: 'Label--success'
38+
}
39+
40+
export const VariantWarning = LabelTemplate.bind({})
41+
VariantWarning.storyName = '[Variant] Warning'
42+
VariantWarning.args = {
43+
text: 'Label text',
44+
inline: false,
45+
variant: 'Label--warning'
46+
}
47+
48+
export const VariantDanger = LabelTemplate.bind({})
49+
VariantDanger.storyName = '[Variant] Danger'
50+
VariantDanger.args = {
51+
text: 'Label text',
52+
inline: false,
53+
variant: 'Label--danger'
54+
}
55+
56+
export const AllVariants = ({}) => (
57+
<>
58+
<LabelTemplate text="Default" variant="Label--default" />
59+
<LabelTemplate text="Primary" variant="Label--primary" />
60+
<LabelTemplate text="Info" variant="Label--info" />
61+
<LabelTemplate text="Success" variant="Label--success" />
62+
<LabelTemplate text="Warning" variant="Label--warning" />
63+
<LabelTemplate text="Danger" variant="Label--danger" />
64+
</>
65+
)
66+
AllVariants.decorators = [
67+
Story => (
68+
<div style={{display: 'flex', gap: '0.5rem'}}>
69+
<Story />
70+
</div>
71+
)
72+
]

0 commit comments

Comments
 (0)