vueless 1.2.15-beta.4 → 1.2.15-beta.6
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/package.json +1 -1
- package/ui.data-list/config.ts +1 -1
- package/ui.data-list/storybook/stories.ts +24 -24
- package/ui.data-list/tests/UDataList.test.ts +7 -7
- package/ui.dropdown-badge/config.ts +1 -1
- package/ui.dropdown-badge/storybook/stories.ts +3 -3
- package/ui.dropdown-badge/tests/UDropdownBadge.test.ts +5 -5
- package/ui.dropdown-button/config.ts +1 -1
- package/ui.dropdown-button/storybook/stories.ts +7 -7
- package/ui.dropdown-button/tests/UDropdownButton.test.ts +5 -5
- package/ui.dropdown-link/config.ts +1 -1
- package/ui.dropdown-link/storybook/stories.ts +3 -3
- package/ui.dropdown-link/tests/UDropdownLink.test.ts +5 -5
- package/ui.form-checkbox-group/UCheckboxGroup.vue +2 -2
- package/ui.form-checkbox-group/config.ts +2 -0
- package/ui.form-checkbox-group/storybook/stories.ts +46 -9
- package/ui.form-checkbox-group/tests/UCheckboxGroup.test.ts +65 -0
- package/ui.form-checkbox-group/types.ts +10 -0
- package/ui.form-listbox/config.ts +1 -1
- package/ui.form-listbox/storybook/stories.ts +25 -25
- package/ui.form-listbox/tests/UListbox.test.ts +6 -6
- package/ui.form-radio-group/URadioGroup.vue +2 -2
- package/ui.form-radio-group/config.ts +2 -0
- package/ui.form-radio-group/storybook/stories.ts +48 -8
- package/ui.form-radio-group/tests/URadioGroup.test.ts +68 -0
- package/ui.form-radio-group/types.ts +18 -4
- package/ui.form-select/config.ts +1 -1
- package/ui.form-select/tests/USelect.test.ts +3 -3
- package/icons/storybook/notifications.svg +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vueless",
|
|
3
|
-
"version": "1.2.15-beta.
|
|
3
|
+
"version": "1.2.15-beta.6",
|
|
4
4
|
"description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
|
|
5
5
|
"author": "Johnny Grid <hello@vueless.com> (https://vueless.com)",
|
|
6
6
|
"homepage": "https://vueless.com",
|
package/ui.data-list/config.ts
CHANGED
|
@@ -30,9 +30,9 @@ export default {
|
|
|
30
30
|
component: UDataList,
|
|
31
31
|
args: {
|
|
32
32
|
list: [
|
|
33
|
-
{ label: "Expenses",
|
|
34
|
-
{ label: "Revenue Streams",
|
|
35
|
-
{ label: "Departments",
|
|
33
|
+
{ label: "Expenses", value: 1 },
|
|
34
|
+
{ label: "Revenue Streams", value: 2 },
|
|
35
|
+
{ label: "Departments", value: 3 },
|
|
36
36
|
],
|
|
37
37
|
},
|
|
38
38
|
argTypes: {
|
|
@@ -87,29 +87,29 @@ Nesting.args = {
|
|
|
87
87
|
list: [
|
|
88
88
|
{
|
|
89
89
|
label: "Expenses",
|
|
90
|
-
|
|
90
|
+
value: 1,
|
|
91
91
|
children: [
|
|
92
|
-
{ label: "Office Supplies",
|
|
93
|
-
{ label: "Travel & Lodging",
|
|
94
|
-
{ label: "Utilities",
|
|
92
|
+
{ label: "Office Supplies", value: 1.1 },
|
|
93
|
+
{ label: "Travel & Lodging", value: 1.2 },
|
|
94
|
+
{ label: "Utilities", value: 1.3 },
|
|
95
95
|
],
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
98
|
label: "Revenue Streams",
|
|
99
|
-
|
|
99
|
+
value: 2,
|
|
100
100
|
children: [
|
|
101
|
-
{ label: "Product Sales",
|
|
102
|
-
{ label: "Subscription Services",
|
|
103
|
-
{ label: "Consulting",
|
|
101
|
+
{ label: "Product Sales", value: 2.1 },
|
|
102
|
+
{ label: "Subscription Services", value: 2.2 },
|
|
103
|
+
{ label: "Consulting", value: 2.3 },
|
|
104
104
|
],
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
107
|
label: "Departments",
|
|
108
|
-
|
|
108
|
+
value: 3,
|
|
109
109
|
children: [
|
|
110
|
-
{ label: "Engineering",
|
|
111
|
-
{ label: "Marketing",
|
|
112
|
-
{ label: "Finance",
|
|
110
|
+
{ label: "Engineering", value: 3.1 },
|
|
111
|
+
{ label: "Marketing", value: 3.2 },
|
|
112
|
+
{ label: "Finance", value: 3.3 },
|
|
113
113
|
],
|
|
114
114
|
},
|
|
115
115
|
],
|
|
@@ -159,17 +159,17 @@ DragSlot.args = {
|
|
|
159
159
|
list: [
|
|
160
160
|
{
|
|
161
161
|
label: "John Doe (Engineering)",
|
|
162
|
-
|
|
162
|
+
value: 1,
|
|
163
163
|
avatar: "https://cdn-icons-png.flaticon.com/128/1999/1999625.png",
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
166
|
label: "Michael Johnson (Finance)",
|
|
167
|
-
|
|
167
|
+
value: 2,
|
|
168
168
|
avatar: "https://cdn-icons-png.flaticon.com/128/4140/4140057.png",
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
171
|
label: "Emma Smith (Marketing)",
|
|
172
|
-
|
|
172
|
+
value: 3,
|
|
173
173
|
avatar: "https://cdn-icons-png.flaticon.com/128/4140/4140047.png",
|
|
174
174
|
},
|
|
175
175
|
],
|
|
@@ -183,18 +183,18 @@ DragSlot.args = {
|
|
|
183
183
|
export const ActionsSlot = DefaultTemplate.bind({});
|
|
184
184
|
ActionsSlot.args = {
|
|
185
185
|
list: [
|
|
186
|
-
{ label: "Expenses",
|
|
186
|
+
{ label: "Expenses", value: 1 },
|
|
187
187
|
{
|
|
188
188
|
label: "Revenue Streams",
|
|
189
|
-
|
|
189
|
+
value: 2,
|
|
190
190
|
actions: false,
|
|
191
191
|
children: [
|
|
192
|
-
{ label: "Product Sales",
|
|
193
|
-
{ label: "Subscription Services",
|
|
194
|
-
{ label: "Consulting",
|
|
192
|
+
{ label: "Product Sales", value: 2.1 },
|
|
193
|
+
{ label: "Subscription Services", value: 2.2 },
|
|
194
|
+
{ label: "Consulting", value: 2.3, actions: false },
|
|
195
195
|
],
|
|
196
196
|
},
|
|
197
|
-
{ label: "Departments",
|
|
197
|
+
{ label: "Departments", value: 3, crossed: true },
|
|
198
198
|
],
|
|
199
199
|
slotTemplate: `
|
|
200
200
|
<template #actions="{ item }">
|
|
@@ -10,21 +10,21 @@ import type { Props, DataListItem } from "../types";
|
|
|
10
10
|
|
|
11
11
|
describe("UDataList.vue", () => {
|
|
12
12
|
const defaultList: DataListItem[] = [
|
|
13
|
-
{
|
|
14
|
-
{
|
|
15
|
-
{
|
|
13
|
+
{ value: 1, label: "Item 1" },
|
|
14
|
+
{ value: 2, label: "Item 2", crossed: true },
|
|
15
|
+
{ value: 3, label: "Item 3", actions: false },
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
const nestedList: DataListItem[] = [
|
|
19
19
|
{
|
|
20
|
-
|
|
20
|
+
value: 1,
|
|
21
21
|
label: "Parent 1",
|
|
22
22
|
children: [
|
|
23
|
-
{
|
|
24
|
-
{
|
|
23
|
+
{ value: 11, label: "Child 1.1" },
|
|
24
|
+
{ value: 12, label: "Child 1.2" },
|
|
25
25
|
],
|
|
26
26
|
},
|
|
27
|
-
{
|
|
27
|
+
{ value: 2, label: "Parent 2" },
|
|
28
28
|
];
|
|
29
29
|
|
|
30
30
|
describe("Props", () => {
|
|
@@ -41,9 +41,9 @@ export default {
|
|
|
41
41
|
args: {
|
|
42
42
|
label: "Order Status",
|
|
43
43
|
options: [
|
|
44
|
-
{ label: "Pending",
|
|
45
|
-
{ label: "Delivered",
|
|
46
|
-
{ label: "Cancelled",
|
|
44
|
+
{ label: "Pending", value: "pending" },
|
|
45
|
+
{ label: "Delivered", value: "delivered" },
|
|
46
|
+
{ label: "Cancelled", value: "cancelled" },
|
|
47
47
|
],
|
|
48
48
|
},
|
|
49
49
|
argTypes: {
|
|
@@ -10,9 +10,9 @@ import type { Props } from "../types";
|
|
|
10
10
|
|
|
11
11
|
describe("UDropdownBadge.vue", () => {
|
|
12
12
|
const defaultOptions = [
|
|
13
|
-
{
|
|
14
|
-
{
|
|
15
|
-
{
|
|
13
|
+
{ value: 1, label: "Option 1" },
|
|
14
|
+
{ value: 2, label: "Option 2" },
|
|
15
|
+
{ value: 3, label: "Option 3" },
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
// Props tests
|
|
@@ -43,7 +43,7 @@ describe("UDropdownBadge.vue", () => {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
// Find the selected option's label
|
|
46
|
-
const selectedOption = defaultOptions.find((option) => option.
|
|
46
|
+
const selectedOption = defaultOptions.find((option) => option.value === modelValue);
|
|
47
47
|
|
|
48
48
|
expect(component.findComponent(UBadge).props("label")).toBe(selectedOption?.label);
|
|
49
49
|
});
|
|
@@ -61,7 +61,7 @@ describe("UDropdownBadge.vue", () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
// Find the selected options' labels
|
|
64
|
-
const selectedOptions = defaultOptions.filter((option) => modelValue.includes(option.
|
|
64
|
+
const selectedOptions = defaultOptions.filter((option) => modelValue.includes(option.value));
|
|
65
65
|
const expectedLabel = selectedOptions.map((option) => option.label).join(", ");
|
|
66
66
|
|
|
67
67
|
expect(component.findComponent(UBadge).props("label")).toBe(expectedLabel);
|
|
@@ -41,9 +41,9 @@ export default {
|
|
|
41
41
|
args: {
|
|
42
42
|
label: "Actions",
|
|
43
43
|
options: [
|
|
44
|
-
{ label: "Edit",
|
|
45
|
-
{ label: "Copy",
|
|
46
|
-
{ label: "Remove",
|
|
44
|
+
{ label: "Edit", value: "edit" },
|
|
45
|
+
{ label: "Copy", value: "copy" },
|
|
46
|
+
{ label: "Remove", value: "delete" },
|
|
47
47
|
],
|
|
48
48
|
},
|
|
49
49
|
argTypes: {
|
|
@@ -365,7 +365,7 @@ export const OptionSlots: StoryFn<DefaultUDropdownButtonArgs> = (args) => ({
|
|
|
365
365
|
:options="[
|
|
366
366
|
{
|
|
367
367
|
label: 'John Doe',
|
|
368
|
-
|
|
368
|
+
value: '1',
|
|
369
369
|
role: 'Developer',
|
|
370
370
|
avatar: johnDoe,
|
|
371
371
|
status: 'online',
|
|
@@ -373,7 +373,7 @@ export const OptionSlots: StoryFn<DefaultUDropdownButtonArgs> = (args) => ({
|
|
|
373
373
|
},
|
|
374
374
|
{
|
|
375
375
|
label: 'Jane Smith',
|
|
376
|
-
|
|
376
|
+
value: '2',
|
|
377
377
|
role: 'Designer',
|
|
378
378
|
avatar: emilyDavis,
|
|
379
379
|
status: 'away',
|
|
@@ -381,7 +381,7 @@ export const OptionSlots: StoryFn<DefaultUDropdownButtonArgs> = (args) => ({
|
|
|
381
381
|
},
|
|
382
382
|
{
|
|
383
383
|
label: 'Mike Johnson',
|
|
384
|
-
|
|
384
|
+
value: '3',
|
|
385
385
|
role: 'Product Manager',
|
|
386
386
|
avatar: alexJohnson,
|
|
387
387
|
status: 'offline',
|
|
@@ -389,7 +389,7 @@ export const OptionSlots: StoryFn<DefaultUDropdownButtonArgs> = (args) => ({
|
|
|
389
389
|
},
|
|
390
390
|
{
|
|
391
391
|
label: 'Sarah Wilson',
|
|
392
|
-
|
|
392
|
+
value: '4',
|
|
393
393
|
role: 'QA Engineer',
|
|
394
394
|
avatar: patMorgan,
|
|
395
395
|
status: 'online',
|
|
@@ -10,9 +10,9 @@ import type { Props } from "../types";
|
|
|
10
10
|
|
|
11
11
|
describe("UDropdownButton.vue", () => {
|
|
12
12
|
const defaultOptions = [
|
|
13
|
-
{
|
|
14
|
-
{
|
|
15
|
-
{
|
|
13
|
+
{ value: 1, label: "Option 1" },
|
|
14
|
+
{ value: 2, label: "Option 2" },
|
|
15
|
+
{ value: 3, label: "Option 3" },
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
// Props tests
|
|
@@ -43,7 +43,7 @@ describe("UDropdownButton.vue", () => {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
// Find the selected option's label
|
|
46
|
-
const selectedOption = defaultOptions.find((option) => option.
|
|
46
|
+
const selectedOption = defaultOptions.find((option) => option.value === modelValue);
|
|
47
47
|
|
|
48
48
|
expect(component.findComponent(UButton).props("label")).toBe(selectedOption?.label);
|
|
49
49
|
});
|
|
@@ -61,7 +61,7 @@ describe("UDropdownButton.vue", () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
// Find the selected options' labels
|
|
64
|
-
const selectedOptions = defaultOptions.filter((option) => modelValue.includes(option.
|
|
64
|
+
const selectedOptions = defaultOptions.filter((option) => modelValue.includes(option.value));
|
|
65
65
|
const expectedLabel = selectedOptions.map((option) => option.label).join(", ");
|
|
66
66
|
|
|
67
67
|
expect(component.findComponent(UButton).props("label")).toBe(expectedLabel);
|
|
@@ -40,9 +40,9 @@ export default {
|
|
|
40
40
|
args: {
|
|
41
41
|
label: "Account",
|
|
42
42
|
options: [
|
|
43
|
-
{ label: "Profile",
|
|
44
|
-
{ label: "Settings",
|
|
45
|
-
{ label: "Logout",
|
|
43
|
+
{ label: "Profile", value: "profile" },
|
|
44
|
+
{ label: "Settings", value: "settings" },
|
|
45
|
+
{ label: "Logout", value: "logout" },
|
|
46
46
|
],
|
|
47
47
|
},
|
|
48
48
|
argTypes: {
|
|
@@ -10,9 +10,9 @@ import type { Props } from "../types";
|
|
|
10
10
|
|
|
11
11
|
describe("UDropdownLink.vue", () => {
|
|
12
12
|
const defaultOptions = [
|
|
13
|
-
{
|
|
14
|
-
{
|
|
15
|
-
{
|
|
13
|
+
{ value: 1, label: "Option 1" },
|
|
14
|
+
{ value: 2, label: "Option 2" },
|
|
15
|
+
{ value: 3, label: "Option 3" },
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
// Props tests
|
|
@@ -43,7 +43,7 @@ describe("UDropdownLink.vue", () => {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
// Find the selected option's label
|
|
46
|
-
const selectedOption = defaultOptions.find((option) => option.
|
|
46
|
+
const selectedOption = defaultOptions.find((option) => option.value === modelValue);
|
|
47
47
|
|
|
48
48
|
expect(component.findComponent(ULink).props("label")).toBe(selectedOption?.label);
|
|
49
49
|
});
|
|
@@ -61,7 +61,7 @@ describe("UDropdownLink.vue", () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
// Find the selected options' labels
|
|
64
|
-
const selectedOptions = defaultOptions.filter((option) => modelValue.includes(option.
|
|
64
|
+
const selectedOptions = defaultOptions.filter((option) => modelValue.includes(option.value));
|
|
65
65
|
const expectedLabel = selectedOptions.map((option) => option.label).join(", ");
|
|
66
66
|
|
|
67
67
|
expect(component.findComponent(ULink).props("label")).toBe(expectedLabel);
|
|
@@ -103,10 +103,10 @@ const { getDataTest, groupLabelAttrs, groupCheckboxAttrs, listAttrs } =
|
|
|
103
103
|
v-for="(option, index) in options"
|
|
104
104
|
:key="index"
|
|
105
105
|
:model-value="modelValue"
|
|
106
|
-
:value="option
|
|
106
|
+
:value="option[valueKey]"
|
|
107
107
|
:true-value="option.trueValue"
|
|
108
108
|
:false-value="option.falseValue"
|
|
109
|
-
:label="option
|
|
109
|
+
:label="String(option[labelKey] || undefined)"
|
|
110
110
|
:description="option.description"
|
|
111
111
|
:disabled="disabled"
|
|
112
112
|
v-bind="groupCheckboxAttrs"
|
|
@@ -33,9 +33,9 @@ export default {
|
|
|
33
33
|
args: {
|
|
34
34
|
label: "Select your preferred communication methods:",
|
|
35
35
|
options: [
|
|
36
|
-
{ label: "Email Notifications",
|
|
37
|
-
{ label: "SMS Alerts",
|
|
38
|
-
{ label: "Push Notifications",
|
|
36
|
+
{ label: "Email Notifications", id: "email" },
|
|
37
|
+
{ label: "SMS Alerts", id: "sms" },
|
|
38
|
+
{ label: "Push Notifications", id: "push" },
|
|
39
39
|
],
|
|
40
40
|
},
|
|
41
41
|
argTypes: {
|
|
@@ -108,7 +108,7 @@ export const Options: StoryFn<UCheckboxGroupArgs> = (args: UCheckboxGroupArgs) =
|
|
|
108
108
|
<UAlert
|
|
109
109
|
:description="modelValue"
|
|
110
110
|
size="sm"
|
|
111
|
-
variant="
|
|
111
|
+
variant="soft"
|
|
112
112
|
color="success"
|
|
113
113
|
bordered
|
|
114
114
|
/>
|
|
@@ -144,11 +144,48 @@ export const LabelSlot = DefaultTemplate.bind({});
|
|
|
144
144
|
LabelSlot.args = {
|
|
145
145
|
name: "LabelSlot",
|
|
146
146
|
slotTemplate: `
|
|
147
|
-
<template #label>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
<UIcon name="notifications" size="xs" />
|
|
151
|
-
</URow>
|
|
147
|
+
<template #label="{ label }">
|
|
148
|
+
{{ label }}
|
|
149
|
+
<span class="text-red-500">*</span>
|
|
152
150
|
</template>
|
|
153
151
|
`,
|
|
154
152
|
};
|
|
153
|
+
|
|
154
|
+
export const CustomKeys: StoryFn<UCheckboxGroupArgs> = (args: UCheckboxGroupArgs) => ({
|
|
155
|
+
components: { UCheckboxGroup, UCol, UAlert },
|
|
156
|
+
setup: () => ({ args, modelValue: ref([]) }),
|
|
157
|
+
template: `
|
|
158
|
+
<UCol>
|
|
159
|
+
<UCheckboxGroup v-bind="args" v-model="modelValue" />
|
|
160
|
+
|
|
161
|
+
<UAlert
|
|
162
|
+
:description="modelValue"
|
|
163
|
+
size="sm"
|
|
164
|
+
variant="soft"
|
|
165
|
+
color="success"
|
|
166
|
+
bordered
|
|
167
|
+
/>
|
|
168
|
+
</UCol>
|
|
169
|
+
`,
|
|
170
|
+
});
|
|
171
|
+
CustomKeys.args = {
|
|
172
|
+
name: "CustomKeys",
|
|
173
|
+
label: "Select your preferred features:",
|
|
174
|
+
labelKey: "name",
|
|
175
|
+
valueKey: "id",
|
|
176
|
+
options: [
|
|
177
|
+
{ id: "dark-mode", name: "Dark Mode" },
|
|
178
|
+
{ id: "auto-save", name: "Auto-save" },
|
|
179
|
+
{ id: "notifications", name: "Notifications" },
|
|
180
|
+
{ id: "two-factor", name: "Two-factor Authentication" },
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
CustomKeys.parameters = {
|
|
184
|
+
docs: {
|
|
185
|
+
description: {
|
|
186
|
+
story:
|
|
187
|
+
"Use `labelKey` and `valueKey` props to specify custom keys for label and value in option objects. " +
|
|
188
|
+
"This is useful when working with data from APIs that use different property names.",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
@@ -185,6 +185,71 @@ describe("UCheckboxGroup.vue", () => {
|
|
|
185
185
|
expect(checkbox.attributes("data-test")).toBe(`${dataTestValue}-item-${idx}-label`);
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
|
+
|
|
189
|
+
it("LabelKey – uses custom label key for option labels", () => {
|
|
190
|
+
const customOptions = [
|
|
191
|
+
{ value: "option-1", name: "Option 1" },
|
|
192
|
+
{ value: "option-2", name: "Option 2" },
|
|
193
|
+
{ value: "option-3", name: "Option 3" },
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
const component = mount(UCheckboxGroup, {
|
|
197
|
+
props: {
|
|
198
|
+
options: customOptions,
|
|
199
|
+
labelKey: "name",
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const checkboxes = component.findAllComponents(UCheckbox);
|
|
204
|
+
|
|
205
|
+
checkboxes.forEach((checkbox, index) => {
|
|
206
|
+
expect(checkbox.props("label")).toBe(customOptions[index].name);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("ValueKey – uses custom value key for option values", () => {
|
|
211
|
+
const customOptions = [
|
|
212
|
+
{ id: "option-1", label: "Option 1" },
|
|
213
|
+
{ id: "option-2", label: "Option 2" },
|
|
214
|
+
{ id: "option-3", label: "Option 3" },
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const component = mount(UCheckboxGroup, {
|
|
218
|
+
props: {
|
|
219
|
+
options: customOptions,
|
|
220
|
+
valueKey: "id",
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const checkboxes = component.findAllComponents(UCheckbox);
|
|
225
|
+
|
|
226
|
+
checkboxes.forEach((checkbox, index) => {
|
|
227
|
+
expect(checkbox.props("value")).toBe(customOptions[index].id);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("LabelKey and ValueKey – works with complex objects", async () => {
|
|
232
|
+
const customOptions = [
|
|
233
|
+
{ planId: "basic", title: "Basic Plan" },
|
|
234
|
+
{ planId: "pro", title: "Pro Plan" },
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
const component = mount(UCheckboxGroup, {
|
|
238
|
+
props: {
|
|
239
|
+
options: customOptions,
|
|
240
|
+
labelKey: "title",
|
|
241
|
+
valueKey: "planId",
|
|
242
|
+
modelValue: [],
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const checkboxes = component.findAllComponents(UCheckbox);
|
|
247
|
+
|
|
248
|
+
expect(checkboxes[0].props("label")).toBe("Basic Plan");
|
|
249
|
+
expect(checkboxes[0].props("value")).toBe("basic");
|
|
250
|
+
expect(checkboxes[1].props("label")).toBe("Pro Plan");
|
|
251
|
+
expect(checkboxes[1].props("value")).toBe("pro");
|
|
252
|
+
});
|
|
188
253
|
});
|
|
189
254
|
|
|
190
255
|
describe("Slots", () => {
|
|
@@ -16,6 +16,16 @@ export interface Props {
|
|
|
16
16
|
*/
|
|
17
17
|
options?: UCheckboxOption[];
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Label key in the item object of options.
|
|
21
|
+
*/
|
|
22
|
+
labelKey?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Value key in the item object of options.
|
|
26
|
+
*/
|
|
27
|
+
valueKey?: string;
|
|
28
|
+
|
|
19
29
|
/**
|
|
20
30
|
* Checkbox group label.
|
|
21
31
|
*/
|
|
@@ -37,11 +37,11 @@ export default {
|
|
|
37
37
|
component: UListbox,
|
|
38
38
|
args: {
|
|
39
39
|
options: [
|
|
40
|
-
{ label: "New York",
|
|
41
|
-
{ label: "Los Angeles",
|
|
42
|
-
{ label: "Chicago",
|
|
43
|
-
{ label: "Houston",
|
|
44
|
-
{ label: "San Francisco",
|
|
40
|
+
{ label: "New York", value: 1 },
|
|
41
|
+
{ label: "Los Angeles", value: 2 },
|
|
42
|
+
{ label: "Chicago", value: 3 },
|
|
43
|
+
{ label: "Houston", value: 4 },
|
|
44
|
+
{ label: "San Francisco", value: 5 },
|
|
45
45
|
],
|
|
46
46
|
},
|
|
47
47
|
argTypes: {
|
|
@@ -176,12 +176,12 @@ GroupedOptions.parameters = {
|
|
|
176
176
|
export const Divider = DefaultTemplate.bind({});
|
|
177
177
|
Divider.args = {
|
|
178
178
|
options: [
|
|
179
|
-
{ label: "North America",
|
|
180
|
-
{ label: "South America",
|
|
179
|
+
{ label: "North America", value: "1" },
|
|
180
|
+
{ label: "South America", value: "2" },
|
|
181
181
|
{ divider: true },
|
|
182
|
-
{ label: "Europe",
|
|
182
|
+
{ label: "Europe", value: "3" },
|
|
183
183
|
{ divider: true },
|
|
184
|
-
{ label: "Asia",
|
|
184
|
+
{ label: "Asia", value: "4" },
|
|
185
185
|
],
|
|
186
186
|
};
|
|
187
187
|
Divider.parameters = {
|
|
@@ -198,12 +198,12 @@ export const OptionSettings = DefaultTemplate.bind({});
|
|
|
198
198
|
OptionSettings.args = {
|
|
199
199
|
multiple: true,
|
|
200
200
|
options: [
|
|
201
|
-
{ label: "New York",
|
|
202
|
-
{ label: "Kyiv",
|
|
203
|
-
{ label: "Los Angeles",
|
|
201
|
+
{ label: "New York", value: "1", disabled: true },
|
|
202
|
+
{ label: "Kyiv", value: "2", disabled: true },
|
|
203
|
+
{ label: "Los Angeles", value: "3", isHidden: true },
|
|
204
204
|
{
|
|
205
205
|
label: "Chicago",
|
|
206
|
-
|
|
206
|
+
value: "4",
|
|
207
207
|
onClick: (option: Option) =>
|
|
208
208
|
alert("onClick function for the third option: " + JSON.stringify(option)),
|
|
209
209
|
},
|
|
@@ -244,7 +244,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
244
244
|
:options="[
|
|
245
245
|
{
|
|
246
246
|
label: 'John Doe',
|
|
247
|
-
|
|
247
|
+
value: '1',
|
|
248
248
|
role: 'Developer',
|
|
249
249
|
avatar: johnDoe,
|
|
250
250
|
status: 'online',
|
|
@@ -252,7 +252,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
252
252
|
},
|
|
253
253
|
{
|
|
254
254
|
label: 'Jane Smith',
|
|
255
|
-
|
|
255
|
+
value: '2',
|
|
256
256
|
role: 'Designer',
|
|
257
257
|
avatar: emilyDavis,
|
|
258
258
|
status: 'away',
|
|
@@ -260,7 +260,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
260
260
|
},
|
|
261
261
|
{
|
|
262
262
|
label: 'Mike Johnson',
|
|
263
|
-
|
|
263
|
+
value: '3',
|
|
264
264
|
role: 'Product Manager',
|
|
265
265
|
avatar: alexJohnson,
|
|
266
266
|
status: 'offline',
|
|
@@ -268,7 +268,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
268
268
|
},
|
|
269
269
|
{
|
|
270
270
|
label: 'Sarah Wilson',
|
|
271
|
-
|
|
271
|
+
value: '4',
|
|
272
272
|
role: 'QA Engineer',
|
|
273
273
|
avatar: patMorgan,
|
|
274
274
|
status: 'online',
|
|
@@ -287,7 +287,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
287
287
|
:options="[
|
|
288
288
|
{
|
|
289
289
|
label: 'John Doe',
|
|
290
|
-
|
|
290
|
+
value: '1',
|
|
291
291
|
role: 'Developer',
|
|
292
292
|
avatar: johnDoe,
|
|
293
293
|
status: 'online',
|
|
@@ -295,7 +295,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
295
295
|
},
|
|
296
296
|
{
|
|
297
297
|
label: 'Jane Smith',
|
|
298
|
-
|
|
298
|
+
value: '2',
|
|
299
299
|
role: 'Designer',
|
|
300
300
|
avatar: emilyDavis,
|
|
301
301
|
status: 'away',
|
|
@@ -303,7 +303,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
303
303
|
},
|
|
304
304
|
{
|
|
305
305
|
label: 'Mike Johnson',
|
|
306
|
-
|
|
306
|
+
value: '3',
|
|
307
307
|
role: 'Product Manager',
|
|
308
308
|
avatar: alexJohnson,
|
|
309
309
|
status: 'offline',
|
|
@@ -311,7 +311,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
311
311
|
},
|
|
312
312
|
{
|
|
313
313
|
label: 'Sarah Wilson',
|
|
314
|
-
|
|
314
|
+
value: '4',
|
|
315
315
|
role: 'QA Engineer',
|
|
316
316
|
avatar: patMorgan,
|
|
317
317
|
status: 'online',
|
|
@@ -341,7 +341,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
341
341
|
:options="[
|
|
342
342
|
{
|
|
343
343
|
label: 'John Doe',
|
|
344
|
-
|
|
344
|
+
value: '1',
|
|
345
345
|
role: 'Developer',
|
|
346
346
|
avatar: johnDoe,
|
|
347
347
|
status: 'online',
|
|
@@ -349,7 +349,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
349
349
|
},
|
|
350
350
|
{
|
|
351
351
|
label: 'Jane Smith',
|
|
352
|
-
|
|
352
|
+
value: '2',
|
|
353
353
|
role: 'Designer',
|
|
354
354
|
avatar: emilyDavis,
|
|
355
355
|
status: 'away',
|
|
@@ -357,7 +357,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
357
357
|
},
|
|
358
358
|
{
|
|
359
359
|
label: 'Mike Johnson',
|
|
360
|
-
|
|
360
|
+
value: '3',
|
|
361
361
|
role: 'Product Manager',
|
|
362
362
|
avatar: alexJohnson,
|
|
363
363
|
status: 'offline',
|
|
@@ -365,7 +365,7 @@ export const OptionSlots: StoryFn<DefaultUListboxArgs> = (args) => ({
|
|
|
365
365
|
},
|
|
366
366
|
{
|
|
367
367
|
label: 'Sarah Wilson',
|
|
368
|
-
|
|
368
|
+
value: '4',
|
|
369
369
|
role: 'QA Engineer',
|
|
370
370
|
avatar: patMorgan,
|
|
371
371
|
status: 'online',
|
|
@@ -9,9 +9,9 @@ import type { Props } from "../types";
|
|
|
9
9
|
|
|
10
10
|
describe("UListbox.vue", () => {
|
|
11
11
|
const defaultOptions = [
|
|
12
|
-
{ label: "Option 1",
|
|
13
|
-
{ label: "Option 2",
|
|
14
|
-
{ label: "Option 3",
|
|
12
|
+
{ label: "Option 1", value: "option1" },
|
|
13
|
+
{ label: "Option 2", value: "option2" },
|
|
14
|
+
{ label: "Option 3", value: "option3" },
|
|
15
15
|
];
|
|
16
16
|
|
|
17
17
|
const highlightedClass = "bg-primary/5";
|
|
@@ -140,10 +140,10 @@ describe("UListbox.vue", () => {
|
|
|
140
140
|
|
|
141
141
|
await options[1].trigger("click");
|
|
142
142
|
|
|
143
|
-
expect(component.emitted("update:modelValue")![0][0]).toEqual([defaultOptions[0].
|
|
143
|
+
expect(component.emitted("update:modelValue")![0][0]).toEqual([defaultOptions[0].value]);
|
|
144
144
|
expect(component.emitted("update:modelValue")![1][0]).toEqual([
|
|
145
|
-
defaultOptions[0].
|
|
146
|
-
defaultOptions[1].
|
|
145
|
+
defaultOptions[0].value,
|
|
146
|
+
defaultOptions[1].value,
|
|
147
147
|
]);
|
|
148
148
|
});
|
|
149
149
|
|
|
@@ -86,8 +86,8 @@ const { getDataTest, groupLabelAttrs, listAttrs, groupRadioAttrs } = useUI<Confi
|
|
|
86
86
|
v-for="(option, index) in options"
|
|
87
87
|
:key="index"
|
|
88
88
|
:model-value="selectedItem"
|
|
89
|
-
:value="option
|
|
90
|
-
:label="option
|
|
89
|
+
:value="option[valueKey]"
|
|
90
|
+
:label="String(option[labelKey] || undefined)"
|
|
91
91
|
:description="option.description"
|
|
92
92
|
:disabled="disabled"
|
|
93
93
|
v-bind="groupRadioAttrs"
|
|
@@ -8,10 +8,11 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import URadioGroup from "../../ui.form-radio-group/URadioGroup.vue";
|
|
10
10
|
import URadio from "../../ui.form-radio/URadio.vue";
|
|
11
|
+
import UAlert from "../../ui.text-alert/UAlert.vue";
|
|
11
12
|
import UCol from "../../ui.container-col/UCol.vue";
|
|
13
|
+
import URow from "../../ui.container-row/URow.vue";
|
|
12
14
|
import UBadge from "../../ui.text-badge/UBadge.vue";
|
|
13
15
|
import UText from "../../ui.text-block/UText.vue";
|
|
14
|
-
import URow from "../../ui.container-row/URow.vue";
|
|
15
16
|
|
|
16
17
|
import type { Meta, StoryFn } from "@storybook/vue3-vite";
|
|
17
18
|
import type { Props } from "../types";
|
|
@@ -28,9 +29,9 @@ export default {
|
|
|
28
29
|
args: {
|
|
29
30
|
label: "Select your preferred delivery option:",
|
|
30
31
|
options: [
|
|
31
|
-
{
|
|
32
|
-
{
|
|
33
|
-
{
|
|
32
|
+
{ id: "standard", label: "Standard Shipping (3-5 business days)" },
|
|
33
|
+
{ id: "express", label: "Express Shipping (1-2 business days)" },
|
|
34
|
+
{ id: "pickup", label: "In-Store Pickup (Available same day)" },
|
|
34
35
|
],
|
|
35
36
|
},
|
|
36
37
|
argTypes: {
|
|
@@ -54,16 +55,17 @@ const DefaultTemplate: StoryFn<URadioGroupArgs> = (args: URadioGroupArgs) => ({
|
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
const EnumTemplate: StoryFn<URadioGroupArgs> = (args: URadioGroupArgs, { argTypes }) => ({
|
|
57
|
-
components: { URadioGroup,
|
|
58
|
+
components: { URadioGroup, URow },
|
|
58
59
|
setup: () => ({ args, argTypes, getArgs }),
|
|
59
60
|
template: `
|
|
60
|
-
<
|
|
61
|
+
<URow>
|
|
61
62
|
<URadioGroup
|
|
62
63
|
v-for="option in argTypes?.[args.enum]?.options"
|
|
63
64
|
v-bind="getArgs(args, option)"
|
|
64
65
|
:key="option"
|
|
66
|
+
:name="option"
|
|
65
67
|
/>
|
|
66
|
-
</
|
|
68
|
+
</URow>
|
|
67
69
|
`,
|
|
68
70
|
});
|
|
69
71
|
|
|
@@ -125,8 +127,46 @@ LabelSlot.args = {
|
|
|
125
127
|
name: "LabelSlot",
|
|
126
128
|
slotTemplate: `
|
|
127
129
|
<template #label="{ label }">
|
|
128
|
-
<span class="text-red-500">*</span>
|
|
129
130
|
{{ label }}
|
|
131
|
+
<span class="text-red-500">*</span>
|
|
130
132
|
</template>
|
|
131
133
|
`,
|
|
132
134
|
};
|
|
135
|
+
|
|
136
|
+
export const CustomKeys: StoryFn<URadioGroupArgs> = (args: URadioGroupArgs) => ({
|
|
137
|
+
components: { URadioGroup, UCol, UAlert },
|
|
138
|
+
setup: () => ({ args }),
|
|
139
|
+
template: `
|
|
140
|
+
<UCol>
|
|
141
|
+
<URadioGroup v-bind="args" v-model="args.modelValue" />
|
|
142
|
+
|
|
143
|
+
<UAlert
|
|
144
|
+
:description="args.modelValue"
|
|
145
|
+
size="sm"
|
|
146
|
+
variant="soft"
|
|
147
|
+
color="success"
|
|
148
|
+
bordered
|
|
149
|
+
/>
|
|
150
|
+
</UCol>
|
|
151
|
+
`,
|
|
152
|
+
});
|
|
153
|
+
CustomKeys.args = {
|
|
154
|
+
name: "CustomKeys",
|
|
155
|
+
label: "Select your subscription plan:",
|
|
156
|
+
labelKey: "title",
|
|
157
|
+
valueKey: "id",
|
|
158
|
+
options: [
|
|
159
|
+
{ id: "basic", title: "Basic Plan - $9.99/month" },
|
|
160
|
+
{ id: "pro", title: "Pro Plan - $19.99/month" },
|
|
161
|
+
{ id: "enterprise", title: "Enterprise Plan - $49.99/month" },
|
|
162
|
+
],
|
|
163
|
+
};
|
|
164
|
+
CustomKeys.parameters = {
|
|
165
|
+
docs: {
|
|
166
|
+
description: {
|
|
167
|
+
story:
|
|
168
|
+
"Use `labelKey` and `valueKey` props to specify custom keys for label and value in option objects. " +
|
|
169
|
+
"This is useful when working with data from APIs that use different property names.",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
};
|
|
@@ -194,6 +194,74 @@ describe("URadioGroup.vue", () => {
|
|
|
194
194
|
expect(radio.attributes("data-test")).toBe(`${dataTestValue}-item-${idx}-label`);
|
|
195
195
|
});
|
|
196
196
|
});
|
|
197
|
+
|
|
198
|
+
it("LabelKey – uses custom label key for option labels", () => {
|
|
199
|
+
const customOptions = [
|
|
200
|
+
{ value: "option-1", name: "Option 1" },
|
|
201
|
+
{ value: "option-2", name: "Option 2" },
|
|
202
|
+
{ value: "option-3", name: "Option 3" },
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
const component = mount(URadioGroup, {
|
|
206
|
+
props: {
|
|
207
|
+
name: defaultName,
|
|
208
|
+
options: customOptions,
|
|
209
|
+
labelKey: "name",
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const radios = component.findAllComponents(URadio);
|
|
214
|
+
|
|
215
|
+
radios.forEach((radio, index) => {
|
|
216
|
+
expect(radio.props("label")).toBe(customOptions[index].name);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("ValueKey – uses custom value key for option values", () => {
|
|
221
|
+
const customOptions = [
|
|
222
|
+
{ id: "option-1", label: "Option 1" },
|
|
223
|
+
{ id: "option-2", label: "Option 2" },
|
|
224
|
+
{ id: "option-3", label: "Option 3" },
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
const component = mount(URadioGroup, {
|
|
228
|
+
props: {
|
|
229
|
+
name: defaultName,
|
|
230
|
+
options: customOptions,
|
|
231
|
+
valueKey: "id",
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const radios = component.findAllComponents(URadio);
|
|
236
|
+
|
|
237
|
+
radios.forEach((radio, index) => {
|
|
238
|
+
expect(radio.props("value")).toBe(customOptions[index].id);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("LabelKey and ValueKey – works with complex objects", async () => {
|
|
243
|
+
const customOptions = [
|
|
244
|
+
{ planId: "basic", title: "Basic Plan" },
|
|
245
|
+
{ planId: "pro", title: "Pro Plan" },
|
|
246
|
+
];
|
|
247
|
+
|
|
248
|
+
const component = mount(URadioGroup, {
|
|
249
|
+
props: {
|
|
250
|
+
name: defaultName,
|
|
251
|
+
options: customOptions,
|
|
252
|
+
labelKey: "title",
|
|
253
|
+
valueKey: "planId",
|
|
254
|
+
modelValue: "",
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const radios = component.findAllComponents(URadio);
|
|
259
|
+
|
|
260
|
+
expect(radios[0].props("label")).toBe("Basic Plan");
|
|
261
|
+
expect(radios[0].props("value")).toBe("basic");
|
|
262
|
+
expect(radios[1].props("label")).toBe("Pro Plan");
|
|
263
|
+
expect(radios[1].props("value")).toBe("pro");
|
|
264
|
+
});
|
|
197
265
|
});
|
|
198
266
|
|
|
199
267
|
describe("Slots", () => {
|
|
@@ -4,12 +4,16 @@ import type { UnknownObject, UnknownArray, ComponentConfig } from "../types";
|
|
|
4
4
|
|
|
5
5
|
export type Config = typeof defaultConfig;
|
|
6
6
|
|
|
7
|
-
export interface
|
|
8
|
-
value
|
|
9
|
-
label
|
|
7
|
+
export interface BaseOption {
|
|
8
|
+
value?: string | number | boolean | UnknownArray | UnknownObject;
|
|
9
|
+
label?: string;
|
|
10
10
|
description?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface Option extends BaseOption {
|
|
14
|
+
[key: string]: string | number | boolean | UnknownArray | UnknownObject | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
export type SetRadioGroupSelectedItem =
|
|
14
18
|
| ((value: string | number | boolean | UnknownArray | UnknownObject) => void)
|
|
15
19
|
| null;
|
|
@@ -23,7 +27,17 @@ export interface Props {
|
|
|
23
27
|
/**
|
|
24
28
|
* Radio group options.
|
|
25
29
|
*/
|
|
26
|
-
options?:
|
|
30
|
+
options?: Option[];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Label key in the item object of options.
|
|
34
|
+
*/
|
|
35
|
+
labelKey?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Value key in the item object of options.
|
|
39
|
+
*/
|
|
40
|
+
valueKey?: string;
|
|
27
41
|
|
|
28
42
|
/**
|
|
29
43
|
* Radio group label.
|
package/ui.form-select/config.ts
CHANGED
|
@@ -11,9 +11,9 @@ import type { Props } from "../types";
|
|
|
11
11
|
|
|
12
12
|
describe("USelect.vue", () => {
|
|
13
13
|
const defaultOptions = [
|
|
14
|
-
{ label: "Option 1",
|
|
15
|
-
{ label: "Option 2",
|
|
16
|
-
{ label: "Option 3",
|
|
14
|
+
{ label: "Option 1", value: "option1" },
|
|
15
|
+
{ label: "Option 2", value: "option2" },
|
|
16
|
+
{ label: "Option 3", value: "option3" },
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
describe("Props", () => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M154.02-194.02v-68.13h77.85v-298.02q0-86.08 50.34-154.77 50.33-68.69 133.72-86.41v-20.56q0-26.8 18.69-45.55 18.69-18.76 45.38-18.76t45.38 18.76q18.69 18.75 18.69 45.55v20.56q83.39 17.48 133.84 86.25 50.46 68.77 50.46 154.93v298.02h77.85v68.13h-652.2ZM480-501.04Zm.12 429.17q-33.83 0-57.93-24.13t-24.1-58.02h164.06q0 33.95-24.15 58.05-24.15 24.1-57.88 24.1ZM300-262.15h360v-298.02q0-74.76-52.5-127.38Q555-740.17 480-740.17t-127.5 52.62Q300-634.93 300-560.17v298.02Z"/></svg>
|