@teammodlr/ui-kit 2.1.45 → 2.1.46
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/lib/components/select/Select.vue.d.ts +90 -2
- package/lib/components/select/types.d.ts +4 -0
- package/lib/index.cjs.js +7 -7
- package/lib/index.es.js +2151 -2132
- package/lib/types/props.d.ts +1 -0
- package/lib/utils/call.d.ts +7 -0
- package/package.json +1 -1
- package/src/components/select/Select.vue +755 -781
- package/src/components/select/examples/basic.vue +26 -21
- package/src/components/select/types.ts +27 -0
- package/src/composables/useInput.ts +151 -151
- package/src/types/props.ts +21 -19
- package/src/utils/call.ts +34 -0
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<MSelect
|
|
3
|
-
v-model="value"
|
|
4
|
-
:options="options"
|
|
5
|
-
:option-value="'id'"
|
|
6
|
-
:option-label="'name'"
|
|
7
|
-
blank
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<MSelect
|
|
3
|
+
v-model="value"
|
|
4
|
+
:options="options"
|
|
5
|
+
:option-value="'id'"
|
|
6
|
+
:option-label="'name'"
|
|
7
|
+
blank
|
|
8
|
+
@update:value="testThis"
|
|
9
|
+
/>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script lang="ts" setup>
|
|
13
|
+
import { ref } from "vue";
|
|
14
|
+
|
|
15
|
+
// make list of options with 1000 items
|
|
16
|
+
const options = Array.from({ length: 50 }, (_, i) => ({
|
|
17
|
+
id: i,
|
|
18
|
+
name: `Option ${i+1}`
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const value = ref();
|
|
22
|
+
|
|
23
|
+
function testThis(value: any, option: any) {
|
|
24
|
+
alert('value: ' + value);
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type ValueAtom = string | number
|
|
2
|
+
export type Value = ValueAtom | string[] | number[] | ValueAtom[]
|
|
3
|
+
export type OnUpdateValue = (
|
|
4
|
+
value: string &
|
|
5
|
+
number &
|
|
6
|
+
ValueAtom &
|
|
7
|
+
string[] &
|
|
8
|
+
number[] &
|
|
9
|
+
ValueAtom[] &
|
|
10
|
+
(ValueAtom | null) &
|
|
11
|
+
(string[] | null) &
|
|
12
|
+
(number[] | null) &
|
|
13
|
+
(ValueAtom[] | null),
|
|
14
|
+
option: object & null
|
|
15
|
+
) => void
|
|
16
|
+
export type OnUpdateValueImpl = (
|
|
17
|
+
value:
|
|
18
|
+
| ValueAtom
|
|
19
|
+
| string[]
|
|
20
|
+
| number[]
|
|
21
|
+
| ValueAtom[]
|
|
22
|
+
| (ValueAtom | null)
|
|
23
|
+
| (string[] | null)
|
|
24
|
+
| (number[] | null)
|
|
25
|
+
| (ValueAtom[] | null),
|
|
26
|
+
option: object | null
|
|
27
|
+
) => void
|
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
// inspired by indielayer ui
|
|
2
|
-
import type { PropType } from 'vue';
|
|
3
|
-
import { ref, watch, inject, computed, onMounted, onUnmounted } from 'vue';
|
|
4
|
-
import { useId } from './useCachedUid';
|
|
5
|
-
import { FORM_STATE } from '../components/form/symbol';
|
|
6
|
-
|
|
7
|
-
export interface FormInput {
|
|
8
|
-
focus: () => void;
|
|
9
|
-
validate: (value: any) => void;
|
|
10
|
-
setError: (value: string) => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const useInput = (
|
|
14
|
-
props: any,
|
|
15
|
-
{
|
|
16
|
-
focus,
|
|
17
|
-
emit,
|
|
18
|
-
withListeners = true
|
|
19
|
-
}: {
|
|
20
|
-
focus: () => void;
|
|
21
|
-
emit: any;
|
|
22
|
-
withListeners?: boolean;
|
|
23
|
-
}
|
|
24
|
-
) => {
|
|
25
|
-
const isFirstValidation = ref(true);
|
|
26
|
-
const formError = ref(props.error);
|
|
27
|
-
|
|
28
|
-
const id = useId(null, 'input');
|
|
29
|
-
const name = props.name ? props.name : id;
|
|
30
|
-
const _name = ref(name);
|
|
31
|
-
|
|
32
|
-
watch(
|
|
33
|
-
() => props.error,
|
|
34
|
-
value => (formError.value = value)
|
|
35
|
-
);
|
|
36
|
-
watch(
|
|
37
|
-
() => props.name,
|
|
38
|
-
value => (name.value = value)
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const form = inject(FORM_STATE, null);
|
|
42
|
-
|
|
43
|
-
const reset = () => {
|
|
44
|
-
formError.value = '';
|
|
45
|
-
isFirstValidation.value = true;
|
|
46
|
-
emit('update:modelValue', '');
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const setError = (value: string) => {
|
|
50
|
-
formError.value = value;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const validate = (value: any): boolean => {
|
|
54
|
-
value = value || props.modelValue;
|
|
55
|
-
|
|
56
|
-
isFirstValidation.value = false;
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i < props.rules.length; i++) {
|
|
59
|
-
const item = props.rules[i];
|
|
60
|
-
|
|
61
|
-
let valid = true;
|
|
62
|
-
|
|
63
|
-
if (typeof item === 'function') {
|
|
64
|
-
valid = item(value);
|
|
65
|
-
} else if (Array.isArray(item) && item.length === 2) {
|
|
66
|
-
const { 0: rule, 1: options } = item;
|
|
67
|
-
valid = rule(value, options);
|
|
68
|
-
} else {
|
|
69
|
-
const rule = item.fn;
|
|
70
|
-
const { options } = item;
|
|
71
|
-
|
|
72
|
-
valid = rule(value, options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (valid !== true) {
|
|
76
|
-
formError.value = valid;
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
formError.value = '';
|
|
82
|
-
return true;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const inputListeners = withListeners
|
|
86
|
-
? computed(() => {
|
|
87
|
-
return {
|
|
88
|
-
blur: (event: Event) => emit('blur', event),
|
|
89
|
-
focus: (event: Event) => emit('focus', event),
|
|
90
|
-
input: (event: Event) => {
|
|
91
|
-
emit(
|
|
92
|
-
'update:modelValue',
|
|
93
|
-
(event.target as HTMLInputElement).value
|
|
94
|
-
);
|
|
95
|
-
},
|
|
96
|
-
change: (event: Event) => emit('change', event)
|
|
97
|
-
};
|
|
98
|
-
})
|
|
99
|
-
: {};
|
|
100
|
-
|
|
101
|
-
onMounted(() => {
|
|
102
|
-
form?.add(
|
|
103
|
-
_name.value,
|
|
104
|
-
focus,
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
validate,
|
|
107
|
-
// @ts-ignore
|
|
108
|
-
setError
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
onUnmounted(() => {
|
|
113
|
-
form?.remove(_name.value);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
id,
|
|
118
|
-
isFirstValidation,
|
|
119
|
-
formError,
|
|
120
|
-
insideForm: form?.insideForm ?? false,
|
|
121
|
-
inputListeners,
|
|
122
|
-
reset,
|
|
123
|
-
validate,
|
|
124
|
-
setError,
|
|
125
|
-
//@ts-ignore
|
|
126
|
-
formDisabled: form?.disabled.value || false,
|
|
127
|
-
//@ts-ignore
|
|
128
|
-
formLoading: form?.loading.value || false
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
useInput.emits = (withListeners = true): string[] => {
|
|
133
|
-
return withListeners
|
|
134
|
-
? ['update:modelValue', 'blur', 'focus', 'input', 'change']
|
|
135
|
-
: ['update:modelValue'];
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
useInput.props = () =>
|
|
139
|
-
({
|
|
140
|
-
modelValue: [String, Number, Boolean, Object, Array] as PropType<
|
|
141
|
-
string | number | boolean | object | any[] | any[] | undefined
|
|
142
|
-
>,
|
|
143
|
-
name: String,
|
|
144
|
-
readonly: Boolean,
|
|
145
|
-
required: Boolean,
|
|
146
|
-
error: String,
|
|
147
|
-
rules: {
|
|
148
|
-
type: Array,
|
|
149
|
-
default: () => []
|
|
150
|
-
}
|
|
151
|
-
}) as const;
|
|
1
|
+
// inspired by indielayer ui
|
|
2
|
+
import type { PropType } from 'vue';
|
|
3
|
+
import { ref, watch, inject, computed, onMounted, onUnmounted } from 'vue';
|
|
4
|
+
import { useId } from './useCachedUid';
|
|
5
|
+
import { FORM_STATE } from '../components/form/symbol';
|
|
6
|
+
|
|
7
|
+
export interface FormInput {
|
|
8
|
+
focus: () => void;
|
|
9
|
+
validate: (value: any) => void;
|
|
10
|
+
setError: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const useInput = (
|
|
14
|
+
props: any,
|
|
15
|
+
{
|
|
16
|
+
focus,
|
|
17
|
+
emit,
|
|
18
|
+
withListeners = true
|
|
19
|
+
}: {
|
|
20
|
+
focus: () => void;
|
|
21
|
+
emit: any;
|
|
22
|
+
withListeners?: boolean;
|
|
23
|
+
}
|
|
24
|
+
) => {
|
|
25
|
+
const isFirstValidation = ref(true);
|
|
26
|
+
const formError = ref(props.error);
|
|
27
|
+
|
|
28
|
+
const id = useId(null, 'input');
|
|
29
|
+
const name = props.name ? props.name : id;
|
|
30
|
+
const _name = ref(name);
|
|
31
|
+
|
|
32
|
+
watch(
|
|
33
|
+
() => props.error,
|
|
34
|
+
value => (formError.value = value)
|
|
35
|
+
);
|
|
36
|
+
watch(
|
|
37
|
+
() => props.name,
|
|
38
|
+
value => (name.value = value)
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const form = inject(FORM_STATE, null);
|
|
42
|
+
|
|
43
|
+
const reset = () => {
|
|
44
|
+
formError.value = '';
|
|
45
|
+
isFirstValidation.value = true;
|
|
46
|
+
emit('update:modelValue', '');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const setError = (value: string) => {
|
|
50
|
+
formError.value = value;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const validate = (value: any): boolean => {
|
|
54
|
+
value = value || props.modelValue;
|
|
55
|
+
|
|
56
|
+
isFirstValidation.value = false;
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < props.rules.length; i++) {
|
|
59
|
+
const item = props.rules[i];
|
|
60
|
+
|
|
61
|
+
let valid = true;
|
|
62
|
+
|
|
63
|
+
if (typeof item === 'function') {
|
|
64
|
+
valid = item(value);
|
|
65
|
+
} else if (Array.isArray(item) && item.length === 2) {
|
|
66
|
+
const { 0: rule, 1: options } = item;
|
|
67
|
+
valid = rule(value, options);
|
|
68
|
+
} else {
|
|
69
|
+
const rule = item.fn;
|
|
70
|
+
const { options } = item;
|
|
71
|
+
|
|
72
|
+
valid = rule(value, options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (valid !== true) {
|
|
76
|
+
formError.value = valid;
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
formError.value = '';
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const inputListeners = withListeners
|
|
86
|
+
? computed(() => {
|
|
87
|
+
return {
|
|
88
|
+
blur: (event: Event) => emit('blur', event),
|
|
89
|
+
focus: (event: Event) => emit('focus', event),
|
|
90
|
+
input: (event: Event) => {
|
|
91
|
+
emit(
|
|
92
|
+
'update:modelValue',
|
|
93
|
+
(event.target as HTMLInputElement).value
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
change: (event: Event) => emit('change', event)
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
: {};
|
|
100
|
+
|
|
101
|
+
onMounted(() => {
|
|
102
|
+
form?.add(
|
|
103
|
+
_name.value,
|
|
104
|
+
focus,
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
validate,
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
setError
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
onUnmounted(() => {
|
|
113
|
+
form?.remove(_name.value);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
id,
|
|
118
|
+
isFirstValidation,
|
|
119
|
+
formError,
|
|
120
|
+
insideForm: form?.insideForm ?? false,
|
|
121
|
+
inputListeners,
|
|
122
|
+
reset,
|
|
123
|
+
validate,
|
|
124
|
+
setError,
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
formDisabled: form?.disabled.value || false,
|
|
127
|
+
//@ts-ignore
|
|
128
|
+
formLoading: form?.loading.value || false
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
useInput.emits = (withListeners = true): string[] => {
|
|
133
|
+
return withListeners
|
|
134
|
+
? ['update:modelValue', 'blur', 'focus', 'input', 'change']
|
|
135
|
+
: ['update:modelValue'];
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
useInput.props = () =>
|
|
139
|
+
({
|
|
140
|
+
modelValue: [String, Number, Boolean, Object, Array] as PropType<
|
|
141
|
+
string | number | boolean | object | any[] | any[] | undefined
|
|
142
|
+
>,
|
|
143
|
+
name: String,
|
|
144
|
+
readonly: Boolean,
|
|
145
|
+
required: Boolean,
|
|
146
|
+
error: String,
|
|
147
|
+
rules: {
|
|
148
|
+
type: Array,
|
|
149
|
+
default: () => []
|
|
150
|
+
}
|
|
151
|
+
}) as const;
|
package/src/types/props.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
2
|
-
|
|
3
|
-
export type Color =
|
|
4
|
-
| 'white'
|
|
5
|
-
| 'black'
|
|
6
|
-
| 'blue'
|
|
7
|
-
| 'green'
|
|
8
|
-
| 'red'
|
|
9
|
-
| 'yellow'
|
|
10
|
-
| 'gray';
|
|
11
|
-
|
|
12
|
-
export type Variant =
|
|
13
|
-
| 'default'
|
|
14
|
-
| 'tertiary'
|
|
15
|
-
| 'primary'
|
|
16
|
-
| 'dark'
|
|
17
|
-
| 'success'
|
|
18
|
-
| 'warning'
|
|
19
|
-
| 'error';
|
|
1
|
+
export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
2
|
+
|
|
3
|
+
export type Color =
|
|
4
|
+
| 'white'
|
|
5
|
+
| 'black'
|
|
6
|
+
| 'blue'
|
|
7
|
+
| 'green'
|
|
8
|
+
| 'red'
|
|
9
|
+
| 'yellow'
|
|
10
|
+
| 'gray';
|
|
11
|
+
|
|
12
|
+
export type Variant =
|
|
13
|
+
| 'default'
|
|
14
|
+
| 'tertiary'
|
|
15
|
+
| 'primary'
|
|
16
|
+
| 'dark'
|
|
17
|
+
| 'success'
|
|
18
|
+
| 'warning'
|
|
19
|
+
| 'error';
|
|
20
|
+
|
|
21
|
+
export type MaybeArray<T> = T | T[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type AnyFunction = (...args: any[]) => any
|
|
2
|
+
|
|
3
|
+
function call(funcs: MaybeArray<() => void>): void
|
|
4
|
+
function call<A1>(funcs: MaybeArray<(a1: A1) => void>, a1: A1): void
|
|
5
|
+
function call<A1, A2>(
|
|
6
|
+
funcs: MaybeArray<(a1: A1, a2: A2) => void>,
|
|
7
|
+
a1: A1,
|
|
8
|
+
a2: A2
|
|
9
|
+
): void
|
|
10
|
+
function call<A1, A2, A3>(
|
|
11
|
+
funcs: MaybeArray<(a1: A1, a2: A2, a3: A3) => void>,
|
|
12
|
+
a1: A1,
|
|
13
|
+
a2: A2,
|
|
14
|
+
a3: A3
|
|
15
|
+
): void
|
|
16
|
+
function call<A1, A2, A3, A4>(
|
|
17
|
+
funcs: MaybeArray<(a1: A1, a2: A2, a3: A3, a4: A4) => void>,
|
|
18
|
+
a1: A1,
|
|
19
|
+
a2: A2,
|
|
20
|
+
a3: A3,
|
|
21
|
+
a4: A4
|
|
22
|
+
): void
|
|
23
|
+
function call<A extends any[]>(
|
|
24
|
+
funcs: AnyFunction[] | AnyFunction,
|
|
25
|
+
...args: A
|
|
26
|
+
): void {
|
|
27
|
+
if (Array.isArray(funcs)) {
|
|
28
|
+
funcs.forEach((func) => (call as any)(func, ...args))
|
|
29
|
+
} else return funcs(...args)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { call }
|
|
33
|
+
|
|
34
|
+
export type MaybeArray<T> = T | T[]
|