vue3-extended-multiselect 0.0.1

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/.browserslistrc +3 -0
  2. package/.eslintrc.js +29 -0
  3. package/CHANGELOG.md +9 -0
  4. package/README.md +696 -0
  5. package/babel.config.js +5 -0
  6. package/index.js +3 -0
  7. package/jest.config.js +57 -0
  8. package/package.json +44 -0
  9. package/public/favicon.ico +0 -0
  10. package/public/index.html +17 -0
  11. package/src/assets/base-arrow.svg +70 -0
  12. package/src/assets/cancel.svg +35 -0
  13. package/src/assets/circle-arrow.svg +7 -0
  14. package/src/assets/double-arrow.svg +39 -0
  15. package/src/assets/inner-arrow.svg +8 -0
  16. package/src/assets/loader.svg +6 -0
  17. package/src/assets/triangle-arrow.svg +72 -0
  18. package/src/assets/triangle-circle-arrow.svg +38 -0
  19. package/src/assets/wide-arrow.svg +72 -0
  20. package/src/components/ExtendedMultiselectCancel.vue +142 -0
  21. package/src/components/ExtendedMultiselectInput.vue +619 -0
  22. package/src/components/ExtendedMultiselectLoader.vue +176 -0
  23. package/src/components/ExtendedMultiselectMultiple.vue +292 -0
  24. package/src/components/ExtendedMultiselectOptions.vue +1088 -0
  25. package/src/components/ExtendedMultiselectToggle.vue +255 -0
  26. package/src/components/Vue3ExtendedMultiselect.vue +1651 -0
  27. package/src/composition/cancel.js +31 -0
  28. package/src/composition/labels.js +40 -0
  29. package/src/composition/preselected-options.js +67 -0
  30. package/src/composition/search-value.js +34 -0
  31. package/src/composition/sizes.js +43 -0
  32. package/src/composition/toggle.js +34 -0
  33. package/src/sass/animations.sass +13 -0
  34. package/src/sass/main.sass +340 -0
  35. package/src/sass/mixins.sass +40 -0
  36. package/src/sass/variables.sass +37 -0
  37. package/src/sets/sets.js +100 -0
  38. package/tests/unit/events.spec.js +136 -0
  39. package/tests/unit/props.spec.js +1041 -0
  40. package/tests/utils/mount.js +38 -0
  41. package/tests/utils/stubs.js +1 -0
  42. package/tests/utils/utils.js +21 -0
  43. package/typings/vue3-extended-multiselect.d.ts +34 -0
