vue3-extended-multiselect 0.2.1 → 1.0.0

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