classcard-ui 0.2.1475 → 0.2.1476

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