vue3-extended-multiselect 1.0.0 → 1.1.2

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.
Files changed (41) hide show
  1. package/.eslintrc.js +34 -34
  2. package/.github/workflows/publish.yml +41 -41
  3. package/CHANGELOG.md +109 -91
  4. package/LICENSE +21 -21
  5. package/README.md +261 -261
  6. package/index.js +2 -2
  7. package/jest.config.js +60 -57
  8. package/package.json +47 -47
  9. package/src/assets/base-arrow.svg +70 -70
  10. package/src/assets/cancel.svg +34 -34
  11. package/src/assets/circle-arrow.svg +7 -7
  12. package/src/assets/double-arrow.svg +39 -39
  13. package/src/assets/inner-arrow.svg +8 -8
  14. package/src/assets/loader.svg +5 -5
  15. package/src/assets/triangle-arrow.svg +72 -72
  16. package/src/assets/triangle-circle-arrow.svg +38 -38
  17. package/src/assets/wide-arrow.svg +72 -72
  18. package/src/components/ExtendedMultiselectCancel.vue +148 -148
  19. package/src/components/ExtendedMultiselectInput.vue +617 -617
  20. package/src/components/ExtendedMultiselectLoader.vue +182 -182
  21. package/src/components/ExtendedMultiselectMultiple.vue +295 -295
  22. package/src/components/ExtendedMultiselectOptions.vue +1092 -1091
  23. package/src/components/ExtendedMultiselectToggle.vue +261 -261
  24. package/src/components/Vue3ExtendedMultiselect.vue +1665 -1660
  25. package/src/composition/cancel.js +33 -33
  26. package/src/composition/image-path.js +16 -16
  27. package/src/composition/labels.js +39 -39
  28. package/src/composition/preselected-options.js +66 -66
  29. package/src/composition/search-value.js +33 -33
  30. package/src/composition/sizes.js +42 -42
  31. package/src/composition/toggle.js +33 -33
  32. package/src/events/emitter.js +2 -2
  33. package/src/sets/sets.js +99 -99
  34. package/src/styles/animations.css +18 -18
  35. package/src/styles/main.css +433 -432
  36. package/src/styles/variables.css +47 -47
  37. package/tests/unit/events.spec.js +135 -135
  38. package/tests/unit/props.spec.js +1040 -1040
  39. package/tests/utils/mount.js +37 -37
  40. package/tests/utils/utils.js +20 -20
  41. package/typings/vue3-extended-multiselect.d.ts +42 -42
