@nuxt/ui 0.4.1 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +63 -50
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +1234 -0
- package/dist/module.d.ts +1234 -0
- package/dist/module.json +8 -0
- package/dist/module.mjs +407 -0
- package/dist/runtime/app.config.d.ts +1203 -0
- package/dist/runtime/app.config.mjs +1057 -0
- package/dist/runtime/components/data/Table.vue +251 -0
- package/dist/runtime/components/data/Table.vue.d.ts +215 -0
- package/dist/runtime/components/elements/Accordion.vue +138 -0
- package/dist/runtime/components/elements/Accordion.vue.d.ts +80 -0
- package/dist/runtime/components/elements/Alert.vue +120 -0
- package/dist/runtime/components/elements/Alert.vue.d.ts +107 -0
- package/dist/runtime/components/elements/Avatar.vue +149 -0
- package/dist/runtime/components/elements/Avatar.vue.d.ts +115 -0
- package/dist/runtime/components/elements/AvatarGroup.d.ts +37 -0
- package/dist/runtime/components/elements/AvatarGroup.mjs +53 -0
- package/dist/runtime/components/elements/Badge.vue +69 -0
- package/dist/runtime/components/elements/Badge.vue.d.ts +63 -0
- package/dist/runtime/components/elements/Button.vue +182 -0
- package/dist/runtime/components/elements/Button.vue.d.ts +187 -0
- package/dist/runtime/components/elements/ButtonGroup.d.ts +39 -0
- package/dist/runtime/components/elements/ButtonGroup.mjs +70 -0
- package/dist/runtime/components/elements/Dropdown.vue +172 -0
- package/dist/runtime/components/elements/Dropdown.vue.d.ts +96 -0
- package/dist/runtime/components/elements/Icon.vue +15 -0
- package/dist/runtime/components/elements/Icon.vue.d.ts +12 -0
- package/dist/runtime/components/elements/Kbd.vue +55 -0
- package/dist/runtime/components/elements/Kbd.vue.d.ts +42 -0
- package/dist/runtime/components/elements/Link.vue +80 -0
- package/dist/runtime/components/elements/Link.vue.d.ts +9 -0
- package/dist/runtime/components/forms/Checkbox.vue +136 -0
- package/dist/runtime/components/forms/Checkbox.vue.d.ts +129 -0
- package/dist/runtime/components/forms/Form.vue +185 -0
- package/dist/runtime/components/forms/Form.vue.d.ts +50 -0
- package/dist/runtime/components/forms/FormGroup.vue +97 -0
- package/dist/runtime/components/forms/FormGroup.vue.d.ts +98 -0
- package/dist/runtime/components/forms/Input.vue +250 -0
- package/dist/runtime/components/forms/Input.vue.d.ts +214 -0
- package/dist/runtime/components/forms/Radio.vue +122 -0
- package/dist/runtime/components/forms/Radio.vue.d.ts +109 -0
- package/dist/runtime/components/forms/Range.vue +163 -0
- package/dist/runtime/components/forms/Range.vue.d.ts +119 -0
- package/dist/runtime/components/forms/Select.vue +307 -0
- package/dist/runtime/components/forms/Select.vue.d.ts +229 -0
- package/dist/runtime/components/forms/SelectMenu.vue +429 -0
- package/dist/runtime/components/forms/SelectMenu.vue.d.ts +330 -0
- package/dist/runtime/components/forms/Textarea.vue +184 -0
- package/dist/runtime/components/forms/Textarea.vue.d.ts +161 -0
- package/dist/runtime/components/forms/Toggle.vue +113 -0
- package/dist/runtime/components/forms/Toggle.vue.d.ts +83 -0
- package/dist/runtime/components/layout/Card.vue +58 -0
- package/dist/runtime/components/layout/Card.vue.d.ts +31 -0
- package/dist/runtime/components/layout/Container.vue +43 -0
- package/dist/runtime/components/layout/Container.vue.d.ts +31 -0
- package/dist/runtime/components/layout/Skeleton.vue +37 -0
- package/dist/runtime/components/layout/Skeleton.vue.d.ts +22 -0
- package/dist/runtime/components/navigation/CommandPalette.vue +304 -0
- package/dist/runtime/components/navigation/CommandPalette.vue.d.ts +224 -0
- package/dist/runtime/components/navigation/CommandPaletteGroup.vue +152 -0
- package/dist/runtime/components/navigation/CommandPaletteGroup.vue.d.ts +63 -0
- package/dist/runtime/components/navigation/Pagination.vue +197 -0
- package/dist/runtime/components/navigation/Pagination.vue.d.ts +125 -0
- package/dist/runtime/components/navigation/Tabs.vue +138 -0
- package/dist/runtime/components/navigation/Tabs.vue.d.ts +69 -0
- package/dist/runtime/components/navigation/VerticalNavigation.vue +79 -0
- package/dist/runtime/components/navigation/VerticalNavigation.vue.d.ts +37 -0
- package/dist/runtime/components/overlays/ContextMenu.vue +74 -0
- package/dist/runtime/components/overlays/ContextMenu.vue.d.ts +54 -0
- package/dist/runtime/components/overlays/Modal.vue +113 -0
- package/dist/runtime/components/overlays/Modal.vue.d.ts +82 -0
- package/dist/runtime/components/overlays/Notification.vue +197 -0
- package/dist/runtime/components/overlays/Notification.vue.d.ts +126 -0
- package/dist/runtime/components/overlays/Notifications.vue +61 -0
- package/dist/runtime/components/overlays/Notifications.vue.d.ts +41 -0
- package/dist/runtime/components/overlays/Popover.vue +139 -0
- package/dist/runtime/components/overlays/Popover.vue.d.ts +82 -0
- package/dist/runtime/components/overlays/Slideover.vue +103 -0
- package/dist/runtime/components/overlays/Slideover.vue.d.ts +84 -0
- package/dist/runtime/components/overlays/Tooltip.vue +118 -0
- package/dist/runtime/components/overlays/Tooltip.vue.d.ts +82 -0
- package/dist/runtime/composables/defineShortcuts.d.ts +13 -0
- package/dist/runtime/composables/defineShortcuts.mjs +108 -0
- package/dist/runtime/composables/useCopyToClipboard.d.ts +10 -0
- package/dist/runtime/composables/useCopyToClipboard.mjs +26 -0
- package/dist/runtime/composables/useFormGroup.d.ts +6 -0
- package/dist/runtime/composables/useFormGroup.mjs +30 -0
- package/dist/runtime/composables/usePopper.d.ts +232 -0
- package/dist/runtime/composables/usePopper.mjs +78 -0
- package/dist/runtime/composables/useShortcuts.d.ts +12 -0
- package/dist/runtime/composables/useShortcuts.mjs +24 -0
- package/dist/runtime/composables/useTimer.d.ts +8 -0
- package/dist/runtime/composables/useTimer.mjs +51 -0
- package/dist/runtime/composables/useToast.d.ts +18 -0
- package/dist/runtime/composables/useToast.mjs +22 -0
- package/dist/runtime/plugins/colors.d.ts +2 -0
- package/dist/runtime/plugins/colors.mjs +46 -0
- package/dist/runtime/types/accordion.d.ts +9 -0
- package/dist/runtime/types/avatar.d.ts +9 -0
- package/dist/runtime/types/button.d.ts +23 -0
- package/dist/runtime/types/clipboard.d.ts +3 -0
- package/dist/runtime/types/command-palette.d.ts +26 -0
- package/dist/runtime/types/dropdown.d.ts +13 -0
- package/dist/runtime/types/form.d.ts +21 -0
- package/dist/runtime/types/index.d.ts +12 -0
- package/dist/runtime/types/link.d.ts +8 -0
- package/dist/runtime/types/notification.d.ts +22 -0
- package/dist/runtime/types/popper.d.ts +14 -0
- package/dist/runtime/types/tabs.d.ts +6 -0
- package/dist/runtime/types/vertical-navigation.d.ts +11 -0
- package/dist/runtime/ui.css +13 -0
- package/dist/runtime/utils/StateEmitter.d.ts +17 -0
- package/dist/runtime/utils/StateEmitter.mjs +21 -0
- package/dist/runtime/utils/index.d.ts +11 -0
- package/dist/runtime/utils/index.mjs +33 -0
- package/dist/types.d.mts +15 -0
- package/dist/types.d.ts +15 -0
- package/package.json +56 -39
- package/LICENSE +0 -21
- package/dist/assets/styles.css +0 -14
- package/dist/components/NButton.vue +0 -22
- package/dist/components/NCard.vue +0 -5
- package/dist/components/NCheckbox.vue +0 -35
- package/dist/components/NDarkToggle.vue +0 -28
- package/dist/components/NDialog.vue +0 -59
- package/dist/components/NDropdown.vue +0 -31
- package/dist/components/NIcon.vue +0 -9
- package/dist/components/NLink.vue +0 -20
- package/dist/components/NRadio.vue +0 -40
- package/dist/components/NSwitch.vue +0 -37
- package/dist/components/NTextInput.vue +0 -34
- package/dist/components/NTip.vue +0 -16
- package/dist/components/NuxtContentLogo.vue +0 -7
- package/dist/components/NuxtExampleLayout.vue +0 -82
- package/dist/components/NuxtLogo.vue +0 -20
- package/dist/components/nuxt/NDarkToggle.vue +0 -28
- package/dist/nuxt.d.ts +0 -16
- package/dist/nuxt.mjs +0 -36
- package/dist/unocss.d.ts +0 -7
- package/dist/unocss.mjs +0 -127
- package/nuxt.cjs +0 -7
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="wrapperClass">
|
|
3
|
+
<input
|
|
4
|
+
ref="input"
|
|
5
|
+
v-model.number="value"
|
|
6
|
+
:name="name"
|
|
7
|
+
:min="min"
|
|
8
|
+
:max="max"
|
|
9
|
+
:disabled="disabled"
|
|
10
|
+
:step="step"
|
|
11
|
+
type="range"
|
|
12
|
+
:class="[inputClass, thumbClass, trackClass]"
|
|
13
|
+
v-bind="attrs"
|
|
14
|
+
@change="onChange"
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
<span :class="progressClass" :style="progressStyle" />
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script>
|
|
22
|
+
import { computed, defineComponent } from "vue";
|
|
23
|
+
import { omit } from "lodash-es";
|
|
24
|
+
import { twMerge, twJoin } from "tailwind-merge";
|
|
25
|
+
import { defuTwMerge } from "../../utils";
|
|
26
|
+
import { useFormGroup } from "../../composables/useFormGroup";
|
|
27
|
+
import { useAppConfig } from "#imports";
|
|
28
|
+
import appConfig from "#build/app.config";
|
|
29
|
+
export default defineComponent({
|
|
30
|
+
inheritAttrs: false,
|
|
31
|
+
props: {
|
|
32
|
+
modelValue: {
|
|
33
|
+
type: Number,
|
|
34
|
+
default: 0
|
|
35
|
+
},
|
|
36
|
+
name: {
|
|
37
|
+
type: String,
|
|
38
|
+
default: null
|
|
39
|
+
},
|
|
40
|
+
disabled: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false
|
|
43
|
+
},
|
|
44
|
+
min: {
|
|
45
|
+
type: Number,
|
|
46
|
+
default: 0
|
|
47
|
+
},
|
|
48
|
+
max: {
|
|
49
|
+
type: Number,
|
|
50
|
+
default: 100
|
|
51
|
+
},
|
|
52
|
+
step: {
|
|
53
|
+
type: Number,
|
|
54
|
+
default: 1
|
|
55
|
+
},
|
|
56
|
+
size: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: () => appConfig.ui.range.default.size,
|
|
59
|
+
validator(value) {
|
|
60
|
+
return Object.keys(appConfig.ui.range.size).includes(value);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
color: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: () => appConfig.ui.range.default.color,
|
|
66
|
+
validator(value) {
|
|
67
|
+
return appConfig.ui.colors.includes(value);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
inputClass: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: null
|
|
73
|
+
},
|
|
74
|
+
ui: {
|
|
75
|
+
type: Object,
|
|
76
|
+
default: () => ({})
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
emits: ["update:modelValue", "change"],
|
|
80
|
+
setup(props, { emit, attrs }) {
|
|
81
|
+
const appConfig2 = useAppConfig();
|
|
82
|
+
const ui = computed(() => defuTwMerge({}, props.ui, appConfig2.ui.range));
|
|
83
|
+
const { emitFormChange, formGroup } = useFormGroup();
|
|
84
|
+
const color = computed(() => formGroup?.error?.value ? "red" : props.color);
|
|
85
|
+
const size = computed(() => formGroup?.size?.value ?? props.size);
|
|
86
|
+
const value = computed({
|
|
87
|
+
get() {
|
|
88
|
+
return props.modelValue;
|
|
89
|
+
},
|
|
90
|
+
set(value2) {
|
|
91
|
+
emit("update:modelValue", value2);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const onChange = (event) => {
|
|
95
|
+
emit("change", event);
|
|
96
|
+
emitFormChange();
|
|
97
|
+
};
|
|
98
|
+
const wrapperClass = computed(() => {
|
|
99
|
+
return twMerge(twJoin(
|
|
100
|
+
ui.value.wrapper,
|
|
101
|
+
ui.value.size[size.value]
|
|
102
|
+
), attrs.class);
|
|
103
|
+
});
|
|
104
|
+
const inputClass = computed(() => {
|
|
105
|
+
return twMerge(twJoin(
|
|
106
|
+
ui.value.base,
|
|
107
|
+
ui.value.background,
|
|
108
|
+
ui.value.rounded,
|
|
109
|
+
ui.value.ring.replaceAll("{color}", color.value),
|
|
110
|
+
ui.value.size[size.value]
|
|
111
|
+
), props.inputClass);
|
|
112
|
+
});
|
|
113
|
+
const thumbClass = computed(() => {
|
|
114
|
+
return twJoin(
|
|
115
|
+
ui.value.thumb.base,
|
|
116
|
+
// Intermediate class to allow thumb ring or background color (set to `current`) as it's impossible to safelist with arbitrary values
|
|
117
|
+
ui.value.thumb.color.replaceAll("{color}", color.value),
|
|
118
|
+
ui.value.thumb.ring,
|
|
119
|
+
ui.value.thumb.background,
|
|
120
|
+
ui.value.thumb.size[size.value]
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
const trackClass = computed(() => {
|
|
124
|
+
return twJoin(
|
|
125
|
+
ui.value.track.base,
|
|
126
|
+
ui.value.track.background,
|
|
127
|
+
ui.value.track.rounded,
|
|
128
|
+
ui.value.track.size[size.value]
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
const progressClass = computed(() => {
|
|
132
|
+
return twJoin(
|
|
133
|
+
ui.value.progress.base,
|
|
134
|
+
ui.value.progress.rounded,
|
|
135
|
+
ui.value.progress.background.replaceAll("{color}", color.value),
|
|
136
|
+
ui.value.progress.size[size.value]
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
const progressStyle = computed(() => {
|
|
140
|
+
const { modelValue, min, max } = props;
|
|
141
|
+
const clampedValue = Math.max(min, Math.min(modelValue, max));
|
|
142
|
+
const relativeValue = (clampedValue - min) / (max - min);
|
|
143
|
+
return {
|
|
144
|
+
width: `${relativeValue * 100}%`
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
attrs: omit(attrs, ["class"]),
|
|
149
|
+
// eslint-disable-next-line vue/no-dupe-keys
|
|
150
|
+
ui,
|
|
151
|
+
value,
|
|
152
|
+
wrapperClass,
|
|
153
|
+
// eslint-disable-next-line vue/no-dupe-keys
|
|
154
|
+
inputClass,
|
|
155
|
+
thumbClass,
|
|
156
|
+
trackClass,
|
|
157
|
+
progressClass,
|
|
158
|
+
progressStyle,
|
|
159
|
+
onChange
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
</script>
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
2
|
+
import type { PropType } from 'vue';
|
|
3
|
+
declare const _default: import("vue").DefineComponent<{
|
|
4
|
+
modelValue: {
|
|
5
|
+
type: NumberConstructor;
|
|
6
|
+
default: number;
|
|
7
|
+
};
|
|
8
|
+
name: {
|
|
9
|
+
type: StringConstructor;
|
|
10
|
+
default: null;
|
|
11
|
+
};
|
|
12
|
+
disabled: {
|
|
13
|
+
type: BooleanConstructor;
|
|
14
|
+
default: boolean;
|
|
15
|
+
};
|
|
16
|
+
min: {
|
|
17
|
+
type: NumberConstructor;
|
|
18
|
+
default: number;
|
|
19
|
+
};
|
|
20
|
+
max: {
|
|
21
|
+
type: NumberConstructor;
|
|
22
|
+
default: number;
|
|
23
|
+
};
|
|
24
|
+
step: {
|
|
25
|
+
type: NumberConstructor;
|
|
26
|
+
default: number;
|
|
27
|
+
};
|
|
28
|
+
size: {
|
|
29
|
+
type: StringConstructor;
|
|
30
|
+
default: () => any;
|
|
31
|
+
validator(value: string): boolean;
|
|
32
|
+
};
|
|
33
|
+
color: {
|
|
34
|
+
type: StringConstructor;
|
|
35
|
+
default: () => any;
|
|
36
|
+
validator(value: string): any;
|
|
37
|
+
};
|
|
38
|
+
inputClass: {
|
|
39
|
+
type: StringConstructor;
|
|
40
|
+
default: null;
|
|
41
|
+
};
|
|
42
|
+
ui: {
|
|
43
|
+
type: PropType<any>;
|
|
44
|
+
default: () => {};
|
|
45
|
+
};
|
|
46
|
+
}, {
|
|
47
|
+
attrs: import("lodash").Omit<{
|
|
48
|
+
[x: string]: unknown;
|
|
49
|
+
}, "class">;
|
|
50
|
+
ui: import("vue").ComputedRef<any>;
|
|
51
|
+
value: import("vue").WritableComputedRef<number>;
|
|
52
|
+
wrapperClass: import("vue").ComputedRef<string>;
|
|
53
|
+
inputClass: import("vue").ComputedRef<string>;
|
|
54
|
+
thumbClass: import("vue").ComputedRef<string>;
|
|
55
|
+
trackClass: import("vue").ComputedRef<string>;
|
|
56
|
+
progressClass: import("vue").ComputedRef<string>;
|
|
57
|
+
progressStyle: import("vue").ComputedRef<{
|
|
58
|
+
width: string;
|
|
59
|
+
}>;
|
|
60
|
+
onChange: (event: Event) => void;
|
|
61
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("change" | "update:modelValue")[], "change" | "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
62
|
+
modelValue: {
|
|
63
|
+
type: NumberConstructor;
|
|
64
|
+
default: number;
|
|
65
|
+
};
|
|
66
|
+
name: {
|
|
67
|
+
type: StringConstructor;
|
|
68
|
+
default: null;
|
|
69
|
+
};
|
|
70
|
+
disabled: {
|
|
71
|
+
type: BooleanConstructor;
|
|
72
|
+
default: boolean;
|
|
73
|
+
};
|
|
74
|
+
min: {
|
|
75
|
+
type: NumberConstructor;
|
|
76
|
+
default: number;
|
|
77
|
+
};
|
|
78
|
+
max: {
|
|
79
|
+
type: NumberConstructor;
|
|
80
|
+
default: number;
|
|
81
|
+
};
|
|
82
|
+
step: {
|
|
83
|
+
type: NumberConstructor;
|
|
84
|
+
default: number;
|
|
85
|
+
};
|
|
86
|
+
size: {
|
|
87
|
+
type: StringConstructor;
|
|
88
|
+
default: () => any;
|
|
89
|
+
validator(value: string): boolean;
|
|
90
|
+
};
|
|
91
|
+
color: {
|
|
92
|
+
type: StringConstructor;
|
|
93
|
+
default: () => any;
|
|
94
|
+
validator(value: string): any;
|
|
95
|
+
};
|
|
96
|
+
inputClass: {
|
|
97
|
+
type: StringConstructor;
|
|
98
|
+
default: null;
|
|
99
|
+
};
|
|
100
|
+
ui: {
|
|
101
|
+
type: PropType<any>;
|
|
102
|
+
default: () => {};
|
|
103
|
+
};
|
|
104
|
+
}>> & {
|
|
105
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
106
|
+
onChange?: ((...args: any[]) => any) | undefined;
|
|
107
|
+
}, {
|
|
108
|
+
color: string;
|
|
109
|
+
ui: any;
|
|
110
|
+
name: string;
|
|
111
|
+
modelValue: number;
|
|
112
|
+
disabled: boolean;
|
|
113
|
+
size: string;
|
|
114
|
+
max: number;
|
|
115
|
+
inputClass: string;
|
|
116
|
+
min: number;
|
|
117
|
+
step: number;
|
|
118
|
+
}, {}>;
|
|
119
|
+
export default _default;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="wrapperClass">
|
|
3
|
+
<select
|
|
4
|
+
:name="name"
|
|
5
|
+
:value="modelValue"
|
|
6
|
+
:required="required"
|
|
7
|
+
:disabled="disabled || loading"
|
|
8
|
+
class="form-select"
|
|
9
|
+
:class="selectClass"
|
|
10
|
+
v-bind="attrs"
|
|
11
|
+
@input="onInput"
|
|
12
|
+
@change="onChange"
|
|
13
|
+
>
|
|
14
|
+
<template v-for="(option, index) in normalizedOptionsWithPlaceholder">
|
|
15
|
+
<optgroup
|
|
16
|
+
v-if="option.children"
|
|
17
|
+
:key="`${option[valueAttribute]}-optgroup-${index}`"
|
|
18
|
+
:value="option[valueAttribute]"
|
|
19
|
+
:label="option[optionAttribute]"
|
|
20
|
+
>
|
|
21
|
+
<option
|
|
22
|
+
v-for="(childOption, index2) in option.children"
|
|
23
|
+
:key="`${childOption[valueAttribute]}-${index}-${index2}`"
|
|
24
|
+
:value="childOption[valueAttribute]"
|
|
25
|
+
:selected="childOption[valueAttribute] === normalizedValue"
|
|
26
|
+
:disabled="childOption.disabled"
|
|
27
|
+
v-text="childOption[optionAttribute]"
|
|
28
|
+
/>
|
|
29
|
+
</optgroup>
|
|
30
|
+
<option
|
|
31
|
+
v-else
|
|
32
|
+
:key="`${option[valueAttribute]}-${index}`"
|
|
33
|
+
:value="option[valueAttribute]"
|
|
34
|
+
:selected="option[valueAttribute] === normalizedValue"
|
|
35
|
+
:disabled="option.disabled"
|
|
36
|
+
v-text="option[optionAttribute]"
|
|
37
|
+
/>
|
|
38
|
+
</template>
|
|
39
|
+
</select>
|
|
40
|
+
|
|
41
|
+
<span v-if="(isLeading && leadingIconName) || $slots.leading" :class="leadingWrapperIconClass">
|
|
42
|
+
<slot name="leading" :disabled="disabled" :loading="loading">
|
|
43
|
+
<UIcon :name="leadingIconName" :class="leadingIconClass" />
|
|
44
|
+
</slot>
|
|
45
|
+
</span>
|
|
46
|
+
|
|
47
|
+
<span v-if="(isTrailing && trailingIconName) || $slots.trailing" :class="trailingWrapperIconClass">
|
|
48
|
+
<slot name="trailing" :disabled="disabled" :loading="loading">
|
|
49
|
+
<UIcon :name="trailingIconName" :class="trailingIconClass" aria-hidden="true" />
|
|
50
|
+
</slot>
|
|
51
|
+
</span>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
56
|
+
import { computed, defineComponent } from "vue";
|
|
57
|
+
import { get, omit } from "lodash-es";
|
|
58
|
+
import { twMerge, twJoin } from "tailwind-merge";
|
|
59
|
+
import UIcon from "../elements/Icon.vue";
|
|
60
|
+
import { defuTwMerge } from "../../utils";
|
|
61
|
+
import { useFormGroup } from "../../composables/useFormGroup";
|
|
62
|
+
import { useAppConfig } from "#imports";
|
|
63
|
+
import appConfig from "#build/app.config";
|
|
64
|
+
export default defineComponent({
|
|
65
|
+
components: {
|
|
66
|
+
UIcon
|
|
67
|
+
},
|
|
68
|
+
inheritAttrs: false,
|
|
69
|
+
props: {
|
|
70
|
+
modelValue: {
|
|
71
|
+
type: [String, Number, Object],
|
|
72
|
+
default: ""
|
|
73
|
+
},
|
|
74
|
+
name: {
|
|
75
|
+
type: String,
|
|
76
|
+
default: null
|
|
77
|
+
},
|
|
78
|
+
placeholder: {
|
|
79
|
+
type: String,
|
|
80
|
+
default: null
|
|
81
|
+
},
|
|
82
|
+
required: {
|
|
83
|
+
type: Boolean,
|
|
84
|
+
default: false
|
|
85
|
+
},
|
|
86
|
+
disabled: {
|
|
87
|
+
type: Boolean,
|
|
88
|
+
default: false
|
|
89
|
+
},
|
|
90
|
+
icon: {
|
|
91
|
+
type: String,
|
|
92
|
+
default: null
|
|
93
|
+
},
|
|
94
|
+
loadingIcon: {
|
|
95
|
+
type: String,
|
|
96
|
+
default: () => appConfig.ui.input.default.loadingIcon
|
|
97
|
+
},
|
|
98
|
+
leadingIcon: {
|
|
99
|
+
type: String,
|
|
100
|
+
default: null
|
|
101
|
+
},
|
|
102
|
+
trailingIcon: {
|
|
103
|
+
type: String,
|
|
104
|
+
default: () => appConfig.ui.select.default.trailingIcon
|
|
105
|
+
},
|
|
106
|
+
trailing: {
|
|
107
|
+
type: Boolean,
|
|
108
|
+
default: false
|
|
109
|
+
},
|
|
110
|
+
leading: {
|
|
111
|
+
type: Boolean,
|
|
112
|
+
default: false
|
|
113
|
+
},
|
|
114
|
+
loading: {
|
|
115
|
+
type: Boolean,
|
|
116
|
+
default: false
|
|
117
|
+
},
|
|
118
|
+
padded: {
|
|
119
|
+
type: Boolean,
|
|
120
|
+
default: true
|
|
121
|
+
},
|
|
122
|
+
options: {
|
|
123
|
+
type: Array,
|
|
124
|
+
default: () => []
|
|
125
|
+
},
|
|
126
|
+
size: {
|
|
127
|
+
type: String,
|
|
128
|
+
default: () => appConfig.ui.select.default.size,
|
|
129
|
+
validator(value) {
|
|
130
|
+
return Object.keys(appConfig.ui.select.size).includes(value);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
color: {
|
|
134
|
+
type: String,
|
|
135
|
+
default: () => appConfig.ui.select.default.color,
|
|
136
|
+
validator(value) {
|
|
137
|
+
return [...appConfig.ui.colors, ...Object.keys(appConfig.ui.select.color)].includes(value);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
variant: {
|
|
141
|
+
type: String,
|
|
142
|
+
default: () => appConfig.ui.select.default.variant,
|
|
143
|
+
validator(value) {
|
|
144
|
+
return [
|
|
145
|
+
...Object.keys(appConfig.ui.select.variant),
|
|
146
|
+
...Object.values(appConfig.ui.select.color).flatMap((value2) => Object.keys(value2))
|
|
147
|
+
].includes(value);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
optionAttribute: {
|
|
151
|
+
type: String,
|
|
152
|
+
default: "label"
|
|
153
|
+
},
|
|
154
|
+
valueAttribute: {
|
|
155
|
+
type: String,
|
|
156
|
+
default: "value"
|
|
157
|
+
},
|
|
158
|
+
selectClass: {
|
|
159
|
+
type: String,
|
|
160
|
+
default: null
|
|
161
|
+
},
|
|
162
|
+
ui: {
|
|
163
|
+
type: Object,
|
|
164
|
+
default: () => ({})
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
emits: ["update:modelValue", "change"],
|
|
168
|
+
setup(props, { emit, attrs, slots }) {
|
|
169
|
+
const appConfig2 = useAppConfig();
|
|
170
|
+
const ui = computed(() => defuTwMerge({}, props.ui, appConfig2.ui.select));
|
|
171
|
+
const { emitFormChange, formGroup } = useFormGroup();
|
|
172
|
+
const color = computed(() => formGroup?.error?.value ? "red" : props.color);
|
|
173
|
+
const size = computed(() => formGroup?.size?.value ?? props.size);
|
|
174
|
+
const onInput = (event) => {
|
|
175
|
+
emit("update:modelValue", event.target.value);
|
|
176
|
+
};
|
|
177
|
+
const onChange = (event) => {
|
|
178
|
+
emitFormChange();
|
|
179
|
+
emit("change", event);
|
|
180
|
+
};
|
|
181
|
+
const guessOptionValue = (option) => {
|
|
182
|
+
return get(option, props.valueAttribute, get(option, props.optionAttribute));
|
|
183
|
+
};
|
|
184
|
+
const guessOptionText = (option) => {
|
|
185
|
+
return get(option, props.optionAttribute, get(option, props.valueAttribute));
|
|
186
|
+
};
|
|
187
|
+
const normalizeOption = (option) => {
|
|
188
|
+
if (["string", "number", "boolean"].includes(typeof option)) {
|
|
189
|
+
return {
|
|
190
|
+
[props.valueAttribute]: option,
|
|
191
|
+
[props.optionAttribute]: option
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
...option,
|
|
196
|
+
[props.valueAttribute]: guessOptionValue(option),
|
|
197
|
+
[props.optionAttribute]: guessOptionText(option)
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
const normalizedOptions = computed(() => {
|
|
201
|
+
return props.options.map((option) => normalizeOption(option));
|
|
202
|
+
});
|
|
203
|
+
const normalizedOptionsWithPlaceholder = computed(() => {
|
|
204
|
+
if (!props.placeholder) {
|
|
205
|
+
return normalizedOptions.value;
|
|
206
|
+
}
|
|
207
|
+
return [
|
|
208
|
+
{
|
|
209
|
+
[props.valueAttribute]: "",
|
|
210
|
+
[props.optionAttribute]: props.placeholder,
|
|
211
|
+
disabled: true
|
|
212
|
+
},
|
|
213
|
+
...normalizedOptions.value
|
|
214
|
+
];
|
|
215
|
+
});
|
|
216
|
+
const normalizedValue = computed(() => {
|
|
217
|
+
const normalizeModelValue = normalizeOption(props.modelValue);
|
|
218
|
+
const foundOption = normalizedOptionsWithPlaceholder.value.find((option) => option[props.valueAttribute] === normalizeModelValue[props.valueAttribute]);
|
|
219
|
+
if (!foundOption) {
|
|
220
|
+
return "";
|
|
221
|
+
}
|
|
222
|
+
return foundOption[props.valueAttribute];
|
|
223
|
+
});
|
|
224
|
+
const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class));
|
|
225
|
+
const selectClass = computed(() => {
|
|
226
|
+
const variant = ui.value.color?.[color.value]?.[props.variant] || ui.value.variant[props.variant];
|
|
227
|
+
return twMerge(twJoin(
|
|
228
|
+
ui.value.base,
|
|
229
|
+
ui.value.rounded,
|
|
230
|
+
ui.value.size[size.value],
|
|
231
|
+
props.padded ? ui.value.padding[size.value] : "p-0",
|
|
232
|
+
variant?.replaceAll("{color}", color.value),
|
|
233
|
+
(isLeading.value || slots.leading) && ui.value.leading.padding[size.value],
|
|
234
|
+
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[size.value]
|
|
235
|
+
), props.selectClass);
|
|
236
|
+
});
|
|
237
|
+
const isLeading = computed(() => {
|
|
238
|
+
return props.icon && props.leading || props.icon && !props.trailing || props.loading && !props.trailing || props.leadingIcon;
|
|
239
|
+
});
|
|
240
|
+
const isTrailing = computed(() => {
|
|
241
|
+
return props.icon && props.trailing || props.loading && props.trailing || props.trailingIcon;
|
|
242
|
+
});
|
|
243
|
+
const leadingIconName = computed(() => {
|
|
244
|
+
if (props.loading) {
|
|
245
|
+
return props.loadingIcon;
|
|
246
|
+
}
|
|
247
|
+
return props.leadingIcon || props.icon;
|
|
248
|
+
});
|
|
249
|
+
const trailingIconName = computed(() => {
|
|
250
|
+
if (props.loading && !isLeading.value) {
|
|
251
|
+
return props.loadingIcon;
|
|
252
|
+
}
|
|
253
|
+
return props.trailingIcon || props.icon;
|
|
254
|
+
});
|
|
255
|
+
const leadingWrapperIconClass = computed(() => {
|
|
256
|
+
return twJoin(
|
|
257
|
+
ui.value.icon.leading.wrapper,
|
|
258
|
+
ui.value.icon.leading.pointer,
|
|
259
|
+
ui.value.icon.leading.padding[size.value]
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
const leadingIconClass = computed(() => {
|
|
263
|
+
return twJoin(
|
|
264
|
+
ui.value.icon.base,
|
|
265
|
+
appConfig2.ui.colors.includes(color.value) && ui.value.icon.color.replaceAll("{color}", color.value),
|
|
266
|
+
ui.value.icon.size[size.value],
|
|
267
|
+
props.loading && "animate-spin"
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
const trailingWrapperIconClass = computed(() => {
|
|
271
|
+
return twJoin(
|
|
272
|
+
ui.value.icon.trailing.wrapper,
|
|
273
|
+
ui.value.icon.trailing.pointer,
|
|
274
|
+
ui.value.icon.trailing.padding[size.value]
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
const trailingIconClass = computed(() => {
|
|
278
|
+
return twJoin(
|
|
279
|
+
ui.value.icon.base,
|
|
280
|
+
appConfig2.ui.colors.includes(color.value) && ui.value.icon.color.replaceAll("{color}", color.value),
|
|
281
|
+
ui.value.icon.size[size.value],
|
|
282
|
+
props.loading && !isLeading.value && "animate-spin"
|
|
283
|
+
);
|
|
284
|
+
});
|
|
285
|
+
return {
|
|
286
|
+
attrs: omit(attrs, ["class"]),
|
|
287
|
+
// eslint-disable-next-line vue/no-dupe-keys
|
|
288
|
+
ui,
|
|
289
|
+
normalizedOptionsWithPlaceholder,
|
|
290
|
+
normalizedValue,
|
|
291
|
+
isLeading,
|
|
292
|
+
isTrailing,
|
|
293
|
+
wrapperClass,
|
|
294
|
+
// eslint-disable-next-line vue/no-dupe-keys
|
|
295
|
+
selectClass,
|
|
296
|
+
leadingIconName,
|
|
297
|
+
leadingIconClass,
|
|
298
|
+
leadingWrapperIconClass,
|
|
299
|
+
trailingIconName,
|
|
300
|
+
trailingIconClass,
|
|
301
|
+
trailingWrapperIconClass,
|
|
302
|
+
onInput,
|
|
303
|
+
onChange
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
</script>
|