sprintify-ui 0.0.135 → 0.0.137
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/sprintify-ui.es.js +6170 -6136
- package/dist/types/src/components/BaseMediaLibrary.vue.d.ts +2 -2
- package/dist/types/src/components/BaseRadioGroup.vue.d.ts +3 -2
- package/dist/types/src/components/BaseSelect.vue.d.ts +28 -0
- package/package.json +1 -1
- package/src/components/BaseMediaLibrary.stories.js +1 -1
- package/src/components/BaseMediaLibrary.vue +18 -6
- package/src/components/BaseRadioGroup.stories.js +0 -1
- package/src/components/BaseRadioGroup.vue +13 -2
- package/src/components/BaseSelect.stories.js +30 -0
- package/src/components/BaseSelect.vue +63 -7
|
@@ -15,7 +15,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
15
15
|
default: undefined;
|
|
16
16
|
};
|
|
17
17
|
max: {
|
|
18
|
-
default:
|
|
18
|
+
default: undefined;
|
|
19
19
|
type: NumberConstructor;
|
|
20
20
|
};
|
|
21
21
|
maxSize: {
|
|
@@ -60,7 +60,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
60
60
|
default: undefined;
|
|
61
61
|
};
|
|
62
62
|
max: {
|
|
63
|
-
default:
|
|
63
|
+
default: undefined;
|
|
64
64
|
type: NumberConstructor;
|
|
65
65
|
};
|
|
66
66
|
maxSize: {
|
|
@@ -6,7 +6,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
6
6
|
type: PropType<Option | undefined>;
|
|
7
7
|
};
|
|
8
8
|
name: {
|
|
9
|
-
|
|
9
|
+
default: undefined;
|
|
10
10
|
type: StringConstructor;
|
|
11
11
|
};
|
|
12
12
|
required: {
|
|
@@ -47,7 +47,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
47
47
|
type: PropType<Option | undefined>;
|
|
48
48
|
};
|
|
49
49
|
name: {
|
|
50
|
-
|
|
50
|
+
default: undefined;
|
|
51
51
|
type: StringConstructor;
|
|
52
52
|
};
|
|
53
53
|
required: {
|
|
@@ -86,6 +86,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
86
86
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
87
87
|
}, {
|
|
88
88
|
required: boolean;
|
|
89
|
+
name: string;
|
|
89
90
|
disabled: boolean;
|
|
90
91
|
modelValue: Option | undefined;
|
|
91
92
|
hasError: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PropType } from 'vue';
|
|
2
|
+
import { Option } from '@/types';
|
|
2
3
|
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
3
4
|
modelValue: {
|
|
4
5
|
default: undefined;
|
|
@@ -24,6 +25,18 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
24
25
|
default: boolean;
|
|
25
26
|
type: BooleanConstructor;
|
|
26
27
|
};
|
|
28
|
+
options: {
|
|
29
|
+
default: undefined;
|
|
30
|
+
type: PropType<Option[]>;
|
|
31
|
+
};
|
|
32
|
+
labelKey: {
|
|
33
|
+
default: undefined;
|
|
34
|
+
type: StringConstructor;
|
|
35
|
+
};
|
|
36
|
+
valueKey: {
|
|
37
|
+
default: undefined;
|
|
38
|
+
type: StringConstructor;
|
|
39
|
+
};
|
|
27
40
|
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
28
41
|
modelValue: {
|
|
29
42
|
default: undefined;
|
|
@@ -49,14 +62,29 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
49
62
|
default: boolean;
|
|
50
63
|
type: BooleanConstructor;
|
|
51
64
|
};
|
|
65
|
+
options: {
|
|
66
|
+
default: undefined;
|
|
67
|
+
type: PropType<Option[]>;
|
|
68
|
+
};
|
|
69
|
+
labelKey: {
|
|
70
|
+
default: undefined;
|
|
71
|
+
type: StringConstructor;
|
|
72
|
+
};
|
|
73
|
+
valueKey: {
|
|
74
|
+
default: undefined;
|
|
75
|
+
type: StringConstructor;
|
|
76
|
+
};
|
|
52
77
|
}>> & {
|
|
53
78
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
54
79
|
}, {
|
|
55
80
|
required: boolean;
|
|
56
81
|
name: string;
|
|
82
|
+
options: Option[];
|
|
57
83
|
disabled: boolean;
|
|
58
84
|
placeholder: string;
|
|
59
85
|
modelValue: (string | number | null) | undefined;
|
|
86
|
+
labelKey: string;
|
|
87
|
+
valueKey: string;
|
|
60
88
|
hasError: boolean;
|
|
61
89
|
}>, {
|
|
62
90
|
default: (_: {}) => any;
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
name="default"
|
|
19
19
|
v-bind="baseFileUploaderProps"
|
|
20
20
|
:max-size="maxSize"
|
|
21
|
-
:max="
|
|
21
|
+
:max="normalizedMax"
|
|
22
22
|
>
|
|
23
23
|
<div
|
|
24
24
|
class="rounded border border-dashed p-6 duration-150"
|
|
@@ -119,7 +119,7 @@ const props = defineProps({
|
|
|
119
119
|
default: undefined,
|
|
120
120
|
},
|
|
121
121
|
max: {
|
|
122
|
-
default:
|
|
122
|
+
default: undefined,
|
|
123
123
|
type: Number,
|
|
124
124
|
},
|
|
125
125
|
maxSize: {
|
|
@@ -170,6 +170,14 @@ const { emitUpdate, enableForm, disableForm } = useField({
|
|
|
170
170
|
errorType: 'alert',
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
+
const normalizedMax = computed(() => {
|
|
174
|
+
if (props.max == null) {
|
|
175
|
+
return 100;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return props.max;
|
|
179
|
+
});
|
|
180
|
+
|
|
173
181
|
const currentMediaInternal = ref(cloneDeep(props.currentMedia));
|
|
174
182
|
|
|
175
183
|
const normalizedModelValue = computed(() => {
|
|
@@ -203,10 +211,12 @@ function onUploadSuccess(file: UploadedFile) {
|
|
|
203
211
|
return;
|
|
204
212
|
}
|
|
205
213
|
|
|
206
|
-
if (numberOfFiles.value >=
|
|
214
|
+
if (numberOfFiles.value >= normalizedMax.value && normalizedMax.value > 1) {
|
|
207
215
|
notifications.push({
|
|
208
216
|
title: i18n.t('sui.whoops'),
|
|
209
|
-
text: i18n.t('sui.you_can_upload_up_to_n_files', {
|
|
217
|
+
text: i18n.t('sui.you_can_upload_up_to_n_files', {
|
|
218
|
+
count: normalizedMax.value,
|
|
219
|
+
}),
|
|
210
220
|
color: 'danger',
|
|
211
221
|
});
|
|
212
222
|
return;
|
|
@@ -214,7 +224,7 @@ function onUploadSuccess(file: UploadedFile) {
|
|
|
214
224
|
|
|
215
225
|
const modelValue = cloneDeep(normalizedModelValue.value);
|
|
216
226
|
|
|
217
|
-
if (
|
|
227
|
+
if (normalizedMax.value == 1) {
|
|
218
228
|
// Remove everything...
|
|
219
229
|
modelValue.to_remove.push(...currentMediaInternal.value.map((m) => m.id));
|
|
220
230
|
modelValue.to_add = [];
|
|
@@ -277,7 +287,9 @@ function sync(modelValue: MediaLibraryPayload) {
|
|
|
277
287
|
}
|
|
278
288
|
|
|
279
289
|
const maxFileText = computed(() => {
|
|
280
|
-
return i18n.t('sui.you_can_upload_up_to_n_files', {
|
|
290
|
+
return i18n.t('sui.you_can_upload_up_to_n_files', {
|
|
291
|
+
count: normalizedMax.value,
|
|
292
|
+
});
|
|
281
293
|
});
|
|
282
294
|
|
|
283
295
|
const maxFileSize = computed(() => {
|
|
@@ -36,6 +36,7 @@ import { PropType } from 'vue';
|
|
|
36
36
|
import { Option } from '@/types';
|
|
37
37
|
import { useHasOptions } from '@/composables/hasOptions';
|
|
38
38
|
import { useField } from '@/composables/field';
|
|
39
|
+
import { uniqueId } from 'lodash';
|
|
39
40
|
|
|
40
41
|
const props = defineProps({
|
|
41
42
|
modelValue: {
|
|
@@ -43,7 +44,7 @@ const props = defineProps({
|
|
|
43
44
|
type: [Object, null] as PropType<Option | undefined>,
|
|
44
45
|
},
|
|
45
46
|
name: {
|
|
46
|
-
|
|
47
|
+
default: undefined,
|
|
47
48
|
type: String,
|
|
48
49
|
},
|
|
49
50
|
required: {
|
|
@@ -82,8 +83,18 @@ const props = defineProps({
|
|
|
82
83
|
|
|
83
84
|
const emit = defineEmits(['update:modelValue']);
|
|
84
85
|
|
|
86
|
+
const dummyName = uniqueId('base-radio-');
|
|
87
|
+
|
|
88
|
+
const normalizedName = computed<string>(() => {
|
|
89
|
+
if (props.name) {
|
|
90
|
+
return props.name;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return dummyName;
|
|
94
|
+
});
|
|
95
|
+
|
|
85
96
|
const { nameInternal, requiredInternal, emitUpdate } = useField({
|
|
86
|
-
name:
|
|
97
|
+
name: normalizedName,
|
|
87
98
|
required: computed(() => props.required),
|
|
88
99
|
hasError: computed(() => props.hasError),
|
|
89
100
|
emit: emit,
|
|
@@ -2,6 +2,8 @@ import BaseSelect from './BaseSelect.vue';
|
|
|
2
2
|
import BaseInputLabel from './BaseInputLabel.vue';
|
|
3
3
|
import ShowValue from '../../.storybook/components/ShowValue.vue';
|
|
4
4
|
import { createFieldStory } from '../../.storybook/utils.js';
|
|
5
|
+
import { options } from '../../.storybook/utils';
|
|
6
|
+
import { computed } from 'vue';
|
|
5
7
|
|
|
6
8
|
export default {
|
|
7
9
|
title: 'Form/BaseSelect',
|
|
@@ -76,6 +78,34 @@ Disabled.args = {
|
|
|
76
78
|
disabled: true,
|
|
77
79
|
};
|
|
78
80
|
|
|
81
|
+
export const OptionsAsProps = (args) => ({
|
|
82
|
+
components: { BaseSelect, ShowValue },
|
|
83
|
+
setup() {
|
|
84
|
+
const value = ref('test');
|
|
85
|
+
const showTest = ref(false);
|
|
86
|
+
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
showTest.value = true;
|
|
89
|
+
}, 3000);
|
|
90
|
+
|
|
91
|
+
const options2 = computed(() => {
|
|
92
|
+
if (!showTest.value) {
|
|
93
|
+
return options;
|
|
94
|
+
}
|
|
95
|
+
return [...options, { label: 'Test', value: 'test' }];
|
|
96
|
+
});
|
|
97
|
+
return { args, options2, value };
|
|
98
|
+
},
|
|
99
|
+
template: `<BaseSelect v-model="value" v-bind="args" class="w-full" :options="options2"></BaseSelect>
|
|
100
|
+
<ShowValue :value="value" />`,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
OptionsAsProps.args = {
|
|
104
|
+
required: true,
|
|
105
|
+
labelKey: 'label',
|
|
106
|
+
valueKey: 'value',
|
|
107
|
+
};
|
|
108
|
+
|
|
79
109
|
export const Field = createFieldStory({
|
|
80
110
|
component: BaseSelect,
|
|
81
111
|
componentName: 'BaseSelect',
|
|
@@ -22,17 +22,29 @@
|
|
|
22
22
|
{{ placeholder ? placeholder : $t('sui.select_an_option') }}
|
|
23
23
|
</option>
|
|
24
24
|
</template>
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
<slot>
|
|
27
|
+
<template v-if="normalizedOptions && normalizedOptions.length">
|
|
28
|
+
<option
|
|
29
|
+
v-for="option in normalizedOptions"
|
|
30
|
+
:key="option.value ?? 'null'"
|
|
31
|
+
:value="option.value"
|
|
32
|
+
>
|
|
33
|
+
{{ option.label }}
|
|
34
|
+
</option>
|
|
35
|
+
</template>
|
|
36
|
+
</slot>
|
|
26
37
|
</select>
|
|
27
38
|
</template>
|
|
28
39
|
|
|
29
40
|
<script lang="ts" setup>
|
|
30
41
|
import { PropType } from 'vue';
|
|
31
|
-
import { get, isEqual } from 'lodash';
|
|
42
|
+
import { get, isArray, isEqual } from 'lodash';
|
|
32
43
|
import { useMutationObserver } from '@vueuse/core';
|
|
33
44
|
import { useField } from '@/composables/field';
|
|
45
|
+
import { NormalizedOption, OptionValue, Option } from '@/types';
|
|
34
46
|
|
|
35
|
-
type
|
|
47
|
+
type SelectOption = string | number | null;
|
|
36
48
|
|
|
37
49
|
const EMPTY_VALUE_INTERNAL = '';
|
|
38
50
|
const EMPTY_VALUE_EXTERNAL = null;
|
|
@@ -40,7 +52,7 @@ const EMPTY_VALUE_EXTERNAL = null;
|
|
|
40
52
|
const props = defineProps({
|
|
41
53
|
modelValue: {
|
|
42
54
|
default: undefined,
|
|
43
|
-
type: [String, Number, null] as PropType<
|
|
55
|
+
type: [String, Number, null] as PropType<SelectOption | undefined>,
|
|
44
56
|
},
|
|
45
57
|
name: {
|
|
46
58
|
default: undefined,
|
|
@@ -62,6 +74,18 @@ const props = defineProps({
|
|
|
62
74
|
default: false,
|
|
63
75
|
type: Boolean,
|
|
64
76
|
},
|
|
77
|
+
options: {
|
|
78
|
+
default: undefined,
|
|
79
|
+
type: Array as PropType<Option[]>,
|
|
80
|
+
},
|
|
81
|
+
labelKey: {
|
|
82
|
+
default: undefined,
|
|
83
|
+
type: String,
|
|
84
|
+
},
|
|
85
|
+
valueKey: {
|
|
86
|
+
default: undefined,
|
|
87
|
+
type: String,
|
|
88
|
+
},
|
|
65
89
|
});
|
|
66
90
|
|
|
67
91
|
const select = ref<HTMLSelectElement | null>(null);
|
|
@@ -134,9 +158,11 @@ function checkIfModelValueIsValid(): boolean {
|
|
|
134
158
|
return true;
|
|
135
159
|
}
|
|
136
160
|
|
|
137
|
-
|
|
138
|
-
options.
|
|
139
|
-
|
|
161
|
+
if (props.options && props.options.length) {
|
|
162
|
+
return props.options.some((o) => isEqual(o.value, props.modelValue));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return options.value.some((o) => isEqual(o.value, props.modelValue));
|
|
140
166
|
}
|
|
141
167
|
|
|
142
168
|
/**
|
|
@@ -158,4 +184,34 @@ function onChange(event: Event) {
|
|
|
158
184
|
|
|
159
185
|
emitUpdate(value);
|
|
160
186
|
}
|
|
187
|
+
|
|
188
|
+
watchEffect(() => {
|
|
189
|
+
if (isArray(props.options) && (!props.labelKey || !props.valueKey)) {
|
|
190
|
+
console.error(
|
|
191
|
+
'BaseSelect: labelKey and valueKey are required when options is an array'
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const normalizedOptions = computed<NormalizedOption[] | undefined>(() => {
|
|
197
|
+
if (!props.options) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!props.labelKey) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!props.valueKey) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return props.options.map((option) => {
|
|
210
|
+
return {
|
|
211
|
+
label: option[props.labelKey as string] as string,
|
|
212
|
+
value: option[props.valueKey as string] as OptionValue,
|
|
213
|
+
option: option,
|
|
214
|
+
} as NormalizedOption;
|
|
215
|
+
});
|
|
216
|
+
});
|
|
161
217
|
</script>
|