@@ -0,0 +1,176 @@
1
+ <template>
2
+ <div class="extended__multiselect-loader">
3
+ <img
4
+ alt=""
5
+ :class="[iconFilterClass, iconSizeClass, 'extended__multiselect-loader-animate']"
6
+ :src="require('../assets/loader.svg')"
7
+ />
8
+ <svg
9
+ version="1.1"
10
+ xmlns="http://www.w3.org/2000/svg"
11
+ xmlns:xlink="http://www.w3.org/1999/xlink"
12
+ width="0"
13
+ height="0"
14
+ >
15
+ <defs>
16
+ <filter
17
+ x="0"
18
+ y="0"
19
+ width="1"
20
+ height="1"
21
+ id="filterLoaderDefault"
22
+ >
23
+ <feFlood flood-color="#00BFFF"/>
24
+ <feComposite
25
+ out="SourceGraphic"
26
+ in2="SourceGraphic"
27
+ operator="in"
28
+ />
29
+ </filter>
30
+ <filter
31
+ x="0"
32
+ y="0"
33
+ width="1"
34
+ height="1"
35
+ id="filterLoaderBasic"
36
+ >
37
+ <feFlood flood-color="#708090"/>
38
+ <feComposite
39
+ out="SourceGraphic"
40
+ in2="SourceGraphic"
41
+ operator="in"
42
+ />
43
+ </filter>
44
+ <filter
45
+ x="0"
46
+ y="0"
47
+ width="1"
48
+ height="1"
49
+ id="filterLoaderSlateGrey"
50
+ >
51
+ <feFlood flood-color="#2F4F4F"/>
52
+ <feComposite
53
+ out="SourceGraphic"
54
+ in2="SourceGraphic"
55
+ operator="in"
56
+ />
57
+ </filter>
58
+ <filter
59
+ x="0"
60
+ y="0"
61
+ width="1"
62
+ height="1"
63
+ id="filterLoaderSlateBlue"
64
+ >
65
+ <feFlood flood-color="#483D8B"/>
66
+ <feComposite
67
+ out="SourceGraphic"
68
+ in2="SourceGraphic"
69
+ operator="in"
70
+ />
71
+ </filter>
72
+ <filter
73
+ x="0"
74
+ y="0"
75
+ width="1"
76
+ height="1"
77
+ id="filterLoaderTeal"
78
+ >
79
+ <feFlood flood-color="#008080"/>
80
+ <feComposite
81
+ out="SourceGraphic"
82
+ in2="SourceGraphic"
83
+ operator="in"
84
+ />
85
+ </filter>
86
+ <filter
87
+ x="0"
88
+ y="0"
89
+ width="1"
90
+ height="1"
91
+ id="filterLoaderStrict"
92
+ >
93
+ <feFlood flood-color="#00BFFF"/>
94
+ <feComposite
95
+ out="SourceGraphic"
96
+ in2="SourceGraphic"
97
+ operator="in"
98
+ />
99
+ </filter>
100
+ </defs>
101
+ </svg>
102
+ </div>
103
+ </template>
104
+
105
+ <script setup>
106
+ import {
107
+ computed,
108
+ defineProps,
109
+ inject,
110
+ toRefs,
111
+ } from "vue";
112
+
113
+ import useSizes from "../composition/sizes";
114
+
115
+ const props = defineProps({
116
+ /**
117
+ * Defines svg-filter for loader icon
118
+ * @property {string} iconFilter
119
+ */
120
+ iconFilter: {
121
+ type: String,
122
+ required: true,
123
+ },
124
+
125
+ /**
126
+ * Provides size to create special size-class
127
+ * for each kind of icon
128
+ * @property {string} iconSize
129
+ */
130
+ iconSize: {
131
+ type: String,
132
+ required: true,
133
+ },
134
+ });
135
+
136
+ const loaderIconFilter = inject("loaderIconFilter");
137
+
138
+ const { iconSize } = toRefs(props);
139
+
140
+ const { iconSizeClass } = useSizes(iconSize);
141
+
142
+ /**
143
+ * Defines class for loader icon
144
+ * depends on injected filter name
145
+ * @function
146
+ * @returns {string} class
147
+ */
148
+ const iconFilterClass = computed(() => {
149
+ let basicFilter = "extended__multiselect-loader";
150
+
151
+ switch(loaderIconFilter) {
152
+ case "default-loader":
153
+ basicFilter = `${basicFilter}_default-loader`;
154
+ break;
155
+ case "basic":
156
+ basicFilter = `${basicFilter}_basic`;
157
+ break;
158
+ case "slate-grey":
159
+ basicFilter = `${basicFilter}_slate-grey`;
160
+ break;
161
+ case "slate-blue":
162
+ basicFilter = `${basicFilter}_slate-blue`;
163
+ break;
164
+ case "teal":
165
+ basicFilter = `${basicFilter}_teal`;
166
+ break;
167
+ case "strict":
168
+ basicFilter = `${basicFilter}_strict`;
169
+ break;
170
+ default:
171
+ basicFilter = `${basicFilter}_default-loader`;
172
+ }
173
+
174
+ return basicFilter;
175
+ });
176
+ </script>
@@ -0,0 +1,292 @@
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
+ });
292
+ </script>