vueless 0.0.716 → 0.0.718
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/constants.js +0 -1
- package/package.json +1 -1
- package/types.ts +0 -2
- package/ui.button-toggle/UToggle.vue +72 -47
- package/ui.button-toggle/config.ts +34 -1
- package/ui.button-toggle/storybook/stories.ts +55 -35
- package/ui.button-toggle/types.ts +9 -0
- package/ui.form-input/UInput.vue +1 -5
- package/ui.button-toggle-item/UToggleItem.vue +0 -145
- package/ui.button-toggle-item/config.ts +0 -40
- package/ui.button-toggle-item/constants.ts +0 -5
- package/ui.button-toggle-item/storybook/docs.mdx +0 -16
- package/ui.button-toggle-item/storybook/stories.ts +0 -90
- package/ui.button-toggle-item/types.ts +0 -60
package/constants.js
CHANGED
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -11,7 +11,6 @@ import UDotDefaultConfig from "./ui.other-dot/config.ts";
|
|
|
11
11
|
import UButtonDefaultConfig from "./ui.button/config.ts";
|
|
12
12
|
import ULinkDefaultConfig from "./ui.button-link/config.ts";
|
|
13
13
|
import UToggleDefaultConfig from "./ui.button-toggle/config.ts";
|
|
14
|
-
import UToggleItemDefaultConfig from "./ui.button-toggle-item/config.ts";
|
|
15
14
|
import UBadgeDefaultConfig from "./ui.text-badge/config.ts";
|
|
16
15
|
import UCalendarDefaultConfig from "./ui.form-calendar/config.ts";
|
|
17
16
|
import UDatePickerConfig from "./ui.form-date-picker/config.ts";
|
|
@@ -196,7 +195,6 @@ export interface Components {
|
|
|
196
195
|
UButton: Partial<typeof UButtonDefaultConfig>;
|
|
197
196
|
ULink: Partial<typeof ULinkDefaultConfig>;
|
|
198
197
|
UToggle: Partial<typeof UToggleDefaultConfig>;
|
|
199
|
-
UToggleItem: Partial<typeof UToggleItemDefaultConfig>;
|
|
200
198
|
UBadge: Partial<typeof UBadgeDefaultConfig>;
|
|
201
199
|
UCalendar: Partial<typeof UCalendarDefaultConfig>;
|
|
202
200
|
UDatePicker: Partial<typeof UDatePickerConfig>;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed
|
|
2
|
+
import { computed } from "vue";
|
|
3
3
|
|
|
4
4
|
import ULabel from "../ui.form-label/ULabel.vue";
|
|
5
|
-
import
|
|
5
|
+
import UButton from "../ui.button/UButton.vue";
|
|
6
6
|
|
|
7
7
|
import useUI from "../composables/useUI.ts";
|
|
8
8
|
import { getDefaults } from "../utils/ui.ts";
|
|
9
9
|
|
|
10
10
|
import defaultConfig from "./config.ts";
|
|
11
|
-
import { COMPONENT_NAME
|
|
11
|
+
import { COMPONENT_NAME } from "./constants.ts";
|
|
12
12
|
|
|
13
|
-
import type { Props, Config } from "./types.ts";
|
|
13
|
+
import type { Props, Config, UToggleOption } from "./types.ts";
|
|
14
14
|
|
|
15
15
|
defineOptions({ inheritAttrs: false });
|
|
16
16
|
|
|
17
17
|
const props = withDefaults(defineProps<Props>(), {
|
|
18
18
|
...getDefaults<Props, Config>(defaultConfig, COMPONENT_NAME),
|
|
19
19
|
options: () => [],
|
|
20
|
-
modelValue:
|
|
20
|
+
modelValue: () => [],
|
|
21
21
|
label: "",
|
|
22
22
|
});
|
|
23
23
|
|
|
@@ -34,45 +34,39 @@ const selectedValue = computed({
|
|
|
34
34
|
set: (value) => emit("update:modelValue", value),
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
function isSelected(item: UToggleOption) {
|
|
38
|
+
if (Array.isArray(selectedValue.value)) {
|
|
39
|
+
return selectedValue.value.includes(item.value);
|
|
40
|
+
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
selectedValue.value = value;
|
|
42
|
+
return selectedValue.value === item.value;
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
function onClickOption(item: UToggleOption) {
|
|
46
|
+
if (props.multiple) {
|
|
47
|
+
const newValue = Array.isArray(selectedValue.value) ? [...selectedValue.value] : [];
|
|
48
|
+
const index = newValue.indexOf(item.value);
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
: selectedValue.value.filter((item) => String(item) !== String(value));
|
|
50
|
+
~index ? newValue.splice(index, 1) : newValue.push(item.value);
|
|
51
|
+
|
|
52
|
+
emit("update:modelValue", newValue);
|
|
52
53
|
} else {
|
|
53
|
-
|
|
54
|
+
emit("update:modelValue", item.value);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
provide("getToggleName", () => props.name);
|
|
58
|
-
provide("getToggleType", () => type.value);
|
|
59
|
-
provide("getToggleSize", () => props.size);
|
|
60
|
-
provide("getToggleRound", () => props.round);
|
|
61
|
-
provide("getToggleBlock", () => props.block);
|
|
62
|
-
provide("getToggleSquare", () => props.square);
|
|
63
|
-
provide("getToggleDisabled", () => props.disabled);
|
|
64
|
-
provide("getToggleSplit", () => props.split);
|
|
65
|
-
|
|
66
|
-
provide("toggleSelectedValue", {
|
|
67
|
-
selectedValue: readonly(selectedValue),
|
|
68
|
-
updateSelectedValue,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
58
|
/**
|
|
72
59
|
* Get element / nested component attributes for each config token ✨
|
|
73
60
|
* Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes.
|
|
74
61
|
*/
|
|
75
|
-
const
|
|
62
|
+
const mutatedProps = computed(() => ({
|
|
63
|
+
split: props.split,
|
|
64
|
+
/* component state, not a props */
|
|
65
|
+
selected: isSelected,
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
const { toggleLabelAttrs, itemsAttrs, toggleButtonInactiveAttrs, toggleButtonActiveAttrs } =
|
|
69
|
+
useUI<Config>(defaultConfig, mutatedProps);
|
|
76
70
|
</script>
|
|
77
71
|
|
|
78
72
|
<template>
|
|
@@ -95,20 +89,51 @@ const { toggleLabelAttrs, itemsAttrs, itemAttrs } = useUI<Config>(defaultConfig)
|
|
|
95
89
|
</template>
|
|
96
90
|
|
|
97
91
|
<div v-bind="itemsAttrs">
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
92
|
+
<UButton
|
|
93
|
+
v-for="(item, index) in options"
|
|
94
|
+
:key="item.value"
|
|
95
|
+
:label="item.label"
|
|
96
|
+
tabindex="0"
|
|
97
|
+
color="gray"
|
|
98
|
+
:size="size"
|
|
99
|
+
:round="round"
|
|
100
|
+
:block="block"
|
|
101
|
+
:square="square"
|
|
102
|
+
:disabled="disabled"
|
|
103
|
+
v-bind="isSelected(item) ? toggleButtonActiveAttrs : toggleButtonInactiveAttrs"
|
|
104
|
+
:data-test="`${dataTest}-item-${index}`"
|
|
105
|
+
@click="onClickOption(item)"
|
|
106
|
+
>
|
|
107
|
+
<template #left="{ iconName }">
|
|
108
|
+
<!--
|
|
109
|
+
@slot Use it to add something before the label.
|
|
110
|
+
@binding {string} icon-name
|
|
111
|
+
@binding {number} index
|
|
112
|
+
-->
|
|
113
|
+
<slot name="left" :icon-name="iconName" :index="index" />
|
|
114
|
+
</template>
|
|
115
|
+
|
|
116
|
+
<template #default="{ label, iconName }">
|
|
117
|
+
<!--
|
|
118
|
+
@slot Use it to add something instead of the toggle item label.
|
|
119
|
+
@binding {string} label
|
|
120
|
+
@binding {string} icon-name
|
|
121
|
+
@binding {number} index
|
|
122
|
+
-->
|
|
123
|
+
<slot name="default" :label="label" :icon-name="iconName" :index="index">
|
|
124
|
+
{{ item.label }}
|
|
125
|
+
</slot>
|
|
126
|
+
</template>
|
|
127
|
+
|
|
128
|
+
<template #right="{ iconName }">
|
|
129
|
+
<!--
|
|
130
|
+
@slot Use it to add something after the label.
|
|
131
|
+
@binding {string} icon-name
|
|
132
|
+
@binding {number} index
|
|
133
|
+
-->
|
|
134
|
+
<slot name="right" :icon-name="iconName" :index="index" />
|
|
135
|
+
</template>
|
|
136
|
+
</UButton>
|
|
112
137
|
</div>
|
|
113
138
|
</ULabel>
|
|
114
139
|
</template>
|
|
@@ -43,7 +43,40 @@ export default /*tw*/ {
|
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
|
-
|
|
46
|
+
toggleButton: {
|
|
47
|
+
base: "{UButton} font-normal focus-visible:ring-offset-0",
|
|
48
|
+
defaults: {
|
|
49
|
+
variant: "thirdary",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
toggleButtonInactive: {
|
|
53
|
+
base: "{>toggleButton}",
|
|
54
|
+
variants: {
|
|
55
|
+
split: {
|
|
56
|
+
false: "border-0",
|
|
57
|
+
true: `
|
|
58
|
+
border border-gray-300 hover:border-gray-400
|
|
59
|
+
hover:bg-transparent dark:hover:bg-transparent
|
|
60
|
+
active:bg-transparent dark:active:bg-transparent
|
|
61
|
+
`,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
toggleButtonActive: {
|
|
66
|
+
base: "{>toggleButton}",
|
|
67
|
+
variants: {
|
|
68
|
+
split: {
|
|
69
|
+
false: "border-0",
|
|
70
|
+
true: `
|
|
71
|
+
border border-brand-600
|
|
72
|
+
`,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
defaults: {
|
|
76
|
+
color: "brand",
|
|
77
|
+
filled: true,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
47
80
|
defaults: {
|
|
48
81
|
labelAlign: "top",
|
|
49
82
|
size: "md",
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import UToggle from "../../ui.button-toggle/UToggle.vue";
|
|
10
10
|
import UIcon from "../../ui.image-icon/UIcon.vue";
|
|
11
|
-
import UToggleItem from "../../ui.button-toggle-item/UToggleItem.vue";
|
|
12
11
|
import URow from "../../ui.container-row/URow.vue";
|
|
13
12
|
import UBadge from "../../ui.text-badge/UBadge.vue";
|
|
14
13
|
|
|
@@ -21,16 +20,16 @@ interface UToggleArgs extends Props {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export default {
|
|
24
|
-
components: { UIcon
|
|
23
|
+
components: { UIcon },
|
|
25
24
|
title: "Buttons & Links / Toggle",
|
|
26
25
|
component: UToggle,
|
|
27
26
|
args: {
|
|
28
|
-
label: "Please choose
|
|
27
|
+
label: "Please choose a role",
|
|
29
28
|
modelValue: "11",
|
|
30
29
|
options: [
|
|
31
30
|
{ value: "11", label: "Admin" },
|
|
32
|
-
{ value: "12", label: "
|
|
33
|
-
{ value: "13", label: "
|
|
31
|
+
{ value: "12", label: "Manager" },
|
|
32
|
+
{ value: "13", label: "Employee" },
|
|
34
33
|
{ value: "14", label: "Guest" },
|
|
35
34
|
],
|
|
36
35
|
},
|
|
@@ -45,25 +44,24 @@ export default {
|
|
|
45
44
|
} as Meta;
|
|
46
45
|
|
|
47
46
|
const DefaultTemplate: StoryFn<UToggleArgs> = (args: UToggleArgs) => ({
|
|
48
|
-
components: { UToggle, UIcon,
|
|
47
|
+
components: { UToggle, UIcon, UBadge },
|
|
49
48
|
setup() {
|
|
50
49
|
const slots = getSlotNames(UToggle.__name);
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return modelValueRef.value?.length === 0 ? "Please select at least one option" : "";
|
|
50
|
+
const errorMessage = computed(() => {
|
|
51
|
+
if (args.name === "error" && Array.isArray(args.modelValue)) {
|
|
52
|
+
return args.modelValue.length === 0 ? "Please select at least one option" : "";
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
return "";
|
|
58
56
|
});
|
|
59
57
|
|
|
60
|
-
return { args, slots,
|
|
58
|
+
return { args, slots, errorMessage };
|
|
61
59
|
},
|
|
62
60
|
template: `
|
|
63
61
|
<UToggle
|
|
64
62
|
v-bind="args"
|
|
65
|
-
v-model="
|
|
66
|
-
:error="
|
|
63
|
+
v-model="args.modelValue"
|
|
64
|
+
:error="errorMessage"
|
|
67
65
|
>
|
|
68
66
|
${args.slotTemplate || getSlotsFragment("")}
|
|
69
67
|
</UToggle>
|
|
@@ -127,6 +125,7 @@ export const Multiple = DefaultTemplate.bind({});
|
|
|
127
125
|
Multiple.args = {
|
|
128
126
|
name: "multiple",
|
|
129
127
|
multiple: true,
|
|
128
|
+
modelValue: [],
|
|
130
129
|
label: "You can choose more than one option",
|
|
131
130
|
};
|
|
132
131
|
|
|
@@ -152,19 +151,14 @@ Square.args = {
|
|
|
152
151
|
name: "square",
|
|
153
152
|
square: true,
|
|
154
153
|
label: "Square prop is useful when icons are present",
|
|
154
|
+
options: [
|
|
155
|
+
{ value: "11", label: "star" },
|
|
156
|
+
{ value: "12", label: "add" },
|
|
157
|
+
{ value: "13", label: "timer" },
|
|
158
|
+
],
|
|
155
159
|
slotTemplate: `
|
|
156
|
-
<template #default>
|
|
157
|
-
<
|
|
158
|
-
<UIcon name="star" color="inherit" />
|
|
159
|
-
</UToggleItem>
|
|
160
|
-
|
|
161
|
-
<UToggleItem value="2" >
|
|
162
|
-
<UIcon name="add" color="inherit" />
|
|
163
|
-
</UToggleItem>
|
|
164
|
-
|
|
165
|
-
<UToggleItem value="3">
|
|
166
|
-
<UIcon name="timer" color="inherit" />
|
|
167
|
-
</UToggleItem>
|
|
160
|
+
<template #default="{ label, index }">
|
|
161
|
+
<UIcon :name="label" color="inherit" />
|
|
168
162
|
</template>
|
|
169
163
|
`,
|
|
170
164
|
};
|
|
@@ -173,17 +167,43 @@ export const DefaultSlot = DefaultTemplate.bind({});
|
|
|
173
167
|
DefaultSlot.args = {
|
|
174
168
|
name: "defaultSlot",
|
|
175
169
|
label: "Please select an operation to proceed",
|
|
170
|
+
options: [
|
|
171
|
+
{ value: "1", label: "Download", rightIcon: "download", color: "green" },
|
|
172
|
+
{ value: "2", label: "Edit", rightIcon: "edit_note", color: "orange" },
|
|
173
|
+
{ value: "3", label: "Delete", rightIcon: "delete", color: "red" },
|
|
174
|
+
],
|
|
176
175
|
slotTemplate: `
|
|
177
|
-
<template #default>
|
|
178
|
-
<
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
</UToggleItem>
|
|
184
|
-
<UToggleItem value="3">
|
|
185
|
-
<UBadge label="Delete" color="red" right-icon="delete" />
|
|
186
|
-
</UToggleItem>
|
|
176
|
+
<template #default="{ label, index }">
|
|
177
|
+
<UBadge
|
|
178
|
+
:label="label"
|
|
179
|
+
:color="args.options[index].color"
|
|
180
|
+
:right-icon="args.options[index].rightIcon"
|
|
181
|
+
/>
|
|
187
182
|
</template>
|
|
188
183
|
`,
|
|
189
184
|
};
|
|
185
|
+
|
|
186
|
+
export const Slots: StoryFn<UToggleArgs> = (args) => ({
|
|
187
|
+
components: { UToggle, URow, UIcon },
|
|
188
|
+
setup() {
|
|
189
|
+
const leftModel = ref("11");
|
|
190
|
+
const rightModel = ref("13");
|
|
191
|
+
|
|
192
|
+
return { args, leftModel, rightModel };
|
|
193
|
+
},
|
|
194
|
+
template: `
|
|
195
|
+
<URow no-mobile>
|
|
196
|
+
<UToggle v-bind="args" v-model="leftModel" name="leftSlot">
|
|
197
|
+
<template #left="{ index }">
|
|
198
|
+
<UIcon v-if="index === 0" name="settings" />
|
|
199
|
+
</template>
|
|
200
|
+
</UToggle>
|
|
201
|
+
|
|
202
|
+
<UToggle v-bind="args" v-model="rightModel" name="rightSlot">
|
|
203
|
+
<template #right="{ index }">
|
|
204
|
+
<UIcon v-if="index === 2" name="person" />
|
|
205
|
+
</template>
|
|
206
|
+
</UToggle>
|
|
207
|
+
</URow>
|
|
208
|
+
`,
|
|
209
|
+
});
|
|
@@ -8,6 +8,10 @@ export interface UToggleOption {
|
|
|
8
8
|
value: string | number;
|
|
9
9
|
label: string;
|
|
10
10
|
disabled?: boolean;
|
|
11
|
+
icon?: string;
|
|
12
|
+
leftIcon?: string;
|
|
13
|
+
rightIcon?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export interface Props {
|
|
@@ -81,6 +85,11 @@ export interface Props {
|
|
|
81
85
|
*/
|
|
82
86
|
square?: boolean;
|
|
83
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Unique element id.
|
|
90
|
+
*/
|
|
91
|
+
id?: string;
|
|
92
|
+
|
|
84
93
|
/**
|
|
85
94
|
* Component config object.
|
|
86
95
|
*/
|
package/ui.form-input/UInput.vue
CHANGED
|
@@ -96,10 +96,6 @@ const inputValue = computed({
|
|
|
96
96
|
set: (value) => emit("update:modelValue", value),
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
const applyPasswordClasses = computed(() => {
|
|
100
|
-
return Boolean(inputValue.value && !isShownPassword.value && isTypePassword.value);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
99
|
const elementId = props.id || useId();
|
|
104
100
|
|
|
105
101
|
const inputType = computed(() => {
|
|
@@ -237,7 +233,7 @@ const mutatedProps = computed(() => ({
|
|
|
237
233
|
error: Boolean(props.error),
|
|
238
234
|
label: Boolean(props.label),
|
|
239
235
|
/* component state, not a props */
|
|
240
|
-
typePassword:
|
|
236
|
+
typePassword: Boolean(inputValue.value && !isShownPassword.value && isTypePassword.value),
|
|
241
237
|
}));
|
|
242
238
|
|
|
243
239
|
const {
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, inject, onMounted, ref, useId } from "vue";
|
|
3
|
-
|
|
4
|
-
import UButton from "../ui.button/UButton.vue";
|
|
5
|
-
|
|
6
|
-
import useUI from "../composables/useUI.ts";
|
|
7
|
-
import { getDefaults } from "../utils/ui.ts";
|
|
8
|
-
|
|
9
|
-
import { TYPE_RADIO } from "../ui.button-toggle/constants.ts";
|
|
10
|
-
|
|
11
|
-
import defaultConfig from "./config.ts";
|
|
12
|
-
import { COMPONENT_NAME } from "./constants.ts";
|
|
13
|
-
|
|
14
|
-
import type { Props, ToggleInjectValues, ToggleContextType, Config } from "./types.ts";
|
|
15
|
-
|
|
16
|
-
type ButtonSize = "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
|
|
17
|
-
|
|
18
|
-
defineOptions({ inheritAttrs: false });
|
|
19
|
-
|
|
20
|
-
const getToggleName = inject<() => string>("getToggleName", () => "toggle");
|
|
21
|
-
const getToggleType = inject<() => string>("getToggleType", () => TYPE_RADIO);
|
|
22
|
-
const getToggleSize = inject<() => ButtonSize>("getToggleSize", () => "md" as ButtonSize);
|
|
23
|
-
const getToggleRound = inject<() => boolean>("getToggleRound", () => false);
|
|
24
|
-
const getToggleBlock = inject<() => boolean>("getToggleBlock", () => false);
|
|
25
|
-
const getToggleSquare = inject<() => boolean>("getToggleSquare", () => false);
|
|
26
|
-
const getToggleSplit = inject<() => boolean>("getToggleSplit", () => false);
|
|
27
|
-
|
|
28
|
-
const getToggleDisabled = inject<() => boolean>(
|
|
29
|
-
"getToggleDisabled",
|
|
30
|
-
() => getDefaults<ToggleInjectValues, Config>(defaultConfig, COMPONENT_NAME).disabled || false,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const { selectedValue, updateSelectedValue } = inject<ToggleContextType>("toggleSelectedValue", {
|
|
34
|
-
selectedValue: ref(""),
|
|
35
|
-
updateSelectedValue: () => {},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
39
|
-
...getDefaults<Props, Config>(defaultConfig, COMPONENT_NAME),
|
|
40
|
-
modelValue: "",
|
|
41
|
-
label: "",
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const emit = defineEmits([
|
|
45
|
-
/**
|
|
46
|
-
* Triggers when new value is set.
|
|
47
|
-
* @property {string} modelValue
|
|
48
|
-
*/
|
|
49
|
-
"update:modelValue",
|
|
50
|
-
]);
|
|
51
|
-
|
|
52
|
-
const elementId = props.id || useId();
|
|
53
|
-
|
|
54
|
-
const selectedItem = ref<string | boolean>("");
|
|
55
|
-
|
|
56
|
-
const isSelected = computed(() => {
|
|
57
|
-
return Array.isArray(selectedValue?.value)
|
|
58
|
-
? selectedValue?.value?.includes(props.value)
|
|
59
|
-
: selectedValue?.value === props.value;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
onMounted(() => {
|
|
63
|
-
const propValueString = props.value?.toString() ?? "";
|
|
64
|
-
|
|
65
|
-
selectedItem.value =
|
|
66
|
-
getToggleType() === TYPE_RADIO
|
|
67
|
-
? (selectedValue?.value ?? "")
|
|
68
|
-
: Boolean(selectedValue?.value?.includes(propValueString));
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
function onClickSetValue() {
|
|
72
|
-
const propValueString = props.value?.toString() ?? "";
|
|
73
|
-
|
|
74
|
-
selectedItem.value =
|
|
75
|
-
getToggleType() === TYPE_RADIO
|
|
76
|
-
? propValueString
|
|
77
|
-
: Boolean(selectedValue?.value?.includes(propValueString));
|
|
78
|
-
|
|
79
|
-
updateSelectedValue && updateSelectedValue(propValueString, !selectedItem.value);
|
|
80
|
-
|
|
81
|
-
emit("update:modelValue", props.value);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get element / nested component attributes for each config token ✨
|
|
86
|
-
* Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes.
|
|
87
|
-
*/
|
|
88
|
-
const mutatedProps = computed(() => ({
|
|
89
|
-
split: getToggleSplit(),
|
|
90
|
-
/* component state, not a props */
|
|
91
|
-
selected: isSelected.value,
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
const { toggleButtonInactiveAttrs, toggleButtonActiveAttrs, toggleInputAttrs } = useUI<Config>(
|
|
95
|
-
defaultConfig,
|
|
96
|
-
mutatedProps,
|
|
97
|
-
);
|
|
98
|
-
</script>
|
|
99
|
-
|
|
100
|
-
<template>
|
|
101
|
-
<UButton
|
|
102
|
-
:label="label"
|
|
103
|
-
tabindex="0"
|
|
104
|
-
color="gray"
|
|
105
|
-
:for="elementId"
|
|
106
|
-
:size="getToggleSize()"
|
|
107
|
-
:round="getToggleRound()"
|
|
108
|
-
:block="getToggleBlock()"
|
|
109
|
-
:square="getToggleSquare()"
|
|
110
|
-
:disabled="getToggleDisabled() || disabled"
|
|
111
|
-
v-bind="isSelected ? toggleButtonActiveAttrs : toggleButtonInactiveAttrs"
|
|
112
|
-
@click="onClickSetValue"
|
|
113
|
-
>
|
|
114
|
-
<template #left>
|
|
115
|
-
<!-- @slot Use it to add something before the label. -->
|
|
116
|
-
<slot name="left" />
|
|
117
|
-
</template>
|
|
118
|
-
|
|
119
|
-
<!-- @slot Use it to add something instead of the label. -->
|
|
120
|
-
<template #default>
|
|
121
|
-
<input
|
|
122
|
-
:id="elementId"
|
|
123
|
-
v-model="selectedItem"
|
|
124
|
-
:name="getToggleName()"
|
|
125
|
-
:type="getToggleType()"
|
|
126
|
-
:value="value"
|
|
127
|
-
:disabled="getToggleDisabled() || disabled"
|
|
128
|
-
v-bind="toggleInputAttrs"
|
|
129
|
-
/>
|
|
130
|
-
|
|
131
|
-
<!--
|
|
132
|
-
@slot Use it to add something instead of the label.
|
|
133
|
-
@binding {string} label
|
|
134
|
-
-->
|
|
135
|
-
<slot name="default" :label="label">
|
|
136
|
-
{{ label }}
|
|
137
|
-
</slot>
|
|
138
|
-
</template>
|
|
139
|
-
|
|
140
|
-
<template #right>
|
|
141
|
-
<!-- @slot Use it to add something after the label. -->
|
|
142
|
-
<slot name="right" />
|
|
143
|
-
</template>
|
|
144
|
-
</UButton>
|
|
145
|
-
</template>
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export default /*tw*/ {
|
|
2
|
-
toggleButton: {
|
|
3
|
-
base: "{UButton} font-normal focus-visible:outline-offset-0",
|
|
4
|
-
defaults: {
|
|
5
|
-
variant: "thirdary",
|
|
6
|
-
},
|
|
7
|
-
},
|
|
8
|
-
toggleButtonInactive: {
|
|
9
|
-
base: "{>toggleButton}",
|
|
10
|
-
variants: {
|
|
11
|
-
split: {
|
|
12
|
-
false: "border-0",
|
|
13
|
-
true: `
|
|
14
|
-
border border-gray-300 hover:border-gray-400
|
|
15
|
-
hover:bg-transparent dark:hover:bg-transparent
|
|
16
|
-
active:bg-transparent dark:active:bg-transparent
|
|
17
|
-
`,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
toggleButtonActive: {
|
|
22
|
-
base: "{>toggleButton}",
|
|
23
|
-
variants: {
|
|
24
|
-
split: {
|
|
25
|
-
false: "border-0",
|
|
26
|
-
true: `
|
|
27
|
-
border border-brand-600
|
|
28
|
-
`,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
defaults: {
|
|
32
|
-
color: "brand",
|
|
33
|
-
filled: true,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
toggleInput: "p-0 m-0 size-0 invisible absolute",
|
|
37
|
-
defaults: {
|
|
38
|
-
disabled: false,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks";
|
|
2
|
-
import { getSource } from "../../utils/storybook.ts";
|
|
3
|
-
|
|
4
|
-
import * as stories from "./stories.ts";
|
|
5
|
-
import defaultConfig from "../config.ts?raw"
|
|
6
|
-
|
|
7
|
-
<Meta of={stories} />
|
|
8
|
-
<Title of={stories} />
|
|
9
|
-
<Subtitle of={stories} />
|
|
10
|
-
<Description of={stories} />
|
|
11
|
-
<Primary of={stories} />
|
|
12
|
-
<Controls of={stories.Default} />
|
|
13
|
-
<Stories of={stories} />
|
|
14
|
-
|
|
15
|
-
## Default config
|
|
16
|
-
<Source code={getSource(defaultConfig)} language="jsx" dark />
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getArgTypes,
|
|
3
|
-
getSlotNames,
|
|
4
|
-
getSlotsFragment,
|
|
5
|
-
getDocsDescription,
|
|
6
|
-
} from "../../utils/storybook.ts";
|
|
7
|
-
|
|
8
|
-
import UToggleItem from "../../ui.button-toggle-item/UToggleItem.vue";
|
|
9
|
-
import UIcon from "../../ui.image-icon/UIcon.vue";
|
|
10
|
-
import URow from "../../ui.container-row/URow.vue";
|
|
11
|
-
|
|
12
|
-
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
13
|
-
import type { Props } from "../types.ts";
|
|
14
|
-
|
|
15
|
-
interface UToggleItemArgs extends Props {
|
|
16
|
-
slotTemplate?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default {
|
|
20
|
-
title: "Buttons & Links / Toggle Item",
|
|
21
|
-
component: UToggleItem,
|
|
22
|
-
args: {
|
|
23
|
-
value: "1",
|
|
24
|
-
label: "Label",
|
|
25
|
-
modelValue: "",
|
|
26
|
-
},
|
|
27
|
-
argTypes: {
|
|
28
|
-
...getArgTypes(UToggleItem.__name),
|
|
29
|
-
value: { control: { type: "text" } },
|
|
30
|
-
},
|
|
31
|
-
parameters: {
|
|
32
|
-
docs: {
|
|
33
|
-
...getDocsDescription(UToggleItem.__name),
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
} as Meta;
|
|
37
|
-
|
|
38
|
-
const DefaultTemplate: StoryFn<UToggleItemArgs> = (args: UToggleItemArgs) => ({
|
|
39
|
-
components: { UToggleItem, UIcon },
|
|
40
|
-
setup() {
|
|
41
|
-
const slots = getSlotNames(UToggleItem.__name);
|
|
42
|
-
|
|
43
|
-
return { args, slots };
|
|
44
|
-
},
|
|
45
|
-
template: `
|
|
46
|
-
<UToggleItem
|
|
47
|
-
v-bind="args"
|
|
48
|
-
v-model="args.modelValue"
|
|
49
|
-
name="toggle"
|
|
50
|
-
>
|
|
51
|
-
${args.slotTemplate || getSlotsFragment("")}
|
|
52
|
-
</UToggleItem>
|
|
53
|
-
`,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export const Default = DefaultTemplate.bind({});
|
|
57
|
-
Default.args = {};
|
|
58
|
-
|
|
59
|
-
export const Disabled = DefaultTemplate.bind({});
|
|
60
|
-
Disabled.args = { disabled: true };
|
|
61
|
-
|
|
62
|
-
export const Slots: StoryFn<UToggleItemArgs> = (args) => ({
|
|
63
|
-
components: { UToggleItem, UIcon, URow },
|
|
64
|
-
setup() {
|
|
65
|
-
return { args };
|
|
66
|
-
},
|
|
67
|
-
template: `
|
|
68
|
-
<URow>
|
|
69
|
-
<UToggleItem label="Download">
|
|
70
|
-
<template #left>
|
|
71
|
-
<UIcon
|
|
72
|
-
name="download"
|
|
73
|
-
color="green"
|
|
74
|
-
size="sm"
|
|
75
|
-
/>
|
|
76
|
-
</template>
|
|
77
|
-
</UToggleItem>
|
|
78
|
-
|
|
79
|
-
<UToggleItem label="Edit">
|
|
80
|
-
<template #right>
|
|
81
|
-
<UIcon
|
|
82
|
-
name="edit"
|
|
83
|
-
color="orange"
|
|
84
|
-
size="sm"
|
|
85
|
-
/>
|
|
86
|
-
</template>
|
|
87
|
-
</UToggleItem>
|
|
88
|
-
</URow>
|
|
89
|
-
`,
|
|
90
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import defaultConfig from "./config.ts";
|
|
2
|
-
|
|
3
|
-
import type { Ref } from "vue";
|
|
4
|
-
import type { ComponentConfig } from "../types.ts";
|
|
5
|
-
|
|
6
|
-
type UpdateSelectedValue = (value: string | number, checked: boolean) => void;
|
|
7
|
-
|
|
8
|
-
export type Config = typeof defaultConfig;
|
|
9
|
-
|
|
10
|
-
export interface ToggleInjectValues {
|
|
11
|
-
type?: string;
|
|
12
|
-
size?: string;
|
|
13
|
-
round?: boolean;
|
|
14
|
-
block?: boolean;
|
|
15
|
-
square?: boolean;
|
|
16
|
-
variant?: string;
|
|
17
|
-
disabled?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ToggleContextType {
|
|
21
|
-
selectedValue: Ref<string>;
|
|
22
|
-
updateSelectedValue: UpdateSelectedValue;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Props {
|
|
26
|
-
/**
|
|
27
|
-
* Selected value.
|
|
28
|
-
*/
|
|
29
|
-
modelValue?: string | number | (string | number)[];
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Value for checkbox state.
|
|
33
|
-
*/
|
|
34
|
-
value?: string | number;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Toggle item label.
|
|
38
|
-
*/
|
|
39
|
-
label?: string;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Make toggle item disabled.
|
|
43
|
-
*/
|
|
44
|
-
disabled?: boolean;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Unique element id.
|
|
48
|
-
*/
|
|
49
|
-
id?: string;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Component config object.
|
|
53
|
-
*/
|
|
54
|
-
config?: ComponentConfig<Config>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Data-test attribute for automated testing.
|
|
58
|
-
*/
|
|
59
|
-
dataTest?: string | null;
|
|
60
|
-
}
|