@weni/unnnic-system 3.9.1-alpha.5 → 3.9.1-alpha.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/dist/components/DateFilter/DateFilter.vue.d.ts +82 -3
- package/dist/components/Input/BaseInput.vue.d.ts +22 -0
- package/dist/components/Input/BaseInput.vue.d.ts.map +1 -1
- package/dist/components/Input/Input.vue.d.ts +82 -3
- package/dist/components/Input/Input.vue.d.ts.map +1 -1
- package/dist/components/Input/TextInput.vue.d.ts +53 -2
- package/dist/components/Input/TextInput.vue.d.ts.map +1 -1
- package/dist/components/InputDatePicker/InputDatePicker.vue.d.ts +82 -3
- package/dist/components/InputNext/InputNext.vue.d.ts +1 -1
- package/dist/components/ModalNext/ModalNext.vue.d.ts +82 -3
- package/dist/components/SelectSmart/SelectSmart.vue.d.ts +53 -2
- package/dist/components/SelectTime/index.vue.d.ts +53 -2
- package/dist/components/index.d.ts +658 -26
- package/dist/components/index.d.ts.map +1 -1
- package/dist/{es-34d30fa1.mjs → es-18dc2623.mjs} +1 -1
- package/dist/{index-70478d63.mjs → index-d490afbf.mjs} +2423 -2365
- package/dist/locales/en.json.d.ts +2 -1
- package/dist/locales/es.json.d.ts +2 -1
- package/dist/locales/pt_br.json.d.ts +2 -1
- package/dist/{pt-br-c6ed3625.mjs → pt-br-ea959d2d.mjs} +1 -1
- package/dist/style.css +1 -1
- package/dist/unnnic.mjs +1 -1
- package/dist/unnnic.umd.js +28 -28
- package/package.json +1 -1
- package/src/assets/scss/scheme-colors.scss +309 -223
- package/src/components/Checkbox/Checkbox.vue +1 -1
- package/src/components/Input/BaseInput.vue +21 -2
- package/src/components/Input/Input.scss +2 -1
- package/src/components/Input/Input.vue +19 -1
- package/src/components/Input/TextInput.vue +66 -21
- package/src/components/Input/__test__/__snapshots__/Input.spec.js.snap +10 -6
- package/src/components/Input/__test__/__snapshots__/TextInput.spec.js.snap +7 -1
- package/src/components/MultiSelectV2/MultSelectOption.vue +67 -0
- package/src/components/MultiSelectV2/__tests__/MultiSelect.spec.js +556 -0
- package/src/components/MultiSelectV2/__tests__/MultiSelectOption.spec.js +229 -0
- package/src/components/MultiSelectV2/__tests__/__snapshots__/MultiSelect.spec.js.snap +121 -0
- package/src/components/MultiSelectV2/__tests__/__snapshots__/MultiSelectOption.spec.js.snap +51 -0
- package/src/components/MultiSelectV2/index.vue +221 -0
- package/src/components/Popover/__tests__/Popover.spec.js +147 -0
- package/src/components/Popover/__tests__/__snapshots__/Popover.spec.js.snap +8 -0
- package/src/components/Popover/index.vue +146 -0
- package/src/components/Select/SelectOption.vue +65 -0
- package/src/components/Select/__tests__/Select.spec.js +412 -0
- package/src/components/Select/__tests__/SelectItem.spec.js +330 -0
- package/src/components/Select/__tests__/SelectOption.spec.js +174 -0
- package/src/components/Select/__tests__/__snapshots__/Select.spec.js.snap +97 -0
- package/src/components/Select/__tests__/__snapshots__/SelectItem.spec.js.snap +15 -0
- package/src/components/Select/__tests__/__snapshots__/SelectOption.spec.js.snap +25 -0
- package/src/components/Select/index.vue +249 -0
- package/src/locales/en.json +2 -1
- package/src/locales/es.json +2 -1
- package/src/locales/pt_br.json +2 -1
- package/src/stories/MultiSelectV2.stories.js +158 -0
- package/src/stories/Select.stories.js +158 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="unnnic-select"
|
|
4
|
+
@keydown="handleKeyDown"
|
|
5
|
+
>
|
|
6
|
+
<UnnnicPopover
|
|
7
|
+
v-model="openPopover"
|
|
8
|
+
:popoverBalloonProps="{ maxHeight: calculatedMaxHeight }"
|
|
9
|
+
>
|
|
10
|
+
<template #trigger>
|
|
11
|
+
<UnnnicInput
|
|
12
|
+
:modelValue="inputValue"
|
|
13
|
+
class="unnnic-select__input"
|
|
14
|
+
readonly
|
|
15
|
+
:forceActiveStatus="openPopover"
|
|
16
|
+
:size="props.size"
|
|
17
|
+
:placeholder="props.placeholder"
|
|
18
|
+
:label="props.label"
|
|
19
|
+
:errors="props.errors"
|
|
20
|
+
:message="props.message"
|
|
21
|
+
:iconRight="openPopover ? 'keyboard_arrow_up' : 'keyboard_arrow_down'"
|
|
22
|
+
:disabled="props.disabled"
|
|
23
|
+
showClear
|
|
24
|
+
@clear="emit('update:modelValue', '')"
|
|
25
|
+
/>
|
|
26
|
+
</template>
|
|
27
|
+
<template #content>
|
|
28
|
+
<div class="unnnic-select__content">
|
|
29
|
+
<UnnnicInput
|
|
30
|
+
v-if="props.enableSearch"
|
|
31
|
+
class="unnnic-select__input-search"
|
|
32
|
+
:modelValue="props.search"
|
|
33
|
+
:placeholder="$t('search')"
|
|
34
|
+
iconLeft="search"
|
|
35
|
+
@update:model-value="handleSearch"
|
|
36
|
+
/>
|
|
37
|
+
<UnnnicSelectOption
|
|
38
|
+
v-for="(option, index) in filteredOptions"
|
|
39
|
+
:key="option[props.itemValue]"
|
|
40
|
+
:data-option-index="index"
|
|
41
|
+
:label="option[props.itemLabel]"
|
|
42
|
+
:active="
|
|
43
|
+
option[props.itemValue] === selectedItem?.[props.itemValue]
|
|
44
|
+
"
|
|
45
|
+
:focused="focusedOptionIndex === index"
|
|
46
|
+
:disabled="option.disabled"
|
|
47
|
+
@click="handleSelectOption(option)"
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
51
|
+
</UnnnicPopover>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script setup lang="ts">
|
|
56
|
+
import { computed, ref, watch, nextTick } from 'vue';
|
|
57
|
+
import UnnnicInput from '../Input/Input.vue';
|
|
58
|
+
import UnnnicPopover from '../Popover/index.vue';
|
|
59
|
+
import UnnnicSelectOption from './SelectOption.vue';
|
|
60
|
+
import UnnnicI18n from '../../mixins/i18n';
|
|
61
|
+
|
|
62
|
+
defineOptions({
|
|
63
|
+
name: 'UnnnicSelect',
|
|
64
|
+
mixins: [UnnnicI18n],
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
interface SelectProps {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
options: Array<{ [key: string]: any }>;
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
modelValue: any;
|
|
72
|
+
returnObject?: boolean;
|
|
73
|
+
itemLabel?: string;
|
|
74
|
+
itemValue?: string;
|
|
75
|
+
placeholder?: string;
|
|
76
|
+
label?: string;
|
|
77
|
+
type?: 'normal' | 'error';
|
|
78
|
+
errors?: string | Array<string>;
|
|
79
|
+
message?: string;
|
|
80
|
+
size?: 'sm' | 'md';
|
|
81
|
+
optionsLines?: number;
|
|
82
|
+
enableSearch?: boolean;
|
|
83
|
+
search?: string;
|
|
84
|
+
locale?: string;
|
|
85
|
+
disabled?: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const props = withDefaults(defineProps<SelectProps>(), {
|
|
89
|
+
size: 'md',
|
|
90
|
+
type: 'normal',
|
|
91
|
+
placeholder: '',
|
|
92
|
+
optionsLines: 5,
|
|
93
|
+
returnObject: false,
|
|
94
|
+
itemLabel: 'label',
|
|
95
|
+
itemValue: 'value',
|
|
96
|
+
locale: 'en',
|
|
97
|
+
enableSearch: false,
|
|
98
|
+
disabled: false,
|
|
99
|
+
label: '',
|
|
100
|
+
errors: '',
|
|
101
|
+
message: '',
|
|
102
|
+
search: '',
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const emit = defineEmits<{
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
'update:modelValue': [value: any];
|
|
108
|
+
'update:search': [value: string];
|
|
109
|
+
}>();
|
|
110
|
+
|
|
111
|
+
const openPopover = ref(false);
|
|
112
|
+
|
|
113
|
+
watch(openPopover, () => {
|
|
114
|
+
if (!openPopover.value) {
|
|
115
|
+
handleSearch('');
|
|
116
|
+
} else {
|
|
117
|
+
focusedOptionIndex.value = -1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (openPopover.value && props.modelValue) {
|
|
121
|
+
const selectedOptionIndex = props.options.findIndex(
|
|
122
|
+
(option) =>
|
|
123
|
+
option[props.itemValue] === selectedItem.value?.[props.itemValue],
|
|
124
|
+
);
|
|
125
|
+
scrollToOption(selectedOptionIndex, 'instant', 'center');
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const handleKeyDown = (event) => {
|
|
130
|
+
const { key } = event;
|
|
131
|
+
const validKeys = ['ArrowUp', 'ArrowDown', 'Enter'];
|
|
132
|
+
if (validKeys.includes(key)) {
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
if (key === 'ArrowUp') {
|
|
135
|
+
if (focusedOptionIndex.value === 0) return;
|
|
136
|
+
focusedOptionIndex.value--;
|
|
137
|
+
scrollToOption(focusedOptionIndex.value);
|
|
138
|
+
}
|
|
139
|
+
if (key === 'ArrowDown') {
|
|
140
|
+
if (focusedOptionIndex.value === filteredOptions.value.length - 1) return;
|
|
141
|
+
focusedOptionIndex.value++;
|
|
142
|
+
scrollToOption(focusedOptionIndex.value);
|
|
143
|
+
}
|
|
144
|
+
if (key === 'Enter') {
|
|
145
|
+
handleSelectOption(filteredOptions.value[focusedOptionIndex.value]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const focusedOptionIndex = ref<number>(-1);
|
|
151
|
+
|
|
152
|
+
const scrollToOption = (
|
|
153
|
+
index: number,
|
|
154
|
+
behavior: 'smooth' | 'instant' = 'smooth',
|
|
155
|
+
block: 'center' | 'start' | 'end' | 'nearest' = 'center',
|
|
156
|
+
) => {
|
|
157
|
+
nextTick(() => {
|
|
158
|
+
const option = document.querySelector(`[data-option-index="${index}"]`);
|
|
159
|
+
if (option) {
|
|
160
|
+
option.scrollIntoView({ behavior, block });
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const calculatedMaxHeight = computed(() => {
|
|
166
|
+
if (!props.options || props.options.length === 0) return 'unset';
|
|
167
|
+
const popoverPadding = 32;
|
|
168
|
+
const popoverGap = 4;
|
|
169
|
+
// 37 = 21px (height) + 16px (padding)
|
|
170
|
+
const fieldsHeight = 37 * props.optionsLines;
|
|
171
|
+
const size =
|
|
172
|
+
fieldsHeight + popoverPadding + (popoverGap * props.optionsLines - 2);
|
|
173
|
+
return `${props.enableSearch ? size + 54 : size}px`;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const selectedItem = computed(() => {
|
|
177
|
+
if (props.returnObject) return props.modelValue;
|
|
178
|
+
|
|
179
|
+
return props.options.find(
|
|
180
|
+
(option) => option[props.itemValue] === props.modelValue,
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const inputValue = computed(() => {
|
|
185
|
+
return selectedItem.value?.[props.itemLabel];
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const handleSelectOption = (option) => {
|
|
189
|
+
if (
|
|
190
|
+
option[props.itemValue] === selectedItem.value?.[props.itemValue] ||
|
|
191
|
+
option.disabled
|
|
192
|
+
)
|
|
193
|
+
return;
|
|
194
|
+
|
|
195
|
+
emit(
|
|
196
|
+
'update:modelValue',
|
|
197
|
+
props.returnObject ? option : option[props.itemValue],
|
|
198
|
+
);
|
|
199
|
+
openPopover.value = false;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const handleSearch = (value: string) => {
|
|
203
|
+
emit('update:search', value);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const filteredOptions = computed(() => {
|
|
207
|
+
if (!props.enableSearch || !props.search) return props.options;
|
|
208
|
+
|
|
209
|
+
return props.options.filter(
|
|
210
|
+
(option) =>
|
|
211
|
+
option[props.itemLabel]
|
|
212
|
+
.toLowerCase()
|
|
213
|
+
.includes(props.search?.toLowerCase()) ||
|
|
214
|
+
option[props.itemValue]
|
|
215
|
+
.toLowerCase()
|
|
216
|
+
.includes(props.search?.toLowerCase()),
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
</script>
|
|
220
|
+
|
|
221
|
+
<style lang="scss" scoped>
|
|
222
|
+
@use '@/assets/scss/unnnic' as *;
|
|
223
|
+
|
|
224
|
+
:deep(.unnnic-select__input) {
|
|
225
|
+
cursor: pointer;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
:deep(.unnnic-select__input-search) {
|
|
229
|
+
> .icon-left {
|
|
230
|
+
color: $unnnic-color-fg-base;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
:deep(.unnnic-select__input) {
|
|
235
|
+
> .icon-right {
|
|
236
|
+
color: $unnnic-color-fg-base;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.unnnic-select {
|
|
241
|
+
&__content {
|
|
242
|
+
display: flex;
|
|
243
|
+
flex-direction: column;
|
|
244
|
+
padding: 0;
|
|
245
|
+
margin: 0;
|
|
246
|
+
gap: $unnnic-space-1;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
</style>
|
package/src/locales/en.json
CHANGED
package/src/locales/es.json
CHANGED
package/src/locales/pt_br.json
CHANGED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import UnnnicMultiSelect from '../components/MultiSelectV2/index.vue';
|
|
2
|
+
|
|
3
|
+
const options = [
|
|
4
|
+
{ label: 'Option 1', value: 'option1', altValue: 'alt_value_option1' },
|
|
5
|
+
{ label: 'Option 2', value: 'option2', altValue: 'alt_value_option2' },
|
|
6
|
+
{ label: 'Option 3', value: 'option3', altValue: 'alt_value_option3' },
|
|
7
|
+
{ label: 'Option 4', value: 'option4', altValue: 'alt_value_option4' },
|
|
8
|
+
{ label: 'Option 5', value: 'option5', altValue: 'alt_value_option5' },
|
|
9
|
+
{ label: 'Option 6', value: 'option6', altValue: 'alt_value_option6' },
|
|
10
|
+
{ label: 'Option 7', value: 'option7', altValue: 'alt_value_option7' },
|
|
11
|
+
{ label: 'Option 8', value: 'option8', altValue: 'alt_value_option8' },
|
|
12
|
+
{ label: 'Option 9', value: 'option9', altValue: 'alt_value_option9' },
|
|
13
|
+
{ label: 'Option 10', value: 'option10', disabled: true },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
title: 'Form/MultiSelectV2',
|
|
18
|
+
component: UnnnicMultiSelect,
|
|
19
|
+
tags: ['autodocs'],
|
|
20
|
+
parameters: {
|
|
21
|
+
docs: {
|
|
22
|
+
description: {
|
|
23
|
+
component:
|
|
24
|
+
'MultiSelect is designed to solve common problems related to multiple option selection.',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
argTypes: {
|
|
29
|
+
options: {
|
|
30
|
+
description:
|
|
31
|
+
'List of items to be displayed in the options. If an item has a `disabled` key set to `true`, that item will be disabled. By default, the component looks for the `label` and `value` keys to display and update the model, but these are not required if you wish to customize them using the `itemLabel` and `itemValue` props, respectively.',
|
|
32
|
+
},
|
|
33
|
+
placeholder: {
|
|
34
|
+
description: 'Text to be displayed in the placeholder.',
|
|
35
|
+
},
|
|
36
|
+
label: {
|
|
37
|
+
description: 'Text to be displayed in the label.',
|
|
38
|
+
},
|
|
39
|
+
modelValue: {
|
|
40
|
+
description:
|
|
41
|
+
'Model variable. Its type will always match a list of the return type of the key specified by `itemValue`, or the entire options object when the `returnObject` property is set to `true`.',
|
|
42
|
+
},
|
|
43
|
+
returnObject: {
|
|
44
|
+
description:
|
|
45
|
+
'Prop to indicate that the full option object should be returned in the v-model.',
|
|
46
|
+
},
|
|
47
|
+
itemLabel: {
|
|
48
|
+
description:
|
|
49
|
+
'Field of the option item that should be used to render the option label.',
|
|
50
|
+
},
|
|
51
|
+
itemValue: {
|
|
52
|
+
description:
|
|
53
|
+
'Field of the option item that should be used to return value to v-model.',
|
|
54
|
+
},
|
|
55
|
+
type: {
|
|
56
|
+
description: 'Select state type',
|
|
57
|
+
},
|
|
58
|
+
errors: {
|
|
59
|
+
description:
|
|
60
|
+
"Error message or messages. When it's an array, the messages will be separated by commas.",
|
|
61
|
+
},
|
|
62
|
+
message: {
|
|
63
|
+
description: 'Help or hint message.',
|
|
64
|
+
},
|
|
65
|
+
size: {
|
|
66
|
+
description: 'Select size',
|
|
67
|
+
},
|
|
68
|
+
optionsLines: {
|
|
69
|
+
description:
|
|
70
|
+
'Number of options to display at most; if exceeded, scrolling will be enabled.',
|
|
71
|
+
},
|
|
72
|
+
enableSearch: {
|
|
73
|
+
description:
|
|
74
|
+
'If true, enables a search field displayed inside the options popover. The `update:search` event is emitted on each input.',
|
|
75
|
+
},
|
|
76
|
+
search: {
|
|
77
|
+
description: 'Search value.',
|
|
78
|
+
},
|
|
79
|
+
locale: {
|
|
80
|
+
description: 'Locale for i18n translations.',
|
|
81
|
+
},
|
|
82
|
+
disabled: {
|
|
83
|
+
description: 'Disable the select.',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
render: (args) => ({
|
|
87
|
+
components: { UnnnicMultiSelect },
|
|
88
|
+
setup() {
|
|
89
|
+
const handleSearch = (value) => {
|
|
90
|
+
args.search = value;
|
|
91
|
+
};
|
|
92
|
+
return { args, handleSearch };
|
|
93
|
+
},
|
|
94
|
+
data() {
|
|
95
|
+
return {
|
|
96
|
+
exampleValue: [],
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
template: `
|
|
100
|
+
<p>modelValue: {{ exampleValue }}</p>
|
|
101
|
+
<unnnic-multi-select v-model="exampleValue" v-bind="args" @update:search="handleSearch" />
|
|
102
|
+
`,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const Default = {
|
|
107
|
+
args: {
|
|
108
|
+
placeholder: 'Placeholder',
|
|
109
|
+
label: 'Label',
|
|
110
|
+
options,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const ReturnObject = {
|
|
115
|
+
args: {
|
|
116
|
+
returnObject: true,
|
|
117
|
+
placeholder: 'Placeholder',
|
|
118
|
+
label: 'Label',
|
|
119
|
+
options,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const AlternativeValueKey = {
|
|
124
|
+
args: {
|
|
125
|
+
itemValue: 'altValue',
|
|
126
|
+
placeholder: 'Placeholder',
|
|
127
|
+
label: 'Label',
|
|
128
|
+
options,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const AlternativeValueLabel = {
|
|
133
|
+
args: {
|
|
134
|
+
itemLabel: 'altValue',
|
|
135
|
+
placeholder: 'Placeholder',
|
|
136
|
+
label: 'Label',
|
|
137
|
+
options,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const Disabled = {
|
|
142
|
+
args: {
|
|
143
|
+
placeholder: 'Placeholder',
|
|
144
|
+
label: 'Label',
|
|
145
|
+
options,
|
|
146
|
+
disabled: true,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const WithSearch = {
|
|
151
|
+
args: {
|
|
152
|
+
placeholder: 'Placeholder',
|
|
153
|
+
label: 'Label',
|
|
154
|
+
options,
|
|
155
|
+
enableSearch: true,
|
|
156
|
+
search: '',
|
|
157
|
+
},
|
|
158
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import UnnnicSelect from '../components/Select/index.vue';
|
|
2
|
+
|
|
3
|
+
const options = [
|
|
4
|
+
{ label: 'Option 1', value: 'option1', altValue: 'alt_value_option1' },
|
|
5
|
+
{ label: 'Option 2', value: 'option2', altValue: 'alt_value_option2' },
|
|
6
|
+
{ label: 'Option 3', value: 'option3', altValue: 'alt_value_option3' },
|
|
7
|
+
{ label: 'Option 4', value: 'option4', altValue: 'alt_value_option4' },
|
|
8
|
+
{ label: 'Option 5', value: 'option5', altValue: 'alt_value_option5' },
|
|
9
|
+
{ label: 'Option 6', value: 'option6', altValue: 'alt_value_option6' },
|
|
10
|
+
{ label: 'Option 7', value: 'option7', altValue: 'alt_value_option7' },
|
|
11
|
+
{ label: 'Option 8', value: 'option8', altValue: 'alt_value_option8' },
|
|
12
|
+
{ label: 'Option 9', value: 'option9', altValue: 'alt_value_option9' },
|
|
13
|
+
{ label: 'Option 10', value: 'option10', disabled: true },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
title: 'Form/Select',
|
|
18
|
+
component: UnnnicSelect,
|
|
19
|
+
tags: ['autodocs'],
|
|
20
|
+
parameters: {
|
|
21
|
+
docs: {
|
|
22
|
+
description: {
|
|
23
|
+
component:
|
|
24
|
+
'Select is designed to solve common problems related to option selection.',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
argTypes: {
|
|
29
|
+
options: {
|
|
30
|
+
description:
|
|
31
|
+
'List of items to be displayed in the options. If an item has a `disabled` key set to `true`, that item will be disabled. By default, the component looks for the `label` and `value` keys to display and update the model, but these are not required if you wish to customize them using the `itemLabel` and `itemValue` props, respectively.',
|
|
32
|
+
},
|
|
33
|
+
placeholder: {
|
|
34
|
+
description: 'Text to be displayed in the placeholder.',
|
|
35
|
+
},
|
|
36
|
+
label: {
|
|
37
|
+
description: 'Text to be displayed in the label.',
|
|
38
|
+
},
|
|
39
|
+
modelValue: {
|
|
40
|
+
description:
|
|
41
|
+
'Model variable. Its type will always match the return type of the key specified by `itemValue`, or the entire options object when `returnObject` prop is set to `true`.',
|
|
42
|
+
},
|
|
43
|
+
returnObject: {
|
|
44
|
+
description:
|
|
45
|
+
'Prop to indicate that the full option object should be returned in the v-model.',
|
|
46
|
+
},
|
|
47
|
+
itemLabel: {
|
|
48
|
+
description:
|
|
49
|
+
'Field of the option item that should be used to render the option label.',
|
|
50
|
+
},
|
|
51
|
+
itemValue: {
|
|
52
|
+
description:
|
|
53
|
+
'Field of the option item that should be used to return value to v-model.',
|
|
54
|
+
},
|
|
55
|
+
type: {
|
|
56
|
+
description: 'Select state type',
|
|
57
|
+
},
|
|
58
|
+
errors: {
|
|
59
|
+
description:
|
|
60
|
+
"Error message or messages. When it's an array, the messages will be separated by commas.",
|
|
61
|
+
},
|
|
62
|
+
message: {
|
|
63
|
+
description: 'Help or hint message.',
|
|
64
|
+
},
|
|
65
|
+
size: {
|
|
66
|
+
description: 'Select size',
|
|
67
|
+
},
|
|
68
|
+
optionsLines: {
|
|
69
|
+
description:
|
|
70
|
+
'Number of options to display at most; if exceeded, scrolling will be enabled.',
|
|
71
|
+
},
|
|
72
|
+
enableSearch: {
|
|
73
|
+
description:
|
|
74
|
+
'If true, enables a search field displayed inside the options popover. The `update:search` event is emitted on each input.',
|
|
75
|
+
},
|
|
76
|
+
search: {
|
|
77
|
+
description: 'Search value.',
|
|
78
|
+
},
|
|
79
|
+
locale: {
|
|
80
|
+
description: 'Locale for i18n translations.',
|
|
81
|
+
},
|
|
82
|
+
disabled: {
|
|
83
|
+
description: 'Disable the select.',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
render: (args) => ({
|
|
87
|
+
components: { UnnnicSelect },
|
|
88
|
+
setup() {
|
|
89
|
+
const handleSearch = (value) => {
|
|
90
|
+
args.search = value;
|
|
91
|
+
};
|
|
92
|
+
return { args, handleSearch };
|
|
93
|
+
},
|
|
94
|
+
data() {
|
|
95
|
+
return {
|
|
96
|
+
exampleValue: null,
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
template: `
|
|
100
|
+
<p>modelValue: {{ exampleValue }}</p>
|
|
101
|
+
<unnnic-select v-model="exampleValue" v-bind="args" @update:search="handleSearch" />
|
|
102
|
+
`,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const Default = {
|
|
107
|
+
args: {
|
|
108
|
+
placeholder: 'Placeholder',
|
|
109
|
+
label: 'Label',
|
|
110
|
+
options,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const ReturnObject = {
|
|
115
|
+
args: {
|
|
116
|
+
returnObject: true,
|
|
117
|
+
placeholder: 'Placeholder',
|
|
118
|
+
label: 'Label',
|
|
119
|
+
options,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const AlternativeValueKey = {
|
|
124
|
+
args: {
|
|
125
|
+
itemValue: 'altValue',
|
|
126
|
+
placeholder: 'Placeholder',
|
|
127
|
+
label: 'Label',
|
|
128
|
+
options,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const AlternativeValueLabel = {
|
|
133
|
+
args: {
|
|
134
|
+
itemLabel: 'altValue',
|
|
135
|
+
placeholder: 'Placeholder',
|
|
136
|
+
label: 'Label',
|
|
137
|
+
options,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const Disabled = {
|
|
142
|
+
args: {
|
|
143
|
+
placeholder: 'Placeholder',
|
|
144
|
+
label: 'Label',
|
|
145
|
+
options,
|
|
146
|
+
disabled: true,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const WithSearch = {
|
|
151
|
+
args: {
|
|
152
|
+
placeholder: 'Placeholder',
|
|
153
|
+
label: 'Label',
|
|
154
|
+
options,
|
|
155
|
+
enableSearch: true,
|
|
156
|
+
search: '',
|
|
157
|
+
},
|
|
158
|
+
};
|