sprintify-ui 0.0.135 → 0.0.136

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.
@@ -6,7 +6,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
6
6
  type: PropType<Option | undefined>;
7
7
  };
8
8
  name: {
9
- required: true;
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
- required: true;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprintify-ui",
3
- "version": "0.0.135",
3
+ "version": "0.0.136",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build-fast": "rimraf dist && vite build",
@@ -7,7 +7,6 @@ export default {
7
7
  component: BaseRadioGroup,
8
8
  argTypes: {},
9
9
  args: {
10
- name: 'character',
11
10
  labelKey: 'label',
12
11
  valueKey: 'value',
13
12
  options: options,
@@ -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
- required: true,
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: computed(() => props.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
- <slot />
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 Option = string | number | null;
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<Option | undefined>,
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
- return (
138
- options.value.findIndex((o) => isEqual(o.value, props.modelValue)) != -1
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>