sprintify-ui 0.0.118 → 0.0.119

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.
@@ -1,9 +1,8 @@
1
1
  import { PropType } from 'vue';
2
- import { Option } from '@/types';
3
2
  declare const _default: import("vue").DefineComponent<{
4
3
  modelValue: {
5
4
  default: undefined;
6
- type: PropType<Option | Option[] | null | undefined>;
5
+ type: PropType<string[] | null | undefined>;
7
6
  };
8
7
  required: {
9
8
  default: boolean;
@@ -25,10 +24,18 @@ declare const _default: import("vue").DefineComponent<{
25
24
  default: boolean;
26
25
  type: BooleanConstructor;
27
26
  };
27
+ name: {
28
+ default: undefined;
29
+ type: StringConstructor;
30
+ };
31
+ hasError: {
32
+ default: boolean;
33
+ type: BooleanConstructor;
34
+ };
28
35
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
29
36
  modelValue: {
30
37
  default: undefined;
31
- type: PropType<Option | Option[] | null | undefined>;
38
+ type: PropType<string[] | null | undefined>;
32
39
  };
33
40
  required: {
34
41
  default: boolean;
@@ -50,13 +57,23 @@ declare const _default: import("vue").DefineComponent<{
50
57
  default: boolean;
51
58
  type: BooleanConstructor;
52
59
  };
60
+ name: {
61
+ default: undefined;
62
+ type: StringConstructor;
63
+ };
64
+ hasError: {
65
+ default: boolean;
66
+ type: BooleanConstructor;
67
+ };
53
68
  }>> & {
54
69
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
55
70
  }, {
56
71
  required: boolean;
72
+ name: string;
57
73
  disabled: boolean;
58
74
  multiple: boolean;
59
- modelValue: Option | Option[] | null | undefined;
75
+ modelValue: string[] | null | undefined;
76
+ hasError: boolean;
60
77
  buttonType: "button" | "submit";
61
78
  colors: string[];
62
79
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprintify-ui",
3
- "version": "0.0.118",
3
+ "version": "0.0.119",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build-fast": "rimraf dist && vite build",
@@ -40,7 +40,7 @@ Multiple.args = {
40
40
  export const Disabled = Template.bind({});
41
41
  Disabled.args = {
42
42
  disabled: true,
43
- modelValue: { label: '#16a34a', value: '#16a34a' },
43
+ modelValue: '#16a34a',
44
44
  };
45
45
 
46
46
  export const Field = createFieldStory({
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div>
3
3
  <BaseButtonGroup
4
- :model-value="modelValue"
4
+ :model-value="normalizeModelValue"
5
5
  :disabled="disabled"
6
6
  value-key="value"
7
7
  label-key="label"
@@ -12,7 +12,7 @@
12
12
  :button-class="''"
13
13
  :button-selected-class="''"
14
14
  :button-unselected-class="''"
15
- @update:model-value="$emit('update:modelValue', $event)"
15
+ @update:model-value="(value) => transformModelValue(value)"
16
16
  >
17
17
  <template #option="option">
18
18
  <div
@@ -32,14 +32,16 @@
32
32
 
33
33
  <script lang="ts" setup>
34
34
  import { PropType } from 'vue';
35
- import { Option } from '@/types';
36
35
  import { BaseButtonGroup } from '.';
36
+ import { isArray } from 'lodash';
37
+ import { useField } from '@/composables/field';
38
+ import { Option } from '@/types';
37
39
 
38
40
  const props = defineProps({
39
41
  modelValue: {
40
42
  default: undefined,
41
- type: [Object, Array, null, undefined] as PropType<
42
- Option[] | Option | null | undefined
43
+ type: [String, Array, null, undefined] as PropType<
44
+ string[] | string[] | null | undefined
43
45
  >,
44
46
  },
45
47
  required: {
@@ -76,9 +78,17 @@ const props = defineProps({
76
78
  default: false,
77
79
  type: Boolean,
78
80
  },
81
+ name: {
82
+ default: undefined,
83
+ type: String,
84
+ },
85
+ hasError: {
86
+ default: false,
87
+ type: Boolean,
88
+ },
79
89
  });
80
90
 
81
- defineEmits(['update:modelValue']);
91
+ const emit = defineEmits(['update:modelValue']);
82
92
 
83
93
  const colorOptions = computed(() => {
84
94
  return props.colors.map((c) => {
@@ -88,4 +98,52 @@ const colorOptions = computed(() => {
88
98
  };
89
99
  });
90
100
  });
101
+
102
+ const normalizeModelValue = computed(() => {
103
+ return isArray(props.modelValue)
104
+ ? props.modelValue?.map((m) => {
105
+ return {
106
+ label: m,
107
+ value: m,
108
+ };
109
+ })
110
+ : {
111
+ label: props.modelValue,
112
+ value: props.modelValue,
113
+ };
114
+ });
115
+
116
+ const { emitUpdate } = useField({
117
+ name: computed(() => props.name),
118
+ required: computed(() => props.required),
119
+ hasError: computed(() => props.hasError),
120
+ emit: emit,
121
+ });
122
+
123
+ function transformModelValue(payload: Option | Option[] | null) {
124
+ if (props.multiple) {
125
+ let newModalValue = [] as string[];
126
+
127
+ if (isArray(payload)) {
128
+ newModalValue = payload.map((option) => {
129
+ return option.value;
130
+ });
131
+ }
132
+
133
+ emitUpdate(newModalValue);
134
+ } else {
135
+ if (payload == null) {
136
+ emitUpdate(null);
137
+ return;
138
+ }
139
+
140
+ if (isArray(payload)) {
141
+ emitUpdate(null);
142
+ return;
143
+ }
144
+
145
+ const newOption = payload.value;
146
+ emitUpdate(newOption);
147
+ }
148
+ }
91
149
  </script>