@kaizen/components 1.45.3 → 1.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  import React from "react"
2
+ import { action } from "@storybook/addon-actions"
2
3
  import { Meta, StoryObj } from "@storybook/react"
3
- import { IconButton } from "~components/Button"
4
+ import { Checkbox } from "~components/Checkbox"
4
5
  import { Divider } from "~components/Divider"
5
- import { ChevronUpIcon, EffectivenessIcon } from "~components/Icon"
6
+ import { EffectivenessIcon } from "~components/Icon"
6
7
  import { Text } from "~components/Text"
7
8
  import {
8
9
  TableCard,
@@ -21,127 +22,54 @@ import {
21
22
  export type TableStoryProps = {
22
23
  container?: TableContainerProps
23
24
  row?: TableRowProps
24
- rowCell?: TableRowCellProps
25
- headerRowCell: Partial<TableHeaderRowCellProps>
26
- card: TableCardProps
25
+ rowCells: TableRowCellProps[]
26
+ headerRowCells: TableHeaderRowCellProps[]
27
+ tableCards: TableCardProps[]
27
28
  }
28
29
 
29
- const Table = ({
30
- container,
31
- row,
32
- rowCell,
33
- headerRowCell,
34
- card,
35
- }: TableStoryProps): JSX.Element => {
36
- const { expanded, ...restCardProps } = card
37
- const { checkable, ...restHeaderRowCellProps } = headerRowCell
38
-
39
- return (
30
+ const TableTemplate: StoryObj<TableStoryProps> = {
31
+ render: ({ container, headerRowCells, tableCards, row, rowCells }) => (
40
32
  <TableContainer {...container}>
41
33
  <TableHeader>
42
34
  <TableRow>
43
- <TableHeaderRowCell
44
- labelText="Resource name"
45
- width={3 / 12}
46
- checkable={checkable}
47
- sorting="descending"
48
- {...restHeaderRowCellProps}
49
- />
50
- <TableHeaderRowCell
51
- labelText="Supplementary information"
52
- width={3 / 12}
53
- sorting="ascending"
54
- {...restHeaderRowCellProps}
55
- />
56
- <TableHeaderRowCell
57
- labelText="Date"
58
- width={3 / 12}
59
- {...restHeaderRowCellProps}
60
- />
61
- <TableHeaderRowCell
62
- labelText="Price"
63
- width={3 / 12}
64
- {...restHeaderRowCellProps}
65
- />
35
+ {headerRowCells.map((headerRowCellProps, index) => (
36
+ <TableHeaderRowCell key={index} {...headerRowCellProps} />
37
+ ))}
66
38
  </TableRow>
67
39
  </TableHeader>
68
- <TableCard
69
- {...restCardProps}
70
- expanded={expanded}
71
- onClick={expanded ? (): void => undefined : undefined}
72
- >
73
- <TableRow {...row}>
74
- <TableRowCell width={3 / 12} {...rowCell}>
75
- <Text tag="div" variant="body">
76
- Resource
77
- </Text>
78
- </TableRowCell>
79
- <TableRowCell width={3 / 12} {...rowCell}>
80
- <Text tag="div" variant="body">
81
- Supplementary
82
- </Text>
83
- </TableRowCell>
84
- <TableRowCell width={3 / 12} {...rowCell}>
85
- <Text tag="div" variant="body">
86
- Today
87
- </Text>
88
- </TableRowCell>
89
- <TableRowCell width={3 / 12} {...rowCell}>
90
- <Text tag="div" variant="body" classNameOverride="mr-24">
91
- 100
92
- </Text>
93
- {expanded && (
94
- <TableRowCell width={3 / 12} {...rowCell}>
95
- <IconButton
96
- label="Expand"
97
- icon={<ChevronUpIcon role="presentation" />}
98
- />
40
+ {tableCards.map((tableCardProps, index) => (
41
+ <TableCard {...tableCardProps} key={index}>
42
+ <TableRow {...row}>
43
+ {rowCells.map(({ children, ...otherProps }, rowCellIndex) => (
44
+ <TableRowCell {...otherProps} key={rowCellIndex}>
45
+ <Text tag="div" variant="body">
46
+ {children}
47
+ </Text>
99
48
  </TableRowCell>
100
- )}
101
- </TableRowCell>
102
- </TableRow>
103
- {expanded && (
104
- <>
105
- <Divider variant="content" />
106
- <Text tag="div" variant="body" classNameOverride="p-16">
107
- Overall progress
108
- </Text>
109
- </>
110
- )}
111
- </TableCard>
112
- <TableCard {...restCardProps}>
113
- <TableRow {...row}>
114
- <TableRowCell width={3 / 12} {...rowCell}>
115
- <Text tag="div" variant="body">
116
- Resource
117
- </Text>
118
- </TableRowCell>
119
- <TableRowCell width={3 / 12} {...rowCell}>
120
- <Text tag="div" variant="body">
121
- Supplementary
122
- </Text>
123
- </TableRowCell>
124
- <TableRowCell width={3 / 12} {...rowCell}>
125
- <Text tag="div" variant="body">
126
- Today
127
- </Text>
128
- </TableRowCell>
129
- <TableRowCell width={3 / 12} {...rowCell}>
130
- <Text tag="div" variant="body">
131
- 100
132
- </Text>
133
- </TableRowCell>
134
- </TableRow>
135
- </TableCard>
49
+ ))}
50
+ </TableRow>
51
+ {tableCardProps.expanded && (
52
+ <>
53
+ <Divider variant="content" />
54
+ <Text tag="div" variant="body" classNameOverride="p-16">
55
+ Overall progress
56
+ </Text>
57
+ </>
58
+ )}
59
+ </TableCard>
60
+ ))}
136
61
  </TableContainer>
137
- )
62
+ ),
138
63
  }
139
64
 
140
- const meta = {
65
+ export default {
66
+ ...TableTemplate,
141
67
  title: "Components/Table",
142
- component: Table,
143
68
  parameters: {
144
69
  chromatic: { disable: false },
70
+ docs: {
71
+ source: { type: "dynamic" },
72
+ },
145
73
  a11y: {
146
74
  config: {
147
75
  rules: [
@@ -160,18 +88,55 @@ const meta = {
160
88
  id: "aria-required-parent",
161
89
  enabled: false,
162
90
  },
163
- {
164
- // Fixing this in a rebuild
165
- id: "label",
166
- enabled: false,
167
- },
168
91
  ],
169
92
  },
170
93
  },
171
94
  },
172
95
  args: {
173
- card: { expanded: false },
174
- headerRowCell: { checkable: false },
96
+ tableCards: [
97
+ {
98
+ expanded: false,
99
+ },
100
+ {
101
+ expanded: false,
102
+ },
103
+ ],
104
+ headerRowCells: [
105
+ {
106
+ labelText: "Resource name",
107
+ width: 3 / 12,
108
+ },
109
+ {
110
+ labelText: "Supplementary information",
111
+ width: 3 / 12,
112
+ },
113
+ {
114
+ labelText: "Date",
115
+ width: 3 / 12,
116
+ },
117
+ {
118
+ labelText: "Price",
119
+ width: 3 / 12,
120
+ },
121
+ ],
122
+ rowCells: [
123
+ {
124
+ width: 3 / 12,
125
+ children: "Resource",
126
+ },
127
+ {
128
+ width: 3 / 12,
129
+ children: "Supplementary",
130
+ },
131
+ {
132
+ width: 3 / 12,
133
+ children: "Today",
134
+ },
135
+ {
136
+ width: 3 / 12,
137
+ children: "100",
138
+ },
139
+ ],
175
140
  },
176
141
  decorators: [
177
142
  Story => (
@@ -180,23 +145,52 @@ const meta = {
180
145
  </div>
181
146
  ),
182
147
  ],
183
- } satisfies Meta<typeof Table>
184
-
185
- export default meta
148
+ } satisfies Meta<TableStoryProps>
186
149
 
187
- type Story = StoryObj<typeof meta>
150
+ export const Playground: StoryObj<TableStoryProps> = {
151
+ ...TableTemplate,
152
+ parameters: {
153
+ docs: {
154
+ source: { type: "dynamic" },
155
+ },
156
+ },
157
+ }
188
158
 
189
- export const Playground: Story = {
190
- render: Table,
159
+ export const Sorting: StoryObj<TableStoryProps> = {
160
+ ...TableTemplate,
191
161
  parameters: {
192
162
  docs: {
193
163
  source: { type: "dynamic" },
194
164
  },
195
165
  },
166
+ args: {
167
+ headerRowCells: [
168
+ {
169
+ labelText: "Resource name",
170
+ sorting: "ascending",
171
+ onClick: action("Sort Resource name"),
172
+ width: 3 / 12,
173
+ },
174
+ {
175
+ labelText: "Supplementary information",
176
+ sorting: "descending",
177
+ onClick: action("Sort Supplementary information"),
178
+ width: 3 / 12,
179
+ },
180
+ {
181
+ labelText: "Date",
182
+ width: 3 / 12,
183
+ },
184
+ {
185
+ labelText: "Price",
186
+ width: 3 / 12,
187
+ },
188
+ ],
189
+ },
196
190
  }
197
191
 
198
- export const Data: Story = {
199
- render: Table,
192
+ export const Data: StoryObj<TableStoryProps> = {
193
+ ...TableTemplate,
200
194
  args: { container: { variant: "data" } },
201
195
  parameters: {
202
196
  docs: {
@@ -205,9 +199,34 @@ export const Data: Story = {
205
199
  },
206
200
  }
207
201
 
208
- export const Reversed: Story = {
209
- render: Table,
210
- args: { headerRowCell: { reversed: true } },
202
+ export const Reversed: StoryObj<TableStoryProps> = {
203
+ ...TableTemplate,
204
+ args: {
205
+ headerRowCells: [
206
+ {
207
+ labelText: "Resource name",
208
+ sorting: "ascending",
209
+ onClick: action("Sort Resource name by ascending"),
210
+ width: 3 / 12,
211
+ reversed: true,
212
+ },
213
+ {
214
+ labelText: "Supplementary information",
215
+ width: 3 / 12,
216
+ reversed: true,
217
+ },
218
+ {
219
+ labelText: "Date",
220
+ width: 3 / 12,
221
+ reversed: true,
222
+ },
223
+ {
224
+ labelText: "Price",
225
+ width: 3 / 12,
226
+ reversed: true,
227
+ },
228
+ ],
229
+ },
211
230
  parameters: {
212
231
  docs: {
213
232
  source: { type: "dynamic" },
@@ -222,8 +241,8 @@ export const Reversed: Story = {
222
241
  ],
223
242
  }
224
243
 
225
- export const Compact: Story = {
226
- render: Table,
244
+ export const Compact: StoryObj<TableStoryProps> = {
245
+ ...TableTemplate,
227
246
  args: { container: { variant: "compact" } },
228
247
  parameters: {
229
248
  docs: {
@@ -232,9 +251,9 @@ export const Compact: Story = {
232
251
  },
233
252
  }
234
253
 
235
- export const CheckboxVariant: Story = {
236
- render: Table,
237
- args: { headerRowCell: { checkable: true } },
254
+ export const Default: StoryObj<TableStoryProps> = {
255
+ ...TableTemplate,
256
+ args: { container: { variant: "default" } },
238
257
  parameters: {
239
258
  docs: {
240
259
  source: { type: "dynamic" },
@@ -242,9 +261,54 @@ export const CheckboxVariant: Story = {
242
261
  },
243
262
  }
244
263
 
245
- export const LinkVariant: Story = {
246
- render: Table,
247
- args: { card: { href: "#?foo=bar" } },
264
+ export const CheckboxVariant: StoryObj<TableStoryProps> = {
265
+ ...TableTemplate,
266
+ args: {
267
+ headerRowCells: [
268
+ {
269
+ checkable: true,
270
+ onCheck: action("onCheck header-1"),
271
+ checkboxLabel: "Select all Employees",
272
+ labelText: "Employee",
273
+ width: 5 / 12,
274
+ },
275
+ {
276
+ labelText: "Job title",
277
+ width: 3 / 12,
278
+ },
279
+ {
280
+ labelText: "Date",
281
+ width: 2 / 12,
282
+ },
283
+ {
284
+ labelText: "Score",
285
+ width: 2 / 12,
286
+ },
287
+ ],
288
+ rowCells: [
289
+ {
290
+ width: 5 / 12,
291
+ children: (
292
+ <span className="flex gap-12">
293
+ <Checkbox aria-label="Employee x" />
294
+ <span>Employee name</span>
295
+ </span>
296
+ ),
297
+ },
298
+ {
299
+ width: 3 / 12,
300
+ children: "Engineer",
301
+ },
302
+ {
303
+ width: 2 / 12,
304
+ children: "Today",
305
+ },
306
+ {
307
+ width: 2 / 12,
308
+ children: "100",
309
+ },
310
+ ],
311
+ },
248
312
  parameters: {
249
313
  docs: {
250
314
  source: { type: "dynamic" },
@@ -252,13 +316,40 @@ export const LinkVariant: Story = {
252
316
  },
253
317
  }
254
318
 
255
- export const IconVariant: Story = {
256
- render: Table,
257
- args: {
258
- headerRowCell: {
259
- icon: <EffectivenessIcon role="presentation" />,
319
+ export const LinkVariant: StoryObj<TableStoryProps> = {
320
+ ...TableTemplate,
321
+ args: { tableCards: [{ href: "#?foo=bar" }, { href: "#?bar=foo" }] },
322
+ parameters: {
323
+ docs: {
324
+ source: { type: "dynamic" },
260
325
  },
261
326
  },
327
+ }
328
+
329
+ export const IconVariant: StoryObj<TableStoryProps> = {
330
+ ...TableTemplate,
331
+ args: {
332
+ headerRowCells: [
333
+ {
334
+ icon: <EffectivenessIcon role="presentation" />,
335
+ labelText: "Resource name",
336
+ width: 3 / 12,
337
+ },
338
+ {
339
+ icon: <EffectivenessIcon role="presentation" />,
340
+ labelText: "Supplementary information",
341
+ width: 3 / 12,
342
+ },
343
+ {
344
+ labelText: "Date",
345
+ width: 3 / 12,
346
+ },
347
+ {
348
+ labelText: "Price",
349
+ width: 3 / 12,
350
+ },
351
+ ],
352
+ },
262
353
  parameters: {
263
354
  docs: {
264
355
  source: { type: "dynamic" },
@@ -266,13 +357,19 @@ export const IconVariant: Story = {
266
357
  },
267
358
  }
268
359
 
269
- export const Expandable: Story = {
270
- render: Table,
360
+ export const Expandable: StoryObj<TableStoryProps> = {
361
+ ...TableTemplate,
271
362
  args: {
272
- card: {
273
- expanded: true,
274
- expandedStyle: "popout",
275
- },
363
+ tableCards: [
364
+ {
365
+ expanded: true,
366
+ expandedStyle: "popout",
367
+ onClick: action("Set expanded to false"),
368
+ },
369
+ {
370
+ expanded: false,
371
+ },
372
+ ],
276
373
  },
277
374
  parameters: {
278
375
  docs: {
@@ -281,14 +378,31 @@ export const Expandable: Story = {
281
378
  },
282
379
  }
283
380
 
284
- export const HeaderAlignmentAndWrapping: Story = {
285
- render: Table,
381
+ export const HeaderAlignmentAndWrapping: StoryObj<TableStoryProps> = {
382
+ ...TableTemplate,
286
383
  args: {
287
- headerRowCell: {
288
- labelText: "Right header align with wrapping",
289
- wrapping: "wrap",
290
- align: "end",
291
- },
384
+ headerRowCells: [
385
+ {
386
+ labelText: "Header align start with wrapping",
387
+ wrapping: "wrap",
388
+ align: "start",
389
+ },
390
+ {
391
+ labelText: "Default alignment",
392
+ width: 3 / 12,
393
+ },
394
+ {
395
+ labelText: "Header center",
396
+ align: "center",
397
+ width: 3 / 12,
398
+ },
399
+ {
400
+ labelText: "Header align with end with wrapping",
401
+ wrapping: "wrap",
402
+ align: "end",
403
+ width: 3 / 12,
404
+ },
405
+ ],
292
406
  },
293
407
  parameters: {
294
408
  docs: {
@@ -297,12 +411,30 @@ export const HeaderAlignmentAndWrapping: Story = {
297
411
  },
298
412
  }
299
413
 
300
- export const Tooltip: Story = {
301
- render: Table,
414
+ export const Tooltip: StoryObj<TableStoryProps> = {
415
+ ...TableTemplate,
302
416
  args: {
303
- headerRowCell: {
304
- tooltipInfo: "This is a tooltip",
305
- },
417
+ headerRowCells: [
418
+ {
419
+ labelText: "Resource name",
420
+ tooltipInfo: "Sort this by ascending",
421
+ sorting: "ascending",
422
+ onClick: action("Sort Resource name by ascending"),
423
+ width: 3 / 12,
424
+ },
425
+ {
426
+ labelText: "Supplementary information",
427
+ width: 3 / 12,
428
+ },
429
+ {
430
+ labelText: "Date",
431
+ width: 3 / 12,
432
+ },
433
+ {
434
+ labelText: "Price",
435
+ width: 3 / 12,
436
+ },
437
+ ],
306
438
  },
307
439
  parameters: {
308
440
  docs: {
@@ -119,16 +119,24 @@ export const StickerSheetDefault: Story = {
119
119
  render: args => (
120
120
  <StickerSheet>
121
121
  <StickerSheet.Row rowTitle="Tab hover">
122
- <TitleBlockZen {...args} id="tab-hover-example" />
122
+ <div className="px-12 bg-purple-600">
123
+ <TitleBlockZen {...args} id="tab-hover-example" />
124
+ </div>
123
125
  </StickerSheet.Row>
124
126
  <StickerSheet.Row rowTitle="Tab focus">
125
- <TitleBlockZen {...args} id="tab-focus-example" />
127
+ <div className="px-12 bg-purple-600">
128
+ <TitleBlockZen {...args} id="tab-focus-example" />
129
+ </div>
126
130
  </StickerSheet.Row>
127
131
  <StickerSheet.Row rowTitle="Breadcrumbs hover">
128
- <TitleBlockZen {...args} id="Breadcrumbs-hover-example" />
132
+ <div className="px-12 bg-purple-600">
133
+ <TitleBlockZen {...args} id="Breadcrumbs-hover-example" />
134
+ </div>
129
135
  </StickerSheet.Row>
130
136
  <StickerSheet.Row rowTitle="Breadcrumbs focus">
131
- <TitleBlockZen {...args} id="Breadcrumbs-focus-example" />
137
+ <div className="px-12 bg-purple-600">
138
+ <TitleBlockZen {...args} id="Breadcrumbs-focus-example" />
139
+ </div>
132
140
  </StickerSheet.Row>
133
141
  </StickerSheet>
134
142
  ),