1
1
import { html } from "lit" ;
2
2
import { ifDefined } from "lit/directives/if-defined.js" ;
3
3
import { styleMap } from "lit/directives/style-map.js" ;
4
+ import { when } from "lit/directives/when.js" ;
4
5
6
+ import { default as IconStories } from "@spectrum-css/icon/stories/icon.stories.js" ;
5
7
import { Template as Typography } from "@spectrum-css/typography/stories/template.js" ;
6
8
import { Template } from "./template" ;
7
9
8
- import { default as IconStories } from "@spectrum-css/icon/stories/icon.stories.js" ;
9
-
10
10
export default {
11
11
title : "Components/Button" ,
12
12
description :
@@ -131,6 +131,18 @@ export default {
131
131
} ,
132
132
} ;
133
133
134
+ /**
135
+ * Optional wrapper for each button used within other templates, to assist with the "stacked"
136
+ * layout and the testing of wrapping text.
137
+ */
138
+ const ButtonWrap = ( layout , content ) => {
139
+ const buttonWrapStyles = {
140
+ 'margin-block' : '15px' ,
141
+ 'max-width' : '480px' ,
142
+ } ;
143
+ return layout === "stacked" ? html `< div style =${ styleMap ( buttonWrapStyles ) } > ${ content } </ div > ` : content ;
144
+ } ;
145
+
134
146
/**
135
147
* Multiple button variations displayed in one story template.
136
148
* Used as the base template for the stories.
@@ -143,15 +155,6 @@ const CustomButton = ({
143
155
customStyles = { } ,
144
156
...args
145
157
} ) => {
146
- // Optional wrapper for each button, to assist with the testing of wrapping text.
147
- const ButtonWrap = ( content ) => {
148
- const buttonWrapStyles = {
149
- 'margin-block' : '15px' ,
150
- 'max-width' : '480px' ,
151
- } ;
152
- return layout === "stacked" ? html `< div style =${ styleMap ( buttonWrapStyles ) } > ${ content } </ div > ` : content ;
153
- } ;
154
-
155
158
return html `
156
159
< div
157
160
style =${ ifDefined ( styleMap ( {
@@ -160,28 +163,30 @@ const CustomButton = ({
160
163
...customStyles
161
164
} ) ) }
162
165
>
163
- ${ ButtonWrap ( Template ( {
166
+ ${ ButtonWrap ( layout , Template ( {
164
167
...args ,
165
168
staticColor,
166
169
iconName : undefined ,
167
170
} ) ) }
168
- ${ ButtonWrap ( Template ( {
171
+ ${ ButtonWrap ( layout , Template ( {
169
172
...args ,
170
173
staticColor,
171
174
iconName : undefined ,
172
175
treatment : "outline" ,
173
176
} ) ) }
174
- ${ ButtonWrap ( Template ( {
177
+ ${ ButtonWrap ( layout , Template ( {
175
178
...args ,
176
179
staticColor,
177
180
iconName : iconName ?? "Edit" ,
178
181
} ) ) }
179
- ${ showIconOnlyButton ? ButtonWrap ( Template ( {
180
- ...args ,
181
- staticColor,
182
- hideLabel : true ,
183
- iconName : iconName ?? "Edit" ,
184
- } ) ) : '' }
182
+ ${ when ( showIconOnlyButton , ( ) =>
183
+ ButtonWrap ( layout , Template ( {
184
+ ...args ,
185
+ staticColor,
186
+ hideLabel : true ,
187
+ iconName : iconName ?? "Edit" ,
188
+ } ) )
189
+ ) }
185
190
</ div >
186
191
` ;
187
192
} ;
@@ -255,6 +260,37 @@ const ButtonsWithForcedColors = ({
255
260
</ div >
256
261
` ;
257
262
263
+ /**
264
+ * Wrapping story template, displaying some additional variants for Chromatic.
265
+ */
266
+ const WrappingTemplate = ( { layout, ...args } ) => {
267
+ if ( window . isChromatic ( ) ) {
268
+ return html `
269
+ ${ CustomButton ( { layout, ...args } ) }
270
+ < div style =${ ifDefined ( styleMap ( { padding : "1rem" } ) ) } >
271
+ ${ ButtonWrap ( layout , Template ( {
272
+ ...args ,
273
+ iconName : "Edit" ,
274
+ treatment : "outline" ,
275
+ } ) ) }
276
+ ${ ButtonWrap ( layout , Template ( {
277
+ ...args ,
278
+ // Uses a UI icon that is smaller than workflow sizing, to test alignment:
279
+ iconName : "Cross100" ,
280
+ } ) ) }
281
+ ${ ButtonWrap ( layout , Template ( {
282
+ ...args ,
283
+ // UI icon that is larger than workflow sizing:
284
+ iconName : "ArrowDown600" ,
285
+ treatment : "outline" ,
286
+ } ) ) }
287
+ </ div >
288
+ ` ;
289
+ }
290
+ // Otherwise use the default template.
291
+ return CustomButton ( { layout, ...args } ) ;
292
+ } ;
293
+
258
294
export const Accent = CustomButton . bind ( { } ) ;
259
295
Accent . args = {
260
296
variant : "accent" ,
@@ -306,7 +342,8 @@ WithForcedColors.args = {
306
342
iconName : "Actions" ,
307
343
} ;
308
344
309
- export const Wrapping = CustomButton . bind ( { } ) ;
345
+ export const Wrapping = WrappingTemplate . bind ( { } ) ;
346
+ Wrapping . storyName = "Wrapping" ;
310
347
Wrapping . args = {
311
348
layout : "stacked" ,
312
349
showIconOnlyButton : false ,
0 commit comments