1
1
import { Story , Canvas , Meta } from ' @storybook/addon-docs/blocks' ;
2
+ // The '!!raw-loader!' syntax is a non-standard, Webpack-specific, syntax.
3
+ // See: https://github.com/webpack-contrib/raw-loader#examples
4
+ // For now, it seems likely Storybook is pretty tied to Webpack, therefore, we are
5
+ // okay with the following Webpack-specific raw loader syntax. It's better to leave
6
+ // the ESLint rule enabled globally, and only thoughtfully disable as needed (e.g.
7
+ // within a Storybook docs page and not within an actual component).
8
+ // This can be revisited in the future if Storybook no longer relies on Webpack.
9
+ // eslint-disable-next-line @cloudfour/import /no-webpack-loader-syntax
10
+ import stylesDemoSource from ' !!raw-loader!./demo/styles.twig' ;
2
11
import stylesDemo from ' ./demo/styles.twig' ;
12
+ // eslint-disable-next-line @cloudfour/import /no-webpack-loader-syntax
13
+ import iconButtonCustomDemoSource from ' !!raw-loader!./demo/icon-button-custom-demo.twig' ;
3
14
import iconButtonCustomDemo from ' ./demo/icon-button-custom-demo.twig' ;
4
15
import button from ' ./button.twig' ;
5
16
const iconControlConfig = {
@@ -17,6 +28,22 @@ const iconControlConfig = {
17
28
},
18
29
defaultValue : ' ' ,
19
30
} ;
31
+ const buttonStory = (args) => {
32
+ // Don't bother with the inline options if they don't exist or are defaults
33
+ if (args .content_start_icon === ' ' ) {
34
+ delete args.content_start_icon;
35
+ }
36
+ if (args .content_end_icon === ' ' ) {
37
+ delete args.content_end_icon;
38
+ }
39
+ if (args .disabled === false ) {
40
+ delete args.disabled;
41
+ }
42
+ if (args .type === ' button' ) {
43
+ delete args.type;
44
+ }
45
+ return button (args );
46
+ } ;
20
47
21
48
<Meta
22
49
title = " Components/Button"
@@ -43,10 +70,10 @@ The `c-button` class may be applied to button and link elements. The button appe
43
70
44
71
<Canvas >
45
72
<Story name = " Button Element" args = { { label: ' Button' , href: false }} >
46
- { (args ) => button (args )}
73
+ { (args ) => buttonStory (args )}
47
74
</Story >
48
75
<Story name = " Link Element" args = { { label: ' Link' , tagName: ' a' }} >
49
- { (args ) => button (args )}
76
+ { (args ) => buttonStory (args )}
50
77
</Story >
51
78
</Canvas >
52
79
@@ -55,13 +82,24 @@ The `c-button` class may be applied to button and link elements. The button appe
55
82
Some buttons may not require as much emphasis as others. The ` c-button--secondary ` and ` c-button--tertiary ` modifiers reflect lesser importance with reduced contrast.
56
83
57
84
<Canvas >
58
- <Story name = " Styles" >{ (args ) => stylesDemo (args )} </Story >
85
+ <Story
86
+ name = " Styles"
87
+ parameters = { { docs: { source: { code: stylesDemoSource } } }}
88
+ >
89
+ { (args ) => stylesDemo (args )}
90
+ </Story >
59
91
</Canvas >
60
92
61
93
All the above visual styles will appear slightly different within [ our dark theme] ( /docs/design-themes--dark ) . These versions retain their visual emphasis relative to one another while remaining visually distinct from form inputs.
62
94
63
95
<Canvas >
64
- <Story name = " Styles (Dark)" parameters = { { theme: ' t-dark' }} >
96
+ <Story
97
+ name = " Styles (Dark)"
98
+ parameters = { {
99
+ theme: ' t-dark' ,
100
+ docs: { source: { code: stylesDemoSource } },
101
+ }}
102
+ >
65
103
{ (args ) => stylesDemo (args )}
66
104
</Story >
67
105
</Canvas >
@@ -71,13 +109,6 @@ All the above visual styles will appear slightly different within [our dark them
71
109
To add an icon, pass the name of any of the [ available icons] ( /docs/design-icons--page )
72
110
to the ` content_start_icon ` or ` content_end_icon ` properties.
73
111
74
- ``` twig
75
- {% embed '@cloudfour/components/button/button.twig' with {
76
- label: 'Get notifications'
77
- content_start_icon: 'bell'
78
- } only %}
79
- ```
80
-
81
112
<Canvas >
82
113
<Story
83
114
name = " Icon"
@@ -86,7 +117,7 @@ to the `content_start_icon` or `content_end_icon` properties.
86
117
label: ' Get notifications' ,
87
118
}}
88
119
>
89
- { (args ) => button (args )}
120
+ { (args ) => buttonStory (args )}
90
121
</Story >
91
122
</Canvas >
92
123
@@ -100,19 +131,15 @@ CSS classes on the `<svg>` element.
100
131
The ` content_start ` /` content_end ` blocks override the
101
132
` content_start_icon ` /` content_end_icon ` values.
102
133
103
- ``` twig
104
- {% embed '@cloudfour/components/button/button.twig' %}
105
- {% block content %}Button with a custom icon{% endblock %}
106
- {% block content_end %}
107
- <svg viewBox="0 0 24 24" width="24" height="24" class="c-icon c-icon--inline">
108
- <circle r="8" cx="12" cy="12"></circle>
109
- </svg>
110
- {% endblock %}
111
- {% endembed %}
112
- ```
113
-
114
134
<Canvas >
115
- <Story name = " Custom Icon" >{ (args ) => iconButtonCustomDemo (args )} </Story >
135
+ <Story
136
+ name = " Custom Icon"
137
+ parameters = { {
138
+ docs: { source: { code: iconButtonCustomDemoSource } },
139
+ }}
140
+ >
141
+ { (args ) => iconButtonCustomDemo (args )}
142
+ </Story >
116
143
</Canvas >
117
144
118
145
## Toggling button
@@ -128,7 +155,7 @@ You can override the `content_start_icon` value to a different icon.
128
155
aria_pressed: ' true' ,
129
156
}}
130
157
>
131
- { (args ) => button (args )}
158
+ { (args ) => buttonStory (args )}
132
159
</Story >
133
160
<Story
134
161
name = " Secondary Toggling Button"
@@ -137,7 +164,7 @@ You can override the `content_start_icon` value to a different icon.
137
164
aria_pressed: ' true' ,
138
165
}}
139
166
>
140
- { (args ) => button (args )}
167
+ { (args ) => buttonStory (args )}
141
168
</Story >
142
169
<Story
143
170
name = " Tertiary Toggling Button"
@@ -146,7 +173,7 @@ You can override the `content_start_icon` value to a different icon.
146
173
aria_pressed: ' true' ,
147
174
}}
148
175
>
149
- { (args ) => button (args )}
176
+ { (args ) => buttonStory (args )}
150
177
</Story >
151
178
<Story name = " Custom Icon Toggling Button" args = { { aria_pressed: ' true' }} >
152
179
{ (args ) => iconButtonCustomDemo (args )}
0 commit comments