uikit-react-public 0.11.24 → 0.14.21
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.
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Badge/Badge.stories.d.ts +15 -0
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Button/Button.d.ts +2 -1
- package/dist/components/CookieNotice/CookieNotice.d.ts +16 -0
- package/dist/components/CookieNotice/index.d.ts +2 -0
- package/dist/components/Dialog/BaseDialog.d.ts +7 -2
- package/dist/components/FileInput/FileInput.d.ts +8 -0
- package/dist/components/FileInput/FileInput.stories.d.ts +16 -0
- package/dist/components/FileInput/__tests__/FileInput.test.d.ts +1 -0
- package/dist/components/FileInput/index.d.ts +2 -0
- package/dist/components/Header/Header.d.ts +4 -1
- package/dist/components/Heading/Heading.d.ts +1 -1
- package/dist/components/Link/BaseLink.d.ts +10 -0
- package/dist/components/Link/Link.d.ts +5 -10
- package/dist/components/Link/Link.stories.d.ts +1 -1
- package/dist/components/Link/index.d.ts +1 -1
- package/dist/components/Menu/MenuContent.d.ts +1 -1
- package/dist/components/Menu/MenuItem.d.ts +2 -0
- package/dist/components/Menu/MenuSection.d.ts +1 -1
- package/dist/components/Search/Search.d.ts +16 -0
- package/dist/components/Search/Search.stories.d.ts +34 -0
- package/dist/components/Search/__tests__/Search.test.d.ts +1 -0
- package/dist/components/Search/index.d.ts +2 -0
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/components/Select/Select.stories.d.ts +3 -7
- package/dist/components/Select/Select.types.d.ts +19 -14
- package/dist/components/Select/subcomponents/CustomOption.d.ts +1 -1
- package/dist/components/Select/subcomponents/CustomSelect.d.ts +1 -2
- package/dist/components/Select/subcomponents/Panel.d.ts +1 -1
- package/dist/components/Select/subcomponents/VisibleField.d.ts +4 -4
- package/dist/components/StandaloneLink/StandaloneLink.d.ts +12 -0
- package/dist/components/StandaloneLink/StandaloneLink.stories.d.ts +13 -0
- package/dist/components/StandaloneLink/__tests__/StandaloneLink.test.d.ts +1 -0
- package/dist/components/StandaloneLink/index.d.ts +2 -0
- package/dist/components/Table/Table.d.ts +10 -8
- package/dist/components/Table/Table.stories.d.ts +21 -0
- package/dist/components/Table/Table.types.d.ts +11 -0
- package/dist/components/Table/__tests__/Table.test.d.ts +1 -0
- package/dist/components/Table/index.d.ts +2 -1
- package/dist/components/Table/subcomponents/Body.d.ts +4 -0
- package/dist/components/Table/subcomponents/Cell/Cell.d.ts +12 -0
- package/dist/components/Table/subcomponents/Cell/Cell.stories.d.ts +313 -0
- package/dist/components/Table/subcomponents/Cell/CellContent.d.ts +10 -0
- package/dist/components/Table/subcomponents/Cell/__tests__/Cell.test.d.ts +1 -0
- package/dist/components/Table/subcomponents/Head.d.ts +4 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.d.ts +13 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.stories.d.ts +312 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCellContent.d.ts +10 -0
- package/dist/components/Table/subcomponents/HeadCell/__tests__/HeadCell.test.d.ts +1 -0
- package/dist/components/Table/subcomponents/Row.d.ts +5 -0
- package/dist/components/Table/subcomponents/SortIcon.d.ts +7 -0
- package/dist/components/Table/subcomponents/index.d.ts +10 -0
- package/dist/components/Tabs/Tab.d.ts +1 -1
- package/dist/components/Tabs/TabContext.d.ts +1 -0
- package/dist/components/Tabs/Tabs.d.ts +3 -1
- package/dist/components/Tabs/Tabs.stories.d.ts +3 -0
- package/dist/components/Timepicker/Timepicker.d.ts +10 -0
- package/dist/components/Timepicker/Timepicker.stories.d.ts +7 -0
- package/dist/components/Timepicker/__tests__/Timepicker.test.d.ts +1 -0
- package/dist/components/Timepicker/index.d.ts +2 -0
- package/dist/components/Timepicker/utils/convertDateToTimeString.d.ts +2 -0
- package/dist/components/Timepicker/utils/convertDateToTimeString.test.d.ts +1 -0
- package/dist/components/Timepicker/utils/index.d.ts +1 -0
- package/dist/components/WeekPicker/WeekPicker.d.ts +3 -0
- package/dist/components/WeekPicker/index.d.ts +1 -0
- package/dist/components/WeekPicker/subcomponents/CustomDatepicker.d.ts +17 -0
- package/dist/components/WeekPicker/subcomponents/DatepickerInput.d.ts +13 -0
- package/dist/components/WeekPicker/subcomponents/VisibleField.d.ts +15 -0
- package/dist/components/WeekPicker/subcomponents/index.d.ts +3 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useFocusTrap.d.ts +9 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5703 -4448
- package/dist/theme/defaultTheme.d.ts +7 -0
- package/dist/theme/useTheme.d.ts +14 -0
- package/dist/utils/__tests__/capitalise.test.d.ts +1 -0
- package/dist/utils/capitalise.d.ts +2 -0
- package/lib/components/Alert/Alert.tsx +7 -1
- package/lib/components/Alert/__tests__/__snapshots__/Alert.test.tsx.snap +4 -0
- package/lib/components/Badge/Badge.stories.tsx +19 -0
- package/lib/components/Badge/Badge.tsx +48 -0
- package/lib/components/Badge/index.ts +2 -0
- package/lib/components/Breadcrumbs/__tests__/__snapshots__/Breadcrumbs.test.tsx.snap +4 -4
- package/lib/components/Button/Button.tsx +5 -2
- package/lib/components/Calendar/subcomponents/Grid.tsx +0 -1
- package/lib/components/CookieNotice/CookieNotice.tsx +114 -0
- package/lib/components/CookieNotice/index.ts +2 -0
- package/lib/components/Dialog/BaseDialog.tsx +44 -4
- package/lib/components/Field/__tests__/Field.test.tsx +148 -148
- package/lib/components/FileInput/FileInput.stories.tsx +70 -0
- package/lib/components/FileInput/FileInput.tsx +68 -0
- package/lib/components/FileInput/__tests__/FileInput.test.tsx +99 -0
- package/lib/components/FileInput/__tests__/__snapshots__/FileInput.test.tsx.snap +91 -0
- package/lib/components/FileInput/index.ts +2 -0
- package/lib/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap +25 -25
- package/lib/components/Header/Header.tsx +19 -2
- package/lib/components/Header/__tests__/__snapshots__/Header.test.tsx.snap +4 -4
- package/lib/components/Heading/Documentation.mdx +1 -1
- package/lib/components/Heading/Heading.tsx +1 -1
- package/lib/components/Heading/__tests__/Heading.test.tsx +7 -19
- package/lib/components/Heading/__tests__/__snapshots__/Heading.test.tsx.snap +7 -7
- package/lib/components/Label/Label.tsx +0 -2
- package/lib/components/Label/__tests__/__snapshots__/Label.test.tsx.snap +7 -7
- package/lib/components/Link/BaseLink.tsx +84 -0
- package/lib/components/Link/Link.tsx +72 -32
- package/lib/components/Link/__tests__/__snapshots__/link.test.tsx.snap +3 -3
- package/lib/components/Link/__tests__/link.test.tsx +6 -13
- package/lib/components/Link/index.ts +1 -1
- package/lib/components/Menu/Menu.context.tsx +3 -1
- package/lib/components/Menu/Menu.tsx +2 -2
- package/lib/components/Menu/MenuContent.tsx +5 -5
- package/lib/components/Menu/MenuItem.tsx +20 -3
- package/lib/components/Menu/MenuSection.tsx +4 -3
- package/lib/components/Pagination/PaginationControls.tsx +1 -3
- package/lib/components/Search/Search.stories.tsx +41 -0
- package/lib/components/Search/Search.tsx +167 -0
- package/lib/components/Search/__tests__/Search.test.tsx +94 -0
- package/lib/components/Search/__tests__/__snapshots__/Search.test.tsx.snap +179 -0
- package/lib/components/Search/index.ts +2 -0
- package/lib/components/Select/Select.stories.tsx +8 -35
- package/lib/components/Select/Select.tsx +2 -2
- package/lib/components/Select/Select.types.ts +20 -15
- package/lib/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +3 -3
- package/lib/components/Select/subcomponents/CustomOption.tsx +22 -9
- package/lib/components/Select/subcomponents/CustomSelect.tsx +31 -20
- package/lib/components/Select/subcomponents/Panel.tsx +4 -5
- package/lib/components/Select/subcomponents/VisibleField.tsx +26 -22
- package/lib/components/StandaloneLink/StandaloneLink.stories.tsx +32 -0
- package/lib/components/StandaloneLink/StandaloneLink.tsx +183 -0
- package/lib/components/StandaloneLink/__tests__/StandaloneLink.test.tsx +57 -0
- package/lib/components/StandaloneLink/__tests__/__snapshots__/StandaloneLink.test.tsx.snap +19 -0
- package/lib/components/StandaloneLink/index.ts +2 -0
- package/lib/components/Table/Table.stories.tsx +337 -0
- package/lib/components/Table/Table.tsx +42 -67
- package/lib/components/Table/Table.types.ts +14 -0
- package/lib/components/Table/__tests__/Table.test.tsx +121 -0
- package/lib/components/Table/__tests__/__snapshots__/Table.test.tsx.snap +210 -0
- package/lib/components/Table/index.ts +8 -1
- package/lib/components/Table/subcomponents/Body.tsx +18 -0
- package/lib/components/Table/subcomponents/Cell/Cell.stories.tsx +151 -0
- package/lib/components/Table/subcomponents/Cell/Cell.tsx +72 -0
- package/lib/components/Table/subcomponents/Cell/CellContent.tsx +91 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/Cell.test.tsx +115 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/__snapshots__/Cell.test.tsx.snap +107 -0
- package/lib/components/Table/subcomponents/Head.tsx +34 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.stories.tsx +85 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.tsx +99 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCellContent.tsx +61 -0
- package/lib/components/Table/subcomponents/HeadCell/__tests__/HeadCell.test.tsx +137 -0
- package/lib/components/Table/subcomponents/HeadCell/__tests__/__snapshots__/HeadCell.test.tsx.snap +110 -0
- package/lib/components/Table/subcomponents/Row.tsx +49 -0
- package/lib/components/Table/subcomponents/SortIcon.tsx +63 -0
- package/lib/components/Table/subcomponents/index.ts +14 -0
- package/lib/components/Tabs/Tab.tsx +3 -3
- package/lib/components/Tabs/TabContext.tsx +1 -0
- package/lib/components/Tabs/Tabs.stories.tsx +9 -3
- package/lib/components/Tabs/Tabs.tsx +10 -32
- package/lib/components/Tabs/__tests__/Tabs.test.tsx +10 -4
- package/lib/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +32 -32
- package/lib/components/Timepicker/Timepicker.stories.tsx +43 -0
- package/lib/components/Timepicker/Timepicker.tsx +96 -0
- package/lib/components/Timepicker/__tests__/Timepicker.test.tsx +55 -0
- package/lib/components/Timepicker/__tests__/__snapshots__/Timepicker.test.tsx.snap +19 -0
- package/lib/components/Timepicker/index.tsx +2 -0
- package/lib/components/Timepicker/utils/convertDateToTimeString.test.ts +54 -0
- package/lib/components/Timepicker/utils/convertDateToTimeString.ts +10 -0
- package/lib/components/Timepicker/utils/index.ts +1 -0
- package/lib/components/WeekPicker/WeekPicker.tsx +26 -0
- package/lib/components/WeekPicker/index.ts +1 -0
- package/lib/components/WeekPicker/subcomponents/CustomDatepicker.tsx +298 -0
- package/lib/components/WeekPicker/subcomponents/DatepickerInput.tsx +111 -0
- package/lib/components/WeekPicker/subcomponents/VisibleField.tsx +126 -0
- package/lib/components/WeekPicker/subcomponents/index.ts +3 -0
- package/lib/components/index.ts +17 -0
- package/lib/hooks/index.ts +2 -0
- package/lib/hooks/useFocusTrap.ts +123 -0
- package/lib/index.ts +1 -0
- package/lib/theme/defaultTheme.ts +7 -0
- package/lib/utils/__tests__/capitalise.test.ts +40 -0
- package/lib/utils/capitalise.ts +4 -0
- package/package.json +1 -1
- package/lib/components/Field/__tests__/__snapshots__/Field.test.tsx.snap +0 -300
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Table > Snapshot: basic table 1`] = `
|
|
4
|
+
<table
|
|
5
|
+
class="css-3bowfr ucl-uikit-table"
|
|
6
|
+
data-testid="ucl-uikit-table"
|
|
7
|
+
>
|
|
8
|
+
<thead
|
|
9
|
+
class="css-3fy35g ucl-uikit-table__head"
|
|
10
|
+
data-testid="ucl-uikit-table__head"
|
|
11
|
+
>
|
|
12
|
+
<tr
|
|
13
|
+
class="css-7kbd2r"
|
|
14
|
+
>
|
|
15
|
+
<th
|
|
16
|
+
class="css-1g8x9da ucl-uikit-table__head-cell"
|
|
17
|
+
data-testid="ucl-uikit-table__head-cell"
|
|
18
|
+
scope="col"
|
|
19
|
+
>
|
|
20
|
+
<div
|
|
21
|
+
class="css-13bwe7d ucl-uikit-table__head-cell-content"
|
|
22
|
+
data-testid="ucl-uikit-table__head-cell-content"
|
|
23
|
+
>
|
|
24
|
+
Header Cell 1
|
|
25
|
+
<svg
|
|
26
|
+
fill="none"
|
|
27
|
+
height="16"
|
|
28
|
+
viewBox="0 0 48 48"
|
|
29
|
+
width="16"
|
|
30
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
31
|
+
>
|
|
32
|
+
<g>
|
|
33
|
+
<path
|
|
34
|
+
d="M8 28L15 35L22 28"
|
|
35
|
+
stroke="#CCCCCC"
|
|
36
|
+
stroke-linecap="round"
|
|
37
|
+
stroke-linejoin="round"
|
|
38
|
+
stroke-width="4"
|
|
39
|
+
/>
|
|
40
|
+
<path
|
|
41
|
+
d="M15 35V10"
|
|
42
|
+
stroke="#CCCCCC"
|
|
43
|
+
stroke-linecap="round"
|
|
44
|
+
stroke-linejoin="round"
|
|
45
|
+
stroke-width="4"
|
|
46
|
+
/>
|
|
47
|
+
<path
|
|
48
|
+
d="M43 19L36 12L29 19"
|
|
49
|
+
stroke="#CCCCCC"
|
|
50
|
+
stroke-linecap="round"
|
|
51
|
+
stroke-linejoin="round"
|
|
52
|
+
stroke-width="4"
|
|
53
|
+
/>
|
|
54
|
+
<path
|
|
55
|
+
d="M36 12V37"
|
|
56
|
+
stroke="#CCCCCC"
|
|
57
|
+
stroke-linecap="round"
|
|
58
|
+
stroke-linejoin="round"
|
|
59
|
+
stroke-width="4"
|
|
60
|
+
/>
|
|
61
|
+
</g>
|
|
62
|
+
</svg>
|
|
63
|
+
</div>
|
|
64
|
+
</th>
|
|
65
|
+
<th
|
|
66
|
+
class="css-1g8x9da ucl-uikit-table__head-cell"
|
|
67
|
+
data-testid="ucl-uikit-table__head-cell"
|
|
68
|
+
scope="col"
|
|
69
|
+
>
|
|
70
|
+
<div
|
|
71
|
+
class="css-13bwe7d ucl-uikit-table__head-cell-content"
|
|
72
|
+
data-testid="ucl-uikit-table__head-cell-content"
|
|
73
|
+
>
|
|
74
|
+
Header Cell 2
|
|
75
|
+
<svg
|
|
76
|
+
fill="none"
|
|
77
|
+
height="16"
|
|
78
|
+
viewBox="0 0 48 48"
|
|
79
|
+
width="16"
|
|
80
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
81
|
+
>
|
|
82
|
+
<g>
|
|
83
|
+
<path
|
|
84
|
+
d="M8 28L15 35L22 28"
|
|
85
|
+
stroke="#CCCCCC"
|
|
86
|
+
stroke-linecap="round"
|
|
87
|
+
stroke-linejoin="round"
|
|
88
|
+
stroke-width="4"
|
|
89
|
+
/>
|
|
90
|
+
<path
|
|
91
|
+
d="M15 35V10"
|
|
92
|
+
stroke="#CCCCCC"
|
|
93
|
+
stroke-linecap="round"
|
|
94
|
+
stroke-linejoin="round"
|
|
95
|
+
stroke-width="4"
|
|
96
|
+
/>
|
|
97
|
+
<path
|
|
98
|
+
d="M43 19L36 12L29 19"
|
|
99
|
+
stroke="#CCCCCC"
|
|
100
|
+
stroke-linecap="round"
|
|
101
|
+
stroke-linejoin="round"
|
|
102
|
+
stroke-width="4"
|
|
103
|
+
/>
|
|
104
|
+
<path
|
|
105
|
+
d="M36 12V37"
|
|
106
|
+
stroke="#CCCCCC"
|
|
107
|
+
stroke-linecap="round"
|
|
108
|
+
stroke-linejoin="round"
|
|
109
|
+
stroke-width="4"
|
|
110
|
+
/>
|
|
111
|
+
</g>
|
|
112
|
+
</svg>
|
|
113
|
+
</div>
|
|
114
|
+
</th>
|
|
115
|
+
<th
|
|
116
|
+
class="css-1g8x9da ucl-uikit-table__head-cell"
|
|
117
|
+
data-testid="ucl-uikit-table__head-cell"
|
|
118
|
+
scope="col"
|
|
119
|
+
>
|
|
120
|
+
<div
|
|
121
|
+
class="css-13bwe7d ucl-uikit-table__head-cell-content"
|
|
122
|
+
data-testid="ucl-uikit-table__head-cell-content"
|
|
123
|
+
>
|
|
124
|
+
Header Cell 3
|
|
125
|
+
<svg
|
|
126
|
+
fill="none"
|
|
127
|
+
height="16"
|
|
128
|
+
viewBox="0 0 48 48"
|
|
129
|
+
width="16"
|
|
130
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
131
|
+
>
|
|
132
|
+
<g>
|
|
133
|
+
<path
|
|
134
|
+
d="M8 28L15 35L22 28"
|
|
135
|
+
stroke="#CCCCCC"
|
|
136
|
+
stroke-linecap="round"
|
|
137
|
+
stroke-linejoin="round"
|
|
138
|
+
stroke-width="4"
|
|
139
|
+
/>
|
|
140
|
+
<path
|
|
141
|
+
d="M15 35V10"
|
|
142
|
+
stroke="#CCCCCC"
|
|
143
|
+
stroke-linecap="round"
|
|
144
|
+
stroke-linejoin="round"
|
|
145
|
+
stroke-width="4"
|
|
146
|
+
/>
|
|
147
|
+
<path
|
|
148
|
+
d="M43 19L36 12L29 19"
|
|
149
|
+
stroke="#CCCCCC"
|
|
150
|
+
stroke-linecap="round"
|
|
151
|
+
stroke-linejoin="round"
|
|
152
|
+
stroke-width="4"
|
|
153
|
+
/>
|
|
154
|
+
<path
|
|
155
|
+
d="M36 12V37"
|
|
156
|
+
stroke="#CCCCCC"
|
|
157
|
+
stroke-linecap="round"
|
|
158
|
+
stroke-linejoin="round"
|
|
159
|
+
stroke-width="4"
|
|
160
|
+
/>
|
|
161
|
+
</g>
|
|
162
|
+
</svg>
|
|
163
|
+
</div>
|
|
164
|
+
</th>
|
|
165
|
+
</tr>
|
|
166
|
+
</thead>
|
|
167
|
+
<tbody
|
|
168
|
+
data-testid="ucl-uikit-table__body"
|
|
169
|
+
>
|
|
170
|
+
<tr
|
|
171
|
+
class="css-jetl3c ucl-uikit-table__row"
|
|
172
|
+
data-testid="ucl-uikit-table__row"
|
|
173
|
+
>
|
|
174
|
+
<td
|
|
175
|
+
class="css-u1gowl ucl-uikit-table__cell"
|
|
176
|
+
data-testid="ucl-uikit-table__cell"
|
|
177
|
+
>
|
|
178
|
+
<div
|
|
179
|
+
class="ucl-uikit-table__cell-content css-1ao6jhw"
|
|
180
|
+
data-testid="ucl-uikit-table__cell-content"
|
|
181
|
+
>
|
|
182
|
+
Test Cell 1
|
|
183
|
+
</div>
|
|
184
|
+
</td>
|
|
185
|
+
<td
|
|
186
|
+
class="css-u1gowl ucl-uikit-table__cell"
|
|
187
|
+
data-testid="ucl-uikit-table__cell"
|
|
188
|
+
>
|
|
189
|
+
<div
|
|
190
|
+
class="ucl-uikit-table__cell-content css-1ao6jhw"
|
|
191
|
+
data-testid="ucl-uikit-table__cell-content"
|
|
192
|
+
>
|
|
193
|
+
Test Cell 2
|
|
194
|
+
</div>
|
|
195
|
+
</td>
|
|
196
|
+
<td
|
|
197
|
+
class="css-u1gowl ucl-uikit-table__cell"
|
|
198
|
+
data-testid="ucl-uikit-table__cell"
|
|
199
|
+
>
|
|
200
|
+
<div
|
|
201
|
+
class="ucl-uikit-table__cell-content css-1ao6jhw"
|
|
202
|
+
data-testid="ucl-uikit-table__cell-content"
|
|
203
|
+
>
|
|
204
|
+
Test Cell 3
|
|
205
|
+
</div>
|
|
206
|
+
</td>
|
|
207
|
+
</tr>
|
|
208
|
+
</tbody>
|
|
209
|
+
</table>
|
|
210
|
+
`;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export { default } from './Table';
|
|
2
|
-
export type { TableProps } from './Table';
|
|
2
|
+
export type { TableProps, ColumnVariant } from './Table.types';
|
|
3
|
+
export type {
|
|
4
|
+
TableHeadProps,
|
|
5
|
+
TableHeadCellProps,
|
|
6
|
+
TableBodyProps,
|
|
7
|
+
TableRowProps,
|
|
8
|
+
TableCellProps,
|
|
9
|
+
} from './subcomponents';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface TableBodyProps
|
|
2
|
+
extends React.HTMLAttributes<HTMLTableSectionElement> {}
|
|
3
|
+
|
|
4
|
+
const NAME = 'ucl-uikit-table__body';
|
|
5
|
+
|
|
6
|
+
const Body = ({ className, children, ...props }: TableBodyProps) => {
|
|
7
|
+
return (
|
|
8
|
+
<tbody
|
|
9
|
+
className={className}
|
|
10
|
+
data-testid={NAME}
|
|
11
|
+
{...props}
|
|
12
|
+
>
|
|
13
|
+
{children}
|
|
14
|
+
</tbody>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default Body;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { useArgs } from '@storybook/preview-api';
|
|
3
|
+
import { css } from '@emotion/css';
|
|
4
|
+
import Row from '../Row';
|
|
5
|
+
import Cell from './Cell';
|
|
6
|
+
import Badge from '../../../Badge/Badge';
|
|
7
|
+
import Icon from '../../../Icon/Icon';
|
|
8
|
+
import Link from '../../../Link/Link';
|
|
9
|
+
|
|
10
|
+
const widthStyle = css`
|
|
11
|
+
width: 200px; // To demonstrate text alignment
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
const meta = {
|
|
15
|
+
title: 'Components/Work in progress/Table/Cell',
|
|
16
|
+
component: Cell,
|
|
17
|
+
parameters: {
|
|
18
|
+
layout: 'centered',
|
|
19
|
+
},
|
|
20
|
+
args: {
|
|
21
|
+
className: widthStyle,
|
|
22
|
+
},
|
|
23
|
+
tags: ['autodocs'],
|
|
24
|
+
decorators: [
|
|
25
|
+
(Story) => (
|
|
26
|
+
<table style={{ borderCollapse: 'collapse' }}>
|
|
27
|
+
<tbody>
|
|
28
|
+
<Row>
|
|
29
|
+
<Story />
|
|
30
|
+
</Row>
|
|
31
|
+
</tbody>
|
|
32
|
+
</table>
|
|
33
|
+
),
|
|
34
|
+
],
|
|
35
|
+
} satisfies Meta<typeof Cell>;
|
|
36
|
+
|
|
37
|
+
export default meta;
|
|
38
|
+
type Story = StoryObj<typeof meta>;
|
|
39
|
+
|
|
40
|
+
export const Default: Story = {
|
|
41
|
+
name: 'Default (text)',
|
|
42
|
+
args: {
|
|
43
|
+
children: 'Default (text)',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Emphasised: Story = {
|
|
48
|
+
name: 'Text emphasised',
|
|
49
|
+
args: {
|
|
50
|
+
children: <strong>Text emphasised</strong>,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const Numeric: Story = {
|
|
55
|
+
name: 'Numeric',
|
|
56
|
+
args: {
|
|
57
|
+
variant: 'numeric',
|
|
58
|
+
children: '12345',
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const NumericEmphasised: Story = {
|
|
63
|
+
name: 'Numeric emphasised',
|
|
64
|
+
args: {
|
|
65
|
+
variant: 'numeric',
|
|
66
|
+
children: <strong>12345</strong>,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const CheckboxStory: Story = {
|
|
71
|
+
name: 'Checkbox',
|
|
72
|
+
args: {
|
|
73
|
+
variant: 'checkbox',
|
|
74
|
+
checked: false,
|
|
75
|
+
},
|
|
76
|
+
render: () => {
|
|
77
|
+
const [args, updateArgs] = useArgs();
|
|
78
|
+
const handleOnCheck = (checked: boolean) => {
|
|
79
|
+
updateArgs({ checked });
|
|
80
|
+
};
|
|
81
|
+
return (
|
|
82
|
+
<>
|
|
83
|
+
<Cell
|
|
84
|
+
{...args}
|
|
85
|
+
onCheck={handleOnCheck}
|
|
86
|
+
/>
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const BadgeStory: Story = {
|
|
93
|
+
name: 'Badge',
|
|
94
|
+
args: {
|
|
95
|
+
children: <Badge>Badge</Badge>,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const MultipleBadges: Story = {
|
|
100
|
+
name: 'Multiple badges',
|
|
101
|
+
args: {
|
|
102
|
+
children: (
|
|
103
|
+
<>
|
|
104
|
+
<Badge>Badge 1</Badge>
|
|
105
|
+
<Badge>Badge 2</Badge>
|
|
106
|
+
</>
|
|
107
|
+
),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const IconStory: Story = {
|
|
112
|
+
name: 'Icon',
|
|
113
|
+
args: {
|
|
114
|
+
icon: <Icon.File />,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const IconAndText: Story = {
|
|
119
|
+
name: 'Icon & text',
|
|
120
|
+
args: {
|
|
121
|
+
icon: <Icon.Compass size={20} />,
|
|
122
|
+
children: 'Icon & text',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const ButtonStory: Story = {
|
|
127
|
+
name: 'Button',
|
|
128
|
+
args: {
|
|
129
|
+
variant: 'button',
|
|
130
|
+
children: 'Button',
|
|
131
|
+
onButtonClick: (event: React.UIEvent) => {
|
|
132
|
+
console.log('UIKit-React Cell button clicked:', event);
|
|
133
|
+
alert('Button clicked!');
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const LinkStory: Story = {
|
|
139
|
+
name: 'Link',
|
|
140
|
+
args: {
|
|
141
|
+
children: (
|
|
142
|
+
<Link
|
|
143
|
+
href='https://www.ucl.ac.uk'
|
|
144
|
+
target='_blank'
|
|
145
|
+
rel='noopener noreferrer'
|
|
146
|
+
>
|
|
147
|
+
Visit us
|
|
148
|
+
</Link>
|
|
149
|
+
),
|
|
150
|
+
},
|
|
151
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import CellContent from './CellContent';
|
|
3
|
+
import { useTheme } from '../../../../theme';
|
|
4
|
+
import type { ColumnVariant } from '../../Table.types';
|
|
5
|
+
|
|
6
|
+
export interface TableCellProps
|
|
7
|
+
extends React.HTMLAttributes<HTMLTableCellElement> {
|
|
8
|
+
variant?: ColumnVariant;
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
checked?: boolean;
|
|
11
|
+
onCheck?: (
|
|
12
|
+
checked: boolean,
|
|
13
|
+
event: React.ChangeEvent<HTMLInputElement>
|
|
14
|
+
) => void;
|
|
15
|
+
onButtonClick?: (event: React.UIEvent) => void;
|
|
16
|
+
className?: string;
|
|
17
|
+
testId?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const NAME = 'ucl-uikit-table__cell';
|
|
21
|
+
|
|
22
|
+
const Cell = ({
|
|
23
|
+
variant = 'default',
|
|
24
|
+
icon,
|
|
25
|
+
onCheck,
|
|
26
|
+
checked,
|
|
27
|
+
onButtonClick = () => {},
|
|
28
|
+
testId = NAME,
|
|
29
|
+
className,
|
|
30
|
+
children,
|
|
31
|
+
...props
|
|
32
|
+
}: TableCellProps) => {
|
|
33
|
+
const [theme] = useTheme();
|
|
34
|
+
|
|
35
|
+
const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
36
|
+
if (variant === 'checkbox' && onCheck) onCheck(event.target.checked, event);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleButtonClick = (event: React.UIEvent) => {
|
|
40
|
+
if (variant === 'button' && onButtonClick) onButtonClick(event);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const baseStyle = css`
|
|
44
|
+
box-sizing: border-box;
|
|
45
|
+
padding: 0 ${theme.padding.p16};
|
|
46
|
+
height: 40px;
|
|
47
|
+
font-family: ${theme.font.family.primary};
|
|
48
|
+
font-size: ${theme.font.size.f14};
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const style = cx(baseStyle, className, NAME);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<td
|
|
55
|
+
className={style}
|
|
56
|
+
data-testid={testId}
|
|
57
|
+
{...props}
|
|
58
|
+
>
|
|
59
|
+
<CellContent
|
|
60
|
+
variant={variant}
|
|
61
|
+
icon={icon}
|
|
62
|
+
checked={checked}
|
|
63
|
+
handleCheckboxChange={handleCheckboxChange}
|
|
64
|
+
handleButtonClick={handleButtonClick}
|
|
65
|
+
>
|
|
66
|
+
{children}
|
|
67
|
+
</CellContent>
|
|
68
|
+
</td>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default Cell;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import Checkbox from '../../../Checkbox/Checkbox';
|
|
3
|
+
import Button from '../../../Button/Button';
|
|
4
|
+
import { useTheme } from '../../../../theme';
|
|
5
|
+
import type { ColumnVariant } from '../../Table.types';
|
|
6
|
+
|
|
7
|
+
interface CellContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
variant: ColumnVariant;
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
checked?: boolean;
|
|
11
|
+
handleCheckboxChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
12
|
+
handleButtonClick: (event: React.UIEvent) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const NAME = 'ucl-uikit-table__cell-content';
|
|
16
|
+
|
|
17
|
+
const CellContent = ({
|
|
18
|
+
variant,
|
|
19
|
+
icon,
|
|
20
|
+
checked,
|
|
21
|
+
handleCheckboxChange,
|
|
22
|
+
handleButtonClick,
|
|
23
|
+
children,
|
|
24
|
+
}: CellContentProps) => {
|
|
25
|
+
const [theme] = useTheme();
|
|
26
|
+
|
|
27
|
+
const baseStyle = css`
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: flex-start;
|
|
31
|
+
gap: ${theme.padding.p8};
|
|
32
|
+
width: 100%;
|
|
33
|
+
height: 100%;
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const variantStyles = {
|
|
37
|
+
default: css`
|
|
38
|
+
font-weight: ${theme.font.weight.regular};
|
|
39
|
+
`,
|
|
40
|
+
numeric: css`
|
|
41
|
+
justify-content: flex-end;
|
|
42
|
+
font-weight: ${theme.font.weight.regular};
|
|
43
|
+
`,
|
|
44
|
+
checkbox: css`
|
|
45
|
+
justify-content: flex-end;
|
|
46
|
+
padding-right: ${theme.padding.p16};
|
|
47
|
+
`,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const buttonStyle = css`
|
|
51
|
+
padding: ${theme.padding.p2};
|
|
52
|
+
height: auto;
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const style = cx(
|
|
56
|
+
baseStyle,
|
|
57
|
+
{
|
|
58
|
+
[variantStyles.default]: variant === 'default',
|
|
59
|
+
[variantStyles.numeric]: variant === 'numeric',
|
|
60
|
+
[variantStyles.checkbox]: variant === 'checkbox',
|
|
61
|
+
},
|
|
62
|
+
NAME
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
className={style}
|
|
68
|
+
data-testid={NAME}
|
|
69
|
+
>
|
|
70
|
+
{icon}
|
|
71
|
+
{variant === 'checkbox' && (
|
|
72
|
+
<Checkbox
|
|
73
|
+
checked={checked}
|
|
74
|
+
onChange={handleCheckboxChange}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
{variant === 'button' && (
|
|
78
|
+
<Button
|
|
79
|
+
variant='tertiary'
|
|
80
|
+
onClick={handleButtonClick}
|
|
81
|
+
className={buttonStyle}
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</Button>
|
|
85
|
+
)}
|
|
86
|
+
{variant !== 'checkbox' && variant !== 'button' && children}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default CellContent;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import Cell from '../Cell';
|
|
4
|
+
import Icon from '../../../../Icon/Icon';
|
|
5
|
+
import { ThemeContextProvider } from '../../../../../theme/useTheme';
|
|
6
|
+
|
|
7
|
+
describe('Cell', () => {
|
|
8
|
+
// Snapshot tests
|
|
9
|
+
|
|
10
|
+
test('Snapshot: default', () => {
|
|
11
|
+
const renderResult = render(
|
|
12
|
+
<ThemeContextProvider>
|
|
13
|
+
<table>
|
|
14
|
+
<tbody>
|
|
15
|
+
<tr>
|
|
16
|
+
<Cell>Default cell</Cell>
|
|
17
|
+
</tr>
|
|
18
|
+
</tbody>
|
|
19
|
+
</table>
|
|
20
|
+
</ThemeContextProvider>
|
|
21
|
+
);
|
|
22
|
+
expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('Snapshot: variants', () => {
|
|
26
|
+
const renderResult = render(
|
|
27
|
+
<ThemeContextProvider>
|
|
28
|
+
<table>
|
|
29
|
+
<tbody>
|
|
30
|
+
<tr>
|
|
31
|
+
<Cell variant='numeric'>123</Cell>
|
|
32
|
+
<Cell variant='checkbox'>Checkbox</Cell>
|
|
33
|
+
<Cell icon={<Icon.Edit />}></Cell>
|
|
34
|
+
<Cell variant='button'>Button</Cell>
|
|
35
|
+
</tr>
|
|
36
|
+
</tbody>
|
|
37
|
+
</table>
|
|
38
|
+
</ThemeContextProvider>
|
|
39
|
+
);
|
|
40
|
+
expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Unit tests
|
|
44
|
+
|
|
45
|
+
test('Text is visible via children prop', () => {
|
|
46
|
+
render(
|
|
47
|
+
<ThemeContextProvider>
|
|
48
|
+
<table>
|
|
49
|
+
<tbody>
|
|
50
|
+
<tr>
|
|
51
|
+
<Cell>Visible text</Cell>
|
|
52
|
+
</tr>
|
|
53
|
+
</tbody>
|
|
54
|
+
</table>
|
|
55
|
+
</ThemeContextProvider>
|
|
56
|
+
);
|
|
57
|
+
expect(screen.getByText('Visible text')).toBeInTheDocument();
|
|
58
|
+
expect(screen.getByText('Visible text')).toBeVisible();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('Can be found via default testId', () => {
|
|
62
|
+
const defaultTestId = 'ucl-uikit-table__cell';
|
|
63
|
+
render(
|
|
64
|
+
<ThemeContextProvider>
|
|
65
|
+
<table>
|
|
66
|
+
<tbody>
|
|
67
|
+
<tr>
|
|
68
|
+
<Cell>Visible text</Cell>
|
|
69
|
+
</tr>
|
|
70
|
+
</tbody>
|
|
71
|
+
</table>
|
|
72
|
+
</ThemeContextProvider>
|
|
73
|
+
);
|
|
74
|
+
expect(screen.getByTestId(defaultTestId)).toBeInTheDocument();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('Can be found via custom testId', () => {
|
|
78
|
+
const customTestId = 'custom-cell-test-id';
|
|
79
|
+
render(
|
|
80
|
+
<ThemeContextProvider>
|
|
81
|
+
<table>
|
|
82
|
+
<tbody>
|
|
83
|
+
<tr>
|
|
84
|
+
<Cell testId={customTestId}>Visible text</Cell>
|
|
85
|
+
</tr>
|
|
86
|
+
</tbody>
|
|
87
|
+
</table>
|
|
88
|
+
</ThemeContextProvider>
|
|
89
|
+
);
|
|
90
|
+
expect(screen.getByTestId(customTestId)).toBeInTheDocument();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('onButtonClick prop is called correctly', () => {
|
|
94
|
+
const handleButtonClick = vi.fn();
|
|
95
|
+
render(
|
|
96
|
+
<ThemeContextProvider>
|
|
97
|
+
<table>
|
|
98
|
+
<tbody>
|
|
99
|
+
<tr>
|
|
100
|
+
<Cell
|
|
101
|
+
variant='button'
|
|
102
|
+
onButtonClick={handleButtonClick}
|
|
103
|
+
>
|
|
104
|
+
Button Cell
|
|
105
|
+
</Cell>
|
|
106
|
+
</tr>
|
|
107
|
+
</tbody>
|
|
108
|
+
</table>
|
|
109
|
+
</ThemeContextProvider>
|
|
110
|
+
);
|
|
111
|
+
const buttonCell = screen.getByText('Button Cell');
|
|
112
|
+
buttonCell.click();
|
|
113
|
+
expect(handleButtonClick).toHaveBeenCalled();
|
|
114
|
+
});
|
|
115
|
+
});
|