@antify/ui 2.2.0 → 2.2.1
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/inputs/AntCheckbox.vue +1 -0
- package/dist/components/inputs/AntCheckboxGroup.vue +1 -0
- package/dist/components/inputs/AntSwitch.vue +1 -0
- package/dist/components/table/AntTable.vue +31 -14
- package/dist/components/table/__stories/AntTable.stories.js +132 -14
- package/dist/components/table/__stories/AntTable.stories.mjs +108 -14
- package/dist/components/table/__types/index.d.ts +0 -1
- package/dist/components/table/__types/index.js +0 -11
- package/dist/components/table/__types/index.mjs +0 -1
- package/package.json +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import {AntTableSize, AntTableSortDirection, type TableHeader} from './__types/TableHeader.types';
|
|
3
|
-
import {computed, ref, type Ref, watch} from 'vue';
|
|
3
|
+
import {computed, onMounted, ref, type Ref, watch} from 'vue';
|
|
4
4
|
import {useVModel} from '@vueuse/core';
|
|
5
5
|
import {Size, State} from '../../enums';
|
|
6
6
|
import AntTh from './AntTh.vue';
|
|
7
7
|
import AntTd from './AntTd.vue';
|
|
8
8
|
import AntSpinner from '../AntSpinner.vue';
|
|
9
9
|
import AntSkeleton from '../AntSkeleton.vue';
|
|
10
|
-
import {hasSlotContent} from "
|
|
10
|
+
import {hasSlotContent} from "../../utils";
|
|
11
11
|
import AntCollapsibleTableRowContent from "./AntCollapsibleTableRowContent.vue";
|
|
12
|
-
import {CollapseStrategy} from "
|
|
12
|
+
import {CollapseStrategy} from "../../types";
|
|
13
13
|
import {faAngleDown, faAngleUp} from "@fortawesome/free-solid-svg-icons";
|
|
14
14
|
import AntButton from "../buttons/AntButton.vue";
|
|
15
15
|
import AntIcon from "../AntIcon.vue";
|
|
@@ -96,9 +96,7 @@ function sortTable(header: TableHeader, newDirection: AntTableSortDirection) {
|
|
|
96
96
|
emits('updateSort', header, newDirection);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
function rowClick(
|
|
100
|
-
e.preventDefault();
|
|
101
|
-
|
|
99
|
+
function rowClick(elem: Record<string, unknown>): void {
|
|
102
100
|
selected.value = elem;
|
|
103
101
|
|
|
104
102
|
emits('rowClick', elem);
|
|
@@ -108,7 +106,7 @@ function toggleRowContent(index: number) {
|
|
|
108
106
|
const isOpen = openItems.value.includes(index);
|
|
109
107
|
|
|
110
108
|
if (isOpen) {
|
|
111
|
-
openItems.value = props.collapseStrategy === CollapseStrategy.single
|
|
109
|
+
openItems.value = props.collapseStrategy === CollapseStrategy.single
|
|
112
110
|
? []
|
|
113
111
|
: openItems.value.filter(item => item !== index);
|
|
114
112
|
} else {
|
|
@@ -118,10 +116,27 @@ function toggleRowContent(index: number) {
|
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
|
|
122
|
-
if (!props.rowsCollapsed) {
|
|
123
|
-
|
|
119
|
+
function openRowsByDefault() {
|
|
120
|
+
if (!props.rowsCollapsed && props.data.length > 0) {
|
|
121
|
+
openItems.value = props.data.map((_, index) => index);
|
|
122
|
+
}
|
|
124
123
|
}
|
|
124
|
+
|
|
125
|
+
watch(() => props.data, (currVal, prevVal) => {
|
|
126
|
+
if (currVal.length > prevVal.length) {
|
|
127
|
+
// Add newest element to the list of open items so it is open by default
|
|
128
|
+
// Necessary when table content is changed dynamically
|
|
129
|
+
if (props.collapseStrategy === CollapseStrategy.single) {
|
|
130
|
+
openItems.value = [currVal.length - 1];
|
|
131
|
+
} else {
|
|
132
|
+
openItems.value = [...openItems.value, currVal.length - 1];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
onMounted(() => {
|
|
138
|
+
openRowsByDefault();
|
|
139
|
+
});
|
|
125
140
|
</script>
|
|
126
141
|
|
|
127
142
|
<template>
|
|
@@ -170,6 +185,7 @@ if (!props.rowsCollapsed) {
|
|
|
170
185
|
v-for="(elem, rowIndex) in data" :key="`table-row-${elem[rowKey]}-${rowIndex}`"
|
|
171
186
|
>
|
|
172
187
|
<tr
|
|
188
|
+
data-e2e="table-row"
|
|
173
189
|
:id="elem[rowKey] as string"
|
|
174
190
|
:class="{
|
|
175
191
|
'bg-primary-200 text-primary-200-font transition-colors': elem === selected,
|
|
@@ -187,12 +203,13 @@ if (!props.rowsCollapsed) {
|
|
|
187
203
|
<template v-for="(header, colIndex) in _headers">
|
|
188
204
|
<AntTd
|
|
189
205
|
v-if="!_showLightVersion || (_showLightVersion && header.lightVersion)"
|
|
190
|
-
:key="`table-cell-${header.identifier}-${colIndex}`"
|
|
206
|
+
:key="`table-cell-${header.identifier}-${rowIndex}-${colIndex}`"
|
|
207
|
+
:data-e2e="`table-cell-${header.identifier}`"
|
|
191
208
|
:header="header"
|
|
192
209
|
:element="elem"
|
|
193
210
|
:align="header.align"
|
|
194
211
|
:size="size"
|
|
195
|
-
@click="
|
|
212
|
+
@click="rowClick(elem)"
|
|
196
213
|
>
|
|
197
214
|
<template #beforeCellContent="props">
|
|
198
215
|
<slot
|
|
@@ -219,7 +236,7 @@ if (!props.rowsCollapsed) {
|
|
|
219
236
|
|
|
220
237
|
<template v-if="!!$slots.afterRowContent">
|
|
221
238
|
<td class="whitespace-nowrap text-sm font-medium relative px-2 py-0 h-9 text-right"
|
|
222
|
-
@click="
|
|
239
|
+
@click="rowClick(elem)">
|
|
223
240
|
<AntButton @click="toggleRowContent(rowIndex)" :size="Size.xs2">
|
|
224
241
|
<AntIcon :icon="openItems.includes(rowIndex) ? faAngleUp : faAngleDown"/>
|
|
225
242
|
</AntButton>
|
|
@@ -233,7 +250,7 @@ if (!props.rowsCollapsed) {
|
|
|
233
250
|
</tr>
|
|
234
251
|
|
|
235
252
|
<template v-if="!!$slots.afterRowContent">
|
|
236
|
-
<tr>
|
|
253
|
+
<tr data-e2e="table-after-row-content">
|
|
237
254
|
<td :colspan="maxColSpan + 1" class="p-0">
|
|
238
255
|
<AntCollapsibleTableRowContent :is-open="openItems.includes(rowIndex)"
|
|
239
256
|
>
|
|
@@ -5,12 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
module.exports = exports.Skeleton = exports.MultipleCollapseStrategy = exports.Loading = exports.Empty = exports.Docs = exports.DefaultCollapseOpen = exports.Collapsible = void 0;
|
|
7
7
|
var _AntTable = _interopRequireDefault(require("../AntTable.vue"));
|
|
8
|
+
var _AntButton = _interopRequireDefault(require("../../buttons/AntButton.vue"));
|
|
9
|
+
var _AntSelect = _interopRequireDefault(require("../../inputs/AntSelect.vue"));
|
|
10
|
+
var _AntCheckboxGroup = _interopRequireDefault(require("../../inputs/AntCheckboxGroup.vue"));
|
|
8
11
|
var _TableHeader = require("../__types/TableHeader.types");
|
|
9
12
|
var _vue = require("vue");
|
|
10
13
|
var _faker = require("@faker-js/faker");
|
|
11
14
|
var _AntSwitch = _interopRequireDefault(require("../../inputs/AntSwitch.vue"));
|
|
15
|
+
var _test = require("@storybook/test");
|
|
12
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
17
|
const meta = {
|
|
18
|
+
components: {
|
|
19
|
+
AntSelect: _AntSelect.default,
|
|
20
|
+
AntCheckboxGroup: _AntCheckboxGroup.default
|
|
21
|
+
},
|
|
14
22
|
title: "Components/Table",
|
|
15
23
|
component: _AntTable.default,
|
|
16
24
|
parameters: {
|
|
@@ -137,7 +145,7 @@ const meta = {
|
|
|
137
145
|
};
|
|
138
146
|
module.exports = meta;
|
|
139
147
|
const testData = (0, _vue.ref)([]);
|
|
140
|
-
|
|
148
|
+
function getRandomEntry() {
|
|
141
149
|
const randomName = _faker.faker.person.firstName() + " " + _faker.faker.person.lastName();
|
|
142
150
|
const randomNumber = _faker.faker.number.int({
|
|
143
151
|
min: 18,
|
|
@@ -145,24 +153,41 @@ for (let i = 0; i < 100; i++) {
|
|
|
145
153
|
});
|
|
146
154
|
const randomEmail = _faker.faker.internet.email();
|
|
147
155
|
const randomBoolean = _faker.faker.datatype.boolean();
|
|
148
|
-
|
|
156
|
+
const randomPermissions = _faker.faker.helpers.arrayElements(["read", "write"], {
|
|
157
|
+
min: 0,
|
|
158
|
+
max: 2
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
149
161
|
name: randomName,
|
|
150
162
|
age: randomNumber,
|
|
151
163
|
email: randomEmail,
|
|
152
|
-
employed: randomBoolean
|
|
153
|
-
|
|
164
|
+
employed: randomBoolean,
|
|
165
|
+
permissions: randomPermissions
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
for (let i = 0; i < 100; i++) {
|
|
169
|
+
testData.value.push(getRandomEntry());
|
|
154
170
|
}
|
|
155
171
|
const Docs = exports.Docs = {
|
|
156
172
|
render: args => ({
|
|
157
173
|
components: {
|
|
158
174
|
AntTable: _AntTable.default,
|
|
159
|
-
AntSwitch: _AntSwitch.default
|
|
175
|
+
AntSwitch: _AntSwitch.default,
|
|
176
|
+
AntCheckboxGroup: _AntCheckboxGroup.default
|
|
160
177
|
},
|
|
161
178
|
setup() {
|
|
162
179
|
const selected = (0, _vue.ref)();
|
|
180
|
+
const checkboxes = [{
|
|
181
|
+
label: "Read",
|
|
182
|
+
value: "read"
|
|
183
|
+
}, {
|
|
184
|
+
label: "Write",
|
|
185
|
+
value: "write"
|
|
186
|
+
}];
|
|
163
187
|
return {
|
|
164
188
|
args,
|
|
165
|
-
selected
|
|
189
|
+
selected,
|
|
190
|
+
checkboxes
|
|
166
191
|
};
|
|
167
192
|
},
|
|
168
193
|
template: `
|
|
@@ -172,11 +197,52 @@ const Docs = exports.Docs = {
|
|
|
172
197
|
<div v-if="header.identifier === 'employed'">
|
|
173
198
|
<AntSwitch v-model="entry.employed"/>
|
|
174
199
|
</div>
|
|
200
|
+
|
|
201
|
+
<div v-if="header.identifier === 'permissions'">
|
|
202
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
203
|
+
</div>
|
|
175
204
|
</template>
|
|
176
205
|
</AntTable>
|
|
177
206
|
</div>
|
|
178
207
|
`
|
|
179
208
|
}),
|
|
209
|
+
play: async ({
|
|
210
|
+
step
|
|
211
|
+
}) => {
|
|
212
|
+
const firstRow = document.querySelectorAll('[data-e2e="table-row"]')[0];
|
|
213
|
+
const employedCell = firstRow.querySelector('[data-e2e="table-cell-employed"]');
|
|
214
|
+
const employedSwitch = employedCell?.querySelector('[data-e2e="switch"]')?.querySelector("button");
|
|
215
|
+
const permissionsCell = firstRow.querySelector('[data-e2e="table-cell-permissions"]');
|
|
216
|
+
const permissionCheckboxWithLabel = permissionsCell?.querySelector('[data-e2e="checkbox"]');
|
|
217
|
+
const permissionCheckbox = permissionCheckboxWithLabel?.querySelector('[type="checkbox"]');
|
|
218
|
+
const permissionLabel = permissionCheckboxWithLabel?.querySelector("label");
|
|
219
|
+
await step("Click on a table cell and expect the row to be selected", async () => {
|
|
220
|
+
await _test.userEvent.click(employedCell);
|
|
221
|
+
await (0, _test.waitFor)(() => (0, _test.expect)(firstRow).toHaveClass("bg-primary-200"), {
|
|
222
|
+
timeout: 600
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
await step("Click on employed switch and expect the value to toggle", async () => {
|
|
226
|
+
const initialAriaChecked = JSON.parse(employedSwitch?.getAttribute("aria-checked"));
|
|
227
|
+
await _test.userEvent.click(employedSwitch);
|
|
228
|
+
await (0, _test.waitFor)(() => {
|
|
229
|
+
const toggledAriaChecked = JSON.parse(employedSwitch?.getAttribute("aria-checked"));
|
|
230
|
+
(0, _test.expect)(toggledAriaChecked).toBe(!initialAriaChecked);
|
|
231
|
+
}, {
|
|
232
|
+
timeout: 600
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
await step("Click on one of the permissions and expect the value to toggle", async () => {
|
|
236
|
+
const initialAriaChecked = JSON.parse(permissionCheckbox?.getAttribute("aria-checked"));
|
|
237
|
+
await _test.userEvent.click(permissionLabel);
|
|
238
|
+
await (0, _test.waitFor)(() => {
|
|
239
|
+
const toggledAriaChecked = JSON.parse(permissionCheckbox?.getAttribute("aria-checked"));
|
|
240
|
+
(0, _test.expect)(toggledAriaChecked).toBe(!initialAriaChecked);
|
|
241
|
+
}, {
|
|
242
|
+
timeout: 600
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
},
|
|
180
246
|
args: {
|
|
181
247
|
headers: [{
|
|
182
248
|
title: "Name",
|
|
@@ -200,6 +266,11 @@ const Docs = exports.Docs = {
|
|
|
200
266
|
identifier: "employed",
|
|
201
267
|
rowClassList: "",
|
|
202
268
|
type: _TableHeader.AntTableRowTypes.slot
|
|
269
|
+
}, {
|
|
270
|
+
title: "Permissions",
|
|
271
|
+
identifier: "permissions",
|
|
272
|
+
rowClassList: "",
|
|
273
|
+
type: _TableHeader.AntTableRowTypes.slot
|
|
203
274
|
}],
|
|
204
275
|
data: testData.value
|
|
205
276
|
}
|
|
@@ -338,13 +409,22 @@ const Collapsible = exports.Collapsible = {
|
|
|
338
409
|
render: args => ({
|
|
339
410
|
components: {
|
|
340
411
|
AntTable: _AntTable.default,
|
|
341
|
-
AntSwitch: _AntSwitch.default
|
|
412
|
+
AntSwitch: _AntSwitch.default,
|
|
413
|
+
AntCheckboxGroup: _AntCheckboxGroup.default
|
|
342
414
|
},
|
|
343
415
|
setup() {
|
|
344
416
|
const selected = (0, _vue.ref)();
|
|
417
|
+
const checkboxes = [{
|
|
418
|
+
label: "Read",
|
|
419
|
+
value: "read"
|
|
420
|
+
}, {
|
|
421
|
+
label: "Write",
|
|
422
|
+
value: "write"
|
|
423
|
+
}];
|
|
345
424
|
return {
|
|
346
425
|
args,
|
|
347
|
-
selected
|
|
426
|
+
selected,
|
|
427
|
+
checkboxes
|
|
348
428
|
};
|
|
349
429
|
},
|
|
350
430
|
template: `
|
|
@@ -354,6 +434,10 @@ const Collapsible = exports.Collapsible = {
|
|
|
354
434
|
<div v-if="header.identifier === 'employed'">
|
|
355
435
|
<AntSwitch v-model="entry.employed"/>
|
|
356
436
|
</div>
|
|
437
|
+
|
|
438
|
+
<div v-if="header.identifier === 'permissions'">
|
|
439
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
440
|
+
</div>
|
|
357
441
|
</template>
|
|
358
442
|
|
|
359
443
|
<template #afterRowContent="{element, rowIndex}">
|
|
@@ -373,13 +457,22 @@ const MultipleCollapseStrategy = exports.MultipleCollapseStrategy = {
|
|
|
373
457
|
render: args => ({
|
|
374
458
|
components: {
|
|
375
459
|
AntTable: _AntTable.default,
|
|
376
|
-
AntSwitch: _AntSwitch.default
|
|
460
|
+
AntSwitch: _AntSwitch.default,
|
|
461
|
+
AntCheckboxGroup: _AntCheckboxGroup.default
|
|
377
462
|
},
|
|
378
463
|
setup() {
|
|
379
464
|
const selected = (0, _vue.ref)();
|
|
465
|
+
const checkboxes = [{
|
|
466
|
+
label: "Read",
|
|
467
|
+
value: "read"
|
|
468
|
+
}, {
|
|
469
|
+
label: "Write",
|
|
470
|
+
value: "write"
|
|
471
|
+
}];
|
|
380
472
|
return {
|
|
381
473
|
args,
|
|
382
|
-
selected
|
|
474
|
+
selected,
|
|
475
|
+
checkboxes
|
|
383
476
|
};
|
|
384
477
|
},
|
|
385
478
|
template: `
|
|
@@ -389,6 +482,10 @@ const MultipleCollapseStrategy = exports.MultipleCollapseStrategy = {
|
|
|
389
482
|
<div v-if="header.identifier === 'employed'">
|
|
390
483
|
<AntSwitch v-model="entry.employed"/>
|
|
391
484
|
</div>
|
|
485
|
+
|
|
486
|
+
<div v-if="header.identifier === 'permissions'">
|
|
487
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
488
|
+
</div>
|
|
392
489
|
</template>
|
|
393
490
|
|
|
394
491
|
<template #afterRowContent="{element, rowIndex}">
|
|
@@ -408,22 +505,43 @@ const DefaultCollapseOpen = exports.DefaultCollapseOpen = {
|
|
|
408
505
|
render: args => ({
|
|
409
506
|
components: {
|
|
410
507
|
AntTable: _AntTable.default,
|
|
411
|
-
AntSwitch: _AntSwitch.default
|
|
508
|
+
AntSwitch: _AntSwitch.default,
|
|
509
|
+
AntCheckboxGroup: _AntCheckboxGroup.default,
|
|
510
|
+
AntButton: _AntButton.default
|
|
412
511
|
},
|
|
413
512
|
setup() {
|
|
414
513
|
const selected = (0, _vue.ref)();
|
|
514
|
+
const data = (0, _vue.ref)(args.data.splice(0, 5));
|
|
515
|
+
const checkboxes = [{
|
|
516
|
+
label: "Read",
|
|
517
|
+
value: "read"
|
|
518
|
+
}, {
|
|
519
|
+
label: "Write",
|
|
520
|
+
value: "write"
|
|
521
|
+
}];
|
|
522
|
+
function addRandomEntry() {
|
|
523
|
+
data.value = [...data.value, getRandomEntry()];
|
|
524
|
+
}
|
|
415
525
|
return {
|
|
416
526
|
args,
|
|
417
|
-
|
|
527
|
+
data,
|
|
528
|
+
selected,
|
|
529
|
+
checkboxes,
|
|
530
|
+
addRandomEntry
|
|
418
531
|
};
|
|
419
532
|
},
|
|
420
533
|
template: `
|
|
421
|
-
<div class="h-96 border border-dashed border-base-300">
|
|
422
|
-
<
|
|
534
|
+
<div class="h-96 border border-dashed border-base-300 flex flex-col gap-2">
|
|
535
|
+
<AntButton state="primary" @click="addRandomEntry" filled>Add Random Entry</AntButton>
|
|
536
|
+
<AntTable v-bind="args" :data="data" v-model="selected" :selected-row="selected" @row-click="(val) => selected = val" :rows-collapsed="false" collapse-strategy="multiple">
|
|
423
537
|
<template #cellContent="{element: entry, header}">
|
|
424
538
|
<div v-if="header.identifier === 'employed'">
|
|
425
539
|
<AntSwitch v-model="entry.employed"/>
|
|
426
540
|
</div>
|
|
541
|
+
|
|
542
|
+
<div v-if="header.identifier === 'permissions'">
|
|
543
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
544
|
+
</div>
|
|
427
545
|
</template>
|
|
428
546
|
|
|
429
547
|
<template #afterRowContent="{element, rowIndex}">
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import AntTable from "../AntTable.vue";
|
|
2
|
+
import AntButton from "../../buttons/AntButton.vue";
|
|
3
|
+
import AntSelect from "../../inputs/AntSelect.vue";
|
|
4
|
+
import AntCheckboxGroup from "../../inputs/AntCheckboxGroup.vue";
|
|
2
5
|
import { AntTableAlign, AntTableRowTypes, AntTableSize } from "../__types/TableHeader.types.mjs";
|
|
3
6
|
import { ref } from "vue";
|
|
4
7
|
import { faker } from "@faker-js/faker";
|
|
5
8
|
import AntSwitch from "../../inputs/AntSwitch.vue";
|
|
9
|
+
import { expect, userEvent, waitFor } from "@storybook/test";
|
|
6
10
|
const meta = {
|
|
11
|
+
components: { AntSelect, AntCheckboxGroup },
|
|
7
12
|
title: "Components/Table",
|
|
8
13
|
component: AntTable,
|
|
9
14
|
parameters: { controls: { sort: "requiredFirst" } },
|
|
@@ -90,24 +95,36 @@ const meta = {
|
|
|
90
95
|
};
|
|
91
96
|
export default meta;
|
|
92
97
|
const testData = ref([]);
|
|
93
|
-
|
|
98
|
+
function getRandomEntry() {
|
|
94
99
|
const randomName = faker.person.firstName() + " " + faker.person.lastName();
|
|
95
100
|
const randomNumber = faker.number.int({ min: 18, max: 60 });
|
|
96
101
|
const randomEmail = faker.internet.email();
|
|
97
102
|
const randomBoolean = faker.datatype.boolean();
|
|
98
|
-
|
|
103
|
+
const randomPermissions = faker.helpers.arrayElements(["read", "write"], { min: 0, max: 2 });
|
|
104
|
+
return {
|
|
99
105
|
name: randomName,
|
|
100
106
|
age: randomNumber,
|
|
101
107
|
email: randomEmail,
|
|
102
|
-
employed: randomBoolean
|
|
103
|
-
|
|
108
|
+
employed: randomBoolean,
|
|
109
|
+
permissions: randomPermissions
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < 100; i++) {
|
|
113
|
+
testData.value.push(getRandomEntry());
|
|
104
114
|
}
|
|
105
115
|
export const Docs = {
|
|
106
116
|
render: (args) => ({
|
|
107
|
-
components: { AntTable, AntSwitch },
|
|
117
|
+
components: { AntTable, AntSwitch, AntCheckboxGroup },
|
|
108
118
|
setup() {
|
|
109
119
|
const selected = ref();
|
|
110
|
-
|
|
120
|
+
const checkboxes = [{
|
|
121
|
+
label: "Read",
|
|
122
|
+
value: "read"
|
|
123
|
+
}, {
|
|
124
|
+
label: "Write",
|
|
125
|
+
value: "write"
|
|
126
|
+
}];
|
|
127
|
+
return { args, selected, checkboxes };
|
|
111
128
|
},
|
|
112
129
|
template: `
|
|
113
130
|
<div class="h-96 border border-dashed border-base-300">
|
|
@@ -116,11 +133,44 @@ export const Docs = {
|
|
|
116
133
|
<div v-if="header.identifier === 'employed'">
|
|
117
134
|
<AntSwitch v-model="entry.employed"/>
|
|
118
135
|
</div>
|
|
136
|
+
|
|
137
|
+
<div v-if="header.identifier === 'permissions'">
|
|
138
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
139
|
+
</div>
|
|
119
140
|
</template>
|
|
120
141
|
</AntTable>
|
|
121
142
|
</div>
|
|
122
143
|
`
|
|
123
144
|
}),
|
|
145
|
+
play: async ({ step }) => {
|
|
146
|
+
const firstRow = document.querySelectorAll('[data-e2e="table-row"]')[0];
|
|
147
|
+
const employedCell = firstRow.querySelector('[data-e2e="table-cell-employed"]');
|
|
148
|
+
const employedSwitch = employedCell?.querySelector('[data-e2e="switch"]')?.querySelector("button");
|
|
149
|
+
const permissionsCell = firstRow.querySelector('[data-e2e="table-cell-permissions"]');
|
|
150
|
+
const permissionCheckboxWithLabel = permissionsCell?.querySelector('[data-e2e="checkbox"]');
|
|
151
|
+
const permissionCheckbox = permissionCheckboxWithLabel?.querySelector('[type="checkbox"]');
|
|
152
|
+
const permissionLabel = permissionCheckboxWithLabel?.querySelector("label");
|
|
153
|
+
await step("Click on a table cell and expect the row to be selected", async () => {
|
|
154
|
+
await userEvent.click(employedCell);
|
|
155
|
+
await waitFor(() => expect(firstRow).toHaveClass("bg-primary-200"), { timeout: 600 });
|
|
156
|
+
});
|
|
157
|
+
await step("Click on employed switch and expect the value to toggle", async () => {
|
|
158
|
+
const initialAriaChecked = JSON.parse(employedSwitch?.getAttribute("aria-checked"));
|
|
159
|
+
await userEvent.click(employedSwitch);
|
|
160
|
+
await waitFor(() => {
|
|
161
|
+
const toggledAriaChecked = JSON.parse(employedSwitch?.getAttribute("aria-checked"));
|
|
162
|
+
expect(toggledAriaChecked).toBe(!initialAriaChecked);
|
|
163
|
+
}, { timeout: 600 });
|
|
164
|
+
});
|
|
165
|
+
await step("Click on one of the permissions and expect the value to toggle", async () => {
|
|
166
|
+
const initialAriaChecked = JSON.parse(permissionCheckbox?.getAttribute("aria-checked"));
|
|
167
|
+
await userEvent.click(permissionLabel);
|
|
168
|
+
await waitFor(() => {
|
|
169
|
+
const toggledAriaChecked = JSON.parse(permissionCheckbox?.getAttribute("aria-checked"));
|
|
170
|
+
expect(toggledAriaChecked).toBe(!initialAriaChecked);
|
|
171
|
+
}, { timeout: 600 });
|
|
172
|
+
});
|
|
173
|
+
},
|
|
124
174
|
args: {
|
|
125
175
|
headers: [
|
|
126
176
|
{
|
|
@@ -148,6 +198,12 @@ export const Docs = {
|
|
|
148
198
|
identifier: "employed",
|
|
149
199
|
rowClassList: "",
|
|
150
200
|
type: AntTableRowTypes.slot
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
title: "Permissions",
|
|
204
|
+
identifier: "permissions",
|
|
205
|
+
rowClassList: "",
|
|
206
|
+
type: AntTableRowTypes.slot
|
|
151
207
|
}
|
|
152
208
|
],
|
|
153
209
|
data: testData.value
|
|
@@ -294,10 +350,17 @@ export const Loading = {
|
|
|
294
350
|
};
|
|
295
351
|
export const Collapsible = {
|
|
296
352
|
render: (args) => ({
|
|
297
|
-
components: { AntTable, AntSwitch },
|
|
353
|
+
components: { AntTable, AntSwitch, AntCheckboxGroup },
|
|
298
354
|
setup() {
|
|
299
355
|
const selected = ref();
|
|
300
|
-
|
|
356
|
+
const checkboxes = [{
|
|
357
|
+
label: "Read",
|
|
358
|
+
value: "read"
|
|
359
|
+
}, {
|
|
360
|
+
label: "Write",
|
|
361
|
+
value: "write"
|
|
362
|
+
}];
|
|
363
|
+
return { args, selected, checkboxes };
|
|
301
364
|
},
|
|
302
365
|
template: `
|
|
303
366
|
<div class="h-96 border border-dashed border-base-300">
|
|
@@ -306,6 +369,10 @@ export const Collapsible = {
|
|
|
306
369
|
<div v-if="header.identifier === 'employed'">
|
|
307
370
|
<AntSwitch v-model="entry.employed"/>
|
|
308
371
|
</div>
|
|
372
|
+
|
|
373
|
+
<div v-if="header.identifier === 'permissions'">
|
|
374
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
375
|
+
</div>
|
|
309
376
|
</template>
|
|
310
377
|
|
|
311
378
|
<template #afterRowContent="{element, rowIndex}">
|
|
@@ -323,10 +390,17 @@ export const Collapsible = {
|
|
|
323
390
|
};
|
|
324
391
|
export const MultipleCollapseStrategy = {
|
|
325
392
|
render: (args) => ({
|
|
326
|
-
components: { AntTable, AntSwitch },
|
|
393
|
+
components: { AntTable, AntSwitch, AntCheckboxGroup },
|
|
327
394
|
setup() {
|
|
328
395
|
const selected = ref();
|
|
329
|
-
|
|
396
|
+
const checkboxes = [{
|
|
397
|
+
label: "Read",
|
|
398
|
+
value: "read"
|
|
399
|
+
}, {
|
|
400
|
+
label: "Write",
|
|
401
|
+
value: "write"
|
|
402
|
+
}];
|
|
403
|
+
return { args, selected, checkboxes };
|
|
330
404
|
},
|
|
331
405
|
template: `
|
|
332
406
|
<div class="h-96 border border-dashed border-base-300">
|
|
@@ -335,6 +409,10 @@ export const MultipleCollapseStrategy = {
|
|
|
335
409
|
<div v-if="header.identifier === 'employed'">
|
|
336
410
|
<AntSwitch v-model="entry.employed"/>
|
|
337
411
|
</div>
|
|
412
|
+
|
|
413
|
+
<div v-if="header.identifier === 'permissions'">
|
|
414
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
415
|
+
</div>
|
|
338
416
|
</template>
|
|
339
417
|
|
|
340
418
|
<template #afterRowContent="{element, rowIndex}">
|
|
@@ -352,18 +430,34 @@ export const MultipleCollapseStrategy = {
|
|
|
352
430
|
};
|
|
353
431
|
export const DefaultCollapseOpen = {
|
|
354
432
|
render: (args) => ({
|
|
355
|
-
components: { AntTable, AntSwitch },
|
|
433
|
+
components: { AntTable, AntSwitch, AntCheckboxGroup, AntButton },
|
|
356
434
|
setup() {
|
|
357
435
|
const selected = ref();
|
|
358
|
-
|
|
436
|
+
const data = ref(args.data.splice(0, 5));
|
|
437
|
+
const checkboxes = [{
|
|
438
|
+
label: "Read",
|
|
439
|
+
value: "read"
|
|
440
|
+
}, {
|
|
441
|
+
label: "Write",
|
|
442
|
+
value: "write"
|
|
443
|
+
}];
|
|
444
|
+
function addRandomEntry() {
|
|
445
|
+
data.value = [...data.value, getRandomEntry()];
|
|
446
|
+
}
|
|
447
|
+
return { args, data, selected, checkboxes, addRandomEntry };
|
|
359
448
|
},
|
|
360
449
|
template: `
|
|
361
|
-
<div class="h-96 border border-dashed border-base-300">
|
|
362
|
-
<
|
|
450
|
+
<div class="h-96 border border-dashed border-base-300 flex flex-col gap-2">
|
|
451
|
+
<AntButton state="primary" @click="addRandomEntry" filled>Add Random Entry</AntButton>
|
|
452
|
+
<AntTable v-bind="args" :data="data" v-model="selected" :selected-row="selected" @row-click="(val) => selected = val" :rows-collapsed="false" collapse-strategy="multiple">
|
|
363
453
|
<template #cellContent="{element: entry, header}">
|
|
364
454
|
<div v-if="header.identifier === 'employed'">
|
|
365
455
|
<AntSwitch v-model="entry.employed"/>
|
|
366
456
|
</div>
|
|
457
|
+
|
|
458
|
+
<div v-if="header.identifier === 'permissions'">
|
|
459
|
+
<AntCheckboxGroup v-model="entry.permissions" :checkboxes="checkboxes" direction="row"/>
|
|
460
|
+
</div>
|
|
367
461
|
</template>
|
|
368
462
|
|
|
369
463
|
<template #afterRowContent="{element, rowIndex}">
|
|
@@ -13,15 +13,4 @@ Object.keys(_TableHeader).forEach(function (key) {
|
|
|
13
13
|
return _TableHeader[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
});
|
|
17
|
-
var _AntCollapsibleTable = require("./AntCollapsibleTable.types");
|
|
18
|
-
Object.keys(_AntCollapsibleTable).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _AntCollapsibleTable[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _AntCollapsibleTable[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
16
|
});
|