@@ -1,296 +1,296 @@
1
- <template>
2
- <div class="extended__multiselect-block extended__multiselect-block--multiple">
3
- <div
4
- v-for="(option, index) in limitRestriction"
5
- :key="index"
6
- >
7
- <slot
8
- name="optionBlock"
9
- :label="optionCreateLabel(option)"
10
- :index="index"
11
- :deselect-block="deselectBlock"
12
- >
13
- <div :class="classes">
14
- <span>{{ optionCreateLabel(option) }}</span>
15
- <div
16
- class="extended__multiselect-block_cancel-wrapper"
17
- v-if="!loading"
18
- >
19
- <img
20
- alt=""
21
- class="extended__multiselect_deselect-block-icon"
22
- :src="deselectImage"
23
- @click.stop="deselectBlock(index)"
24
- />
25
- </div>
26
- </div>
27
- </slot>
28
- </div>
29
- <slot
30
- name="maxElements"
31
- v-if="optionsLimitAchieved && !toggleMultipleBlocksLimit"
32
- >
33
- {{ multipleBlocksLimitMessage(overLimitOptionsCount) }}
34
- </slot>
35
- <slot
36
- name="showMore"
37
- v-if="optionIncreaserAvailable"
38
- :show-more-options="showMoreOptions"
39
- >
40
- <div
41
- :class="[classes, increaserClass]"
42
- @click.stop="showMoreOptions"
43
- >
44
- Show more options
45
- </div>
46
- </slot>
47
- </div>
48
- </template>
49
-
50
- <script setup>
51
- import {
52
- computed,
53
- defineProps,
54
- onBeforeMount,
55
- ref,
56
- toRefs,
57
- watch,
58
- } from "vue";
59
-
60
- import emitter from "../events/emitter";
61
-
62
- import useImagePath from "../composition/image-path";
63
- import useLabels from "../composition/labels";
64
-
65
- const props = defineProps({
66
- /**
67
- * Function that creates custom label for
68
- * block with selected option
69
- * @property {Function} createCustomOptionLabel
70
- */
71
- createCustomOptionLabel: {
72
- type: Function,
73
- required: true,
74
- },
75
-
76
- /**
77
- * Blocks deselect block button
78
- * @property {boolean} disabled
79
- */
80
- disabled: {
81
- type: Boolean,
82
- required: true,
83
- },
84
-
85
- /**
86
- * Defines label for blocks with options of type "object"
87
- * or Array instances which length/keys length equals 0
88
- * @property {string} emptyObjectsPlaceholder
89
- */
90
- emptyObjectsPlaceholder: {
91
- type: String,
92
- required: true,
93
- },
94
-
95
- /**
96
- * Limit of hidden options amount to be shown next
97
- * @property {number} increaseDisplayBy
98
- */
99
- increaseDisplayBy: {
100
- type: Number,
101
- required: true,
102
- },
103
-
104
- /**
105
- * Hides all deselect buttons if equals true
106
- * @property {boolean} loading
107
- */
108
- loading: {
109
- type: Boolean,
110
- required: true,
111
- },
112
-
113
- /**
114
- * Limit of option blocks amount
115
- * @property {number} multipleBlocksLimit
116
- */
117
- multipleBlocksLimit: {
118
- type: Number,
119
- default: null,
120
- },
121
-
122
- /**
123
- * Allows to increase limit of displayed selected option blocks
124
- * @property {boolean} toggleMultipleBlocksLimit
125
- */
126
- toggleMultipleBlocksLimit: {
127
- type: Boolean,
128
- required: true,
129
- },
130
-
131
- /**
132
- * Function that creates limit message for maximal of selected options
133
- * @property {Function} multipleBlocksLimitMessage
134
- */
135
- multipleBlocksLimitMessage: {
136
- type: Function,
137
- required: true,
138
- },
139
-
140
- /**
141
- * List of selected options that will be shown as option blocks
142
- * @property {Array} selectedOptions
143
- */
144
- selectedOptions: {
145
- type: Array,
146
- required: true,
147
- },
148
-
149
- /**
150
- * Current theme of extended-multiselect
151
- * used in class definition
152
- * @property {string} themeType
153
- */
154
- themeType: {
155
- type: String,
156
- required: true,
157
- },
158
- });
159
-
160
- const {
161
- createCustomOptionLabel,
162
- disabled,
163
- emptyObjectsPlaceholder,
164
- increaseDisplayBy,
165
- loading,
166
- multipleBlocksLimit,
167
- selectedOptions,
168
- themeType,
169
- toggleMultipleBlocksLimit,
170
- } = toRefs(props);
171
-
172
- const { createImagePath } = useImagePath();
173
-
174
- const optionsLimitIncreaser = ref(null);
175
- const increaserClass = ref("extended__multiselect-increaser");
176
- const deselectImage = ref(createImagePath("cancel.svg"));
177
-
178
- const { optionCreateLabel } = useLabels(createCustomOptionLabel, emptyObjectsPlaceholder);
179
-
180
- /**
181
- * Defines class for every selected option block
182
- * depends on current theme of extended multiselect
183
- * @function
184
- * @returns {string} class
185
- */
186
- const classes = computed(() => {
187
- const basicClassName = "extended__multiselect--multiple";
188
-
189
- switch(themeType.value) {
190
- case "basic":
191
- return `${basicClassName}-basic`;
192
- case "slate-grey":
193
- return `${basicClassName}-slate-grey`;
194
- case "slate-blue":
195
- return `${basicClassName}-slate-blue`;
196
- case "teal":
197
- return `${basicClassName}-teal`;
198
- case "strict":
199
- return `${basicClassName}-strict`;
200
- default:
201
- return `${basicClassName}-basic`;
202
- }
203
- });
204
-
205
- /**
206
- * Defines current limited amount of displayed option blocks
207
- * @function
208
- * @returns {Array} UnionPropType
209
- */
210
- const limitRestriction = computed(() => {
211
- if (!optionsLimitIncreaser.value) return selectedOptions.value;
212
-
213
- return selectedOptions.value.filter((selectedOption, index) => {
214
- const limit = typeof optionsLimitIncreaser.value === "number"
215
- ? optionsLimitIncreaser.value
216
- : optionsLimitIncreaser.value.value;
217
-
218
- return ++index <= limit;
219
- });
220
- });
221
-
222
- /**
223
- * Determines whether user can increase limited amount of displayed option blocks
224
- * @function
225
- * @returns {boolean} possibility
226
- */
227
- const optionIncreaserAvailable = computed(() => {
228
- return toggleMultipleBlocksLimit.value && optionsLimitAchieved.value;
229
- });
230
-
231
- /**
232
- * Determines whether current limit of displayed option blocks amount
233
- * was reached
234
- * @function
235
- * @returns {boolean} reaching
236
- */
237
- const optionsLimitAchieved = computed(() => {
238
- return optionsLimitIncreaser.value && selectedOptions.value.length > optionsLimitIncreaser.value;
239
- });
240
-
241
- /**
242
- * Amount of selected options exceeding the limit
243
- * determined by "multipleBlocksLimit" prop
244
- * @function
245
- * @returns {number|null} amount
246
- */
247
- const overLimitOptionsCount = computed(() => {
248
- if (selectedOptions.value.length <= multipleBlocksLimit.value) return null;
249
-
250
- return selectedOptions.value.length - multipleBlocksLimit.value;
251
- });
252
-
253
- /**
254
- * If limit of selected options was achieved restricts further
255
- * extension of options container if "multiple" prop equals true
256
- * @function
257
- * @param {Array} - array of selected options
258
- */
259
- watch(selectedOptions, (value) => {
260
- if (!value.length || value.length <= multipleBlocksLimit.value) {
261
- optionsLimitIncreaser.value = multipleBlocksLimit.value;
262
- }
263
- }, { deep: true });
264
-
265
- /**
266
- * Deselects option by users click on its element cancel icon
267
- * if "multiple" prop equals true
268
- * @function
269
- * @emits extended:deselect-option
270
- * @param {number} index - index of deselected option
271
- */
272
- const deselectBlock = (index) => {
273
- if (loading.value || disabled.value) return;
274
-
275
- emitter.emit("extended:deselect-option", { index });
276
- };
277
-
278
- /**
279
- * Shows next hidden options
280
- * This behavior restricts by "toggleMultipleBlocksLimit" prop
281
- * if "multiple" prop equals true
282
- * @function
283
- * @emits extended:increase-display
284
- */
285
- const showMoreOptions = () => {
286
- optionsLimitIncreaser.value += increaseDisplayBy.value;
287
- emitter.emit("extended:increase-display", optionsLimitIncreaser.value);
288
- };
289
-
290
- /**
291
- * "onBeforeMount" hook of ExtendedMultiselectMultiple component
292
- */
293
- onBeforeMount(() => {
294
- optionsLimitIncreaser.value = multipleBlocksLimit.value;
295
- });
1
+ <template>
2
+ <div class="extended__multiselect-block extended__multiselect-block--multiple">
3
+ <div
4
+ v-for="(option, index) in limitRestriction"
5
+ :key="index"
6
+ >
7
+ <slot
8
+ name="optionBlock"
9
+ :label="optionCreateLabel(option)"
10
+ :index="index"
11
+ :deselect-block="deselectBlock"
12
+ >
13
+ <div :class="classes">
14
+ <span>{{ optionCreateLabel(option) }}</span>
15
+ <div
16
+ class="extended__multiselect-block_cancel-wrapper"
17
+ v-if="!loading"
18
+ >
19
+ <img
20
+ alt=""
21
+ class="extended__multiselect_deselect-block-icon"
22
+ :src="deselectImage"
23
+ @click.stop="deselectBlock(index)"
24
+ />
25
+ </div>
26
+ </div>
27
+ </slot>
28
+ </div>
29
+ <slot
30
+ name="maxElements"
31
+ v-if="optionsLimitAchieved && !toggleMultipleBlocksLimit"
32
+ >
33
+ {{ multipleBlocksLimitMessage(overLimitOptionsCount) }}
34
+ </slot>
35
+ <slot
36
+ name="showMore"
37
+ v-if="optionIncreaserAvailable"
38
+ :show-more-options="showMoreOptions"
39
+ >
40
+ <div
41
+ :class="[classes, increaserClass]"
42
+ @click.stop="showMoreOptions"
43
+ >
44
+ Show more options
45
+ </div>
46
+ </slot>
47
+ </div>
48
+ </template>
49
+
50
+ <script setup>
51
+ import {
52
+ computed,
53
+ defineProps,
54
+ onBeforeMount,
55
+ ref,
56
+ toRefs,
57
+ watch,
58
+ } from "vue";
59
+
60
+ import emitter from "../events/emitter";
61
+
62
+ import useImagePath from "../composition/image-path";
63
+ import useLabels from "../composition/labels";
64
+
65
+ const props = defineProps({
66
+ /**
67
+ * Function that creates custom label for
68
+ * block with selected option
69
+ * @property {Function} createCustomOptionLabel
70
+ */
71
+ createCustomOptionLabel: {
72
+ type: Function,
73
+ required: true,
74
+ },
75
+
76
+ /**
77
+ * Blocks deselect block button
78
+ * @property {boolean} disabled
79
+ */
80
+ disabled: {
81
+ type: Boolean,
82
+ required: true,
83
+ },
84
+
85
+ /**
86
+ * Defines label for blocks with options of type "object"
87
+ * or Array instances which length/keys length equals 0
88
+ * @property {string} emptyObjectsPlaceholder
89
+ */
90
+ emptyObjectsPlaceholder: {
91
+ type: String,
92
+ required: true,
93
+ },
94
+
95
+ /**
96
+ * Limit of hidden options amount to be shown next
97
+ * @property {number} increaseDisplayBy
98
+ */
99
+ increaseDisplayBy: {
100
+ type: Number,
101
+ required: true,
102
+ },
103
+
104
+ /**
105
+ * Hides all deselect buttons if equals true
106
+ * @property {boolean} loading
107
+ */
108
+ loading: {
109
+ type: Boolean,
110
+ required: true,
111
+ },
112
+
113
+ /**
114
+ * Limit of option blocks amount
115
+ * @property {number} multipleBlocksLimit
116
+ */
117
+ multipleBlocksLimit: {
118
+ type: Number,
119
+ default: null,
120
+ },
121
+
122
+ /**
123
+ * Allows to increase limit of displayed selected option blocks
124
+ * @property {boolean} toggleMultipleBlocksLimit
125
+ */
126
+ toggleMultipleBlocksLimit: {
127
+ type: Boolean,
128
+ required: true,
129
+ },
130
+
131
+ /**
132
+ * Function that creates limit message for maximal of selected options
133
+ * @property {Function} multipleBlocksLimitMessage
134
+ */
135
+ multipleBlocksLimitMessage: {
136
+ type: Function,
137
+ required: true,
138
+ },
139
+
140
+ /**
141
+ * List of selected options that will be shown as option blocks
142
+ * @property {Array} selectedOptions
143
+ */
144
+ selectedOptions: {
145
+ type: Array,
146
+ required: true,
147
+ },
148
+
149
+ /**
150
+ * Current theme of extended-multiselect
151
+ * used in class definition
152
+ * @property {string} themeType
153
+ */
154
+ themeType: {
155
+ type: String,
156
+ required: true,
157
+ },
158
+ });
159
+
160
+ const {
161
+ createCustomOptionLabel,
162
+ disabled,
163
+ emptyObjectsPlaceholder,
164
+ increaseDisplayBy,
165
+ loading,
166
+ multipleBlocksLimit,
167
+ selectedOptions,
168
+ themeType,
169
+ toggleMultipleBlocksLimit,
170
+ } = toRefs(props);
171
+
172
+ const { createImagePath } = useImagePath();
173
+
174
+ const optionsLimitIncreaser = ref(null);
175
+ const increaserClass = ref("extended__multiselect-increaser");
176
+ const deselectImage = ref(createImagePath("cancel.svg"));
177
+
178
+ const { optionCreateLabel } = useLabels(createCustomOptionLabel, emptyObjectsPlaceholder);
179
+
180
+ /**
181
+ * Defines class for every selected option block
182
+ * depends on current theme of extended multiselect
183
+ * @function
184
+ * @returns {string} class
185
+ */
186
+ const classes = computed(() => {
187
+ const basicClassName = "extended__multiselect--multiple";
188
+
189
+ switch(themeType.value) {
190
+ case "basic":
191
+ return `${basicClassName}-basic`;
192
+ case "slate-grey":
193
+ return `${basicClassName}-slate-grey`;
194
+ case "slate-blue":
195
+ return `${basicClassName}-slate-blue`;
196
+ case "teal":
197
+ return `${basicClassName}-teal`;
198
+ case "strict":
199
+ return `${basicClassName}-strict`;
200
+ default:
201
+ return `${basicClassName}-basic`;
202
+ }
203
+ });
204
+
205
+ /**
206
+ * Defines current limited amount of displayed option blocks
207
+ * @function
208
+ * @returns {Array} UnionPropType
209
+ */
210
+ const limitRestriction = computed(() => {
211
+ if (!optionsLimitIncreaser.value) return selectedOptions.value;
212
+
213
+ return selectedOptions.value.filter((selectedOption, index) => {
214
+ const limit = typeof optionsLimitIncreaser.value === "number"
215
+ ? optionsLimitIncreaser.value
216
+ : optionsLimitIncreaser.value.value;
217
+
218
+ return ++index <= limit;
219
+ });
220
+ });
221
+
222
+ /**
223
+ * Determines whether user can increase limited amount of displayed option blocks
224
+ * @function
225
+ * @returns {boolean} possibility
226
+ */
227
+ const optionIncreaserAvailable = computed(() => {
228
+ return toggleMultipleBlocksLimit.value && optionsLimitAchieved.value;
229
+ });
230
+
231
+ /**
232
+ * Determines whether current limit of displayed option blocks amount
233
+ * was reached
234
+ * @function
235
+ * @returns {boolean} reaching
236
+ */
237
+ const optionsLimitAchieved = computed(() => {
238
+ return optionsLimitIncreaser.value && selectedOptions.value.length > optionsLimitIncreaser.value;
239
+ });
240
+
241
+ /**
242
+ * Amount of selected options exceeding the limit
243
+ * determined by "multipleBlocksLimit" prop
244
+ * @function
245
+ * @returns {number|null} amount
246
+ */
247
+ const overLimitOptionsCount = computed(() => {
248
+ if (selectedOptions.value.length <= multipleBlocksLimit.value) return null;
249
+
250
+ return selectedOptions.value.length - multipleBlocksLimit.value;
251
+ });
252
+
253
+ /**
254
+ * If limit of selected options was achieved restricts further
255
+ * extension of options container if "multiple" prop equals true
256
+ * @function
257
+ * @param {Array} - array of selected options
258
+ */
259
+ watch(selectedOptions, (value) => {
260
+ if (!value.length || value.length <= multipleBlocksLimit.value) {
261
+ optionsLimitIncreaser.value = multipleBlocksLimit.value;
262
+ }
263
+ }, { deep: true });
264
+
265
+ /**
266
+ * Deselects option by users click on its element cancel icon
267
+ * if "multiple" prop equals true
268
+ * @function
269
+ * @emits extended:deselect-option
270
+ * @param {number} index - index of deselected option
271
+ */
272
+ const deselectBlock = (index) => {
273
+ if (loading.value || disabled.value) return;
274
+
275
+ emitter.emit("extended:deselect-option", { index });
276
+ };
277
+
278
+ /**
279
+ * Shows next hidden options
280
+ * This behavior restricts by "toggleMultipleBlocksLimit" prop
281
+ * if "multiple" prop equals true
282
+ * @function
283
+ * @emits extended:increase-display
284
+ */
285
+ const showMoreOptions = () => {
286
+ optionsLimitIncreaser.value += increaseDisplayBy.value;
287
+ emitter.emit("extended:increase-display", optionsLimitIncreaser.value);
288
+ };
289
+
290
+ /**
291
+ * "onBeforeMount" hook of ExtendedMultiselectMultiple component
292
+ */
293
+ onBeforeMount(() => {
294
+ optionsLimitIncreaser.value = multipleBlocksLimit.value;
295
+ });
296
296
  </script>