@ouestfrance/sipa-bms-ui 8.8.1 → 8.9.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/dist/components/form/BmsMultiSelect.vue.d.ts +4 -4
- package/dist/components/form/BmsServerAutocomplete.vue.d.ts +30 -0
- package/dist/components/form/RawAutocomplete.vue.d.ts +1 -0
- package/dist/components/table/BmsServerTable.vue.d.ts +5 -5
- package/dist/components/table/BmsTable.vue.d.ts +1 -1
- package/dist/composables/search.composable.d.ts +6 -0
- package/dist/models/table.model.d.ts +5 -2
- package/dist/sipa-bms-ui.css +42 -29
- package/dist/sipa-bms-ui.es.js +526 -384
- package/dist/sipa-bms-ui.es.js.map +1 -1
- package/dist/sipa-bms-ui.umd.js +532 -390
- package/dist/sipa-bms-ui.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/form/BmsMultiSelect.stories.js +6 -6
- package/src/components/form/BmsMultiSelect.vue +48 -23
- package/src/components/form/BmsSelect.vue +3 -3
- package/src/components/form/BmsServerAutocomplete.stories.js +74 -0
- package/src/components/form/BmsServerAutocomplete.vue +143 -0
- package/src/components/form/RawAutocomplete.vue +3 -2
- package/src/components/table/BmsTableFilters.vue +4 -0
- package/src/models/table.model.ts +6 -1
- package/src/showroom/pages/autocomplete.vue +27 -4
- package/src/showroom/pages/server-table.vue +17 -73
- package/src/showroom/server.js +24 -0
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@ export const Default = Template.bind({});
|
|
|
30
30
|
Default.args = {
|
|
31
31
|
label: 'My label',
|
|
32
32
|
captions: ['Helping text'],
|
|
33
|
-
modelValue:
|
|
33
|
+
modelValue: null,
|
|
34
34
|
options: [
|
|
35
35
|
{ label: 'optionA', value: 'a' },
|
|
36
36
|
{ label: 'optionB', value: 'b' },
|
|
@@ -40,7 +40,7 @@ Default.args = {
|
|
|
40
40
|
export const WithValue = Template.bind({});
|
|
41
41
|
WithValue.args = {
|
|
42
42
|
label: 'My label',
|
|
43
|
-
modelValue: [
|
|
43
|
+
modelValue: ['a'],
|
|
44
44
|
options: [
|
|
45
45
|
{ label: 'optionA', value: 'a' },
|
|
46
46
|
{ label: 'optionB', value: 'b' },
|
|
@@ -50,7 +50,7 @@ WithValue.args = {
|
|
|
50
50
|
export const Disabled = Template.bind({});
|
|
51
51
|
Disabled.args = {
|
|
52
52
|
label: 'My label',
|
|
53
|
-
modelValue: [
|
|
53
|
+
modelValue: ['a'],
|
|
54
54
|
options: [
|
|
55
55
|
{ label: 'optionA', value: 'a' },
|
|
56
56
|
{ label: 'optionB', value: 'b' },
|
|
@@ -61,7 +61,7 @@ Disabled.args = {
|
|
|
61
61
|
export const Opened = Template.bind({});
|
|
62
62
|
Opened.args = {
|
|
63
63
|
label: 'My label',
|
|
64
|
-
modelValue:
|
|
64
|
+
modelValue: null,
|
|
65
65
|
options: [
|
|
66
66
|
{ label: 'optionA', value: 'a' },
|
|
67
67
|
{ label: 'optionB', value: 'b' },
|
|
@@ -72,7 +72,7 @@ Opened.args = {
|
|
|
72
72
|
export const WithErrors = Template.bind({});
|
|
73
73
|
WithErrors.args = {
|
|
74
74
|
label: 'My label',
|
|
75
|
-
modelValue:
|
|
75
|
+
modelValue: null,
|
|
76
76
|
options: [
|
|
77
77
|
{ label: 'optionA', value: 'a' },
|
|
78
78
|
{ label: 'optionB', value: 'b' },
|
|
@@ -83,7 +83,7 @@ WithErrors.args = {
|
|
|
83
83
|
export const WithIncorrectValue = Template.bind({});
|
|
84
84
|
WithIncorrectValue.args = {
|
|
85
85
|
label: 'My label',
|
|
86
|
-
modelValue: [
|
|
86
|
+
modelValue: ['a'],
|
|
87
87
|
options: [
|
|
88
88
|
{ label: 'optionB', value: 'b' },
|
|
89
89
|
{ label: 'optionC', value: 'c' },
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<RawSelect
|
|
3
3
|
v-bind="$props"
|
|
4
|
-
:options="
|
|
4
|
+
:options="filteredOptions"
|
|
5
5
|
:model-value="modelValue"
|
|
6
6
|
:open="isDatalistOpen"
|
|
7
7
|
@select="onSelect"
|
|
8
|
+
@click="setFocus"
|
|
8
9
|
>
|
|
9
10
|
<template #input>
|
|
10
11
|
<div class="tags">
|
|
11
12
|
<BmsTag
|
|
12
|
-
v-for="tag in
|
|
13
|
+
v-for="tag in selectedItems"
|
|
13
14
|
:small="small"
|
|
14
15
|
active
|
|
15
16
|
@dismiss="removeOption(tag.value)"
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
</div>
|
|
32
33
|
|
|
33
34
|
<span class="icon-container">
|
|
34
|
-
<template v-if="modelValue
|
|
35
|
+
<template v-if="modelValue && modelValue?.length">
|
|
35
36
|
<X class="icon icon-clear" @click.stop="clearInput" />
|
|
36
37
|
</template>
|
|
37
38
|
<template v-else>
|
|
@@ -58,17 +59,17 @@
|
|
|
58
59
|
</template>
|
|
59
60
|
|
|
60
61
|
<script lang="ts" setup>
|
|
61
|
-
import { computed,
|
|
62
|
+
import { computed, Ref, ref } from 'vue';
|
|
62
63
|
import { ChevronDown, ChevronUp, X } from 'lucide-vue-next';
|
|
63
64
|
import BmsTag from './BmsTag.vue';
|
|
64
65
|
import { InputOption } from '@/models';
|
|
65
|
-
import _ from 'lodash';
|
|
66
66
|
import { searchString } from '@/helpers';
|
|
67
67
|
import { FieldComponentProps } from '@/plugins/field/field-component.model';
|
|
68
68
|
import RawSelect from './RawSelect.vue';
|
|
69
|
+
import { onClickOutside } from '@vueuse/core';
|
|
69
70
|
|
|
70
71
|
export interface Props extends FieldComponentProps {
|
|
71
|
-
options: InputOption[];
|
|
72
|
+
options: InputOption[] | string[];
|
|
72
73
|
placeholder?: string;
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -77,7 +78,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
77
78
|
disabled: false,
|
|
78
79
|
required: false,
|
|
79
80
|
});
|
|
80
|
-
|
|
81
|
+
|
|
82
|
+
const inputElement: Ref<HTMLElement | null> = ref(null);
|
|
81
83
|
|
|
82
84
|
const isDatalistOpen = ref(false);
|
|
83
85
|
|
|
@@ -86,12 +88,19 @@ const openDatalist = () => (isDatalistOpen.value = true);
|
|
|
86
88
|
|
|
87
89
|
const searching = ref('');
|
|
88
90
|
|
|
89
|
-
const modelValue = defineModel<
|
|
90
|
-
|
|
91
|
+
const modelValue = defineModel<string[] | null>('modelValue', { default: [] });
|
|
92
|
+
|
|
93
|
+
onClickOutside(inputElement, closeDatalist, {
|
|
94
|
+
ignore: ['.datalist-option', '.icon-toggle-button'],
|
|
91
95
|
});
|
|
92
96
|
|
|
93
97
|
const onBackspace = () => {
|
|
94
|
-
|
|
98
|
+
if (
|
|
99
|
+
searching.value.length === 0 &&
|
|
100
|
+
modelValue.value &&
|
|
101
|
+
modelValue.value.length > 0
|
|
102
|
+
)
|
|
103
|
+
modelValue.value.splice(-1);
|
|
95
104
|
};
|
|
96
105
|
|
|
97
106
|
const setFocus = () => {
|
|
@@ -100,15 +109,20 @@ const setFocus = () => {
|
|
|
100
109
|
}
|
|
101
110
|
};
|
|
102
111
|
|
|
103
|
-
const onSelect = (option:
|
|
104
|
-
|
|
112
|
+
const onSelect = (option: InputOption | string) => {
|
|
113
|
+
if (typeof option === 'string') {
|
|
114
|
+
modelValue.value = (modelValue.value ?? []).concat(option);
|
|
115
|
+
} else if (option.value) {
|
|
116
|
+
modelValue.value = (modelValue.value ?? []).concat(option.value);
|
|
117
|
+
}
|
|
118
|
+
|
|
105
119
|
searching.value = '';
|
|
106
120
|
setFocus();
|
|
107
121
|
closeDatalist();
|
|
108
122
|
};
|
|
109
123
|
|
|
110
124
|
const removeOption = (value: string) => {
|
|
111
|
-
modelValue.value = modelValue.value.filter((o) => o
|
|
125
|
+
modelValue.value = (modelValue.value ?? []).filter((o) => o !== value);
|
|
112
126
|
};
|
|
113
127
|
|
|
114
128
|
const clearInput = () => {
|
|
@@ -116,18 +130,29 @@ const clearInput = () => {
|
|
|
116
130
|
searching.value = '';
|
|
117
131
|
};
|
|
118
132
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
const selectedItems = computed<InputOption[]>(() => {
|
|
134
|
+
if (!modelValue.value) return [];
|
|
135
|
+
|
|
136
|
+
const items: InputOption[] = [];
|
|
137
|
+
modelValue.value.forEach((selectedValue) => {
|
|
138
|
+
const item = optionsLabelValue.value.find(
|
|
139
|
+
(option) => option.value === selectedValue,
|
|
140
|
+
);
|
|
141
|
+
if (item) items.push(item);
|
|
142
|
+
});
|
|
143
|
+
return items;
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const optionsLabelValue = computed(() =>
|
|
147
|
+
Array.isArray(props.options) &&
|
|
148
|
+
!!props.options.length &&
|
|
149
|
+
typeof props.options[0] === 'string'
|
|
150
|
+
? props.options.map((o) => ({ label: o, value: o }) as InputOption)
|
|
151
|
+
: (props.options as InputOption[]),
|
|
125
152
|
);
|
|
126
153
|
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
props.options.find((option) => option.value === o.value),
|
|
130
|
-
),
|
|
154
|
+
const filteredOptions = computed(() =>
|
|
155
|
+
optionsLabelValue.value.filter((o) => searchString(o.label, searching.value)),
|
|
131
156
|
);
|
|
132
157
|
</script>
|
|
133
158
|
|
|
@@ -32,13 +32,12 @@
|
|
|
32
32
|
|
|
33
33
|
<script lang="ts" setup>
|
|
34
34
|
import { ChevronDown, ChevronUp } from 'lucide-vue-next';
|
|
35
|
-
import { computed, Ref, ref
|
|
35
|
+
import { computed, Ref, ref } from 'vue';
|
|
36
36
|
import _ from 'lodash';
|
|
37
37
|
import { InputOption } from '@/models';
|
|
38
38
|
import { FieldComponentProps } from '@/plugins/field/field-component.model';
|
|
39
39
|
import RawSelect from './RawSelect.vue';
|
|
40
40
|
import { onClickOutside } from '@vueuse/core';
|
|
41
|
-
import { v4 as uuid } from 'uuid';
|
|
42
41
|
|
|
43
42
|
export interface Props extends FieldComponentProps {
|
|
44
43
|
options: InputOption[];
|
|
@@ -56,7 +55,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
56
55
|
});
|
|
57
56
|
|
|
58
57
|
const modelValue = defineModel<any>('modelValue', { required: true });
|
|
59
|
-
|
|
58
|
+
|
|
59
|
+
const inputElement: Ref<HTMLElement | null> = ref(null);
|
|
60
60
|
|
|
61
61
|
const isDatalistOpen = ref(props.open);
|
|
62
62
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import BmsServerAutocomplete from '@/components/form/BmsServerAutocomplete.vue';
|
|
2
|
+
import { http, HttpResponse } from 'msw';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Composants/form/ServerAutocomplete',
|
|
6
|
+
component: BmsServerAutocomplete,
|
|
7
|
+
argTypes: {
|
|
8
|
+
disableSearch: {
|
|
9
|
+
control: { type: 'boolean' },
|
|
10
|
+
},
|
|
11
|
+
headers: {},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const mswRequestHandler = () =>
|
|
16
|
+
http.get('https://fakeapi.com/items', () =>
|
|
17
|
+
HttpResponse.json([
|
|
18
|
+
{
|
|
19
|
+
label: 'Label 1',
|
|
20
|
+
value: '1',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: 'Label 2',
|
|
24
|
+
value: '2',
|
|
25
|
+
},
|
|
26
|
+
]),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const Template = (args) => ({
|
|
30
|
+
components: {
|
|
31
|
+
BmsServerAutocomplete,
|
|
32
|
+
},
|
|
33
|
+
setup() {
|
|
34
|
+
return { args };
|
|
35
|
+
},
|
|
36
|
+
template: `
|
|
37
|
+
<BmsServerAutocomplete v-bind="args">
|
|
38
|
+
</BmsServerAutocomplete>
|
|
39
|
+
`,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const Default = Template.bind({});
|
|
43
|
+
Default.parameters = {
|
|
44
|
+
msw: {
|
|
45
|
+
handlers: [mswRequestHandler()],
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
Default.args = {
|
|
49
|
+
label: 'My autocomplete field',
|
|
50
|
+
modelValue: '',
|
|
51
|
+
url: 'https://fakeapi.com/items',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const WithRequest = Template.bind({});
|
|
55
|
+
WithRequest.args = {
|
|
56
|
+
label: 'My autocomplete field',
|
|
57
|
+
modelValue: '',
|
|
58
|
+
request: () => {
|
|
59
|
+
return new Promise((resolve) =>
|
|
60
|
+
resolve({
|
|
61
|
+
data: [
|
|
62
|
+
{
|
|
63
|
+
label: 'Label 1',
|
|
64
|
+
value: '1',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: 'Label 2',
|
|
68
|
+
value: '2',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<RawAutocomplete
|
|
3
|
+
v-model="modelValue"
|
|
4
|
+
:options="options"
|
|
5
|
+
:open="open"
|
|
6
|
+
:label="label"
|
|
7
|
+
:optional="optional"
|
|
8
|
+
:disabled="disabled"
|
|
9
|
+
:errors="errors"
|
|
10
|
+
:captions="captions"
|
|
11
|
+
:required="required"
|
|
12
|
+
:helperText="helperText"
|
|
13
|
+
:placeholder="placeholder"
|
|
14
|
+
:small="small"
|
|
15
|
+
:canAddNewOption="false"
|
|
16
|
+
@input="onInput"
|
|
17
|
+
@select="(option: any) => emits('select', option)"
|
|
18
|
+
>
|
|
19
|
+
<template #icon-start v-if="currentOptionIcon">
|
|
20
|
+
<span
|
|
21
|
+
class="icon"
|
|
22
|
+
v-if="typeof currentOptionIcon === 'string'"
|
|
23
|
+
v-html="currentOptionIcon"
|
|
24
|
+
></span>
|
|
25
|
+
<component v-else :is="currentOptionIcon" />
|
|
26
|
+
</template>
|
|
27
|
+
<template #icon-end>
|
|
28
|
+
<BmsLoader v-if="loading" :size="16" />
|
|
29
|
+
</template>
|
|
30
|
+
<template #option="{ option }: { option: any }">
|
|
31
|
+
<template v-if="option.icon">
|
|
32
|
+
<span
|
|
33
|
+
class="icon datalist-icon"
|
|
34
|
+
v-if="typeof option.icon === 'string'"
|
|
35
|
+
v-html="option.icon"
|
|
36
|
+
></span>
|
|
37
|
+
|
|
38
|
+
<component class="icon datalist-icon" v-else :is="option.icon" />
|
|
39
|
+
</template>
|
|
40
|
+
{{ option.label }}
|
|
41
|
+
</template>
|
|
42
|
+
</RawAutocomplete>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup lang="ts">
|
|
46
|
+
import { computed, onMounted, ref, watch } from 'vue';
|
|
47
|
+
import RawAutocomplete from './RawAutocomplete.vue';
|
|
48
|
+
import { InputOption } from '@/models';
|
|
49
|
+
import { FieldComponentProps } from '@/plugins/field/field-component.model';
|
|
50
|
+
import BmsLoader from '../feedback/BmsLoader.vue';
|
|
51
|
+
|
|
52
|
+
export interface Props extends FieldComponentProps {
|
|
53
|
+
url?: string;
|
|
54
|
+
request?: (
|
|
55
|
+
abortController: AbortController,
|
|
56
|
+
inputValue?: string,
|
|
57
|
+
url?: string,
|
|
58
|
+
) => Promise<{ data: InputOption[] }>;
|
|
59
|
+
|
|
60
|
+
modelValue?: string;
|
|
61
|
+
placeholder?: string;
|
|
62
|
+
open?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
66
|
+
open: false,
|
|
67
|
+
request: async (controller: AbortController, url?: string) => {
|
|
68
|
+
if (!url) {
|
|
69
|
+
throw 'URL must be defined';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const response = await fetch(url, {
|
|
73
|
+
method: 'GET',
|
|
74
|
+
signal: controller.signal,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const data = await response.json();
|
|
78
|
+
return { data };
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const modelValue = defineModel<string>('modelValue', {
|
|
83
|
+
default: null,
|
|
84
|
+
});
|
|
85
|
+
const emits = defineEmits<{
|
|
86
|
+
addNewOption: [newOption: string];
|
|
87
|
+
select: [option: InputOption];
|
|
88
|
+
}>();
|
|
89
|
+
|
|
90
|
+
const options = ref<InputOption[]>([]);
|
|
91
|
+
const loading = ref(true);
|
|
92
|
+
const controller = ref<AbortController>();
|
|
93
|
+
|
|
94
|
+
const loadData = async (search: string) => {
|
|
95
|
+
loading.value = true;
|
|
96
|
+
try {
|
|
97
|
+
if (controller.value) {
|
|
98
|
+
controller.value.abort();
|
|
99
|
+
}
|
|
100
|
+
controller.value = new AbortController();
|
|
101
|
+
loading.value = true;
|
|
102
|
+
|
|
103
|
+
const { data } = await props.request(controller.value, search, props.url);
|
|
104
|
+
|
|
105
|
+
options.value = data;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.error(e);
|
|
108
|
+
} finally {
|
|
109
|
+
loading.value = false;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
onMounted(() => loadData(''));
|
|
114
|
+
const onInput = (e: InputEvent) => {
|
|
115
|
+
loadData((e.target as HTMLInputElement)?.value);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const currentOptionIcon = computed(() => {
|
|
119
|
+
const option = options.value.find((o) => o.value === modelValue.value);
|
|
120
|
+
if (!option || typeof option === 'string') return undefined;
|
|
121
|
+
return option.icon;
|
|
122
|
+
});
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<style scoped lang="scss">
|
|
126
|
+
.icon {
|
|
127
|
+
height: 1em;
|
|
128
|
+
width: 1em;
|
|
129
|
+
|
|
130
|
+
&.datalist-icon {
|
|
131
|
+
margin: 0 0.5em;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
:deep(svg) {
|
|
135
|
+
height: 100%;
|
|
136
|
+
width: 100%;
|
|
137
|
+
|
|
138
|
+
* {
|
|
139
|
+
fill: currentColor !important;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
</style>
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
<script setup lang="ts">
|
|
54
54
|
import { searchString } from '@/helpers/string.helper';
|
|
55
55
|
import FieldDatalist from '@/plugins/field/FieldDatalist.vue';
|
|
56
|
-
import { computed,
|
|
56
|
+
import { computed, Ref, ref, watch } from 'vue';
|
|
57
57
|
import RawInputText from '@/components/form/RawInputText.vue';
|
|
58
58
|
import { InputOption, InputType } from '@/models';
|
|
59
59
|
import { ChevronDown, ChevronUp, X } from 'lucide-vue-next';
|
|
@@ -72,11 +72,12 @@ export interface Props extends FieldComponentProps {
|
|
|
72
72
|
const props = withDefaults(defineProps<Props>(), {
|
|
73
73
|
modelValue: null,
|
|
74
74
|
open: false,
|
|
75
|
+
canAddNewOption: false,
|
|
75
76
|
});
|
|
76
77
|
|
|
77
78
|
const modelValue = defineModel<string | null>('modelValue', { required: true });
|
|
78
79
|
|
|
79
|
-
const rawInput =
|
|
80
|
+
const rawInput: Ref<HTMLElement | null> = ref(null);
|
|
80
81
|
|
|
81
82
|
const emits = defineEmits<{
|
|
82
83
|
addNewOption: [newOption: string];
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
transformValueForComponent(filter?.valueFrom, filter.type)
|
|
51
51
|
"
|
|
52
52
|
:valueTo="transformValueForComponent(filter?.valueTo, filter.type)"
|
|
53
|
+
:autocompleteRequest="filter?.autocompleteRequest"
|
|
53
54
|
:options="getFilterOptions(filter) as any"
|
|
54
55
|
@input="
|
|
55
56
|
(e: InputEvent) =>
|
|
@@ -95,6 +96,7 @@ import _cloneDeep from 'lodash/cloneDeep';
|
|
|
95
96
|
import BmsIconButton from '../button/BmsIconButton.vue';
|
|
96
97
|
import BmsBetweenInput from '@/components/form/BmsBetweenInput.vue';
|
|
97
98
|
import { isBetweenFilter } from '@/composables/search.helper';
|
|
99
|
+
import BmsServerAutocomplete from '../form/BmsServerAutocomplete.vue';
|
|
98
100
|
|
|
99
101
|
const route = useRoute();
|
|
100
102
|
|
|
@@ -156,6 +158,8 @@ const getFilterComponent = (type: FilterType) => {
|
|
|
156
158
|
return BmsInputDateTime;
|
|
157
159
|
case 'autocomplete':
|
|
158
160
|
return BmsAutocomplete;
|
|
161
|
+
case 'autocompleteServer':
|
|
162
|
+
return BmsServerAutocomplete;
|
|
159
163
|
case 'select':
|
|
160
164
|
return BmsSelect;
|
|
161
165
|
case 'betweenNumber':
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputType } from './form.model';
|
|
1
|
+
import { InputOption, InputType } from './form.model';
|
|
2
2
|
import { Sort, SortFunction } from './sort.model';
|
|
3
3
|
|
|
4
4
|
export enum ColumnType {
|
|
@@ -34,6 +34,7 @@ export type FilterType =
|
|
|
34
34
|
| 'inputDate'
|
|
35
35
|
| 'boolean'
|
|
36
36
|
| 'autocomplete'
|
|
37
|
+
| 'autocompleteServer'
|
|
37
38
|
| 'betweenNumber'
|
|
38
39
|
| 'betweenDate'
|
|
39
40
|
| 'betweenDateTime';
|
|
@@ -48,6 +49,10 @@ export interface Filter {
|
|
|
48
49
|
valueTo?: any;
|
|
49
50
|
selectOptions?: { label: string; value: any }[];
|
|
50
51
|
autocompleteOptions?: string[] | { label: string; value: string }[];
|
|
52
|
+
autocompleteRequest?: (
|
|
53
|
+
abortController: AbortController,
|
|
54
|
+
url?: string,
|
|
55
|
+
) => Promise<{ data: InputOption[] }>;
|
|
51
56
|
customFilter?: Function;
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
v-model="inputText"
|
|
27
27
|
/>
|
|
28
28
|
|
|
29
|
+
Valeur: {{ select }}
|
|
29
30
|
<BmsSelect
|
|
30
31
|
label="Select"
|
|
31
32
|
@blur="console.log('blur')"
|
|
@@ -33,12 +34,26 @@
|
|
|
33
34
|
:options="optionsLabelValue"
|
|
34
35
|
/>
|
|
35
36
|
|
|
37
|
+
Valeur: {{ multiSelect }}
|
|
36
38
|
<BmsMultiSelect
|
|
37
39
|
label="Multi-select"
|
|
38
40
|
v-model="multiSelect"
|
|
39
41
|
:options="optionsLabelValue"
|
|
40
42
|
/>
|
|
41
43
|
<br />
|
|
44
|
+
Valeur: {{ multiSelectText }}
|
|
45
|
+
<BmsMultiSelect
|
|
46
|
+
label="Multi-select text"
|
|
47
|
+
v-model="multiSelectText"
|
|
48
|
+
:options="optionsText"
|
|
49
|
+
/>
|
|
50
|
+
<br />
|
|
51
|
+
Valeur: {{ autocompleteText }}
|
|
52
|
+
<BmsServerAutocomplete
|
|
53
|
+
label="Autocomplete avec un appel API"
|
|
54
|
+
:request="autocompleteRequest"
|
|
55
|
+
v-model="autocompleteText"
|
|
56
|
+
/>
|
|
42
57
|
</template>
|
|
43
58
|
|
|
44
59
|
<script setup lang="ts">
|
|
@@ -49,12 +64,11 @@ import { ref } from 'vue';
|
|
|
49
64
|
import BmsButton from '@/components/button/BmsButton.vue';
|
|
50
65
|
import BmsSelect from '@/components/form/BmsSelect.vue';
|
|
51
66
|
import BmsMultiSelect from '@/components/form/BmsMultiSelect.vue';
|
|
52
|
-
import
|
|
53
|
-
import RawAutocomplete from '@/components/form/RawAutocomplete.vue';
|
|
54
|
-
import BmsInputText from '@/components/form/BmsInputText.vue';
|
|
67
|
+
import BmsServerAutocomplete from '@/components/form/BmsServerAutocomplete.vue';
|
|
55
68
|
|
|
56
69
|
const select = ref('');
|
|
57
|
-
const multiSelect = ref(
|
|
70
|
+
const multiSelect = ref(null);
|
|
71
|
+
const multiSelectText = ref(null);
|
|
58
72
|
|
|
59
73
|
const optionsLabelValue = ref(
|
|
60
74
|
range(0, 30).map((i) =>
|
|
@@ -69,6 +83,7 @@ const optionsText = ref(
|
|
|
69
83
|
range(0, 30).map((i) => (Math.random() > 0.5 ? `toto-${i}` : `titi-${i}`)),
|
|
70
84
|
);
|
|
71
85
|
const inputText = ref('');
|
|
86
|
+
const autocompleteText = ref('');
|
|
72
87
|
|
|
73
88
|
const optionsIcon = ref(
|
|
74
89
|
range(0, 30).map((i) =>
|
|
@@ -82,4 +97,12 @@ const inputValueIcon = ref('');
|
|
|
82
97
|
const onAddNewOption = (newOption: string) => {
|
|
83
98
|
optionsLabelValue.value.push({ label: newOption, value: newOption });
|
|
84
99
|
};
|
|
100
|
+
|
|
101
|
+
const autocompleteRequest = (
|
|
102
|
+
abortController: AbortController,
|
|
103
|
+
searchString?: string,
|
|
104
|
+
) =>
|
|
105
|
+
fetch(`http://localhost:3000/pokemon-types?search=${searchString}`).then(
|
|
106
|
+
(res) => res.json(),
|
|
107
|
+
);
|
|
85
108
|
</script>
|