classcard-ui 0.2.1509 → 0.2.1510

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 (217) hide show
  1. package/README.md +24 -24
  2. package/dist/classcard-ui.common.js +90 -89
  3. package/dist/classcard-ui.common.js.map +1 -1
  4. package/dist/classcard-ui.css +1 -1
  5. package/dist/classcard-ui.umd.js +90 -89
  6. package/dist/classcard-ui.umd.js.map +1 -1
  7. package/dist/classcard-ui.umd.min.js +1 -1
  8. package/dist/classcard-ui.umd.min.js.map +1 -1
  9. package/package.json +84 -84
  10. package/src/.DS_Store +0 -0
  11. package/src/App.vue +16 -16
  12. package/src/colorConfig.js +52 -52
  13. package/src/components/CAlertModal/CAlertModal.vue +181 -181
  14. package/src/components/CAlertModal/index.js +3 -3
  15. package/src/components/CAlerts/CAlerts.vue +114 -114
  16. package/src/components/CAlerts/index.js +2 -2
  17. package/src/components/CAnchorTabs/CAnchorTabs.vue +100 -100
  18. package/src/components/CAnchorTabs/index.js +2 -2
  19. package/src/components/CAnchorTag/CAnchorTag.vue +84 -84
  20. package/src/components/CAnchorTag/index.js +2 -2
  21. package/src/components/CAvatar/CAvatar.vue +231 -231
  22. package/src/components/CAvatar/index.js +2 -2
  23. package/src/components/CAvatarGroup/CAvatarGroup.vue +213 -213
  24. package/src/components/CAvatarGroup/index.js +2 -2
  25. package/src/components/CBasicTable/CBasicTable.vue +184 -184
  26. package/src/components/CBasicTable/index.js +2 -2
  27. package/src/components/CBreadcrumbs/CBreadcrumbs.vue +38 -38
  28. package/src/components/CBreadcrumbs/index.js +2 -2
  29. package/src/components/CButton/CButton.vue +239 -239
  30. package/src/components/CButton/index.js +2 -2
  31. package/src/components/CButtonGroup/CButtonGroup.vue +155 -155
  32. package/src/components/CButtonGroup/index.js +2 -2
  33. package/src/components/CButtonIcon/CButtonIcon.vue +166 -166
  34. package/src/components/CButtonIcon/index.js +2 -2
  35. package/src/components/CButtonLink/CButtonLink.vue +43 -43
  36. package/src/components/CButtonLink/index.js +2 -2
  37. package/src/components/CButtonSelect/CButtonSelect.vue +186 -186
  38. package/src/components/CButtonSelect/index.js +2 -2
  39. package/src/components/CButtonSelectBorder/CButtonSelectBorder.vue +265 -265
  40. package/src/components/CButtonSelectBorder/index.js +3 -3
  41. package/src/components/CButtonWithDropdown/CButtonWithDropdown.vue +208 -208
  42. package/src/components/CButtonWithDropdown/index.js +2 -2
  43. package/src/components/CCalendar/CCalendar.vue +443 -443
  44. package/src/components/CCalendar/index.js +3 -3
  45. package/src/components/CCard/CCard.vue +53 -53
  46. package/src/components/CCard/index.js +2 -2
  47. package/src/components/CCheckbox/CCheckbox.vue +200 -200
  48. package/src/components/CCheckbox/index.js +2 -2
  49. package/src/components/CCircularButton/CCircularButton.vue +57 -57
  50. package/src/components/CCircularButton/index.js +2 -2
  51. package/src/components/CCollapsibleSection/CCollapsibleSection.vue +121 -121
  52. package/src/components/CCollapsibleSection/index.js +2 -2
  53. package/src/components/CColorDots/CColorDots.vue +52 -52
  54. package/src/components/CColorDots/index.js +3 -3
  55. package/src/components/CConfirmActionModal/CConfirmActionModal.vue +290 -290
  56. package/src/components/CConfirmActionModal/index.js +3 -3
  57. package/src/components/CDatepicker/CDatepicker.vue +235 -235
  58. package/src/components/CDatepicker/index.js +2 -2
  59. package/src/components/CDualSelect/CDualSelect.vue +193 -193
  60. package/src/components/CDualSelect/index.js +2 -2
  61. package/src/components/CEditor/CEditor.vue +137 -137
  62. package/src/components/CEditor/index.js +6 -6
  63. package/src/components/CEditor/quill-font-setup.js +133 -133
  64. package/src/components/CFormSectionHeading/CFormSectionHeading.vue +76 -76
  65. package/src/components/CFormSectionHeading/index.js +2 -2
  66. package/src/components/CGroupedFilterDropdown/CGroupedFilterDropdown.vue +331 -331
  67. package/src/components/CGroupedFilterDropdown/index.js +2 -2
  68. package/src/components/CGroupedSelect/CGroupedSelect.vue +393 -393
  69. package/src/components/CGroupedSelect/index.js +3 -3
  70. package/src/components/CIcon/CIcon.vue +112 -112
  71. package/src/components/CIcon/index.js +2 -2
  72. package/src/components/CIconDropdown/CIconDropdown.vue +206 -206
  73. package/src/components/CIconDropdown/index.js +2 -2
  74. package/src/components/CIconSelect/CIconSelect.vue +182 -182
  75. package/src/components/CIconSelect/index.js +3 -3
  76. package/src/components/CInput/CInput.vue +227 -227
  77. package/src/components/CInput/index.js +2 -2
  78. package/src/components/CInputAddon/CInputAddon.vue +297 -297
  79. package/src/components/CInputAddon/index.js +2 -2
  80. package/src/components/CInputEmail/CInputEmail.vue +107 -107
  81. package/src/components/CInputEmail/index.js +2 -2
  82. package/src/components/CInsetTabs/CInsetTabs.vue +222 -222
  83. package/src/components/CInsetTabs/index.js +3 -3
  84. package/src/components/CLinearProgressBar/CLinearProgressBar.vue +35 -35
  85. package/src/components/CLinearProgressBar/index.js +2 -2
  86. package/src/components/CModalHeading/CModalHeading.vue +22 -22
  87. package/src/components/CModalHeading/index.js +2 -2
  88. package/src/components/CModuleHelpLinks/CModuleHelpLinks.vue +88 -88
  89. package/src/components/CModuleHelpLinks/index.js +3 -3
  90. package/src/components/CMultiselect/CMultiselect.vue +1314 -1314
  91. package/src/components/CMultiselect/index.js +2 -2
  92. package/src/components/CMultiselectr/CMultiselectr.vue +44 -44
  93. package/src/components/CMultiselectr/index.js +2 -2
  94. package/src/components/CPageHeading/CPageHeading.vue +83 -83
  95. package/src/components/CPageHeading/index.js +2 -2
  96. package/src/components/CPagination/CPagination.vue +239 -239
  97. package/src/components/CPagination/index.js +2 -2
  98. package/src/components/CPhoneNumber/CPhoneNumber.vue +213 -213
  99. package/src/components/CPhoneNumber/index.js +2 -2
  100. package/src/components/CProgress/CProgress.vue +95 -95
  101. package/src/components/CProgress/index.js +2 -2
  102. package/src/components/CRadio/CRadio.vue +198 -198
  103. package/src/components/CRadio/index.js +2 -2
  104. package/src/components/CRadioGroup/CRadioGroup.vue +96 -96
  105. package/src/components/CRadioGroup/index.js +2 -2
  106. package/src/components/CRangeSlider/CRangeSlider.vue +55 -55
  107. package/src/components/CRangeSlider/index.js +2 -2
  108. package/src/components/CReorderableStackedList/CReorderableStackedList.vue +94 -94
  109. package/src/components/CReorderableStackedList/index.js +2 -2
  110. package/src/components/CSelect/CSelect.vue +1225 -1225
  111. package/src/components/CSelect/index.js +2 -2
  112. package/src/components/CSmallTimeline/CSmallTimeline.vue +40 -40
  113. package/src/components/CSmallTimeline/index.js +2 -2
  114. package/src/components/CStackedList/CStackedList.vue +162 -162
  115. package/src/components/CStackedList/index.js +2 -2
  116. package/src/components/CStats/CStats.vue +157 -157
  117. package/src/components/CStats/index.js +2 -2
  118. package/src/components/CSwitch/CSwitch.vue +200 -200
  119. package/src/components/CSwitch/index.js +2 -2
  120. package/src/components/CTabLazy/CTabLazy.vue +83 -83
  121. package/src/components/CTabLazy/index.js +2 -2
  122. package/src/components/CTable/CTable.vue +1114 -1114
  123. package/src/components/CTable/index.js +2 -2
  124. package/src/components/CTabs/CTabs.vue +250 -250
  125. package/src/components/CTabs/index.js +2 -2
  126. package/src/components/CTag/CTag.vue +109 -109
  127. package/src/components/CTag/index.js +2 -2
  128. package/src/components/CTextarea/CTextarea.vue +118 -118
  129. package/src/components/CTextarea/index.js +2 -2
  130. package/src/components/CTimeline/CTimeline.vue +237 -237
  131. package/src/components/CTimeline/index.js +2 -2
  132. package/src/components/CTokenEditor/CTokenEditor.vue +804 -804
  133. package/src/components/CTokenEditor/index.js +3 -3
  134. package/src/components/CToolTip/CToolTip.vue +108 -108
  135. package/src/components/CToolTip/index.js +3 -3
  136. package/src/components/CUpload/CUpload.vue +332 -332
  137. package/src/components/CUpload/index.js +2 -2
  138. package/src/components/NumberAnimator.vue +112 -112
  139. package/src/components/index.js +60 -60
  140. package/src/helper.js +8 -8
  141. package/src/icons.js +870 -859
  142. package/src/main.js +22 -22
  143. package/src/stories/CAlertModal.stories.js +30 -30
  144. package/src/stories/CAlerts.stories.js +39 -39
  145. package/src/stories/CAnchorTabs.stories.js +29 -29
  146. package/src/stories/CAnchorTag.stories.js +38 -38
  147. package/src/stories/CAvatar.stories.js +38 -38
  148. package/src/stories/CAvatarGroup.stories.js +136 -136
  149. package/src/stories/CBasicTable.stories.js +316 -316
  150. package/src/stories/CBreadcrumbs.stories.js +24 -24
  151. package/src/stories/CButton.stories.js +49 -49
  152. package/src/stories/CButtonGroup.stories.js +43 -43
  153. package/src/stories/CButtonIcon.stories.js +27 -27
  154. package/src/stories/CButtonLink.stories.js +24 -24
  155. package/src/stories/CButtonSelect.stories.js +44 -44
  156. package/src/stories/CButtonSelectBorder.stories.js +56 -56
  157. package/src/stories/CButtonWithDropdown.stories.js +41 -41
  158. package/src/stories/CCalendar.stories.js +16 -16
  159. package/src/stories/CCard.stories.js +30 -30
  160. package/src/stories/CCheckbox.stories.js +38 -38
  161. package/src/stories/CCircularButton.stories.js +29 -29
  162. package/src/stories/CCollapsibleSection.stories.js +29 -29
  163. package/src/stories/CColorDots.stories.js +37 -37
  164. package/src/stories/CConfirmActionModal.stories.js +67 -67
  165. package/src/stories/CDatepicker.stories.js +31 -31
  166. package/src/stories/CDualSelect.stories.js +29 -29
  167. package/src/stories/CEditor.stories.js +36 -36
  168. package/src/stories/CFormSectionHeading.stories.js +37 -37
  169. package/src/stories/CGroupedFilterDropdown.stories.js +131 -131
  170. package/src/stories/CGroupedSelect.stories.js +103 -103
  171. package/src/stories/CIcon.stories.js +31 -31
  172. package/src/stories/CIconDropdown.stories.js +52 -52
  173. package/src/stories/CIconSelect.stories.js +45 -45
  174. package/src/stories/CInput.stories.js +50 -50
  175. package/src/stories/CInputAddon.stories.js +37 -37
  176. package/src/stories/CInputEmail.stories.js +27 -27
  177. package/src/stories/CInsetTabs.stories.js +50 -50
  178. package/src/stories/CLinearProgressBar.stories.js +22 -22
  179. package/src/stories/CModalHeading.stories.js +25 -25
  180. package/src/stories/CModuleHelpLinks.stories.js +25 -25
  181. package/src/stories/CMultiselect.stories.js +146 -146
  182. package/src/stories/CMultiselectr.stories.js +23 -23
  183. package/src/stories/CPageHeading.stories.js +32 -32
  184. package/src/stories/CPagination.stories.js +30 -30
  185. package/src/stories/CPhoneNumber.stories.js +37 -37
  186. package/src/stories/CProgress.stories.js +23 -23
  187. package/src/stories/CRadio.stories.js +44 -44
  188. package/src/stories/CRadioGroup.stories.js +51 -51
  189. package/src/stories/CRangeSlider.stories.js +23 -23
  190. package/src/stories/CReorderableStackedList.stories.js +23 -23
  191. package/src/stories/CSelect.stories.js +157 -157
  192. package/src/stories/CSmallTimeline.stories.js +26 -26
  193. package/src/stories/CStackedList.stories.js +37 -37
  194. package/src/stories/CStats.stories.js +53 -53
  195. package/src/stories/CSwitch.stories.js +28 -28
  196. package/src/stories/CTabLazy.stories.js +42 -42
  197. package/src/stories/CTable.stories.js +203 -203
  198. package/src/stories/CTabs.stories.js +36 -36
  199. package/src/stories/CTag.stories.js +37 -37
  200. package/src/stories/CTextarea.stories.js +32 -32
  201. package/src/stories/CTimeline.stories.js +26 -26
  202. package/src/stories/CTokenEditor.stories.js +136 -136
  203. package/src/stories/CToolTip.stories.js +27 -27
  204. package/src/stories/CUpload.stories.js +36 -36
  205. package/src/stories/Introduction.stories.mdx +207 -207
  206. package/src/stories/Page.vue +88 -88
  207. package/src/stories/assets/code-brackets.svg +0 -0
  208. package/src/stories/assets/colors.svg +0 -0
  209. package/src/stories/assets/comments.svg +0 -0
  210. package/src/stories/assets/direction.svg +0 -0
  211. package/src/stories/assets/flow.svg +0 -0
  212. package/src/stories/assets/plugin.svg +0 -0
  213. package/src/stories/assets/repo.svg +0 -0
  214. package/src/stories/assets/stackalt.svg +0 -0
  215. package/src/stories/header.css +26 -26
  216. package/src/stories/page.css +69 -69
  217. package/src/stories/utils.css +32 -32
