-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbutton.stories.ts
338 lines (325 loc) · 8.01 KB
/
button.stories.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import type { Args, Meta, StoryObj } from '@storybook/web-components';
import { html, unsafeStatic } from 'lit/static-html.js';
import { spread } from '@open-wc/lit-helpers';
import { repeat } from 'lit/directives/repeat.js';
import { BADGE } from '@geometricpanda/storybook-addon-badges';
const meta: Meta = {
title: 'Components/Button',
parameters: {
badges: [BADGE.NEEDS_REVISION],
design: {
type: 'figma',
url: 'https://www.figma.com/file/xZ0IW0MJO0vnFicmrHiKaY/Components-Post?type=design&node-id=10576-49992&mode=design&t=OK8meBHjpJvBhwZI-4',
},
},
args: {
text: 'Button',
tag: 'button',
type: 'button',
variant: 'btn-primary',
size: 'null',
animated: true,
icon: 'null',
iconOnly: false,
iconPosition: 'start',
disabled: false,
},
argTypes: {
text: {
name: 'Text',
description: 'Text within the button.',
control: {
type: 'text',
},
table: {
category: 'Content',
},
},
tag: {
name: 'Tag',
description: 'Defines the HTML element used for the component.',
control: {
type: 'inline-radio',
labels: {
button: 'Button',
a: 'Link',
input: 'Input',
},
},
options: ['button', 'a', 'input'],
table: {
category: 'General',
},
},
type: {
name: 'Input type',
description: 'Defines the input type.',
if: {
arg: 'tag',
eq: 'input',
},
control: {
type: 'inline-radio',
labels: {
button: 'Button',
submit: 'Submit',
reset: 'Reset',
},
},
options: ['button', 'submit', 'reset'],
table: {
category: 'General',
},
},
variant: {
name: 'Variant',
description: 'Defines a style variant.',
control: {
type: 'inline-radio',
labels: {
'btn-primary': 'Primary',
'btn-secondary': 'Secondary',
'btn-tertiary': 'Tertiary',
// 'btn-success': 'Success',
// 'btn-danger': 'Danger',
// 'btn-warning': 'Warning',
// 'btn-info': 'Info',
},
},
options: [
'btn-primary',
'btn-secondary',
'btn-tertiary',
// 'btn-success',
// 'btn-danger',
// 'btn-warning',
// 'btn-info',
],
table: {
category: 'General',
},
},
size: {
name: 'Size',
description: 'Sets the size of the component.',
control: {
type: 'select',
labels: {
'btn-sm': 'Small',
'btn-rg': 'Regular',
'null': 'Medium',
'btn-lg': 'Large',
},
},
options: ['btn-sm', 'btn-rg', 'null', 'btn-lg'],
table: {
category: 'General',
},
},
animated: {
name: 'Animated',
description: 'When set to `true`, the component animates on hover.',
if: {
arg: 'icon',
eq: 'null',
},
control: {
type: 'boolean',
},
table: {
category: 'General',
},
},
icon: {
name: 'Icon',
description:
'Defines a custom icon.' +
'<span className="mt-mini alert alert-info alert-sm">' +
'To use a custom icon, you must first ' +
'<a href="/?path=/docs/icons-getting-started--docs">set up the icons in your project</a>' +
'.</span>',
if: {
arg: 'tag',
neq: 'input',
},
control: {
type: 'select',
labels: {
'null': 'None',
'2069': 'Search (2069)',
'3193': 'Edit (3193)',
'2059': 'Save (2059)',
'2015': 'Remove (2015)',
'2286': 'Like (2286)',
},
},
options: ['null', '2069', '3193', '2059', '2015', '2286'],
table: {
category: 'Icon',
},
},
iconOnly: {
name: 'Icon only',
description: "When set to `true`, hides the component's text.",
if: {
arg: 'tag',
neq: 'input',
},
control: {
type: 'boolean',
},
table: {
category: 'Icon',
},
},
iconPosition: {
name: 'Icon position',
description: 'Defines the icon position.',
if: {
arg: 'tag',
neq: 'input',
},
control: {
type: 'inline-radio',
labels: {
start: 'Start',
end: 'End',
},
},
options: ['start', 'end'],
table: {
category: 'Icon',
},
},
disabled: {
name: 'Disabled',
description:
'When set to `true`, makes the component appear inactive and disables its functionality.<div className="mt-mini alert alert-info alert-sm">There are accessibility concerns with the disabled state.<br/>Please read our <a href="/?path=/docs/foundations-accessibility--docs#disabled-state">disabled state accessibility guide</a>.</div>',
control: {
type: 'boolean',
},
table: {
category: 'States',
},
},
},
};
export default meta;
type Story = StoryObj;
const Template = {
render: (args: Args) => {
const tagName = unsafeStatic(args.tag);
const isAnimated = args.tag !== 'input' && args.animated;
const props = createProps(args, isAnimated);
if (args.tag === 'input') {
return html`
<${tagName} ${spread(props)} />
`;
} else {
const icon = html`
<post-icon aria-hidden="true" name="${args.icon}"></post-icon>
`;
const iconOnlyContent = html`
<span class="visually-hidden">${args.text}</span>
`;
const animatedContent = html`
<span>${args.text}</span>
`;
const text = html`
${args.text}
`;
return html`
<${tagName} ${spread(props)}>
${args.icon !== 'null' && args.iconPosition === 'start' ? icon : null}
${(args.iconOnly && iconOnlyContent) || (isAnimated && animatedContent) || text}
${args.icon !== 'null' && args.iconPosition === 'end' ? icon : null}
</${tagName}>
`;
}
},
};
function createProps(args: Args, isAnimated: boolean) {
const additionalClasses = args.additionalClasses ?? [];
return {
class: [
'btn',
args.variant,
args.size,
isAnimated && 'btn-animated',
args.iconOnly && 'btn-icon',
...additionalClasses,
]
.filter(c => c && c !== 'null')
.join(' '),
href: args.tag === 'a' ? '#' : null,
type: args.tag === 'input' ? args.type : null,
value: args.tag === 'input' ? args.text : null,
disabled: args.disabled ? args.disabled : null,
};
}
export const Default: Story = {
...Template,
};
export const Inverted: Story = {
...Template,
decorators: [
(story: Function) => html`
<div class="p-3 bg-dark">${story()}</div>
`,
],
};
const VariantsTemplate = {
parameters: {
controls: {
exclude: ['Text', 'Tag', 'Type', 'Variant', 'variants'],
},
},
decorators: [
(story: Function) =>
html`
<div class="d-flex gap-small-r flex-wrap">${story()}</div>
`,
],
render: (args: Args) =>
html`
${repeat(args.variants, (variant: string) =>
Template.render({
...args,
text: variant.replace(/^btn-(.)/g, (_m: string, g: string) => g.toUpperCase()),
variant,
}),
)}
`,
};
export const AccentColors: Story = {
...VariantsTemplate,
args: {
variants: [
'btn-nightblue',
'btn-nightblue-bright',
'btn-petrol',
'btn-petrol-bright',
'btn-coral',
'btn-coral-bright',
'btn-olive',
'btn-olive-bright',
'btn-purple',
'btn-purple-bright',
'btn-aubergine',
'btn-aubergine-bright',
],
},
};
export const ContextualColors: Story = {
...VariantsTemplate,
args: {
variants: ['btn-success', 'btn-info', 'btn-warning', 'btn-danger'],
},
};
export const FullWidth: Story = {
...VariantsTemplate,
args: {
variants: ['btn-primary'],
additionalClasses: ['w-sm-100', 'w-md-auto'],
},
};