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
-
5
- import { Template } from "./template" ;
4
+ import { when } from "lit/directives/when.js" ;
6
5
7
6
import { default as IconStories } from "@spectrum-css/icon/stories/icon.stories.js" ;
7
+ import { Template } from "./template" ;
8
8
9
9
export default {
10
10
title : "Components/Button" ,
@@ -119,6 +119,18 @@ export default {
119
119
} ,
120
120
} ;
121
121
122
+ /**
123
+ * Optional wrapper for each button used within other templates, to assist with the "stacked"
124
+ * layout and the testing of wrapping text.
125
+ */
126
+ const ButtonWrap = ( layout , content ) => {
127
+ const buttonWrapStyles = {
128
+ 'margin-block' : '15px' ,
129
+ 'max-width' : '480px' ,
130
+ } ;
131
+ return layout === "stacked" ? html `< div style =${ styleMap ( buttonWrapStyles ) } > ${ content } </ div > ` : content ;
132
+ } ;
133
+
122
134
/**
123
135
* Multiple button variations displayed in one story template.
124
136
* Used as the base template for the stories.
@@ -131,15 +143,6 @@ const CustomButton = ({
131
143
customStyles = { } ,
132
144
...args
133
145
} ) => {
134
- // Optional wrapper for each button, to assist with the testing of wrapping text.
135
- const ButtonWrap = ( content ) => {
136
- const buttonWrapStyles = {
137
- 'margin-block' : '15px' ,
138
- 'max-width' : '480px' ,
139
- } ;
140
- return layout === "stacked" ? html `< div style =${ styleMap ( buttonWrapStyles ) } > ${ content } </ div > ` : content ;
141
- } ;
142
-
143
146
return html `
144
147
< div
145
148
style =${ ifDefined ( styleMap ( {
@@ -148,32 +151,65 @@ const CustomButton = ({
148
151
...customStyles
149
152
} ) ) }
150
153
>
151
- ${ ButtonWrap ( Template ( {
154
+ ${ ButtonWrap ( layout , Template ( {
152
155
...args ,
153
156
staticColor,
154
157
iconName : undefined ,
155
158
} ) ) }
156
- ${ ButtonWrap ( Template ( {
159
+ ${ ButtonWrap ( layout , Template ( {
157
160
...args ,
158
161
staticColor,
159
162
iconName : undefined ,
160
163
treatment : "outline" ,
161
164
} ) ) }
162
- ${ ButtonWrap ( Template ( {
165
+ ${ ButtonWrap ( layout , Template ( {
163
166
...args ,
164
167
staticColor,
165
168
iconName : iconName ?? "Edit" ,
166
169
} ) ) }
167
- ${ showIconOnlyButton ? ButtonWrap ( Template ( {
168
- ...args ,
169
- staticColor,
170
- hideLabel : true ,
171
- iconName : iconName ?? "Edit" ,
172
- } ) ) : '' }
170
+ ${ when ( showIconOnlyButton , ( ) =>
171
+ ButtonWrap ( layout , Template ( {
172
+ ...args ,
173
+ staticColor,
174
+ hideLabel : true ,
175
+ iconName : iconName ?? "Edit" ,
176
+ } ) )
177
+ ) }
173
178
</ div >
174
179
` ;
175
180
} ;
176
181
182
+ /**
183
+ * Wrapping story template, displaying some additional variants for Chromatic.
184
+ */
185
+ const WrappingTemplate = ( { layout, ...args } ) => {
186
+ if ( window . isChromatic ( ) ) {
187
+ return html `
188
+ ${ CustomButton ( { layout, ...args } ) }
189
+ < div style =${ ifDefined ( styleMap ( { padding : "1rem" } ) ) } >
190
+ ${ ButtonWrap ( layout , Template ( {
191
+ ...args ,
192
+ iconName : "Edit" ,
193
+ treatment : "outline" ,
194
+ } ) ) }
195
+ ${ ButtonWrap ( layout , Template ( {
196
+ ...args ,
197
+ // Uses a UI icon that is smaller than workflow sizing, to test alignment:
198
+ iconName : "Cross100" ,
199
+ } ) ) }
200
+ ${ ButtonWrap ( layout , Template ( {
201
+ ...args ,
202
+ // UI icon that is larger than workflow sizing:
203
+ iconName : "ArrowDown600" ,
204
+ treatment : "outline" ,
205
+ } ) ) }
206
+ </ div >
207
+ ` ;
208
+ }
209
+ // Otherwise use the default template.
210
+ return CustomButton ( { layout, ...args } ) ;
211
+ } ;
212
+
177
213
export const Accent = CustomButton . bind ( { } ) ;
178
214
Accent . args = {
179
215
variant : "accent" ,
@@ -219,7 +255,8 @@ WithForcedColors.args = {
219
255
iconName : "Actions" ,
220
256
} ;
221
257
222
- export const Wrapping = CustomButton . bind ( { } ) ;
258
+ export const Wrapping = WrappingTemplate . bind ( { } ) ;
259
+ Wrapping . storyName = "Wrapping" ;
223
260
Wrapping . args = {
224
261
layout : "stacked" ,
225
262
showIconOnlyButton : false ,
0 commit comments