@@ -1,1314 +1,1314 @@
1
- <template>
2
- <div>
3
- <div class="mb-1 flex w-full items-center justify-between" v-if="label">
4
- <div class="flex items-center">
5
- <!-- label of multiselect field -->
6
- <label v-if="label" class="text-sm font-medium text-gray-900">{{
7
- label
8
- }}</label>
9
- <!-- asterisk sign to render if field is required -->
10
- <p v-if="isRequired" class="ml-1 text-red-600">*</p>
11
- </div>
12
- <span v-if="hint" class="text-sm text-gray-500">{{ hint }}</span>
13
- </div>
14
- <div class="relative">
15
- <v-select
16
- ref="vselect"
17
- :class="[
18
- 'disabled:custom-disabled-state absolute inline-block h-full w-full text-sm',
19
- isMultiple && showOverFlowCount ? 'c-multiselect--capped-pills' : '',
20
- ]"
21
- :placeholder="placeholder"
22
- :multiple="isMultiple"
23
- :taggable="isTaggable"
24
- :push-tags="pushTags"
25
- :filterable="filterable"
26
- @keydown.native="handleKeydown"
27
- v-model="value"
28
- :options="isGrouped ? groupedArray : options"
29
- @input="setSelectedOptions"
30
- @search="fetchOptions"
31
- @search:focus="$emit('search:focus')"
32
- @option:selecting="handleSingleSelect"
33
- @option:selected="($event) => (addCheckBox ? null : $event)"
34
- @option:deselected="($event) => (addCheckBox ? null : $event)"
35
- :label="optionLabel"
36
- :clearable="clearable"
37
- :loading="loading"
38
- :id="id"
39
- @open="onOpen"
40
- @close="onClose"
41
- :disabled="isDisabled"
42
- :selectable="
43
- isGrouped
44
- ? (option) => (option.header ? false : getDisableOptions(option))
45
- : (option) => getDisableOptions(option)
46
- "
47
- :closeOnSelect="addCheckBox ? false : isGrouped ? false : true"
48
- >
49
- <template #open-indicator="{ attributes }">
50
- <span
51
- v-bind="attributes"
52
- :style="!shouldIconRotate ? 'transform:none;' : ''"
53
- >
54
- <c-icon
55
- v-if="icon"
56
- :name="icon.name"
57
- :type="icon.type"
58
- class="h-5 w-5 text-gray-400"
59
- />
60
- <c-icon
61
- v-else
62
- name="chevron-down"
63
- type="solid"
64
- class="h-5 w-5 text-gray-400"
65
- />
66
- </span>
67
- </template>
68
- <template
69
- #selected-option-container="{ option, deselect, multiple, disabled }"
70
- >
71
- <template v-for="row in [getPillRow(option)]">
72
- <div
73
- v-if="row && row.showPill"
74
- :key="row.slotKey"
75
- class="vs__selected vs__selected--capped inline-flex items-center gap-1.5"
76
- >
77
- <p
78
- v-if="!option.header"
79
- :class="[
80
- 'vs__selected-inner inline-flex min-w-0 max-w-[120px] items-center gap-1.5 rounded bg-gray-100 px-2 py-1 text-gray-800',
81
- isDisabled ? 'text-gray-500' : '',
82
- ]"
83
- >
84
- <c-icon
85
- v-if="option.icon"
86
- :name="option.icon.name"
87
- :type="option.icon.type"
88
- :class="[
89
- 'h-4 w-4 flex-shrink-0 text-gray-400',
90
- option.icon.optionIconClass,
91
- ]"
92
- />
93
- <c-avatar
94
- v-if="option.image && displaySelectedOptionAvatar"
95
- :size="
96
- option.description && showAdditionalText
97
- ? 'extrasmall'
98
- : 'extraextrasmall'
99
- "
100
- :image="option.image"
101
- :rounded="true"
102
- :description="option.description"
103
- class="flex-shrink-0"
104
- ></c-avatar>
105
- <c-avatar
106
- v-else-if="option.initials && displaySelectedOptionAvatar"
107
- size="extraextrasmall"
108
- :nameInitials="option.initials"
109
- :description="option.description"
110
- :rounded="true"
111
- :isDynamicallyColored="true"
112
- class="flex-shrink-0"
113
- ></c-avatar>
114
- <span class="min-w-0 flex-1 truncate">{{ row.label }}</span>
115
- <button
116
- v-if="multiple"
117
- type="button"
118
- class="flex h-2 w-2 flex-shrink-0 items-center justify-center rounded text-gray-400 focus:outline-none"
119
- :disabled="disabled"
120
- :title="`Deselect ${row.label}`"
121
- :aria-label="`Deselect ${row.label}`"
122
- @click.stop.prevent="deselect(option)"
123
- >
124
- <span class="text-base leading-none" aria-hidden="true"
125
- >×</span
126
- >
127
- </button>
128
- </p>
129
- <span
130
- v-if="row.showOverflowBadge"
131
- class="vs__selected-overflow inline-flex w-max rounded bg-gray-100 px-2 py-1 text-gray-800"
132
- aria-live="polite"
133
- >
134
- +{{ selectedOverflowCount }}
135
- </span>
136
- </div>
137
- </template>
138
- </template>
139
- <!-- eslint-disable-next-line vue/no-unused-vars -->
140
- <template #no-options="{ search, searching, loading }">
141
- <span v-if="search.length < 1"
142
- >Start typing to search for options...</span
143
- >
144
- <span v-else>No options found, try searching something else.</span>
145
- </template>
146
- <template #spinner="{ loading }">
147
- <svg
148
- class="h-5 w-5 animate-spin text-gray-400"
149
- xmlns="http://www.w3.org/2000/svg"
150
- fill="none"
151
- viewBox="0 0 24 24"
152
- v-if="loading"
153
- >
154
- <circle
155
- class="opacity-25"
156
- cx="12"
157
- cy="12"
158
- r="10"
159
- stroke="currentColor"
160
- stroke-width="4"
161
- ></circle>
162
- <path
163
- class="opacity-75"
164
- fill="currentColor"
165
- d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
166
- ></path>
167
- </svg>
168
- </template>
169
- <template v-slot:option="option">
170
- <slot
171
- v-if="$scopedSlots['custom-option']"
172
- name="custom-option"
173
- :option="option"
174
- />
175
- <template v-else>
176
- <div v-if="!isGrouped">
177
- <div v-if="option.hasNoData" class="dropdown-menu-bordered"></div>
178
- <div v-else class="group mt-1 flex h-full w-full items-center">
179
- <div @click.stop v-if="addCheckBox" class="flex-shrink-0">
180
- <c-checkbox
181
- :value="isChecked(option)"
182
- @onChange="handleSingleSelect(option)"
183
- />
184
- </div>
185
- <p v-if="showOptionImage" class="flex-shrink-0">
186
- <c-avatar
187
- v-if="option[imageLabel]"
188
- :size="
189
- option.description && showAdditionalText
190
- ? 'extrasmall'
191
- : 'extraextrasmall'
192
- "
193
- :image="option[imageLabel]"
194
- :rounded="true"
195
- :description="option.description"
196
- class="mr-2"
197
- ></c-avatar>
198
- <c-avatar
199
- v-if="
200
- !option.icon && !option[imageLabel] && option.initials
201
- "
202
- :size="
203
- option.description && showAdditionalText
204
- ? 'extrasmall'
205
- : 'extraextrasmall'
206
- "
207
- :nameInitials="option.initials"
208
- :description="option.description"
209
- :rounded="true"
210
- :isDynamicallyColored="true"
211
- class="mr-2"
212
- ></c-avatar>
213
- <c-icon
214
- v-if="
215
- option.icon && !option[imageLabel] && !option.initials
216
- "
217
- :name="option.icon.name"
218
- :type="option.icon.type"
219
- :class="[
220
- 'mr-2 h-5 w-5 text-gray-400',
221
- option.icon.optionIconClass,
222
- option.isDisabled || option.disabled
223
- ? 'opacity-50'
224
- : 'opacity-100',
225
- ]"
226
- :viewBox="option.icon.viewBox || '0 0 20 20'"
227
- :cursorType="
228
- option.isDisabled || option.disabled
229
- ? 'cursor-not-allowed'
230
- : 'cursor-pointer'
231
- "
232
- />
233
- </p>
234
- <div class="w-full">
235
- <div
236
- :class="`flex items-center justify-between ${checkboxWrapperClass}`"
237
- >
238
- <div :class="`flex items-center ${tagWrapperClass}`">
239
- <p>
240
- {{
241
- option[optionLabelSecondary]
242
- ? option[optionLabelSecondary]
243
- : option[optionLabel]
244
- }}
245
- </p>
246
- <div class="ml-3">
247
- <c-tag
248
- v-if="tags && option.info && option.info !== ''"
249
- :label="option.info"
250
- color="gray"
251
- ></c-tag>
252
- <span v-else class="-ml-3 text-gray-300">
253
- &nbsp;{{ option.info }}
254
- </span>
255
- </div>
256
- </div>
257
- </div>
258
- <p
259
- class="text-xs"
260
- v-if="option.description && showAdditionalText"
261
- >
262
- {{ option.description }}
263
- </p>
264
- </div>
265
- </div>
266
- </div>
267
- <div
268
- v-if="isGrouped"
269
- :class="[
270
- option.header
271
- ? 'sticky-group-header -mx-4 -my-2 bg-gray-200 px-3 py-2'
272
- : '',
273
- ]"
274
- >
275
- <v-list-subheader
276
- v-if="option.header"
277
- class="flex items-center gap-1 text-gray-900"
278
- >
279
- <c-icon
280
- v-if="option.icon"
281
- :name="option.icon.name"
282
- :type="option.icon.type"
283
- :class="`${
284
- option.icon.headerIconClass
285
- ? option.icon.headerIconClass
286
- : 'h-4 w-4'
287
- } text-gray-400`"
288
- />
289
- {{ option.header }}
290
- </v-list-subheader>
291
- <div
292
- :class="[
293
- 'group mt-1 flex h-full w-full',
294
- option.description ? 'items-start' : 'items-center',
295
- ]"
296
- >
297
- <div @click.stop v-if="addCheckBox && !option.header">
298
- <c-checkbox
299
- :value="isChecked(option)"
300
- @onChange="handleSingleSelect(option)"
301
- />
302
- </div>
303
- <div v-if="!option.header && showOptionImage">
304
- <c-avatar
305
- v-if="option.image"
306
- size="extraextrasmall"
307
- :image="option.image"
308
- :rounded="true"
309
- :description="option.description"
310
- class="mr-2"
311
- ></c-avatar>
312
- <c-avatar
313
- v-else
314
- size="extraextrasmall"
315
- :nameInitials="option.initials"
316
- :description="option.description"
317
- :rounded="true"
318
- :isDynamicallyColored="true"
319
- class="mr-2"
320
- ></c-avatar>
321
- </div>
322
- <div class="w-full">
323
- <div class="flex items-center">
324
- <p>
325
- {{
326
- option[optionLabelSecondary]
327
- ? option[optionLabelSecondary]
328
- : option[optionLabel]
329
- }}
330
- </p>
331
- <div class="ml-3">
332
- <span
333
- v-if="tags && option.info && option.info !== ''"
334
- class="inline-flex rounded-md bg-gray-400 px-2 py-px text-sm leading-5 text-white"
335
- >
336
- {{ option.info }}
337
- </span>
338
- <span v-else class="text-gray-300">
339
- {{ option.info }}
340
- </span>
341
- </div>
342
- </div>
343
-
344
- <p class="text-xs" v-if="option.description">
345
- {{ option.description }}
346
- </p>
347
- </div>
348
- </div>
349
- </div>
350
- </template>
351
- </template>
352
- <template #list-footer="{ search }">
353
- <li ref="load" class="loader" v-show="hasNextPage">
354
- Loading more options...
355
- </li>
356
-
357
- <!-- Footer buttons when footer buttons are visible -->
358
- <div
359
- v-if="showFooterButton || showFooterButton2"
360
- :class="[
361
- 'group sticky bottom-0 mt-1 bg-white',
362
- showFooterButton && showFooterButton2 ? 'space-y-2' : '',
363
- ]"
364
- >
365
- <li
366
- v-if="showFooterButton"
367
- :class="footerBtnClasses"
368
- class="cursor-pointer select-none bg-gray-50 py-2 pl-3 pr-9 text-gray-700 hover:bg-gray-100 hover:text-gray-900"
369
- :id="getActionIDFn(footerButtonText)"
370
- role="option"
371
- @click="$emit('footerButtonClick')"
372
- >
373
- <div class="flex items-center">
374
- <svg
375
- xmlns="http://www.w3.org/2000/svg"
376
- class="h-6 w-6 flex-shrink-0 text-gray-400"
377
- viewBox="0 0 20 20"
378
- fill="currentColor"
379
- >
380
- <path
381
- fill-rule="evenodd"
382
- d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z"
383
- clip-rule="evenodd"
384
- />
385
- </svg>
386
- <span class="ml-3 block truncate font-semibold">
387
- {{ footerButtonText }}
388
- </span>
389
- </div>
390
- </li>
391
- <li
392
- v-if="showFooterButton2"
393
- class="cursor-pointer select-none bg-gray-50 py-2 pl-3 pr-9 text-gray-700 hover:bg-gray-100 hover:text-gray-900"
394
- :class="footerBtnClasses2"
395
- :id="getActionIDFn(footerButtonText2)"
396
- role="option"
397
- @click="$emit('footerButtonClick2')"
398
- >
399
- <div class="flex items-center">
400
- <svg
401
- xmlns="http://www.w3.org/2000/svg"
402
- class="h-6 w-6 flex-shrink-0 text-gray-400"
403
- viewBox="0 0 20 20"
404
- fill="currentColor"
405
- >
406
- <path
407
- fill-rule="evenodd"
408
- d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z"
409
- clip-rule="evenodd"
410
- />
411
- </svg>
412
- <span class="ml-3 block truncate font-semibold">
413
- {{ footerButtonText2 }}
414
- </span>
415
- </div>
416
- </li>
417
- </div>
418
-
419
- <!-- Create option button when showCreateOption is true and there is a search term -->
420
- <div
421
- v-if="
422
- showCreateOption &&
423
- showCreateOptionAfterSearch &&
424
- search &&
425
- search.trim()
426
- "
427
- ref="createOption"
428
- class="sticky z-10 flex min-h-[44px] items-start gap-3 bg-white px-3 py-2 shadow-lg ring-1 ring-gray-900 ring-opacity-5"
429
- :style="footerStickyStyles.create"
430
- >
431
- <span class="word-break flex-1 text-sm text-gray-700">{{
432
- search
433
- }}</span>
434
-
435
- <button
436
- type="button"
437
- :id="id + '_create_button'"
438
- @mousedown="handleCreateOption($event, search)"
439
- class="flex items-center gap-1 text-sm text-indigo-700"
440
- >
441
- <c-icon
442
- type="solid"
443
- name="plus-circle-solid-v2"
444
- class="h-5 w-5 text-indigo-600"
445
- viewBox="0 0 24 24"
446
- ></c-icon>
447
- Create
448
- </button>
449
- </div>
450
-
451
- <!-- Other option checkbox when otherOption is true -->
452
- <div
453
- v-if="otherOption"
454
- ref="otherOption"
455
- class="sticky z-10 border-t border-gray-100 bg-gray-50 px-3 py-2"
456
- :style="footerStickyStyles.other"
457
- >
458
- <div class="flex" @mousedown.prevent.stop>
459
- <c-checkbox
460
- :value="isChecked(otherOption)"
461
- @onChange="handleOtherOptionChange"
462
- />
463
- <div class="flex-1" @click.stop="handleOtherOptionChange">
464
- <p class="text-sm font-medium text-gray-700">
465
- {{ otherOption[optionLabel] }}
466
- </p>
467
- <p class="mt-1 text-sm text-gray-500">
468
- {{ otherOption.description }}
469
- </p>
470
- </div>
471
- </div>
472
- </div>
473
-
474
- <!-- Clear all button when multiple is true and there are selected values -->
475
- <button
476
- v-if="isMultiple && hasSelectedValues"
477
- ref="clearAllButton"
478
- type="button"
479
- class="sticky z-10 w-full border-t border-gray-200 bg-gray-50 px-4 py-3 text-left text-sm text-gray-500 hover:text-gray-900 focus:outline-none"
480
- :style="footerStickyStyles.clear"
481
- :id="id + '_clear_all_button'"
482
- aria-label="Clear all selections"
483
- @mousedown.prevent.stop="handleClearAll"
484
- >
485
- Clear all
486
- </button>
487
- </template>
488
- </v-select>
489
- <button
490
- class="z-100 absolute top-2.5 right-10"
491
- :id="id + '_close_button'"
492
- v-if="showCloseButton && (value == null || value.length == 0)"
493
- @click.stop="handleCrossClick"
494
- >
495
- <c-icon
496
- name="close"
497
- type="outline-v2"
498
- class="h-4 w-4 text-gray-400"
499
- cursorType="cursor-pointer"
500
- />
501
- </button>
502
- </div>
503
- <p v-if="subLabel" class="mt-2 text-sm text-gray-500">{{ subLabel }}</p>
504
- <p
505
- v-if="!isValidate && errorMessage"
506
- class="mt-2 text-left text-sm text-red-600"
507
- >
508
- {{ errorMessage }}
509
- </p>
510
- <p v-if="helpText && isValidate == true" class="mt-2 text-sm text-gray-500">
511
- {{ helpText }}
512
- </p>
513
- </div>
514
- </template>
515
- <script>
516
- import vSelect from "vue-select";
517
- import CAvatar from "../CAvatar/CAvatar.vue";
518
- import CIcon from "../CIcon/CIcon.vue";
519
- import CCheckbox from "../CCheckbox/CCheckbox.vue";
520
- import { debounce } from "lodash-es";
521
- import "vue-select/dist/vue-select.css";
522
- import { getActionID } from "../../helper";
523
- import CTag from "../CTag/CTag.vue";
524
- export default {
525
- name: "CMultiselect",
526
- components: { vSelect, CAvatar, CCheckbox, CIcon, CTag },
527
- props: {
528
- id: {
529
- type: String,
530
- },
531
- clearInput: {
532
- type: Boolean,
533
- default: false,
534
- },
535
- options: {
536
- type: Array,
537
- required: true,
538
- },
539
- extraDetails: {
540
- type: Boolean,
541
- default: false,
542
- },
543
- displaySelectedOptionAvatar: {
544
- type: Boolean,
545
- default: false,
546
- },
547
- showFooterButton: {
548
- type: Boolean,
549
- default: false,
550
- },
551
- footerButtonText: {
552
- type: String,
553
- default: "",
554
- },
555
- label: String,
556
- isRequired: {
557
- type: Boolean,
558
- },
559
- subLabel: String,
560
- placeholder: {
561
- type: String,
562
- },
563
- // whether multiple fields are allowed or not
564
- isMultiple: {
565
- type: Boolean,
566
- },
567
- // append newly created tags in options
568
- pushTags: {
569
- type: Boolean,
570
- },
571
- // whether to allow user to create new options
572
- isTaggable: {
573
- type: Boolean,
574
- },
575
- getOptions: {
576
- // function to emit on search{
577
- type: Function,
578
- },
579
- customiseOption: {
580
- type: Boolean,
581
- },
582
- // whether to show profile picture in option
583
- showOptionImage: {
584
- type: Boolean,
585
- },
586
- // the name of the option to render in the selectpicker
587
- optionLabel: {
588
- type: String,
589
- },
590
- // the name of the option to render in the selectpicker
591
- optionLabelSecondary: {
592
- type: String,
593
- },
594
- selectedOptionLabel: {
595
- type: String,
596
- },
597
- // the key to compare the options when addCheckBox is true
598
- primaryComparisonKey: {
599
- type: String,
600
- default: "id",
601
- },
602
- // action to trigger after selecting option from dropdown
603
- onSelectOptions: {
604
- type: Function,
605
- },
606
- optionsSelected: {
607
- type: [Array, Object],
608
- },
609
- filterable: {
610
- type: Boolean,
611
- default: false,
612
- },
613
- clearable: {
614
- type: Boolean,
615
- default: true,
616
- },
617
- isValidate: {
618
- type: Boolean,
619
- default: true,
620
- },
621
- errorMessage: {
622
- type: String,
623
- },
624
- loading: {
625
- type: Boolean,
626
- default: false,
627
- },
628
- hasNextPage: {
629
- type: Boolean,
630
- default: false,
631
- },
632
- isDisabled: {
633
- type: Boolean,
634
- default: false,
635
- },
636
- // text adjacent to label of dropdown to provide hint about field
637
- hint: { type: String },
638
- helpText: {
639
- type: String,
640
- },
641
- tags: {
642
- type: Boolean,
643
- default: false,
644
- },
645
- isGrouped: {
646
- type: Boolean,
647
- default: false,
648
- },
649
- //to show the additional text, default true to prevent failure at any other place
650
- showAdditionalText: {
651
- type: Boolean,
652
- default: true,
653
- },
654
- addCheckBox: {
655
- type: Boolean,
656
- default: false,
657
- },
658
- showSelectedAvatar: {
659
- type: Boolean,
660
- default: false,
661
- },
662
- icon: {
663
- type: Object,
664
- },
665
- footerBtnClasses: {
666
- type: String,
667
- },
668
- shouldIconRotate: {
669
- type: Boolean,
670
- default: true,
671
- },
672
- imageLabel: {
673
- type: String,
674
- default: "image",
675
- },
676
- showFooterButton2: {
677
- type: Boolean,
678
- default: false,
679
- },
680
- footerButtonText2: {
681
- type: String,
682
- default: "",
683
- },
684
- footerBtnClasses2: {
685
- type: String,
686
- },
687
- showCloseButton: {
688
- type: Boolean,
689
- default: false,
690
- },
691
- showCreateOption: {
692
- type: Boolean,
693
- default: false,
694
- },
695
- otherOption: {
696
- type: Object,
697
- },
698
- tagWrapperClass: {
699
- type: String,
700
- default: "",
701
- },
702
- checkboxWrapperClass: {
703
- type: String,
704
- default: "",
705
- },
706
- // Enables/disables chip insert animation flow (phase 1 + phase 2 sweep).
707
- chipAnimationEnabled: {
708
- type: Boolean,
709
- default: false,
710
- },
711
- // When true, render all selected pills and hide "+N" overflow counter.
712
- showOverFlowCount: {
713
- type: Boolean,
714
- default: true,
715
- },
716
- //these are the options we don't want to display, but want to have the selectedState for, checkbox ticked;
717
- secondarySelectedOptions: {
718
- type: Array,
719
- default: () => [],
720
- },
721
- },
722
- computed: {
723
- groupedArray() {
724
- const groups = {};
725
-
726
- this.options.forEach((x) => {
727
- // create empty object if it doesn't exists.
728
- groups[x.category] = groups[x.category] || {
729
- text: x.category,
730
- list: [],
731
- ...(x.icon ? { icon: x.icon } : {}),
732
- };
733
-
734
- groups[x.category].list.push(x);
735
- });
736
-
737
- // The flattened list of items that holds items as well as unique headers
738
- const flattened = [];
739
-
740
- // Iterate over all the unique categories and
741
- // then flatten into a list that v-select needs.
742
- Object.keys(groups).forEach((categoryId) => {
743
- const category = groups[categoryId];
744
- const categoryName = category.text;
745
-
746
- // Create a group
747
- flattened.push({
748
- header: categoryName,
749
- ...(category.icon ? { icon: category.icon } : {}),
750
- });
751
-
752
- // Add all the items followed by category header
753
- flattened.push(...category.list);
754
- });
755
-
756
- return flattened;
757
- },
758
- showCreateOptionAfterSearch() {
759
- if (!this.showCreateOption) return false;
760
-
761
- // Get current search term from v-select
762
- const vSelectRef = this.$refs.vselect;
763
- const search = (vSelectRef && vSelectRef.search) || "";
764
- const term = search.trim().toLowerCase();
765
- if (!term) return false;
766
-
767
- // Check if any options exactly match the search term
768
- const hasExactMatch = this.options.some((option) => {
769
- const label = option[this.optionLabel];
770
- return label && String(label).toLowerCase() === term;
771
- });
772
-
773
- return !hasExactMatch;
774
- },
775
- /*
776
- This function is used to get the remaining count of options that are not shown in the dropdown.
777
- */
778
- selectedOverflowCount() {
779
- if (!this.isMultiple || !this.showOverFlowCount) return 0;
780
- const totalSelectedOptions = Array.isArray(this.value)
781
- ? this.value.length
782
- : 0;
783
- return totalSelectedOptions > 2 ? totalSelectedOptions - 2 : 0;
784
- },
785
- hasSelectedValues() {
786
- return Array.isArray(this.value) && this.value.length > 0;
787
- },
788
- /**
789
- * Pre-built pill rows keyed by `value[i]` and by vue-select option key.
790
- * Recomputes only when selection / multi / overflow-relevant state changes — not on dropdown hover.
791
- * Index comes from `value` order (same order vue-select uses for selected-option-container).
792
- */
793
- pillRowsBySlotLookup() {
794
- if (!Array.isArray(this.value)) {
795
- return { byRef: new Map(), byKey: new Map() };
796
- }
797
- const byRef = new Map();
798
- const byKey = new Map();
799
- const overflow = this.selectedOverflowCount;
800
-
801
- this.value.forEach((item, index) => {
802
- const label = this.getDisplayLabelForOption(item);
803
- const key = this.getVueSelectOptionKey(item);
804
- const slotKey = `slot-${index}-${String(key)}`;
805
- const meta = { index, key, label, slotKey };
806
- const showPill = this.isMultiple;
807
- const showOverflowBadge =
808
- this.isMultiple &&
809
- this.showOverFlowCount &&
810
- index === 1 &&
811
- overflow > 0;
812
- const row = {
813
- meta,
814
- showPill,
815
- showOverflowBadge,
816
- label,
817
- slotKey,
818
- };
819
- byRef.set(item, row);
820
- if (!byKey.has(key)) {
821
- byKey.set(key, row);
822
- }
823
- });
824
- return { byRef, byKey };
825
- },
826
- /**
827
- * Sticky `bottom` offsets so create → other → clear stack without overlap.
828
- * DOM order is create (top of sticky group), other, clear (anchored to dropdown bottom).
829
- */
830
- footerStickyStyles() {
831
- const clearH = Number(this.footerMetaData.clearAllHeight) || 0;
832
- const otherH = Number(this.footerMetaData.otherOptionHeight) || 0;
833
- return {
834
- create: { bottom: `${clearH + otherH}px` },
835
- other: { bottom: `${clearH}px` },
836
- clear: { bottom: "0px" },
837
- };
838
- },
839
- },
840
- data() {
841
- return {
842
- loaderSearching: true,
843
- value:
844
- this.optionsSelected && this.optionsSelected.length
845
- ? this.optionsSelected
846
- : [],
847
- observer: null,
848
- chipAnimationTimeout: null,
849
- chipAnimationCycle: 0,
850
- hasMounted: false,
851
- footerMetaData: {
852
- clearAllHeight: 0,
853
- otherOptionHeight: 0,
854
- createOptionHeight: 0,
855
- },
856
- };
857
- },
858
- methods: {
859
- clearChipAnimationTimeout() {
860
- if (this.chipAnimationTimeout) {
861
- clearTimeout(this.chipAnimationTimeout);
862
- this.chipAnimationTimeout = null;
863
- }
864
- },
865
- startChipInsertAnimation(insertedCount) {
866
- if (!this.isMultiple || !this.chipAnimationEnabled || !insertedCount)
867
- return;
868
-
869
- this.clearChipAnimationTimeout();
870
- // Increment a cycle token so any previously scheduled async animation work
871
- // can detect it is stale and bail out.
872
- this.chipAnimationCycle += 1;
873
- const animationCycle = this.chipAnimationCycle;
874
- this.$nextTick(() => {
875
- // Guard against race conditions: if another insert happened before this
876
- // tick runs, skip this stale cycle.
877
- if (animationCycle !== this.chipAnimationCycle || !this.$refs.vselect)
878
- return;
879
-
880
- const vSelectEl = this.$refs.vselect.$el;
881
- if (!vSelectEl) return;
882
-
883
- requestAnimationFrame(() => {
884
- // Re-check at frame time because DOM work is deferred one more step.
885
- if (animationCycle !== this.chipAnimationCycle) return;
886
-
887
- const chipElements = Array.from(
888
- vSelectEl.querySelectorAll(".vs__selected")
889
- );
890
- const chipsToAnimate = chipElements.slice(-insertedCount);
891
-
892
- if (!chipsToAnimate.length) {
893
- return;
894
- }
895
-
896
- const staggerMs = chipsToAnimate.length > 1 ? 80 : 0;
897
- chipsToAnimate.forEach((chipEl, index) => {
898
- chipEl.classList.remove("chip-entering");
899
- void chipEl.offsetWidth;
900
- chipEl.style.setProperty(
901
- "--chip-enter-delay",
902
- `${index * staggerMs}ms`
903
- );
904
- chipEl.classList.add("chip-entering");
905
- });
906
-
907
- const totalPhaseOneDuration =
908
- (chipsToAnimate.length - 1) * staggerMs + 320;
909
- this.chipAnimationTimeout = setTimeout(() => {
910
- if (animationCycle !== this.chipAnimationCycle) return;
911
- chipsToAnimate.forEach((chipEl) => {
912
- chipEl.classList.remove("chip-entering");
913
- chipEl.style.removeProperty("--chip-enter-delay");
914
- });
915
- }, totalPhaseOneDuration);
916
- });
917
- });
918
- },
919
- getActionIDFn(name) {
920
- return getActionID(name, this.id);
921
- },
922
- handleCrossClick(event) {
923
- event.preventDefault();
924
- this.$emit("hide-multiselect-dropdown");
925
- },
926
- fetchOptions(search, loaderSearching) {
927
- this.emitGetOptions(search, loaderSearching);
928
-
929
- this._updateFooterHeights();
930
- },
931
- emitGetOptions: debounce(function (search, loaderSearching) {
932
- this.$emit("getOptions", search.trim(), loaderSearching);
933
- }, 300),
934
- setSelectedOptions(params) {
935
- //this prevents animation to run, we have a watcher that will instate value correctly
936
- if (!this.chipAnimationEnabled) {
937
- this.value = params;
938
- }
939
- this.$emit("onSelectOptions", params);
940
- if (this.clearInput) {
941
- this.value = [];
942
- this.$nextTick(() => {
943
- if (this.$refs.vselect) {
944
- this.$refs.vselect.search = "";
945
- }
946
- });
947
- }
948
- },
949
- async onOpen() {
950
- if (this.hasNextPage) {
951
- await this.$nextTick();
952
- if (this.$refs ? this.$refs.load : false && this.observer) {
953
- this.observer.observe(this.$refs.load);
954
- } else {
955
- setTimeout(() => {
956
- this.onOpen();
957
- }, 500);
958
- }
959
- }
960
- this.emitGetOptions("", true);
961
- },
962
- onClose() {
963
- if (this.observer) {
964
- this.observer.disconnect();
965
- }
966
- },
967
- async infiniteScroll([{ isIntersecting }]) {
968
- if (isIntersecting) {
969
- this.emitLoadNextPage();
970
- }
971
- },
972
- /*
973
- This function is used to create a unique key for the option.
974
- */
975
- createUniqueKeyForOption(sortable) {
976
- const ordered = {};
977
- Object.keys(sortable)
978
- .sort()
979
- .forEach((key) => {
980
- ordered[key] = sortable[key];
981
- });
982
- return JSON.stringify(ordered);
983
- },
984
- /*
985
- This function is used to get the key of the option for the selected pills.
986
- Aligns with vue-select default getOptionKey.
987
- Reference: https://vue-select.org/api/props.html#getoptionkey
988
- */
989
- getVueSelectOptionKey(option) {
990
- if (typeof option !== "object" || option === null) {
991
- return option;
992
- }
993
- try {
994
- return Object.prototype.hasOwnProperty.call(option, "id")
995
- ? option.id
996
- : this.createUniqueKeyForOption(option);
997
- } catch (e) {
998
- return String(option);
999
- }
1000
- },
1001
- getDisplayLabelForOption(option) {
1002
- if (!option) return "";
1003
- if (this.selectedOptionLabel && option[this.selectedOptionLabel]) {
1004
- return option[this.selectedOptionLabel];
1005
- }
1006
- if (this.optionLabelSecondary && option[this.optionLabelSecondary]) {
1007
- return option[this.optionLabelSecondary];
1008
- }
1009
- if (this.optionLabel && option[this.optionLabel]) {
1010
- return option[this.optionLabel];
1011
- }
1012
- return "";
1013
- },
1014
- /**
1015
- * Easy lookup for each selected-option slot.
1016
- */
1017
- getPillRow(option) {
1018
- const { byRef, byKey } = this.pillRowsBySlotLookup;
1019
- if (byRef.has(option)) {
1020
- return byRef.get(option);
1021
- }
1022
- const k = this.getVueSelectOptionKey(option);
1023
- return byKey.get(k) || null;
1024
- },
1025
- handleClearAll() {
1026
- this.value = [];
1027
- this.$emit("onSelectOptions", []);
1028
- this.$nextTick(() => {
1029
- if (this.$refs.vselect) {
1030
- this.$refs.vselect.search = "";
1031
- }
1032
- });
1033
- },
1034
- isChecked(option) {
1035
- const selectedItemsArray = [
1036
- ...this.value,
1037
- ...this.secondarySelectedOptions,
1038
- ];
1039
- return selectedItemsArray.some(
1040
- (item) =>
1041
- item[this.primaryComparisonKey] === option[this.primaryComparisonKey]
1042
- )
1043
- ? 1
1044
- : 0;
1045
- },
1046
- handleSingleSelect(option) {
1047
- if (this.addCheckBox) {
1048
- if (this.isChecked(option) === 1) {
1049
- this.value = this.value.filter(
1050
- (item) =>
1051
- item[this.primaryComparisonKey] !==
1052
- option[this.primaryComparisonKey]
1053
- );
1054
- } else {
1055
- this.value = [...this.value, option];
1056
- }
1057
- this.$emit("onSelectOptions", this.value);
1058
-
1059
- return false;
1060
- }
1061
- },
1062
- handleOtherOptionChange() {
1063
- const isSelected = this.isChecked(this.otherOption) === 1;
1064
- if (isSelected) {
1065
- this.value = this.value.filter(
1066
- (item) =>
1067
- item[this.primaryComparisonKey] !==
1068
- this.otherOption[this.primaryComparisonKey]
1069
- );
1070
- } else {
1071
- this.value = [...this.value, this.otherOption];
1072
- }
1073
- this.$emit("onSelectOptions", this.value);
1074
-
1075
- this.$nextTick(() => {
1076
- if (this.$refs.vselect) {
1077
- this.$refs.vselect.open = false;
1078
- this.$refs.vselect.search = "";
1079
- }
1080
-
1081
- const input = this.$refs.vselect.$el.querySelector("input");
1082
- if (input) {
1083
- input.blur();
1084
- }
1085
- });
1086
- },
1087
- getDisableOptions(option) {
1088
- if (!option) return true;
1089
- if (option.header) return false;
1090
- if (option.isDisabled || option.disabled) return false;
1091
- return true;
1092
- },
1093
-
1094
- // a function that will set the location when the component has mounted and the location is passed after that
1095
- forceSetData(params) {
1096
- this.value = params;
1097
- },
1098
- emitLoadNextPage: debounce(function () {
1099
- this.$emit("loadNextPage");
1100
- }, 300),
1101
- handleCreateOption(event, searchText) {
1102
- event.preventDefault();
1103
-
1104
- this.$emit("handleCreateOption", {
1105
- event,
1106
- searchText: searchText.trim(),
1107
- });
1108
- this.$refs.vselect.open = false;
1109
- this.$refs.vselect.search = "";
1110
-
1111
- this.$nextTick(() => {
1112
- const input = this.$refs.vselect.$el.querySelector("input");
1113
- if (input) {
1114
- input.blur();
1115
- }
1116
- });
1117
- },
1118
- handleKeydown(event) {
1119
- if (event.key === "Enter") {
1120
- event.preventDefault();
1121
- event.stopPropagation();
1122
-
1123
- const vSelectRef = this.$refs.vselect;
1124
- const search = (vSelectRef && vSelectRef.search) || "";
1125
-
1126
- if (
1127
- this.showCreateOption &&
1128
- this.showCreateOptionAfterSearch &&
1129
- search &&
1130
- search.trim()
1131
- ) {
1132
- this.handleCreateOption(event, search.trim());
1133
- }
1134
- }
1135
- },
1136
- _updateFooterHeights() {
1137
- this.$nextTick(() => {
1138
- const createEl = this.$refs.createOption;
1139
- const otherEl = this.$refs.otherOption;
1140
- const clearEl = this.$refs.clearAllButton;
1141
-
1142
- this.footerMetaData = {
1143
- createOptionHeight: createEl ? createEl.offsetHeight : 0,
1144
- otherOptionHeight: otherEl ? otherEl.offsetHeight : 0,
1145
- clearAllHeight: clearEl ? clearEl.offsetHeight : 0,
1146
- };
1147
- });
1148
- },
1149
- },
1150
- watch: {
1151
- optionsSelected: {
1152
- handler(newVal, oldVal) {
1153
- this.value = newVal;
1154
- if (!this.hasMounted) return;
1155
- if (!this.isMultiple || !this.chipAnimationEnabled) return;
1156
- const newLength = Array.isArray(newVal) ? newVal.length : 0;
1157
- const oldLength = Array.isArray(oldVal) ? oldVal.length : 0;
1158
- const insertedCount = Math.max(0, newLength - oldLength);
1159
- if (insertedCount > 0) {
1160
- this.startChipInsertAnimation(insertedCount);
1161
- }
1162
- },
1163
- deep: true,
1164
- },
1165
- value() {
1166
- this._updateFooterHeights();
1167
- },
1168
- },
1169
- mounted() {
1170
- this.hasMounted = true;
1171
- this.observer = new IntersectionObserver(this.infiniteScroll);
1172
- },
1173
- beforeDestroy() {
1174
- this.clearChipAnimationTimeout();
1175
- if (this.observer) {
1176
- this.observer.disconnect();
1177
- this.observer = null;
1178
- }
1179
- },
1180
- };
1181
- </script>
1182
- <style>
1183
- .v-select {
1184
- @apply cursor-pointer;
1185
- }
1186
-
1187
- .vs__dropdown-toggle {
1188
- @apply min-h-9 w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-left shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm;
1189
- }
1190
-
1191
- .vs__selected-options {
1192
- @apply flex items-center gap-1.5 p-0;
1193
- }
1194
-
1195
- .c-multiselect--capped-pills .vs__selected-options {
1196
- @apply min-w-0 flex-nowrap overflow-hidden;
1197
- }
1198
-
1199
- /* Hide 3rd+ chips if they still mount (key mismatch); keeps one row */
1200
- .c-multiselect--capped-pills
1201
- .vs__selected-options
1202
- > .vs__selected:nth-child(n + 3) {
1203
- display: none !important;
1204
- }
1205
-
1206
- .vs--open .vs__dropdown-toggle {
1207
- border-bottom-color: rgba(212, 212, 216, var(--tw-border-opacity));
1208
- @apply rounded-b-md;
1209
- }
1210
- .vs__selected {
1211
- @apply m-0 !bg-transparent !p-0 text-gray-700;
1212
- border: 1px solid transparent;
1213
- transition: background-color 220ms ease, border-color 220ms ease,
1214
- color 220ms ease;
1215
- }
1216
-
1217
- .vs__selected.chip-entering {
1218
- background-color: #f0f9ff;
1219
- border-color: #7dd3fc;
1220
- color: #0284c7;
1221
- animation: chip-entry-pop 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
1222
- animation-delay: var(--chip-enter-delay, 0ms);
1223
- }
1224
-
1225
- .vs__selected.chip-entering .vs__selected-inner {
1226
- background-color: #f0f9ff;
1227
- border-color: #7dd3fc;
1228
- color: #0284c7;
1229
- }
1230
-
1231
- @keyframes chip-entry-pop {
1232
- 0% {
1233
- opacity: 0;
1234
- transform: translateY(6px) scale(0.94);
1235
- }
1236
- 70% {
1237
- opacity: 1;
1238
- transform: translateY(-1px) scale(1.01);
1239
- }
1240
- 100% {
1241
- opacity: 1;
1242
- transform: translateY(0) scale(1);
1243
- }
1244
- }
1245
- .extra:hover {
1246
- color: white;
1247
- }
1248
- .vs__search,
1249
- .vs__search:focus {
1250
- @apply m-0 p-0;
1251
- }
1252
- .vs__search::placeholder {
1253
- @apply text-gray-500;
1254
- }
1255
- .vs__actions {
1256
- @apply p-0;
1257
- }
1258
- .vs__dropdown-menu {
1259
- @apply mt-2 max-h-60 overflow-auto rounded-md bg-white py-0 text-base shadow-lg ring-1 ring-opacity-5 focus:outline-none sm:text-sm;
1260
- }
1261
-
1262
- .dropdown-menu-bordered {
1263
- @apply border-b border-gray-200;
1264
- }
1265
-
1266
- .vs__dropdown-menu li {
1267
- min-height: fit-content;
1268
- }
1269
-
1270
- .vs__dropdown-menu li:has(.sticky-group-header) {
1271
- @apply sticky top-0 z-10 bg-gray-200;
1272
- }
1273
-
1274
- /* Remove li padding if it contains a bordered option */
1275
- .vs__dropdown-menu li:has(.dropdown-menu-bordered) {
1276
- padding: 0 !important;
1277
- }
1278
-
1279
- .vs__dropdown-option {
1280
- @apply whitespace-normal !px-3 !py-2 text-gray-700;
1281
- }
1282
-
1283
- .vs__dropdown-toggle.vs__dropdown-option--highlight {
1284
- @apply bg-indigo-700 text-white;
1285
- }
1286
-
1287
- .vs__dropdown-option--highlight {
1288
- @apply bg-indigo-700 text-white;
1289
- }
1290
-
1291
- .vs__dropdown-option--disabled {
1292
- @apply cursor-not-allowed !border-gray-200 !bg-gray-50 !text-gray-500 opacity-100 shadow-none;
1293
- }
1294
-
1295
- .vs__dropdown-option--disabled * {
1296
- @apply text-gray-500;
1297
- }
1298
-
1299
- .vs__dropdown-menu li {
1300
- @apply opacity-100;
1301
- }
1302
-
1303
- .v-list-subheader {
1304
- @apply pointer-events-none opacity-100;
1305
- }
1306
-
1307
- .vs__no-options {
1308
- @apply px-4 py-3 text-sm text-gray-500;
1309
- }
1310
-
1311
- .vs__deselect {
1312
- @apply ml-2 mr-0 my-0;
1313
- }
1314
- </style>
1
+ <template>
2
+ <div>
3
+ <div class="mb-1 flex w-full items-center justify-between" v-if="label">
4
+ <div class="flex items-center">
5
+ <!-- label of multiselect field -->
6
+ <label v-if="label" class="text-sm font-medium text-gray-900">{{
7
+ label
8
+ }}</label>
9
+ <!-- asterisk sign to render if field is required -->
10
+ <p v-if="isRequired" class="ml-1 text-red-600">*</p>
11
+ </div>
12
+ <span v-if="hint" class="text-sm text-gray-500">{{ hint }}</span>
13
+ </div>
14
+ <div class="relative">
15
+ <v-select
16
+ ref="vselect"
17
+ :class="[
18
+ 'disabled:custom-disabled-state absolute inline-block h-full w-full text-sm',
19
+ isMultiple && showOverFlowCount ? 'c-multiselect--capped-pills' : '',
20
+ ]"
21
+ :placeholder="placeholder"
22
+ :multiple="isMultiple"
23
+ :taggable="isTaggable"
24
+ :push-tags="pushTags"
25
+ :filterable="filterable"
26
+ @keydown.native="handleKeydown"
27
+ v-model="value"
28
+ :options="isGrouped ? groupedArray : options"
29
+ @input="setSelectedOptions"
30
+ @search="fetchOptions"
31
+ @search:focus="$emit('search:focus')"
32
+ @option:selecting="handleSingleSelect"
33
+ @option:selected="($event) => (addCheckBox ? null : $event)"
34
+ @option:deselected="($event) => (addCheckBox ? null : $event)"
35
+ :label="optionLabel"
36
+ :clearable="clearable"
37
+ :loading="loading"
38
+ :id="id"
39
+ @open="onOpen"
40
+ @close="onClose"
41
+ :disabled="isDisabled"
42
+ :selectable="
43
+ isGrouped
44
+ ? (option) => (option.header ? false : getDisableOptions(option))
45
+ : (option) => getDisableOptions(option)
46
+ "
47
+ :closeOnSelect="addCheckBox ? false : isGrouped ? false : true"
48
+ >
49
+ <template #open-indicator="{ attributes }">
50
+ <span
51
+ v-bind="attributes"
52
+ :style="!shouldIconRotate ? 'transform:none;' : ''"
53
+ >
54
+ <c-icon
55
+ v-if="icon"
56
+ :name="icon.name"
57
+ :type="icon.type"
58
+ class="h-5 w-5 text-gray-400"
59
+ />
60
+ <c-icon
61
+ v-else
62
+ name="chevron-down"
63
+ type="solid"
64
+ class="h-5 w-5 text-gray-400"
65
+ />
66
+ </span>
67
+ </template>
68
+ <template
69
+ #selected-option-container="{ option, deselect, multiple, disabled }"
70
+ >
71
+ <template v-for="row in [getPillRow(option)]">
72
+ <div
73
+ v-if="row && row.showPill"
74
+ :key="row.slotKey"
75
+ class="vs__selected vs__selected--capped inline-flex items-center gap-1.5"
76
+ >
77
+ <p
78
+ v-if="!option.header"
79
+ :class="[
80
+ 'vs__selected-inner inline-flex min-w-0 max-w-[120px] items-center gap-1.5 rounded bg-gray-100 px-2 py-1 text-gray-800',
81
+ isDisabled ? 'text-gray-500' : '',
82
+ ]"
83
+ >
84
+ <c-icon
85
+ v-if="option.icon"
86
+ :name="option.icon.name"
87
+ :type="option.icon.type"
88
+ :class="[
89
+ 'h-4 w-4 flex-shrink-0 text-gray-400',
90
+ option.icon.optionIconClass,
91
+ ]"
92
+ />
93
+ <c-avatar
94
+ v-if="option.image && displaySelectedOptionAvatar"
95
+ :size="
96
+ option.description && showAdditionalText
97
+ ? 'extrasmall'
98
+ : 'extraextrasmall'
99
+ "
100
+ :image="option.image"
101
+ :rounded="true"
102
+ :description="option.description"
103
+ class="flex-shrink-0"
104
+ ></c-avatar>
105
+ <c-avatar
106
+ v-else-if="option.initials && displaySelectedOptionAvatar"
107
+ size="extraextrasmall"
108
+ :nameInitials="option.initials"
109
+ :description="option.description"
110
+ :rounded="true"
111
+ :isDynamicallyColored="true"
112
+ class="flex-shrink-0"
113
+ ></c-avatar>
114
+ <span class="min-w-0 flex-1 truncate">{{ row.label }}</span>
115
+ <button
116
+ v-if="multiple"
117
+ type="button"
118
+ class="flex h-2 w-2 flex-shrink-0 items-center justify-center rounded text-gray-400 focus:outline-none"
119
+ :disabled="disabled"
120
+ :title="`Deselect ${row.label}`"
121
+ :aria-label="`Deselect ${row.label}`"
122
+ @click.stop.prevent="deselect(option)"
123
+ >
124
+ <span class="text-base leading-none" aria-hidden="true"
125
+ >×</span
126
+ >
127
+ </button>
128
+ </p>
129
+ <span
130
+ v-if="row.showOverflowBadge"
131
+ class="vs__selected-overflow inline-flex w-max rounded bg-gray-100 px-2 py-1 text-gray-800"
132
+ aria-live="polite"
133
+ >
134
+ +{{ selectedOverflowCount }}
135
+ </span>
136
+ </div>
137
+ </template>
138
+ </template>
139
+ <!-- eslint-disable-next-line vue/no-unused-vars -->
140
+ <template #no-options="{ search, searching, loading }">
141
+ <span v-if="search.length < 1"
142
+ >Start typing to search for options...</span
143
+ >
144
+ <span v-else>No options found, try searching something else.</span>
145
+ </template>
146
+ <template #spinner="{ loading }">
147
+ <svg
148
+ class="h-5 w-5 animate-spin text-gray-400"
149
+ xmlns="http://www.w3.org/2000/svg"
150
+ fill="none"
151
+ viewBox="0 0 24 24"
152
+ v-if="loading"
153
+ >
154
+ <circle
155
+ class="opacity-25"
156
+ cx="12"
157
+ cy="12"
158
+ r="10"
159
+ stroke="currentColor"
160
+ stroke-width="4"
161
+ ></circle>
162
+ <path
163
+ class="opacity-75"
164
+ fill="currentColor"
165
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
166
+ ></path>
167
+ </svg>
168
+ </template>
169
+ <template v-slot:option="option">
170
+ <slot
171
+ v-if="$scopedSlots['custom-option']"
172
+ name="custom-option"
173
+ :option="option"
174
+ />
175
+ <template v-else>
176
+ <div v-if="!isGrouped">
177
+ <div v-if="option.hasNoData" class="dropdown-menu-bordered"></div>
178
+ <div v-else class="group mt-1 flex h-full w-full items-center">
179
+ <div @click.stop v-if="addCheckBox" class="flex-shrink-0">
180
+ <c-checkbox
181
+ :value="isChecked(option)"
182
+ @onChange="handleSingleSelect(option)"
183
+ />
184
+ </div>
185
+ <p v-if="showOptionImage" class="flex-shrink-0">
186
+ <c-avatar
187
+ v-if="option[imageLabel]"
188
+ :size="
189
+ option.description && showAdditionalText
190
+ ? 'extrasmall'
191
+ : 'extraextrasmall'
192
+ "
193
+ :image="option[imageLabel]"
194
+ :rounded="true"
195
+ :description="option.description"
196
+ class="mr-2"
197
+ ></c-avatar>
198
+ <c-avatar
199
+ v-if="
200
+ !option.icon && !option[imageLabel] && option.initials
201
+ "
202
+ :size="
203
+ option.description && showAdditionalText
204
+ ? 'extrasmall'
205
+ : 'extraextrasmall'
206
+ "
207
+ :nameInitials="option.initials"
208
+ :description="option.description"
209
+ :rounded="true"
210
+ :isDynamicallyColored="true"
211
+ class="mr-2"
212
+ ></c-avatar>
213
+ <c-icon
214
+ v-if="
215
+ option.icon && !option[imageLabel] && !option.initials
216
+ "
217
+ :name="option.icon.name"
218
+ :type="option.icon.type"
219
+ :class="[
220
+ 'mr-2 h-5 w-5 text-gray-400',
221
+ option.icon.optionIconClass,
222
+ option.isDisabled || option.disabled
223
+ ? 'opacity-50'
224
+ : 'opacity-100',
225
+ ]"
226
+ :viewBox="option.icon.viewBox || '0 0 20 20'"
227
+ :cursorType="
228
+ option.isDisabled || option.disabled
229
+ ? 'cursor-not-allowed'
230
+ : 'cursor-pointer'
231
+ "
232
+ />
233
+ </p>
234
+ <div class="w-full">
235
+ <div
236
+ :class="`flex items-center justify-between ${checkboxWrapperClass}`"
237
+ >
238
+ <div :class="`flex items-center ${tagWrapperClass}`">
239
+ <p>
240
+ {{
241
+ option[optionLabelSecondary]
242
+ ? option[optionLabelSecondary]
243
+ : option[optionLabel]
244
+ }}
245
+ </p>
246
+ <div class="ml-3">
247
+ <c-tag
248
+ v-if="tags && option.info && option.info !== ''"
249
+ :label="option.info"
250
+ color="gray"
251
+ ></c-tag>
252
+ <span v-else class="-ml-3 text-gray-300">
253
+ &nbsp;{{ option.info }}
254
+ </span>
255
+ </div>
256
+ </div>
257
+ </div>
258
+ <p
259
+ class="text-xs"
260
+ v-if="option.description && showAdditionalText"
261
+ >
262
+ {{ option.description }}
263
+ </p>
264
+ </div>
265
+ </div>
266
+ </div>
267
+ <div
268
+ v-if="isGrouped"
269
+ :class="[
270
+ option.header
271
+ ? 'sticky-group-header -mx-4 -my-2 bg-gray-200 px-3 py-2'
272
+ : '',
273
+ ]"
274
+ >
275
+ <v-list-subheader
276
+ v-if="option.header"
277
+ class="flex items-center gap-1 text-gray-900"
278
+ >
279
+ <c-icon
280
+ v-if="option.icon"
281
+ :name="option.icon.name"
282
+ :type="option.icon.type"
283
+ :class="`${
284
+ option.icon.headerIconClass
285
+ ? option.icon.headerIconClass
286
+ : 'h-4 w-4'
287
+ } text-gray-400`"
288
+ />
289
+ {{ option.header }}
290
+ </v-list-subheader>
291
+ <div
292
+ :class="[
293
+ 'group mt-1 flex h-full w-full',
294
+ option.description ? 'items-start' : 'items-center',
295
+ ]"
296
+ >
297
+ <div @click.stop v-if="addCheckBox && !option.header">
298
+ <c-checkbox
299
+ :value="isChecked(option)"
300
+ @onChange="handleSingleSelect(option)"
301
+ />
302
+ </div>
303
+ <div v-if="!option.header && showOptionImage">
304
+ <c-avatar
305
+ v-if="option.image"
306
+ size="extraextrasmall"
307
+ :image="option.image"
308
+ :rounded="true"
309
+ :description="option.description"
310
+ class="mr-2"
311
+ ></c-avatar>
312
+ <c-avatar
313
+ v-else
314
+ size="extraextrasmall"
315
+ :nameInitials="option.initials"
316
+ :description="option.description"
317
+ :rounded="true"
318
+ :isDynamicallyColored="true"
319
+ class="mr-2"
320
+ ></c-avatar>
321
+ </div>
322
+ <div class="w-full">
323
+ <div class="flex items-center">
324
+ <p>
325
+ {{
326
+ option[optionLabelSecondary]
327
+ ? option[optionLabelSecondary]
328
+ : option[optionLabel]
329
+ }}
330
+ </p>
331
+ <div class="ml-3">
332
+ <span
333
+ v-if="tags && option.info && option.info !== ''"
334
+ class="inline-flex rounded-md bg-gray-400 px-2 py-px text-sm leading-5 text-white"
335
+ >
336
+ {{ option.info }}
337
+ </span>
338
+ <span v-else class="text-gray-300">
339
+ {{ option.info }}
340
+ </span>
341
+ </div>
342
+ </div>
343
+
344
+ <p class="text-xs" v-if="option.description">
345
+ {{ option.description }}
346
+ </p>
347
+ </div>
348
+ </div>
349
+ </div>
350
+ </template>
351
+ </template>
352
+ <template #list-footer="{ search }">
353
+ <li ref="load" class="loader" v-show="hasNextPage">
354
+ Loading more options...
355
+ </li>
356
+
357
+ <!-- Footer buttons when footer buttons are visible -->
358
+ <div
359
+ v-if="showFooterButton || showFooterButton2"
360
+ :class="[
361
+ 'group sticky bottom-0 mt-1 bg-white',
362
+ showFooterButton && showFooterButton2 ? 'space-y-2' : '',
363
+ ]"
364
+ >
365
+ <li
366
+ v-if="showFooterButton"
367
+ :class="footerBtnClasses"
368
+ class="cursor-pointer select-none bg-gray-50 py-2 pl-3 pr-9 text-gray-700 hover:bg-gray-100 hover:text-gray-900"
369
+ :id="getActionIDFn(footerButtonText)"
370
+ role="option"
371
+ @click="$emit('footerButtonClick')"
372
+ >
373
+ <div class="flex items-center">
374
+ <svg
375
+ xmlns="http://www.w3.org/2000/svg"
376
+ class="h-6 w-6 flex-shrink-0 text-gray-400"
377
+ viewBox="0 0 20 20"
378
+ fill="currentColor"
379
+ >
380
+ <path
381
+ fill-rule="evenodd"
382
+ d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z"
383
+ clip-rule="evenodd"
384
+ />
385
+ </svg>
386
+ <span class="ml-3 block truncate font-semibold">
387
+ {{ footerButtonText }}
388
+ </span>
389
+ </div>
390
+ </li>
391
+ <li
392
+ v-if="showFooterButton2"
393
+ class="cursor-pointer select-none bg-gray-50 py-2 pl-3 pr-9 text-gray-700 hover:bg-gray-100 hover:text-gray-900"
394
+ :class="footerBtnClasses2"
395
+ :id="getActionIDFn(footerButtonText2)"
396
+ role="option"
397
+ @click="$emit('footerButtonClick2')"
398
+ >
399
+ <div class="flex items-center">
400
+ <svg
401
+ xmlns="http://www.w3.org/2000/svg"
402
+ class="h-6 w-6 flex-shrink-0 text-gray-400"
403
+ viewBox="0 0 20 20"
404
+ fill="currentColor"
405
+ >
406
+ <path
407
+ fill-rule="evenodd"
408
+ d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z"
409
+ clip-rule="evenodd"
410
+ />
411
+ </svg>
412
+ <span class="ml-3 block truncate font-semibold">
413
+ {{ footerButtonText2 }}
414
+ </span>
415
+ </div>
416
+ </li>
417
+ </div>
418
+
419
+ <!-- Create option button when showCreateOption is true and there is a search term -->
420
+ <div
421
+ v-if="
422
+ showCreateOption &&
423
+ showCreateOptionAfterSearch &&
424
+ search &&
425
+ search.trim()
426
+ "
427
+ ref="createOption"
428
+ class="sticky z-10 flex min-h-[44px] items-start gap-3 bg-white px-3 py-2 shadow-lg ring-1 ring-gray-900 ring-opacity-5"
429
+ :style="footerStickyStyles.create"
430
+ >
431
+ <span class="word-break flex-1 text-sm text-gray-700">{{
432
+ search
433
+ }}</span>
434
+
435
+ <button
436
+ type="button"
437
+ :id="id + '_create_button'"
438
+ @mousedown="handleCreateOption($event, search)"
439
+ class="flex items-center gap-1 text-sm text-indigo-700"
440
+ >
441
+ <c-icon
442
+ type="solid"
443
+ name="plus-circle-solid-v2"
444
+ class="h-5 w-5 text-indigo-600"
445
+ viewBox="0 0 24 24"
446
+ ></c-icon>
447
+ Create
448
+ </button>
449
+ </div>
450
+
451
+ <!-- Other option checkbox when otherOption is true -->
452
+ <div
453
+ v-if="otherOption"
454
+ ref="otherOption"
455
+ class="sticky z-10 border-t border-gray-100 bg-gray-50 px-3 py-2"
456
+ :style="footerStickyStyles.other"
457
+ >
458
+ <div class="flex" @mousedown.prevent.stop>
459
+ <c-checkbox
460
+ :value="isChecked(otherOption)"
461
+ @onChange="handleOtherOptionChange"
462
+ />
463
+ <div class="flex-1" @click.stop="handleOtherOptionChange">
464
+ <p class="text-sm font-medium text-gray-700">
465
+ {{ otherOption[optionLabel] }}
466
+ </p>
467
+ <p class="mt-1 text-sm text-gray-500">
468
+ {{ otherOption.description }}
469
+ </p>
470
+ </div>
471
+ </div>
472
+ </div>
473
+
474
+ <!-- Clear all button when multiple is true and there are selected values -->
475
+ <button
476
+ v-if="isMultiple && hasSelectedValues"
477
+ ref="clearAllButton"
478
+ type="button"
479
+ class="sticky z-10 w-full border-t border-gray-200 bg-gray-50 px-4 py-3 text-left text-sm text-gray-500 hover:text-gray-900 focus:outline-none"
480
+ :style="footerStickyStyles.clear"
481
+ :id="id + '_clear_all_button'"
482
+ aria-label="Clear all selections"
483
+ @mousedown.prevent.stop="handleClearAll"
484
+ >
485
+ Clear all
486
+ </button>
487
+ </template>
488
+ </v-select>
489
+ <button
490
+ class="z-100 absolute top-2.5 right-10"
491
+ :id="id + '_close_button'"
492
+ v-if="showCloseButton && (value == null || value.length == 0)"
493
+ @click.stop="handleCrossClick"
494
+ >
495
+ <c-icon
496
+ name="close"
497
+ type="outline-v2"
498
+ class="h-4 w-4 text-gray-400"
499
+ cursorType="cursor-pointer"
500
+ />
501
+ </button>
502
+ </div>
503
+ <p v-if="subLabel" class="mt-2 text-sm text-gray-500">{{ subLabel }}</p>
504
+ <p
505
+ v-if="!isValidate && errorMessage"
506
+ class="mt-2 text-left text-sm text-red-600"
507
+ >
508
+ {{ errorMessage }}
509
+ </p>
510
+ <p v-if="helpText && isValidate == true" class="mt-2 text-sm text-gray-500">
511
+ {{ helpText }}
512
+ </p>
513
+ </div>
514
+ </template>
515
+ <script>
516
+ import vSelect from "vue-select";
517
+ import CAvatar from "../CAvatar/CAvatar.vue";
518
+ import CIcon from "../CIcon/CIcon.vue";
519
+ import CCheckbox from "../CCheckbox/CCheckbox.vue";
520
+ import { debounce } from "lodash-es";
521
+ import "vue-select/dist/vue-select.css";
522
+ import { getActionID } from "../../helper";
523
+ import CTag from "../CTag/CTag.vue";
524
+ export default {
525
+ name: "CMultiselect",
526
+ components: { vSelect, CAvatar, CCheckbox, CIcon, CTag },
527
+ props: {
528
+ id: {
529
+ type: String,
530
+ },
531
+ clearInput: {
532
+ type: Boolean,
533
+ default: false,
534
+ },
535
+ options: {
536
+ type: Array,
537
+ required: true,
538
+ },
539
+ extraDetails: {
540
+ type: Boolean,
541
+ default: false,
542
+ },
543
+ displaySelectedOptionAvatar: {
544
+ type: Boolean,
545
+ default: false,
546
+ },
547
+ showFooterButton: {
548
+ type: Boolean,
549
+ default: false,
550
+ },
551
+ footerButtonText: {
552
+ type: String,
553
+ default: "",
554
+ },
555
+ label: String,
556
+ isRequired: {
557
+ type: Boolean,
558
+ },
559
+ subLabel: String,
560
+ placeholder: {
561
+ type: String,
562
+ },
563
+ // whether multiple fields are allowed or not
564
+ isMultiple: {
565
+ type: Boolean,
566
+ },
567
+ // append newly created tags in options
568
+ pushTags: {
569
+ type: Boolean,
570
+ },
571
+ // whether to allow user to create new options
572
+ isTaggable: {
573
+ type: Boolean,
574
+ },
575
+ getOptions: {
576
+ // function to emit on search{
577
+ type: Function,
578
+ },
579
+ customiseOption: {
580
+ type: Boolean,
581
+ },
582
+ // whether to show profile picture in option
583
+ showOptionImage: {
584
+ type: Boolean,
585
+ },
586
+ // the name of the option to render in the selectpicker
587
+ optionLabel: {
588
+ type: String,
589
+ },
590
+ // the name of the option to render in the selectpicker
591
+ optionLabelSecondary: {
592
+ type: String,
593
+ },
594
+ selectedOptionLabel: {
595
+ type: String,
596
+ },
597
+ // the key to compare the options when addCheckBox is true
598
+ primaryComparisonKey: {
599
+ type: String,
600
+ default: "id",
601
+ },
602
+ // action to trigger after selecting option from dropdown
603
+ onSelectOptions: {
604
+ type: Function,
605
+ },
606
+ optionsSelected: {
607
+ type: [Array, Object],
608
+ },
609
+ filterable: {
610
+ type: Boolean,
611
+ default: false,
612
+ },
613
+ clearable: {
614
+ type: Boolean,
615
+ default: true,
616
+ },
617
+ isValidate: {
618
+ type: Boolean,
619
+ default: true,
620
+ },
621
+ errorMessage: {
622
+ type: String,
623
+ },
624
+ loading: {
625
+ type: Boolean,
626
+ default: false,
627
+ },
628
+ hasNextPage: {
629
+ type: Boolean,
630
+ default: false,
631
+ },
632
+ isDisabled: {
633
+ type: Boolean,
634
+ default: false,
635
+ },
636
+ // text adjacent to label of dropdown to provide hint about field
637
+ hint: { type: String },
638
+ helpText: {
639
+ type: String,
640
+ },
641
+ tags: {
642
+ type: Boolean,
643
+ default: false,
644
+ },
645
+ isGrouped: {
646
+ type: Boolean,
647
+ default: false,
648
+ },
649
+ //to show the additional text, default true to prevent failure at any other place
650
+ showAdditionalText: {
651
+ type: Boolean,
652
+ default: true,
653
+ },
654
+ addCheckBox: {
655
+ type: Boolean,
656
+ default: false,
657
+ },
658
+ showSelectedAvatar: {
659
+ type: Boolean,
660
+ default: false,
661
+ },
662
+ icon: {
663
+ type: Object,
664
+ },
665
+ footerBtnClasses: {
666
+ type: String,
667
+ },
668
+ shouldIconRotate: {
669
+ type: Boolean,
670
+ default: true,
671
+ },
672
+ imageLabel: {
673
+ type: String,
674
+ default: "image",
675
+ },
676
+ showFooterButton2: {
677
+ type: Boolean,
678
+ default: false,
679
+ },
680
+ footerButtonText2: {
681
+ type: String,
682
+ default: "",
683
+ },
684
+ footerBtnClasses2: {
685
+ type: String,
686
+ },
687
+ showCloseButton: {
688
+ type: Boolean,
689
+ default: false,
690
+ },
691
+ showCreateOption: {
692
+ type: Boolean,
693
+ default: false,
694
+ },
695
+ otherOption: {
696
+ type: Object,
697
+ },
698
+ tagWrapperClass: {
699
+ type: String,
700
+ default: "",
701
+ },
702
+ checkboxWrapperClass: {
703
+ type: String,
704
+ default: "",
705
+ },
706
+ // Enables/disables chip insert animation flow (phase 1 + phase 2 sweep).
707
+ chipAnimationEnabled: {
708
+ type: Boolean,
709
+ default: false,
710
+ },
711
+ // When true, render all selected pills and hide "+N" overflow counter.
712
+ showOverFlowCount: {
713
+ type: Boolean,
714
+ default: true,
715
+ },
716
+ //these are the options we don't want to display, but want to have the selectedState for, checkbox ticked;
717
+ secondarySelectedOptions: {
718
+ type: Array,
719
+ default: () => [],
720
+ },
721
+ },
722
+ computed: {
723
+ groupedArray() {
724
+ const groups = {};
725
+
726
+ this.options.forEach((x) => {
727
+ // create empty object if it doesn't exists.
728
+ groups[x.category] = groups[x.category] || {
729
+ text: x.category,
730
+ list: [],
731
+ ...(x.icon ? { icon: x.icon } : {}),
732
+ };
733
+
734
+ groups[x.category].list.push(x);
735
+ });
736
+
737
+ // The flattened list of items that holds items as well as unique headers
738
+ const flattened = [];
739
+
740
+ // Iterate over all the unique categories and
741
+ // then flatten into a list that v-select needs.
742
+ Object.keys(groups).forEach((categoryId) => {
743
+ const category = groups[categoryId];
744
+ const categoryName = category.text;
745
+
746
+ // Create a group
747
+ flattened.push({
748
+ header: categoryName,
749
+ ...(category.icon ? { icon: category.icon } : {}),
750
+ });
751
+
752
+ // Add all the items followed by category header
753
+ flattened.push(...category.list);
754
+ });
755
+
756
+ return flattened;
757
+ },
758
+ showCreateOptionAfterSearch() {
759
+ if (!this.showCreateOption) return false;
760
+
761
+ // Get current search term from v-select
762
+ const vSelectRef = this.$refs.vselect;
763
+ const search = (vSelectRef && vSelectRef.search) || "";
764
+ const term = search.trim().toLowerCase();
765
+ if (!term) return false;
766
+
767
+ // Check if any options exactly match the search term
768
+ const hasExactMatch = this.options.some((option) => {
769
+ const label = option[this.optionLabel];
770
+ return label && String(label).toLowerCase() === term;
771
+ });
772
+
773
+ return !hasExactMatch;
774
+ },
775
+ /*
776
+ This function is used to get the remaining count of options that are not shown in the dropdown.
777
+ */
778
+ selectedOverflowCount() {
779
+ if (!this.isMultiple || !this.showOverFlowCount) return 0;
780
+ const totalSelectedOptions = Array.isArray(this.value)
781
+ ? this.value.length
782
+ : 0;
783
+ return totalSelectedOptions > 2 ? totalSelectedOptions - 2 : 0;
784
+ },
785
+ hasSelectedValues() {
786
+ return Array.isArray(this.value) && this.value.length > 0;
787
+ },
788
+ /**
789
+ * Pre-built pill rows keyed by `value[i]` and by vue-select option key.
790
+ * Recomputes only when selection / multi / overflow-relevant state changes — not on dropdown hover.
791
+ * Index comes from `value` order (same order vue-select uses for selected-option-container).
792
+ */
793
+ pillRowsBySlotLookup() {
794
+ if (!Array.isArray(this.value)) {
795
+ return { byRef: new Map(), byKey: new Map() };
796
+ }
797
+ const byRef = new Map();
798
+ const byKey = new Map();
799
+ const overflow = this.selectedOverflowCount;
800
+
801
+ this.value.forEach((item, index) => {
802
+ const label = this.getDisplayLabelForOption(item);
803
+ const key = this.getVueSelectOptionKey(item);
804
+ const slotKey = `slot-${index}-${String(key)}`;
805
+ const meta = { index, key, label, slotKey };
806
+ const showPill = this.isMultiple;
807
+ const showOverflowBadge =
808
+ this.isMultiple &&
809
+ this.showOverFlowCount &&
810
+ index === 1 &&
811
+ overflow > 0;
812
+ const row = {
813
+ meta,
814
+ showPill,
815
+ showOverflowBadge,
816
+ label,
817
+ slotKey,
818
+ };
819
+ byRef.set(item, row);
820
+ if (!byKey.has(key)) {
821
+ byKey.set(key, row);
822
+ }
823
+ });
824
+ return { byRef, byKey };
825
+ },
826
+ /**
827
+ * Sticky `bottom` offsets so create → other → clear stack without overlap.
828
+ * DOM order is create (top of sticky group), other, clear (anchored to dropdown bottom).
829
+ */
830
+ footerStickyStyles() {
831
+ const clearH = Number(this.footerMetaData.clearAllHeight) || 0;
832
+ const otherH = Number(this.footerMetaData.otherOptionHeight) || 0;
833
+ return {
834
+ create: { bottom: `${clearH + otherH}px` },
835
+ other: { bottom: `${clearH}px` },
836
+ clear: { bottom: "0px" },
837
+ };
838
+ },
839
+ },
840
+ data() {
841
+ return {
842
+ loaderSearching: true,
843
+ value:
844
+ this.optionsSelected && this.optionsSelected.length
845
+ ? this.optionsSelected
846
+ : [],
847
+ observer: null,
848
+ chipAnimationTimeout: null,
849
+ chipAnimationCycle: 0,
850
+ hasMounted: false,
851
+ footerMetaData: {
852
+ clearAllHeight: 0,
853
+ otherOptionHeight: 0,
854
+ createOptionHeight: 0,
855
+ },
856
+ };
857
+ },
858
+ methods: {
859
+ clearChipAnimationTimeout() {
860
+ if (this.chipAnimationTimeout) {
861
+ clearTimeout(this.chipAnimationTimeout);
862
+ this.chipAnimationTimeout = null;
863
+ }
864
+ },
865
+ startChipInsertAnimation(insertedCount) {
866
+ if (!this.isMultiple || !this.chipAnimationEnabled || !insertedCount)
867
+ return;
868
+
869
+ this.clearChipAnimationTimeout();
870
+ // Increment a cycle token so any previously scheduled async animation work
871
+ // can detect it is stale and bail out.
872
+ this.chipAnimationCycle += 1;
873
+ const animationCycle = this.chipAnimationCycle;
874
+ this.$nextTick(() => {
875
+ // Guard against race conditions: if another insert happened before this
876
+ // tick runs, skip this stale cycle.
877
+ if (animationCycle !== this.chipAnimationCycle || !this.$refs.vselect)
878
+ return;
879
+
880
+ const vSelectEl = this.$refs.vselect.$el;
881
+ if (!vSelectEl) return;
882
+
883
+ requestAnimationFrame(() => {
884
+ // Re-check at frame time because DOM work is deferred one more step.
885
+ if (animationCycle !== this.chipAnimationCycle) return;
886
+
887
+ const chipElements = Array.from(
888
+ vSelectEl.querySelectorAll(".vs__selected")
889
+ );
890
+ const chipsToAnimate = chipElements.slice(-insertedCount);
891
+
892
+ if (!chipsToAnimate.length) {
893
+ return;
894
+ }
895
+
896
+ const staggerMs = chipsToAnimate.length > 1 ? 80 : 0;
897
+ chipsToAnimate.forEach((chipEl, index) => {
898
+ chipEl.classList.remove("chip-entering");
899
+ void chipEl.offsetWidth;
900
+ chipEl.style.setProperty(
901
+ "--chip-enter-delay",
902
+ `${index * staggerMs}ms`
903
+ );
904
+ chipEl.classList.add("chip-entering");
905
+ });
906
+
907
+ const totalPhaseOneDuration =
908
+ (chipsToAnimate.length - 1) * staggerMs + 320;
909
+ this.chipAnimationTimeout = setTimeout(() => {
910
+ if (animationCycle !== this.chipAnimationCycle) return;
911
+ chipsToAnimate.forEach((chipEl) => {
912
+ chipEl.classList.remove("chip-entering");
913
+ chipEl.style.removeProperty("--chip-enter-delay");
914
+ });
915
+ }, totalPhaseOneDuration);
916
+ });
917
+ });
918
+ },
919
+ getActionIDFn(name) {
920
+ return getActionID(name, this.id);
921
+ },
922
+ handleCrossClick(event) {
923
+ event.preventDefault();
924
+ this.$emit("hide-multiselect-dropdown");
925
+ },
926
+ fetchOptions(search, loaderSearching) {
927
+ this.emitGetOptions(search, loaderSearching);
928
+
929
+ this._updateFooterHeights();
930
+ },
931
+ emitGetOptions: debounce(function (search, loaderSearching) {
932
+ this.$emit("getOptions", search.trim(), loaderSearching);
933
+ }, 300),
934
+ setSelectedOptions(params) {
935
+ //this prevents animation to run, we have a watcher that will instate value correctly
936
+ if (!this.chipAnimationEnabled) {
937
+ this.value = params;
938
+ }
939
+ this.$emit("onSelectOptions", params);
940
+ if (this.clearInput) {
941
+ this.value = [];
942
+ this.$nextTick(() => {
943
+ if (this.$refs.vselect) {
944
+ this.$refs.vselect.search = "";
945
+ }
946
+ });
947
+ }
948
+ },
949
+ async onOpen() {
950
+ if (this.hasNextPage) {
951
+ await this.$nextTick();
952
+ if (this.$refs ? this.$refs.load : false && this.observer) {
953
+ this.observer.observe(this.$refs.load);
954
+ } else {
955
+ setTimeout(() => {
956
+ this.onOpen();
957
+ }, 500);
958
+ }
959
+ }
960
+ this.emitGetOptions("", true);
961
+ },
962
+ onClose() {
963
+ if (this.observer) {
964
+ this.observer.disconnect();
965
+ }
966
+ },
967
+ async infiniteScroll([{ isIntersecting }]) {
968
+ if (isIntersecting) {
969
+ this.emitLoadNextPage();
970
+ }
971
+ },
972
+ /*
973
+ This function is used to create a unique key for the option.
974
+ */
975
+ createUniqueKeyForOption(sortable) {
976
+ const ordered = {};
977
+ Object.keys(sortable)
978
+ .sort()
979
+ .forEach((key) => {
980
+ ordered[key] = sortable[key];
981
+ });
982
+ return JSON.stringify(ordered);
983
+ },
984
+ /*
985
+ This function is used to get the key of the option for the selected pills.
986
+ Aligns with vue-select default getOptionKey.
987
+ Reference: https://vue-select.org/api/props.html#getoptionkey
988
+ */
989
+ getVueSelectOptionKey(option) {
990
+ if (typeof option !== "object" || option === null) {
991
+ return option;
992
+ }
993
+ try {
994
+ return Object.prototype.hasOwnProperty.call(option, "id")
995
+ ? option.id
996
+ : this.createUniqueKeyForOption(option);
997
+ } catch (e) {
998
+ return String(option);
999
+ }
1000
+ },
1001
+ getDisplayLabelForOption(option) {
1002
+ if (!option) return "";
1003
+ if (this.selectedOptionLabel && option[this.selectedOptionLabel]) {
1004
+ return option[this.selectedOptionLabel];
1005
+ }
1006
+ if (this.optionLabelSecondary && option[this.optionLabelSecondary]) {
1007
+ return option[this.optionLabelSecondary];
1008
+ }
1009
+ if (this.optionLabel && option[this.optionLabel]) {
1010
+ return option[this.optionLabel];
1011
+ }
1012
+ return "";
1013
+ },
1014
+ /**
1015
+ * Easy lookup for each selected-option slot.
1016
+ */
1017
+ getPillRow(option) {
1018
+ const { byRef, byKey } = this.pillRowsBySlotLookup;
1019
+ if (byRef.has(option)) {
1020
+ return byRef.get(option);
1021
+ }
1022
+ const k = this.getVueSelectOptionKey(option);
1023
+ return byKey.get(k) || null;
1024
+ },
1025
+ handleClearAll() {
1026
+ this.value = [];
1027
+ this.$emit("onSelectOptions", []);
1028
+ this.$nextTick(() => {
1029
+ if (this.$refs.vselect) {
1030
+ this.$refs.vselect.search = "";
1031
+ }
1032
+ });
1033
+ },
1034
+ isChecked(option) {
1035
+ const selectedItemsArray = [
1036
+ ...this.value,
1037
+ ...this.secondarySelectedOptions,
1038
+ ];
1039
+ return selectedItemsArray.some(
1040
+ (item) =>
1041
+ item[this.primaryComparisonKey] === option[this.primaryComparisonKey]
1042
+ )
1043
+ ? 1
1044
+ : 0;
1045
+ },
1046
+ handleSingleSelect(option) {
1047
+ if (this.addCheckBox) {
1048
+ if (this.isChecked(option) === 1) {
1049
+ this.value = this.value.filter(
1050
+ (item) =>
1051
+ item[this.primaryComparisonKey] !==
1052
+ option[this.primaryComparisonKey]
1053
+ );
1054
+ } else {
1055
+ this.value = [...this.value, option];
1056
+ }
1057
+ this.$emit("onSelectOptions", this.value);
1058
+
1059
+ return false;
1060
+ }
1061
+ },
1062
+ handleOtherOptionChange() {
1063
+ const isSelected = this.isChecked(this.otherOption) === 1;
1064
+ if (isSelected) {
1065
+ this.value = this.value.filter(
1066
+ (item) =>
1067
+ item[this.primaryComparisonKey] !==
1068
+ this.otherOption[this.primaryComparisonKey]
1069
+ );
1070
+ } else {
1071
+ this.value = [...this.value, this.otherOption];
1072
+ }
1073
+ this.$emit("onSelectOptions", this.value);
1074
+
1075
+ this.$nextTick(() => {
1076
+ if (this.$refs.vselect) {
1077
+ this.$refs.vselect.open = false;
1078
+ this.$refs.vselect.search = "";
1079
+ }
1080
+
1081
+ const input = this.$refs.vselect.$el.querySelector("input");
1082
+ if (input) {
1083
+ input.blur();
1084
+ }
1085
+ });
1086
+ },
1087
+ getDisableOptions(option) {
1088
+ if (!option) return true;
1089
+ if (option.header) return false;
1090
+ if (option.isDisabled || option.disabled) return false;
1091
+ return true;
1092
+ },
1093
+
1094
+ // a function that will set the location when the component has mounted and the location is passed after that
1095
+ forceSetData(params) {
1096
+ this.value = params;
1097
+ },
1098
+ emitLoadNextPage: debounce(function () {
1099
+ this.$emit("loadNextPage");
1100
+ }, 300),
1101
+ handleCreateOption(event, searchText) {
1102
+ event.preventDefault();
1103
+
1104
+ this.$emit("handleCreateOption", {
1105
+ event,
1106
+ searchText: searchText.trim(),
1107
+ });
1108
+ this.$refs.vselect.open = false;
1109
+ this.$refs.vselect.search = "";
1110
+
1111
+ this.$nextTick(() => {
1112
+ const input = this.$refs.vselect.$el.querySelector("input");
1113
+ if (input) {
1114
+ input.blur();
1115
+ }
1116
+ });
1117
+ },
1118
+ handleKeydown(event) {
1119
+ if (event.key === "Enter") {
1120
+ event.preventDefault();
1121
+ event.stopPropagation();
1122
+
1123
+ const vSelectRef = this.$refs.vselect;
1124
+ const search = (vSelectRef && vSelectRef.search) || "";
1125
+
1126
+ if (
1127
+ this.showCreateOption &&
1128
+ this.showCreateOptionAfterSearch &&
1129
+ search &&
1130
+ search.trim()
1131
+ ) {
1132
+ this.handleCreateOption(event, search.trim());
1133
+ }
1134
+ }
1135
+ },
1136
+ _updateFooterHeights() {
1137
+ this.$nextTick(() => {
1138
+ const createEl = this.$refs.createOption;
1139
+ const otherEl = this.$refs.otherOption;
1140
+ const clearEl = this.$refs.clearAllButton;
1141
+
1142
+ this.footerMetaData = {
1143
+ createOptionHeight: createEl ? createEl.offsetHeight : 0,
1144
+ otherOptionHeight: otherEl ? otherEl.offsetHeight : 0,
1145
+ clearAllHeight: clearEl ? clearEl.offsetHeight : 0,
1146
+ };
1147
+ });
1148
+ },
1149
+ },
1150
+ watch: {
1151
+ optionsSelected: {
1152
+ handler(newVal, oldVal) {
1153
+ this.value = newVal;
1154
+ if (!this.hasMounted) return;
1155
+ if (!this.isMultiple || !this.chipAnimationEnabled) return;
1156
+ const newLength = Array.isArray(newVal) ? newVal.length : 0;
1157
+ const oldLength = Array.isArray(oldVal) ? oldVal.length : 0;
1158
+ const insertedCount = Math.max(0, newLength - oldLength);
1159
+ if (insertedCount > 0) {
1160
+ this.startChipInsertAnimation(insertedCount);
1161
+ }
1162
+ },
1163
+ deep: true,
1164
+ },
1165
+ value() {
1166
+ this._updateFooterHeights();
1167
+ },
1168
+ },
1169
+ mounted() {
1170
+ this.hasMounted = true;
1171
+ this.observer = new IntersectionObserver(this.infiniteScroll);
1172
+ },
1173
+ beforeDestroy() {
1174
+ this.clearChipAnimationTimeout();
1175
+ if (this.observer) {
1176
+ this.observer.disconnect();
1177
+ this.observer = null;
1178
+ }
1179
+ },
1180
+ };
1181
+ </script>
1182
+ <style>
1183
+ .v-select {
1184
+ @apply cursor-pointer;
1185
+ }
1186
+
1187
+ .vs__dropdown-toggle {
1188
+ @apply min-h-9 w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-left shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm;
1189
+ }
1190
+
1191
+ .vs__selected-options {
1192
+ @apply flex items-center gap-1.5 p-0;
1193
+ }
1194
+
1195
+ .c-multiselect--capped-pills .vs__selected-options {
1196
+ @apply min-w-0 flex-nowrap overflow-hidden;
1197
+ }
1198
+
1199
+ /* Hide 3rd+ chips if they still mount (key mismatch); keeps one row */
1200
+ .c-multiselect--capped-pills
1201
+ .vs__selected-options
1202
+ > .vs__selected:nth-child(n + 3) {
1203
+ display: none !important;
1204
+ }
1205
+
1206
+ .vs--open .vs__dropdown-toggle {
1207
+ border-bottom-color: rgba(212, 212, 216, var(--tw-border-opacity));
1208
+ @apply rounded-b-md;
1209
+ }
1210
+ .vs__selected {
1211
+ @apply m-0 !bg-transparent !p-0 text-gray-700;
1212
+ border: 1px solid transparent;
1213
+ transition: background-color 220ms ease, border-color 220ms ease,
1214
+ color 220ms ease;
1215
+ }
1216
+
1217
+ .vs__selected.chip-entering {
1218
+ background-color: #f0f9ff;
1219
+ border-color: #7dd3fc;
1220
+ color: #0284c7;
1221
+ animation: chip-entry-pop 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
1222
+ animation-delay: var(--chip-enter-delay, 0ms);
1223
+ }
1224
+
1225
+ .vs__selected.chip-entering .vs__selected-inner {
1226
+ background-color: #f0f9ff;
1227
+ border-color: #7dd3fc;
1228
+ color: #0284c7;
1229
+ }
1230
+
1231
+ @keyframes chip-entry-pop {
1232
+ 0% {
1233
+ opacity: 0;
1234
+ transform: translateY(6px) scale(0.94);
1235
+ }
1236
+ 70% {
1237
+ opacity: 1;
1238
+ transform: translateY(-1px) scale(1.01);
1239
+ }
1240
+ 100% {
1241
+ opacity: 1;
1242
+ transform: translateY(0) scale(1);
1243
+ }
1244
+ }
1245
+ .extra:hover {
1246
+ color: white;
1247
+ }
1248
+ .vs__search,
1249
+ .vs__search:focus {
1250
+ @apply m-0 p-0;
1251
+ }
1252
+ .vs__search::placeholder {
1253
+ @apply text-gray-500;
1254
+ }
1255
+ .vs__actions {
1256
+ @apply p-0;
1257
+ }
1258
+ .vs__dropdown-menu {
1259
+ @apply mt-2 max-h-60 overflow-auto rounded-md bg-white py-0 text-base shadow-lg ring-1 ring-opacity-5 focus:outline-none sm:text-sm;
1260
+ }
1261
+
1262
+ .dropdown-menu-bordered {
1263
+ @apply border-b border-gray-200;
1264
+ }
1265
+
1266
+ .vs__dropdown-menu li {
1267
+ min-height: fit-content;
1268
+ }
1269
+
1270
+ .vs__dropdown-menu li:has(.sticky-group-header) {
1271
+ @apply sticky top-0 z-10 bg-gray-200;
1272
+ }
1273
+
1274
+ /* Remove li padding if it contains a bordered option */
1275
+ .vs__dropdown-menu li:has(.dropdown-menu-bordered) {
1276
+ padding: 0 !important;
1277
+ }
1278
+
1279
+ .vs__dropdown-option {
1280
+ @apply whitespace-normal !px-3 !py-2 text-gray-700;
1281
+ }
1282
+
1283
+ .vs__dropdown-toggle.vs__dropdown-option--highlight {
1284
+ @apply bg-indigo-700 text-white;
1285
+ }
1286
+
1287
+ .vs__dropdown-option--highlight {
1288
+ @apply bg-indigo-700 text-white;
1289
+ }
1290
+
1291
+ .vs__dropdown-option--disabled {
1292
+ @apply cursor-not-allowed !border-gray-200 !bg-gray-50 !text-gray-500 opacity-100 shadow-none;
1293
+ }
1294
+
1295
+ .vs__dropdown-option--disabled * {
1296
+ @apply text-gray-500;
1297
+ }
1298
+
1299
+ .vs__dropdown-menu li {
1300
+ @apply opacity-100;
1301
+ }
1302
+
1303
+ .v-list-subheader {
1304
+ @apply pointer-events-none opacity-100;
1305
+ }
1306
+
1307
+ .vs__no-options {
1308
+ @apply px-4 py-3 text-sm text-gray-500;
1309
+ }
1310
+
1311
+ .vs__deselect {
1312
+ @apply ml-2 mr-0 my-0;
1313
+ }
1314
+ </style>