@antify/ui 3.1.10 → 3.1.12

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.
@@ -78,6 +78,8 @@ const isOpen = ref(false);
78
78
  const _modelValue = computed<string[]>(() => [
79
79
  ...props.modelValue || [],
80
80
  ]);
81
+ let actuallyValueLength = ref<number>(0);
82
+
81
83
  const hasInputState = computed(() => props.skeleton || props.readonly || props.disabled);
82
84
  const inputClasses = computed(() => {
83
85
  const variants: Record<InputState, string> = {
@@ -148,15 +150,15 @@ const valueLabel = computed(() => {
148
150
  return;
149
151
  }
150
152
 
151
- if (_modelValue.value.length === 0) {
153
+ if (actuallyValueLength.value === 0) {
152
154
  return props.label || props.placeholder;
153
155
  }
154
156
 
155
- if (_modelValue.value.length === 1) {
156
- return `${_modelValue.value.length} ${props.singularValueLabel}`;
157
+ if (actuallyValueLength.value === 1) {
158
+ return `${actuallyValueLength.value} ${props.singularValueLabel}`;
157
159
  }
158
160
 
159
- return `${_modelValue.value.length} ${props.pluralValueLabel}`;
161
+ return `${actuallyValueLength.value} ${props.pluralValueLabel}`;
160
162
  });
161
163
  const iconSize = computed(() => {
162
164
  if (props.size === Size.lg || props.size === Size.md || props.size === Size.sm) {
@@ -165,21 +167,11 @@ const iconSize = computed(() => {
165
167
 
166
168
  return IconSize.xs;
167
169
  });
168
- const selectedCheckboxes = ref<string[]>( [
170
+ const selectedCheckboxes = ref<string[]>([
169
171
  ..._modelValue.value,
170
172
  ]);
171
173
  const inputRef = ref<HTMLElement | null>(null);
172
174
 
173
- onMounted(() => {
174
- handleEnumValidation(props.size, Size, 'size');
175
- handleEnumValidation(props.state, InputState, 'state');
176
- handleEnumValidation(props.grouped, Grouped, 'grouped');
177
-
178
- if (!props.skeleton && props.modelValue !== null) {
179
- emit('validate', props.modelValue);
180
- }
181
- });
182
-
183
175
  watch(isOpen, (val) => {
184
176
  if (!val) {
185
177
  emit('update:modelValue', selectedCheckboxes.value);
@@ -199,10 +191,13 @@ watch(() => props.skeleton, (val) => {
199
191
  }
200
192
  });
201
193
  watch(_modelValue, () => {
194
+ getActuallySelectedItems();
195
+
202
196
  if (props.messages.length > 0) {
203
197
  emit('validate', props.modelValue);
204
198
  }
205
199
  });
200
+ watch(() => props.options, () => getActuallySelectedItems());
206
201
 
207
202
  function onBlur(e: FocusEvent) {
208
203
  emit('validate', props.modelValue);
@@ -222,6 +217,36 @@ function onClickSelectInput(e: MouseEvent) {
222
217
 
223
218
  isOpen.value = !isOpen.value;
224
219
  }
220
+
221
+ function onClickClear() {
222
+ const optionValues = props.options.map(option => option.value);
223
+ const clearedValue = _modelValue.value.filter((value) => !optionValues.includes(value));
224
+
225
+ emit('update:modelValue', clearedValue);
226
+ }
227
+
228
+ function getActuallySelectedItems() {
229
+ actuallyValueLength.value = 0;
230
+
231
+ _modelValue.value.forEach((value) => {
232
+ props.options.forEach((option) => {
233
+ if (value === option.value) {
234
+ actuallyValueLength.value++;
235
+ }
236
+ });
237
+ });
238
+ }
239
+
240
+ onMounted(() => {
241
+ getActuallySelectedItems();
242
+ handleEnumValidation(props.size, Size, 'size');
243
+ handleEnumValidation(props.state, InputState, 'state');
244
+ handleEnumValidation(props.grouped, Grouped, 'grouped');
245
+
246
+ if (!props.skeleton && props.modelValue !== null) {
247
+ emit('validate', props.modelValue);
248
+ }
249
+ });
225
250
  </script>
226
251
 
227
252
  <template>
@@ -263,14 +288,14 @@ function onClickSelectInput(e: MouseEvent) {
263
288
  <slot name="icon" />
264
289
 
265
290
  <div
266
- v-if="(_modelValue === null || _modelValue.length === 0) && placeholder !== undefined"
291
+ v-if="(_modelValue === null || actuallyValueLength === 0) && placeholder !== undefined"
267
292
  :class="placeholderClasses"
268
293
  >
269
294
  {{ placeholder }}
270
295
  </div>
271
296
 
272
297
  <div
273
- v-else-if="(_modelValue === null || _modelValue.length === 0) && label !== undefined"
298
+ v-else-if="(_modelValue === null || actuallyValueLength === 0) && label !== undefined"
274
299
  :class="placeholderClasses"
275
300
  >
276
301
  {{ label }}
@@ -311,7 +336,7 @@ function onClickSelectInput(e: MouseEvent) {
311
336
  :icon-left="faMultiply"
312
337
  :grouped="Grouped.right"
313
338
  :size="size"
314
- @click="emit('update:modelValue', [])"
339
+ @click="onClickClear"
315
340
  />
316
341
  </div>
317
342
  </AntSkeleton>
@@ -8,6 +8,7 @@ var _Size = require("../../../enums/Size.enum");
8
8
  var _AntMultiSelect = _interopRequireDefault(require("../AntMultiSelect.vue"));
9
9
  var _AntFormGroup = _interopRequireDefault(require("../../forms/AntFormGroup.vue"));
10
10
  var _AntFormGroupLabel = _interopRequireDefault(require("../../forms/AntFormGroupLabel.vue"));
11
+ var _AntButton = _interopRequireDefault(require("../../AntButton.vue"));
11
12
  var _vue = require("vue");
12
13
  var _enums = require("../../../enums");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -79,7 +80,7 @@ const meta = {
79
80
  }
80
81
  };
81
82
  module.exports = meta;
82
- const options = [{
83
+ const options1 = [{
83
84
  label: "Option 1",
84
85
  value: "1"
85
86
  }, {
@@ -88,7 +89,8 @@ const options = [{
88
89
  }, {
89
90
  label: "Option 3",
90
91
  value: "3"
91
- }, {
92
+ }];
93
+ const options2 = [{
92
94
  label: "Option 4",
93
95
  value: "4"
94
96
  }, {
@@ -97,82 +99,49 @@ const options = [{
97
99
  }, {
98
100
  label: "Option 6",
99
101
  value: "6"
100
- }, {
101
- label: "Option 7",
102
- value: "7"
103
- }, {
104
- label: "Option 8",
105
- value: "8"
106
- }, {
107
- label: "Option 9",
108
- value: "9"
109
- }, {
110
- label: "Option 10",
111
- value: "10"
112
- }, {
113
- label: "Option 11",
114
- value: "11"
115
- }, {
116
- label: "Option 12",
117
- value: "12"
118
- }, {
119
- label: "Option 13",
120
- value: "13"
121
- }, {
122
- label: "Option 14",
123
- value: "14"
124
- }, {
125
- label: "Option 15",
126
- value: "15"
127
- }, {
128
- label: "Option 16",
129
- value: "16"
130
- }, {
131
- label: "Option 17",
132
- value: "17"
133
- }, {
134
- label: "Option 18",
135
- value: "18"
136
- }, {
137
- label: "Option 19",
138
- value: "19"
139
- }, {
140
- label: "Option 20",
141
- value: "20"
142
- }, {
143
- label: "Option 21",
144
- value: "21"
145
- }, {
146
- label: "Option 22",
147
- value: "22"
148
- }, {
149
- label: "Option 23",
150
- value: "23"
151
- }, {
152
- label: "Option 24",
153
- value: "24"
154
102
  }];
155
103
  const Docs = exports.Docs = {
156
104
  render: args => ({
157
105
  components: {
158
- AntMultiSelect: _AntMultiSelect.default
106
+ AntMultiSelect: _AntMultiSelect.default,
107
+ AntButton: _AntButton.default
159
108
  },
160
109
  setup() {
161
- const value = (0, _vue.ref)(null);
110
+ const value = (0, _vue.ref)(["26", "3"]);
111
+ const currentOptions = (0, _vue.ref)(options1);
112
+ const selectOptions = number => currentOptions.value = number === 1 ? options1 : options2;
162
113
  return {
163
114
  args,
164
- value
115
+ value,
116
+ State: _enums.State,
117
+ currentOptions,
118
+ selectOptions
165
119
  };
166
120
  },
167
121
  template: `
168
- <div class="flex flex-col justify-center">
169
- <AntMultiSelect v-bind="args" v-model="value"/>
122
+ <div class="flex flex-col justify-center gap-2.5">
123
+ <div class="flex gap-2.5">
124
+ <AntButton
125
+ :state="currentOptions[0].value === '1' ? State.primary : State.base"
126
+ :filled="currentOptions[0].value === '1'"
127
+ @click="selectOptions(1)"
128
+ >
129
+ Options 1
130
+ </AntButton>
131
+ <AntButton
132
+ :state="currentOptions[0].value === '4' ? State.primary : State.base"
133
+ :filled="currentOptions[0].value === '4'"
134
+ @click="selectOptions()"
135
+ >
136
+ Options 2
137
+ </AntButton>
138
+ </div>
139
+ <AntMultiSelect v-bind="args" v-model="value" :options="currentOptions"/>
170
140
  </div>
171
141
  `
172
142
  }),
173
143
  args: {
174
144
  label: "Label",
175
- options,
176
145
  description: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod",
177
146
  nullable: true
178
147
  }
@@ -243,6 +212,6 @@ const Summary = exports.Summary = {
243
212
  }),
244
213
  args: {
245
214
  placeholder: "Placeholder",
246
- options
215
+ options: options1
247
216
  }
248
217
  };
@@ -4,13 +4,15 @@ import {
4
4
  import AntMultiSelect from "../AntMultiSelect.vue";
5
5
  import AntFormGroup from "../../forms/AntFormGroup.vue";
6
6
  import AntFormGroupLabel from "../../forms/AntFormGroupLabel.vue";
7
+ import AntButton from "../../AntButton.vue";
7
8
  import {
8
9
  ref
9
10
  } from "vue";
10
11
  import {
11
12
  Direction,
12
13
  Grouped,
13
- InputState
14
+ InputState,
15
+ State
14
16
  } from "../../../enums/index.mjs";
15
17
  const meta = {
16
18
  computed: {
@@ -80,7 +82,7 @@ const meta = {
80
82
  }
81
83
  };
82
84
  export default meta;
83
- const options = [
85
+ const options1 = [
84
86
  {
85
87
  label: "Option 1",
86
88
  value: "1"
@@ -92,7 +94,9 @@ const options = [
92
94
  {
93
95
  label: "Option 3",
94
96
  value: "3"
95
- },
97
+ }
98
+ ];
99
+ const options2 = [
96
100
  {
97
101
  label: "Option 4",
98
102
  value: "4"
@@ -104,101 +108,53 @@ const options = [
104
108
  {
105
109
  label: "Option 6",
106
110
  value: "6"
107
- },
108
- {
109
- label: "Option 7",
110
- value: "7"
111
- },
112
- {
113
- label: "Option 8",
114
- value: "8"
115
- },
116
- {
117
- label: "Option 9",
118
- value: "9"
119
- },
120
- {
121
- label: "Option 10",
122
- value: "10"
123
- },
124
- {
125
- label: "Option 11",
126
- value: "11"
127
- },
128
- {
129
- label: "Option 12",
130
- value: "12"
131
- },
132
- {
133
- label: "Option 13",
134
- value: "13"
135
- },
136
- {
137
- label: "Option 14",
138
- value: "14"
139
- },
140
- {
141
- label: "Option 15",
142
- value: "15"
143
- },
144
- {
145
- label: "Option 16",
146
- value: "16"
147
- },
148
- {
149
- label: "Option 17",
150
- value: "17"
151
- },
152
- {
153
- label: "Option 18",
154
- value: "18"
155
- },
156
- {
157
- label: "Option 19",
158
- value: "19"
159
- },
160
- {
161
- label: "Option 20",
162
- value: "20"
163
- },
164
- {
165
- label: "Option 21",
166
- value: "21"
167
- },
168
- {
169
- label: "Option 22",
170
- value: "22"
171
- },
172
- {
173
- label: "Option 23",
174
- value: "23"
175
- },
176
- {
177
- label: "Option 24",
178
- value: "24"
179
111
  }
180
112
  ];
181
113
  export const Docs = {
182
114
  render: (args) => ({
183
115
  components: {
184
- AntMultiSelect
116
+ AntMultiSelect,
117
+ AntButton
185
118
  },
186
119
  setup() {
187
- const value = ref(null);
120
+ const value = ref([
121
+ "26",
122
+ "3"
123
+ ]);
124
+ const currentOptions = ref(options1);
125
+ const selectOptions = (number) => currentOptions.value = number === 1 ? options1 : options2;
188
126
  return {
189
127
  args,
190
- value
128
+ value,
129
+ State,
130
+ currentOptions,
131
+ selectOptions
191
132
  };
192
133
  },
193
134
  template: `
194
- <div class="flex flex-col justify-center">
195
- <AntMultiSelect v-bind="args" v-model="value"/>
135
+ <div class="flex flex-col justify-center gap-2.5">
136
+ <div class="flex gap-2.5">
137
+ <AntButton
138
+ :state="currentOptions[0].value === '1' ? State.primary : State.base"
139
+ :filled="currentOptions[0].value === '1'"
140
+ @click="selectOptions(1)"
141
+ >
142
+ Options 1
143
+ </AntButton>
144
+ <AntButton
145
+ :state="currentOptions[0].value === '4' ? State.primary : State.base"
146
+ :filled="currentOptions[0].value === '4'"
147
+ @click="selectOptions()"
148
+ >
149
+ Options 2
150
+ </AntButton>
151
+ </div>
152
+ <AntMultiSelect v-bind="args" v-model="value" :options="currentOptions"/>
196
153
  </div>
197
154
  `
198
155
  }),
199
156
  args: {
200
157
  label: "Label",
201
- options,
202
158
  description: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod",
203
159
  nullable: true
204
160
  }
@@ -273,6 +229,6 @@ export const Summary = {
273
229
  }),
274
230
  args: {
275
231
  placeholder: "Placeholder",
276
- options
232
+ options: options1
277
233
  }
278
234
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antify/ui",
3
- "version": "3.1.10",
3
+ "version": "3.1.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {