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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "1.2.15-beta.4",
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",
@@ -53,7 +53,7 @@ export default /*tw*/ {
53
53
  defaults: {
54
54
  size: "md",
55
55
  labelKey: "label",
56
- valueKey: "id",
56
+ valueKey: "value",
57
57
  animationDuration: 200,
58
58
  /* icons */
59
59
  dragIcon: "drag_indicator",
@@ -30,9 +30,9 @@ export default {
30
30
  component: UDataList,
31
31
  args: {
32
32
  list: [
33
- { label: "Expenses", id: 1 },
34
- { label: "Revenue Streams", id: 2 },
35
- { label: "Departments", id: 3 },
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
- id: 1,
90
+ value: 1,
91
91
  children: [
92
- { label: "Office Supplies", id: 1.1 },
93
- { label: "Travel & Lodging", id: 1.2 },
94
- { label: "Utilities", id: 1.3 },
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
- id: 2,
99
+ value: 2,
100
100
  children: [
101
- { label: "Product Sales", id: 2.1 },
102
- { label: "Subscription Services", id: 2.2 },
103
- { label: "Consulting", id: 2.3 },
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
- id: 3,
108
+ value: 3,
109
109
  children: [
110
- { label: "Engineering", id: 3.1 },
111
- { label: "Marketing", id: 3.2 },
112
- { label: "Finance", id: 3.3 },
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
- id: 1,
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
- id: 2,
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
- id: 3,
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", id: 1 },
186
+ { label: "Expenses", value: 1 },
187
187
  {
188
188
  label: "Revenue Streams",
189
- id: 2,
189
+ value: 2,
190
190
  actions: false,
191
191
  children: [
192
- { label: "Product Sales", id: 2.1 },
193
- { label: "Subscription Services", id: 2.2 },
194
- { label: "Consulting", id: 2.3, actions: false },
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", id: 3, crossed: true },
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
- { id: 1, label: "Item 1" },
14
- { id: 2, label: "Item 2", crossed: true },
15
- { id: 3, label: "Item 3", actions: false },
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
- id: 1,
20
+ value: 1,
21
21
  label: "Parent 1",
22
22
  children: [
23
- { id: 11, label: "Child 1.1" },
24
- { id: 12, label: "Child 1.2" },
23
+ { value: 11, label: "Child 1.1" },
24
+ { value: 12, label: "Child 1.2" },
25
25
  ],
26
26
  },
27
- { id: 2, label: "Parent 2" },
27
+ { value: 2, label: "Parent 2" },
28
28
  ];
29
29
 
30
30
  describe("Props", () => {
@@ -37,7 +37,7 @@ export default /*tw*/ {
37
37
  size: "md",
38
38
  variant: "solid",
39
39
  labelKey: "label",
40
- valueKey: "id",
40
+ valueKey: "value",
41
41
  groupLabelKey: "label",
42
42
  yPosition: "bottom",
43
43
  xPosition: "left",
@@ -41,9 +41,9 @@ export default {
41
41
  args: {
42
42
  label: "Order Status",
43
43
  options: [
44
- { label: "Pending", id: "pending" },
45
- { label: "Delivered", id: "delivered" },
46
- { label: "Cancelled", id: "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
- { id: 1, label: "Option 1" },
14
- { id: 2, label: "Option 2" },
15
- { id: 3, label: "Option 3" },
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.id === modelValue);
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.id));
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);
@@ -50,7 +50,7 @@ export default /*tw*/ {
50
50
  size: "md",
51
51
  variant: "solid",
52
52
  labelKey: "label",
53
- valueKey: "id",
53
+ valueKey: "value",
54
54
  groupLabelKey: "label",
55
55
  yPosition: "bottom",
56
56
  xPosition: "left",
@@ -41,9 +41,9 @@ export default {
41
41
  args: {
42
42
  label: "Actions",
43
43
  options: [
44
- { label: "Edit", id: "edit" },
45
- { label: "Copy", id: "copy" },
46
- { label: "Remove", id: "delete" },
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
- id: '1',
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
- id: '2',
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
- id: '3',
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
- id: '4',
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
- { id: 1, label: "Option 1" },
14
- { id: 2, label: "Option 2" },
15
- { id: 3, label: "Option 3" },
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.id === modelValue);
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.id));
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);
@@ -32,7 +32,7 @@ export default /*tw*/ {
32
32
  color: "primary",
33
33
  size: "md",
34
34
  labelKey: "label",
35
- valueKey: "id",
35
+ valueKey: "value",
36
36
  groupLabelKey: "label",
37
37
  yPosition: "bottom",
38
38
  xPosition: "left",
@@ -40,9 +40,9 @@ export default {
40
40
  args: {
41
41
  label: "Account",
42
42
  options: [
43
- { label: "Profile", id: "profile" },
44
- { label: "Settings", id: "settings" },
45
- { label: "Logout", id: "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
- { id: 1, label: "Option 1" },
14
- { id: 2, label: "Option 2" },
15
- { id: 3, label: "Option 3" },
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.id === modelValue);
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.id));
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.value"
106
+ :value="option[valueKey]"
107
107
  :true-value="option.trueValue"
108
108
  :false-value="option.falseValue"
109
- :label="option.label"
109
+ :label="String(option[labelKey] || undefined)"
110
110
  :description="option.description"
111
111
  :disabled="disabled"
112
112
  v-bind="groupCheckboxAttrs"
@@ -14,6 +14,8 @@ export default /*tw*/ {
14
14
  defaults: {
15
15
  color: "primary",
16
16
  size: "md",
17
+ labelKey: "label",
18
+ valueKey: "value",
17
19
  disabled: false,
18
20
  },
19
21
  };
@@ -33,9 +33,9 @@ export default {
33
33
  args: {
34
34
  label: "Select your preferred communication methods:",
35
35
  options: [
36
- { label: "Email Notifications", value: "email" },
37
- { label: "SMS Alerts", value: "sms" },
38
- { label: "Push Notifications", value: "push" },
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="ghost"
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
- <URow gap="2xs" align="center">
149
- <UText>Select your <ULink label="notification preferences" /></UText>
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
  */
@@ -100,7 +100,7 @@ export default /*tw*/ {
100
100
  color: "primary",
101
101
  size: "md",
102
102
  labelKey: "label",
103
- valueKey: "id",
103
+ valueKey: "value",
104
104
  visibleOptions: undefined,
105
105
  debounce: 0,
106
106
  optionsLimit: 0,
@@ -37,11 +37,11 @@ export default {
37
37
  component: UListbox,
38
38
  args: {
39
39
  options: [
40
- { label: "New York", id: 1 },
41
- { label: "Los Angeles", id: 2 },
42
- { label: "Chicago", id: 3 },
43
- { label: "Houston", id: 4 },
44
- { label: "San Francisco", id: 5 },
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", id: "1" },
180
- { label: "South America", id: "2" },
179
+ { label: "North America", value: "1" },
180
+ { label: "South America", value: "2" },
181
181
  { divider: true },
182
- { label: "Europe", id: "3" },
182
+ { label: "Europe", value: "3" },
183
183
  { divider: true },
184
- { label: "Asia", id: "4" },
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", id: "1", disabled: true },
202
- { label: "Kyiv", id: "2", disabled: true },
203
- { label: "Los Angeles", id: "3", isHidden: true },
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
- id: "4",
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
- id: '1',
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
- id: '2',
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
- id: '3',
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
- id: '4',
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
- id: '1',
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
- id: '2',
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
- id: '3',
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
- id: '4',
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
- id: '1',
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
- id: '2',
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
- id: '3',
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
- id: '4',
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", id: "option1" },
13
- { label: "Option 2", id: "option2" },
14
- { label: "Option 3", id: "option3" },
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].id]);
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].id,
146
- defaultOptions[1].id,
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.value"
90
- :label="option.label"
89
+ :value="option[valueKey]"
90
+ :label="String(option[labelKey] || undefined)"
91
91
  :description="option.description"
92
92
  :disabled="disabled"
93
93
  v-bind="groupRadioAttrs"
@@ -14,6 +14,8 @@ export default /*tw*/ {
14
14
  defaults: {
15
15
  color: "primary",
16
16
  size: "md",
17
+ labelKey: "label",
18
+ valueKey: "value",
17
19
  disabled: false,
18
20
  },
19
21
  };
@@ -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
- { value: "standard", label: "Standard Shipping (3-5 business days)" },
32
- { value: "express", label: "Express Shipping (1-2 business days)" },
33
- { value: "pickup", label: "In-Store Pickup (Available same day)" },
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, UCol },
58
+ components: { URadioGroup, URow },
58
59
  setup: () => ({ args, argTypes, getArgs }),
59
60
  template: `
60
- <UCol>
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
- </UCol>
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 URadioGroupOption {
8
- value: string | number | boolean | UnknownArray | UnknownObject;
9
- label: string;
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?: URadioGroupOption[];
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.
@@ -138,7 +138,7 @@ export default /*tw*/ {
138
138
  size: "md",
139
139
  labelAlign: "topInside",
140
140
  openDirection: "auto",
141
- valueKey: "id",
141
+ valueKey: "value",
142
142
  labelKey: "label",
143
143
  groupLabelKey: "label",
144
144
  multipleVariant: "inline",
@@ -11,9 +11,9 @@ import type { Props } from "../types";
11
11
 
12
12
  describe("USelect.vue", () => {
13
13
  const defaultOptions = [
14
- { label: "Option 1", id: "option1" },
15
- { label: "Option 2", id: "option2" },
16
- { label: "Option 3", id: "option3" },
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>