classcard-ui 0.2.1069 → 0.2.1071

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 (190) hide show
  1. package/README.md +24 -24
  2. package/dist/classcard-ui.common.js +62 -59
  3. package/dist/classcard-ui.common.js.map +1 -1
  4. package/dist/classcard-ui.umd.js +62 -59
  5. package/dist/classcard-ui.umd.js.map +1 -1
  6. package/dist/classcard-ui.umd.min.js +1 -1
  7. package/dist/classcard-ui.umd.min.js.map +1 -1
  8. package/package.json +82 -82
  9. package/src/App.vue +16 -16
  10. package/src/components/CAlerts/CAlerts.vue +70 -70
  11. package/src/components/CAlerts/index.js +2 -2
  12. package/src/components/CAnchorTabs/CAnchorTabs.vue +96 -96
  13. package/src/components/CAnchorTabs/index.js +2 -2
  14. package/src/components/CAnchorTag/CAnchorTag.vue +62 -62
  15. package/src/components/CAnchorTag/index.js +2 -2
  16. package/src/components/CAvatar/CAvatar.vue +212 -212
  17. package/src/components/CAvatar/index.js +2 -2
  18. package/src/components/CAvatarGroup/CAvatarGroup.vue +145 -145
  19. package/src/components/CAvatarGroup/index.js +2 -2
  20. package/src/components/CBasicTable/CBasicTable.vue +184 -184
  21. package/src/components/CBasicTable/index.js +2 -2
  22. package/src/components/CBreadcrumbs/CBreadcrumbs.vue +38 -38
  23. package/src/components/CBreadcrumbs/index.js +2 -2
  24. package/src/components/CButton/CButton.vue +152 -152
  25. package/src/components/CButton/index.js +2 -2
  26. package/src/components/CButtonGroup/CButtonGroup.vue +118 -118
  27. package/src/components/CButtonGroup/index.js +2 -2
  28. package/src/components/CButtonIcon/CButtonIcon.vue +117 -117
  29. package/src/components/CButtonIcon/index.js +2 -2
  30. package/src/components/CButtonLink/CButtonLink.vue +39 -39
  31. package/src/components/CButtonLink/index.js +2 -2
  32. package/src/components/CButtonSelect/CButtonSelect.vue +134 -134
  33. package/src/components/CButtonSelect/index.js +2 -2
  34. package/src/components/CButtonSelectBorder/CButtonSelectBorder.vue +135 -135
  35. package/src/components/CButtonSelectBorder/index.js +3 -3
  36. package/src/components/CButtonWithDropdown/CButtonWithDropdown.vue +135 -135
  37. package/src/components/CButtonWithDropdown/index.js +2 -2
  38. package/src/components/CCalendar/CCalendar.vue +410 -410
  39. package/src/components/CCalendar/index.js +3 -3
  40. package/src/components/CCard/CCard.vue +49 -49
  41. package/src/components/CCard/index.js +2 -2
  42. package/src/components/CCheckbox/CCheckbox.vue +123 -123
  43. package/src/components/CCheckbox/index.js +2 -2
  44. package/src/components/CCircularButton/CCircularButton.vue +53 -53
  45. package/src/components/CCircularButton/index.js +2 -2
  46. package/src/components/CCollapsibleSection/CCollapsibleSection.vue +101 -101
  47. package/src/components/CCollapsibleSection/index.js +2 -2
  48. package/src/components/CColorDots/CColorDots.vue +51 -51
  49. package/src/components/CColorDots/index.js +3 -3
  50. package/src/components/CConfirmActionModal/CConfirmActionModal.vue +180 -180
  51. package/src/components/CConfirmActionModal/index.js +3 -3
  52. package/src/components/CDatepicker/CDatepicker.vue +201 -201
  53. package/src/components/CDatepicker/index.js +2 -2
  54. package/src/components/CDualSelect/CDualSelect.vue +193 -193
  55. package/src/components/CDualSelect/index.js +2 -2
  56. package/src/components/CEditor/CEditor.vue +98 -98
  57. package/src/components/CEditor/index.js +2 -2
  58. package/src/components/CFormSectionHeading/CFormSectionHeading.vue +53 -53
  59. package/src/components/CFormSectionHeading/index.js +2 -2
  60. package/src/components/CGroupedSelect/CGroupedSelect.vue +245 -245
  61. package/src/components/CGroupedSelect/index.js +3 -3
  62. package/src/components/CIcon/CIcon.vue +91 -91
  63. package/src/components/CIcon/index.js +2 -2
  64. package/src/components/CIconDropdown/CIconDropdown.vue +146 -146
  65. package/src/components/CIconDropdown/index.js +2 -2
  66. package/src/components/CInput/CInput.vue +134 -134
  67. package/src/components/CInput/index.js +2 -2
  68. package/src/components/CInputAddon/CInputAddon.vue +228 -228
  69. package/src/components/CInputAddon/index.js +2 -2
  70. package/src/components/CInputEmail/CInputEmail.vue +93 -93
  71. package/src/components/CInputEmail/index.js +2 -2
  72. package/src/components/CInsetTabs/CInsetTabs.vue +88 -88
  73. package/src/components/CInsetTabs/index.js +3 -3
  74. package/src/components/CModalHeading/CModalHeading.vue +22 -22
  75. package/src/components/CModalHeading/index.js +2 -2
  76. package/src/components/CModuleHelpLinks/CModuleHelpLinks.vue +70 -70
  77. package/src/components/CModuleHelpLinks/index.js +3 -3
  78. package/src/components/CMultiselect/CMultiselect.vue +615 -615
  79. package/src/components/CMultiselect/index.js +2 -2
  80. package/src/components/CMultiselectr/CMultiselectr.vue +44 -44
  81. package/src/components/CMultiselectr/index.js +2 -2
  82. package/src/components/CPageHeading/CPageHeading.vue +56 -56
  83. package/src/components/CPageHeading/index.js +2 -2
  84. package/src/components/CPagination/CPagination.vue +233 -233
  85. package/src/components/CPagination/index.js +2 -2
  86. package/src/components/CPhoneNumber/CPhoneNumber.vue +114 -114
  87. package/src/components/CPhoneNumber/index.js +2 -2
  88. package/src/components/CProgress/CProgress.vue +57 -57
  89. package/src/components/CProgress/index.js +2 -2
  90. package/src/components/CRadio/CRadio.vue +126 -126
  91. package/src/components/CRadio/index.js +2 -2
  92. package/src/components/CRangeSlider/CRangeSlider.vue +55 -55
  93. package/src/components/CRangeSlider/index.js +2 -2
  94. package/src/components/CReorderableStackedList/CReorderableStackedList.vue +94 -94
  95. package/src/components/CReorderableStackedList/index.js +2 -2
  96. package/src/components/CSelect/CSelect.vue +539 -539
  97. package/src/components/CSelect/index.js +2 -2
  98. package/src/components/CSmallTimeline/CSmallTimeline.vue +40 -40
  99. package/src/components/CSmallTimeline/index.js +2 -2
  100. package/src/components/CStackedList/CStackedList.vue +150 -150
  101. package/src/components/CStackedList/index.js +2 -2
  102. package/src/components/CStats/CStats.vue +116 -116
  103. package/src/components/CStats/index.js +2 -2
  104. package/src/components/CSwitch/CSwitch.vue +176 -176
  105. package/src/components/CSwitch/index.js +2 -2
  106. package/src/components/CTabLazy/CTabLazy.vue +63 -63
  107. package/src/components/CTabLazy/index.js +2 -2
  108. package/src/components/CTable/CTable.vue +671 -671
  109. package/src/components/CTable/index.js +2 -2
  110. package/src/components/CTabs/CTabs.vue +169 -169
  111. package/src/components/CTabs/index.js +2 -2
  112. package/src/components/CTag/CTag.vue +59 -59
  113. package/src/components/CTag/index.js +2 -2
  114. package/src/components/CTextarea/CTextarea.vue +107 -107
  115. package/src/components/CTextarea/index.js +2 -2
  116. package/src/components/CTimeline/CTimeline.vue +237 -237
  117. package/src/components/CTimeline/index.js +2 -2
  118. package/src/components/CUpload/CUpload.vue +267 -267
  119. package/src/components/CUpload/index.js +2 -2
  120. package/src/components/index.js +53 -53
  121. package/src/icons.js +459 -453
  122. package/src/main.js +22 -22
  123. package/src/stories/CAlerts.stories.js +37 -37
  124. package/src/stories/CAnchorTabs.stories.js +29 -29
  125. package/src/stories/CAnchorTag.stories.js +36 -36
  126. package/src/stories/CAvatar.stories.js +38 -38
  127. package/src/stories/CAvatarGroup.stories.js +100 -100
  128. package/src/stories/CBasicTable.stories.js +316 -316
  129. package/src/stories/CBreadcrumbs.stories.js +24 -24
  130. package/src/stories/CButton.stories.js +47 -47
  131. package/src/stories/CButtonGroup.stories.js +33 -33
  132. package/src/stories/CButtonIcon.stories.js +27 -27
  133. package/src/stories/CButtonLink.stories.js +24 -24
  134. package/src/stories/CButtonSelect.stories.js +41 -41
  135. package/src/stories/CButtonSelectBorder.stories.js +48 -48
  136. package/src/stories/CButtonWithDropdown.stories.js +41 -41
  137. package/src/stories/CCalendar.stories.js +16 -16
  138. package/src/stories/CCard.stories.js +30 -30
  139. package/src/stories/CCheckbox.stories.js +29 -29
  140. package/src/stories/CCircularButton.stories.js +29 -29
  141. package/src/stories/CCollapsibleSection.stories.js +28 -28
  142. package/src/stories/CColorDots.stories.js +28 -28
  143. package/src/stories/CConfirmActionModal.stories.js +59 -59
  144. package/src/stories/CDatepicker.stories.js +30 -30
  145. package/src/stories/CDualSelect.stories.js +29 -29
  146. package/src/stories/CEditor.stories.js +30 -30
  147. package/src/stories/CFormSectionHeading.stories.js +34 -34
  148. package/src/stories/CGroupedSelect.stories.js +71 -71
  149. package/src/stories/CIcon.stories.js +28 -28
  150. package/src/stories/CIconDropdown.stories.js +45 -45
  151. package/src/stories/CInput.stories.js +36 -36
  152. package/src/stories/CInputAddon.stories.js +37 -37
  153. package/src/stories/CInputEmail.stories.js +27 -27
  154. package/src/stories/CInsetTabs.stories.js +38 -38
  155. package/src/stories/CModalHeading.stories.js +25 -25
  156. package/src/stories/CModuleHelpLinks.stories.js +25 -25
  157. package/src/stories/CMultiselect.stories.js +167 -167
  158. package/src/stories/CMultiselectr.stories.js +23 -23
  159. package/src/stories/CPageHeading.stories.js +32 -32
  160. package/src/stories/CPagination.stories.js +30 -30
  161. package/src/stories/CPhoneNumber.stories.js +29 -29
  162. package/src/stories/CProgress.stories.js +23 -23
  163. package/src/stories/CRadio.stories.js +36 -36
  164. package/src/stories/CRangeSlider.stories.js +23 -23
  165. package/src/stories/CReorderableStackedList.stories.js +23 -23
  166. package/src/stories/CSelect.stories.js +109 -109
  167. package/src/stories/CSmallTimeline.stories.js +26 -26
  168. package/src/stories/CStackedList.stories.js +37 -37
  169. package/src/stories/CStats.stories.js +33 -33
  170. package/src/stories/CSwitch.stories.js +28 -28
  171. package/src/stories/CTabLazy.stories.js +26 -26
  172. package/src/stories/CTable.stories.js +169 -169
  173. package/src/stories/CTabs.stories.js +36 -36
  174. package/src/stories/CTag.stories.js +34 -34
  175. package/src/stories/CTextarea.stories.js +32 -32
  176. package/src/stories/CTimeline.stories.js +26 -26
  177. package/src/stories/CUpload.stories.js +36 -36
  178. package/src/stories/Introduction.stories.mdx +207 -207
  179. package/src/stories/Page.vue +88 -88
  180. package/src/stories/assets/code-brackets.svg +0 -0
  181. package/src/stories/assets/colors.svg +0 -0
  182. package/src/stories/assets/comments.svg +0 -0
  183. package/src/stories/assets/direction.svg +0 -0
  184. package/src/stories/assets/flow.svg +0 -0
  185. package/src/stories/assets/plugin.svg +0 -0
  186. package/src/stories/assets/repo.svg +0 -0
  187. package/src/stories/assets/stackalt.svg +0 -0
  188. package/src/stories/header.css +26 -26
  189. package/src/stories/page.css +69 -69
  190. package/src/stories/utils.css +17 -17
@@ -1,539 +1,539 @@
1
- <template>
2
- <div>
3
- <div
4
- :class="`flex w-full items-center ${
5
- label ? 'justify-between' : 'justify-end'
6
- }`"
7
- >
8
- <div class="flex items-center" v-if="label">
9
- <!-- label of select field -->
10
- <label class="block text-sm font-medium text-gray-900">
11
- {{ label }}
12
- </label>
13
- <!-- asterisk sign to render if field is required -->
14
- <p v-if="isRequired" class="ml-1 text-red-600">*</p>
15
- </div>
16
- <button
17
- v-if="actionBtn"
18
- class="block text-sm font-medium text-indigo-800 hover:underline"
19
- @click="actionBtnEvent($event)"
20
- >
21
- {{ actionBtn }}
22
- </button>
23
- <span v-if="hint" class="text-sm text-gray-500">{{ hint }}</span>
24
- </div>
25
- <div class="relative">
26
- <div :class="label || actionBtn ? 'mt-1' : ''">
27
- <input
28
- type="text"
29
- v-model="selectSearch"
30
- @click="toggleDropdown = !toggleDropdown"
31
- @focus="type == 'tertiary' ? (showFocus = true) : ''"
32
- @input="search()"
33
- aria-haspopup="listbox"
34
- aria-expanded="true"
35
- aria-labelledby="listbox-label"
36
- class="w-full cursor-pointer py-2 pl-2 pr-10 text-left text-sm focus:ring-0 disabled:opacity-50 sm:text-sm"
37
- :class="[classes, inputClasses, customBorderRadius]"
38
- :disabled="isDisabled"
39
- autocomplete="off"
40
- @blur="handleElementBlur"
41
- :style="inputStyle"
42
- />
43
-
44
- <div
45
- class="pointer-events-none absolute inset-0 left-3 flex h-[38px] items-center overflow-hidden pr-10"
46
- >
47
- <div class="flex items-center truncate" :style="selectedOptionStyles">
48
- <div
49
- class="flex shrink-0"
50
- v-if="!addCheckBox && showImage && !selectSearch && value"
51
- >
52
- <c-avatar
53
- v-if="value.photo"
54
- size="extraextrasmall"
55
- :image="value.photo"
56
- :rounded="true"
57
- ></c-avatar>
58
- <c-avatar
59
- v-else
60
- size="extraextrasmall"
61
- :nameInitials="value.initials"
62
- :rounded="true"
63
- :isDynamicallyColored="coloredAvatars"
64
- ></c-avatar>
65
- </div>
66
- <div
67
- class="flex flex-shrink-0 shrink-0"
68
- v-if="
69
- addCheckBox &&
70
- showImage &&
71
- !selectSearch &&
72
- value &&
73
- value.length
74
- "
75
- >
76
- <c-avatar
77
- v-if="value[0].photo"
78
- size="extraextrasmall"
79
- :image="value[0].photo"
80
- :rounded="true"
81
- ></c-avatar>
82
- <c-avatar
83
- v-else
84
- size="extraextrasmall"
85
- :nameInitials="value[0].initials"
86
- :rounded="true"
87
- :isDynamicallyColored="coloredAvatars"
88
- ></c-avatar>
89
- </div>
90
- <c-icon
91
- v-if="icon && !showImage && !selectSearch"
92
- :class="icon.class"
93
- :name="icon.name"
94
- :type="icon.type"
95
- >
96
- </c-icon>
97
- <div
98
- v-if="addCheckBox"
99
- class="flex items-center overflow-hidden text-sm"
100
- >
101
- <p
102
- class="ml-1 block truncate"
103
- v-if="
104
- selectedValuesArray.length > 0 &&
105
- (!selectSearch || selectSearch == '')
106
- "
107
- >
108
- {{ selectedValuesArray[0][renderOptionName] }}
109
- </p>
110
- <p v-else>
111
- {{ !selectSearch || selectSearch == "" ? placeholder : null }}
112
- </p>
113
- <p
114
- v-if="
115
- selectedValuesArray.length > 1 &&
116
- (!selectSearch || selectSearch == '')
117
- "
118
- class="ml-1 block"
119
- >
120
- +{{ selectedValuesArray.length - 1 }}
121
- </p>
122
- </div>
123
- <p
124
- v-else
125
- :class="showImage ? 'ml-3' : ''"
126
- class="block truncate text-sm"
127
- >
128
- {{
129
- selectedValue
130
- ? selectedValue
131
- : !selectSearch || selectSearch == ""
132
- ? placeholder
133
- : null
134
- }}
135
- </p>
136
- </div>
137
- </div>
138
- <div class="pointer-events-none absolute top-2 right-3 flex">
139
- <div
140
- v-if="type == 'tertiary' ? showFocus : true"
141
- class="pointer-events-none right-0 flex items-center"
142
- >
143
- <c-icon
144
- name="selector"
145
- type="solid"
146
- class="h-5 w-5 text-gray-400"
147
- ></c-icon>
148
- </div>
149
- </div>
150
- </div>
151
- <transition
152
- enter-active-class="transition ease-out duration-100"
153
- enter-class="transform opacity-0 scale-95"
154
- enter-to-class="transform opacity-100 scale-100"
155
- leave-active-class="transition ease-in duration-75"
156
- leave-class="transform opacity-100 scale-100"
157
- leave-to-class="transform opacity-0 scale-95"
158
- >
159
- <div
160
- v-if="toggleDropdown && !isDisabled"
161
- :class="`${dropDownToTop} absolute z-10 mt-1 ${
162
- customWidth ? customWidth : 'w-full'
163
- } rounded-md bg-white shadow-lg`"
164
- >
165
- <ul
166
- tabindex="-1"
167
- role="listbox"
168
- aria-labelledby="listbox-label"
169
- class="focus:outline-none max-h-60 overflow-auto rounded-md py-1 text-base ring-1 ring-gray-900 ring-opacity-5 sm:text-sm"
170
- :class="dropDownToTop2"
171
- @mousedown="handlePreventBlur"
172
- >
173
- <li
174
- v-if="addAction"
175
- @mousedown="actionEvent($event)"
176
- class="relative flex cursor-pointer select-none py-2 pl-3 pr-9 text-indigo-500 hover:bg-indigo-100 hover:text-indigo-700"
177
- >
178
- <c-icon
179
- type="outline"
180
- class="mr-1 h-5 w-5 text-indigo-400 group-hover:text-indigo-500"
181
- name="plus"
182
- ></c-icon>
183
- {{ addAction.label }}
184
- </li>
185
- <li
186
- v-for="(option, index) in renderOptions"
187
- :key="index"
188
- id="listbox-option-0"
189
- role="option"
190
- :ref="`option-${String(index)}`"
191
- @mousedown="handleSelect($event, option)"
192
- class="group relative cursor-pointer select-none py-2 text-gray-900 hover:bg-indigo-700 hover:text-white"
193
- :class="[
194
- option.isDisabled ? 'pointer-events-none opacity-50' : '',
195
- optionClasses,
196
- addCheckBox ? 'pr-2 pl-2 ' : 'pr-9 pl-3',
197
- ]"
198
- >
199
- <span class="flex w-full items-center justify-between">
200
- <div
201
- class="flex items-center"
202
- :class="addCheckBox ? 'w-5/6' : 'w-auto'"
203
- >
204
- <div v-if="option.showImage" class="flex-shrink-0">
205
- <c-avatar
206
- v-if="option.photo"
207
- size="extraextrasmall"
208
- :image="option.photo"
209
- :rounded="true"
210
- ></c-avatar>
211
- <c-avatar
212
- v-else
213
- size="extraextrasmall"
214
- :nameInitials="option.initials"
215
- :rounded="true"
216
- :isDynamicallyColored="coloredAvatars"
217
- ></c-avatar>
218
- </div>
219
- <c-icon
220
- class="flex-none"
221
- v-if="option.showIcon && option.icon"
222
- :class="option.icon.class"
223
- :name="option.icon.name"
224
- :type="option.icon.type"
225
- >
226
- </c-icon>
227
- <span
228
- :class="[
229
- option.photo || option.initials ? 'ml-3' : 'text-left',
230
- addCheckBox ? 'ml-2 mr-2 overflow-hidden' : '',
231
- ]"
232
- class="list-options block break-words font-normal"
233
- >{{ option[renderOptionName] }}
234
- </span>
235
- </div>
236
- <div
237
- v-if="addCheckBox"
238
- class="flex w-1/6 items-center justify-end"
239
- >
240
- <div class="flex h-5 items-center">
241
- <input
242
- type="checkbox"
243
- name="staff"
244
- class="pointer-events-none h-4 w-4 cursor-pointer rounded border-gray-300 text-indigo-600 focus:ring-indigo-500 disabled:opacity-50"
245
- :checked="selectAll ? true : isChecked(option)"
246
- />
247
- </div>
248
- </div>
249
- </span>
250
-
251
- <span
252
- class="absolute inset-y-0 right-0 flex items-center pr-4 text-indigo-600"
253
- v-show="showSelectedValue"
254
- >
255
- <c-icon
256
- id="list-icon"
257
- name="check"
258
- type="solid"
259
- class="h-5 w-5"
260
- ></c-icon>
261
- </span>
262
- </li>
263
- </ul>
264
- </div>
265
- </transition>
266
- </div>
267
- <p
268
- v-if="helpText && isValidate == true"
269
- class="mt-1 text-left text-sm text-gray-500"
270
- >
271
- {{ helpText }}
272
- </p>
273
- <!-- validation error message -->
274
- <p v-if="!isValidate" class="mt-2 text-left text-sm text-red-600">
275
- {{ errorMessage }}
276
- </p>
277
- </div>
278
- </template>
279
- <script>
280
- import CIcon from "../CIcon/CIcon.vue";
281
- import CAvatar from "../CAvatar/CAvatar.vue";
282
-
283
- import { isNumber } from "lodash";
284
- export default {
285
- name: "CSelect",
286
- components: { CIcon, CAvatar },
287
- props: {
288
- // label of selectpicker
289
- label: {
290
- type: String,
291
- },
292
- // action button of selectpicker
293
- actionBtn: {
294
- type: String,
295
- default: null,
296
- },
297
- // placeholder in selectpicker
298
- placeholder: {
299
- type: String,
300
- },
301
- // list to render in dropdown
302
- options: {
303
- type: Array,
304
- required: true,
305
- },
306
- // show the avatars with different colors
307
- coloredAvatars: {
308
- type: Boolean,
309
- },
310
- // text below dropdown to describe more about the field
311
- helpText: {
312
- type: String,
313
- },
314
- // style input field
315
- inputStyle: {
316
- type: String,
317
- },
318
- // text adjacent to label of dropdown to provide hint about field
319
- hint: { type: String },
320
- // to show if image is present along with dropdown option
321
- showImage: { type: Boolean },
322
- // whether the select field is mandatory or not
323
- isRequired: {
324
- type: Boolean,
325
- },
326
- // validation is passed or not
327
- isValidate: { type: Boolean, default: true },
328
- // will truncate the text in input field
329
- selectedOptionStyles: {
330
- type: String,
331
- },
332
- // validation error message
333
- errorMessage: {
334
- type: String,
335
- },
336
- // perform action on first option in dropdown
337
- addAction: { type: Object },
338
- // icons in dropdown list
339
- icon: { type: Object },
340
- // value to set as default option in dropdown
341
- value: { type: [Object, String, Array], default: null },
342
- // type of dropdown - gray,tertiary or default
343
- type: {
344
- type: String,
345
- },
346
- // name of the field in array to that contains text to render in dropdown
347
- renderOptionName: {
348
- type: String,
349
- default: "option",
350
- },
351
- // whether to disable the selectpicker
352
- isDisabled: {
353
- type: Boolean,
354
- default: false,
355
- },
356
- inputClasses: {
357
- type: String,
358
- default: "",
359
- },
360
- optionClasses: {
361
- type: String,
362
- default: "",
363
- },
364
- // to display the dropdown modal from bottom to top (absolute, bottom-full)
365
- dropDownToTop: {
366
- type: String,
367
- default: "",
368
- },
369
- // to display the dropdown modal from bottom to top (absolute, bottom-full)
370
- dropDownToTop2: {
371
- type: String,
372
- default: "",
373
- },
374
- // customised width for the dropdown
375
- customWidth: {
376
- type: String,
377
- default: null,
378
- },
379
- customBorderRadius: {
380
- type: String,
381
- default: "rounded-md",
382
- },
383
- addCheckBox: {
384
- type: Boolean,
385
- default: false,
386
- },
387
- selectAll: {
388
- type: Boolean,
389
- default: false,
390
- },
391
- },
392
- data() {
393
- return {
394
- toggleDropdown: false,
395
- selectedValue: null,
396
- showSelectedValue: false,
397
- showFocus: false,
398
- selectSearch: null,
399
- renderOptions: this.options,
400
- selectedValuesArray: [],
401
- };
402
- },
403
- computed: {
404
- classes() {
405
- return {
406
- "text-gray-900 border border-gray-200 hover:bg-gray-200 bg-gray-100 focus:ring-2 focus:border-gray-200 focus:ring-gray-200 focus:ring-offset-2 shadow-sm":
407
- this.type == "gray",
408
- "bg-white border border-gray-200 hover:bg-indigo-100 text-indigo-600 hover:text-indigo-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-200":
409
- this.type == "tertiary",
410
- "border border-gray-300 focus:ring-indigo-500 focus:border-indigo-500 bg-white shadow-sm focus:ring-1":
411
- this.type == null,
412
- };
413
- },
414
- },
415
- methods: {
416
- handleSelect(event, option) {
417
- this.selectSearch = null;
418
- this.selectedValue = option[this.renderOptionName];
419
- if (this.addCheckBox) {
420
- if (this.getIndex(option) == -1) {
421
- this.selectedValuesArray = [...this.selectedValuesArray, option];
422
- } else if (this.selectedValuesArray.length == 1) {
423
- this.selectedValuesArray = [option];
424
- } else {
425
- this.selectedValuesArray = this.selectedValuesArray.filter(
426
- (item) => option.id !== item.id
427
- );
428
- }
429
- this.$emit("onChangeChecked", this.selectedValuesArray);
430
- }
431
-
432
- this.$emit("onChangeValue", option);
433
- if (!this.addCheckBox) {
434
- this.toggleDropdown = false;
435
- }
436
- this.type === "tertiary" ? (this.showFocus = false) : "";
437
- this.renderOptions = this.options;
438
- },
439
- actionEvent(event) {
440
- this.$emit("listAction", event);
441
- },
442
- actionBtnEvent(event) {
443
- this.$emit("listAction", event);
444
- },
445
- handleElementBlur() {
446
- this.toggleDropdown = false;
447
- if (this.addCheckBox) {
448
- this.$emit("onClickOutside", this.selectedValuesArray);
449
- }
450
- this.selectSearch = null;
451
- this.renderOptions = this.options;
452
- },
453
- //this prevents the blur to be called when the user clicks on the scrollbar
454
- handlePreventBlur(event) {
455
- event.preventDefault();
456
- },
457
- // close() {
458
- // console.log("Close");
459
- // this.selectSearch = null;
460
- // this.toggleDropdown = false;
461
- // this.type === "tertiary" ? (this.showFocus = false) : "";
462
- // this.renderOptions = this.options;
463
- // },
464
- search() {
465
- this.selectedValue = null;
466
- if (!this.selectSearch || this.selectSearch == "") {
467
- this.renderOptions = this.options;
468
- return;
469
- }
470
- let options = [...this.options];
471
- this.renderOptions = options.filter((option) => {
472
- isNumber(option[this.renderOptionName])
473
- ? (option[this.renderOptionName] =
474
- option[this.renderOptionName].toString())
475
- : "";
476
- return option[this.renderOptionName]
477
- .toLowerCase()
478
- .includes(this.selectSearch.toLowerCase());
479
- });
480
-
481
- if (this.renderOptions.length === 0) {
482
- console.log("Search ", this.selectSearch);
483
- this.$emit("search-term", this.selectSearch);
484
- }
485
- },
486
- async scrollOptionIntoView(refName) {
487
- await this.$nextTick();
488
- this.$refs[refName][0].scrollIntoView({
489
- behavior: "smooth",
490
- block: "nearest", //changed due to pop up issue in main menu
491
- });
492
- },
493
- getIndex(option) {
494
- return this.selectedValuesArray.findIndex((item) => item.id == option.id);
495
- },
496
- isChecked(option) {
497
- return this.selectedValuesArray.findIndex(
498
- (item) => item.id == option.id
499
- ) == -1
500
- ? false
501
- : true;
502
- },
503
- },
504
- watch: {
505
- value() {
506
- this.selectedValue =
507
- this.value !== null && this.value[this.renderOptionName]
508
- ? this.value[this.renderOptionName]
509
- : this.value;
510
- if (this.addCheckBox) {
511
- this.selectedValuesArray = this.value ? this.value : [];
512
- }
513
- },
514
- options() {
515
- this.renderOptions = this.options;
516
- },
517
- toggleDropdown(newValue) {
518
- if (newValue) {
519
- let index = this.renderOptions.findIndex(
520
- (option) => option[this.renderOptionName] === this.selectedValue
521
- );
522
- if (index !== -1) {
523
- let refName = `option-${String(index)}`;
524
- this.scrollOptionIntoView(refName);
525
- }
526
- }
527
- },
528
- },
529
- mounted() {
530
- this.selectedValue =
531
- this.value !== null && this.value[this.renderOptionName]
532
- ? this.value[this.renderOptionName]
533
- : this.value;
534
- if (this.addCheckBox) {
535
- this.selectedValuesArray = this.value ? this.value : [];
536
- }
537
- },
538
- };
539
- </script>
1
+ <template>
2
+ <div>
3
+ <div
4
+ :class="`flex w-full items-center ${
5
+ label ? 'justify-between' : 'justify-end'
6
+ }`"
7
+ >
8
+ <div class="flex items-center" v-if="label">
9
+ <!-- label of select field -->
10
+ <label class="block text-sm font-medium text-gray-900">
11
+ {{ label }}
12
+ </label>
13
+ <!-- asterisk sign to render if field is required -->
14
+ <p v-if="isRequired" class="ml-1 text-red-600">*</p>
15
+ </div>
16
+ <button
17
+ v-if="actionBtn"
18
+ class="block text-sm font-medium text-indigo-800 hover:underline"
19
+ @click="actionBtnEvent($event)"
20
+ >
21
+ {{ actionBtn }}
22
+ </button>
23
+ <span v-if="hint" class="text-sm text-gray-500">{{ hint }}</span>
24
+ </div>
25
+ <div class="relative">
26
+ <div :class="label || actionBtn ? 'mt-1' : ''">
27
+ <input
28
+ type="text"
29
+ v-model="selectSearch"
30
+ @click="toggleDropdown = !toggleDropdown"
31
+ @focus="type == 'tertiary' ? (showFocus = true) : ''"
32
+ @input="search()"
33
+ aria-haspopup="listbox"
34
+ aria-expanded="true"
35
+ aria-labelledby="listbox-label"
36
+ class="w-full cursor-pointer py-2 pl-2 pr-10 text-left text-sm focus:ring-0 disabled:opacity-50 sm:text-sm"
37
+ :class="[classes, inputClasses, customBorderRadius]"
38
+ :disabled="isDisabled"
39
+ autocomplete="off"
40
+ @blur="handleElementBlur"
41
+ :style="inputStyle"
42
+ />
43
+
44
+ <div
45
+ class="pointer-events-none absolute inset-0 left-3 flex h-[38px] items-center overflow-hidden pr-10"
46
+ >
47
+ <div class="flex items-center truncate" :style="selectedOptionStyles">
48
+ <div
49
+ class="flex shrink-0"
50
+ v-if="!addCheckBox && showImage && !selectSearch && value"
51
+ >
52
+ <c-avatar
53
+ v-if="value.photo"
54
+ size="extraextrasmall"
55
+ :image="value.photo"
56
+ :rounded="true"
57
+ ></c-avatar>
58
+ <c-avatar
59
+ v-else
60
+ size="extraextrasmall"
61
+ :nameInitials="value.initials"
62
+ :rounded="true"
63
+ :isDynamicallyColored="coloredAvatars"
64
+ ></c-avatar>
65
+ </div>
66
+ <div
67
+ class="flex flex-shrink-0 shrink-0"
68
+ v-if="
69
+ addCheckBox &&
70
+ showImage &&
71
+ !selectSearch &&
72
+ value &&
73
+ value.length
74
+ "
75
+ >
76
+ <c-avatar
77
+ v-if="value[0].photo"
78
+ size="extraextrasmall"
79
+ :image="value[0].photo"
80
+ :rounded="true"
81
+ ></c-avatar>
82
+ <c-avatar
83
+ v-else
84
+ size="extraextrasmall"
85
+ :nameInitials="value[0].initials"
86
+ :rounded="true"
87
+ :isDynamicallyColored="coloredAvatars"
88
+ ></c-avatar>
89
+ </div>
90
+ <c-icon
91
+ v-if="icon && !showImage && !selectSearch"
92
+ :class="icon.class"
93
+ :name="icon.name"
94
+ :type="icon.type"
95
+ >
96
+ </c-icon>
97
+ <div
98
+ v-if="addCheckBox"
99
+ class="flex items-center overflow-hidden text-sm"
100
+ >
101
+ <p
102
+ class="ml-1 block truncate"
103
+ v-if="
104
+ selectedValuesArray.length > 0 &&
105
+ (!selectSearch || selectSearch == '')
106
+ "
107
+ >
108
+ {{ selectedValuesArray[0][renderOptionName] }}
109
+ </p>
110
+ <p v-else>
111
+ {{ !selectSearch || selectSearch == "" ? placeholder : null }}
112
+ </p>
113
+ <p
114
+ v-if="
115
+ selectedValuesArray.length > 1 &&
116
+ (!selectSearch || selectSearch == '')
117
+ "
118
+ class="ml-1 block"
119
+ >
120
+ +{{ selectedValuesArray.length - 1 }}
121
+ </p>
122
+ </div>
123
+ <p
124
+ v-else
125
+ :class="showImage ? 'ml-3' : ''"
126
+ class="block truncate text-sm"
127
+ >
128
+ {{
129
+ selectedValue
130
+ ? selectedValue
131
+ : !selectSearch || selectSearch == ""
132
+ ? placeholder
133
+ : null
134
+ }}
135
+ </p>
136
+ </div>
137
+ </div>
138
+ <div class="pointer-events-none absolute top-2 right-3 flex">
139
+ <div
140
+ v-if="type == 'tertiary' ? showFocus : true"
141
+ class="pointer-events-none right-0 flex items-center"
142
+ >
143
+ <c-icon
144
+ name="selector"
145
+ type="solid"
146
+ class="h-5 w-5 text-gray-400"
147
+ ></c-icon>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ <transition
152
+ enter-active-class="transition ease-out duration-100"
153
+ enter-class="transform opacity-0 scale-95"
154
+ enter-to-class="transform opacity-100 scale-100"
155
+ leave-active-class="transition ease-in duration-75"
156
+ leave-class="transform opacity-100 scale-100"
157
+ leave-to-class="transform opacity-0 scale-95"
158
+ >
159
+ <div
160
+ v-if="toggleDropdown && !isDisabled"
161
+ :class="`${dropDownToTop} absolute z-10 mt-1 ${
162
+ customWidth ? customWidth : 'w-full'
163
+ } rounded-md bg-white shadow-lg`"
164
+ >
165
+ <ul
166
+ tabindex="-1"
167
+ role="listbox"
168
+ aria-labelledby="listbox-label"
169
+ class="focus:outline-none max-h-60 overflow-auto rounded-md py-1 text-base ring-1 ring-gray-900 ring-opacity-5 sm:text-sm"
170
+ :class="dropDownToTop2"
171
+ @mousedown="handlePreventBlur"
172
+ >
173
+ <li
174
+ v-if="addAction"
175
+ @mousedown="actionEvent($event)"
176
+ class="relative flex cursor-pointer select-none py-2 pl-3 pr-9 text-indigo-500 hover:bg-indigo-100 hover:text-indigo-700"
177
+ >
178
+ <c-icon
179
+ type="outline"
180
+ class="mr-1 h-5 w-5 text-indigo-400 group-hover:text-indigo-500"
181
+ name="plus"
182
+ ></c-icon>
183
+ {{ addAction.label }}
184
+ </li>
185
+ <li
186
+ v-for="(option, index) in renderOptions"
187
+ :key="index"
188
+ id="listbox-option-0"
189
+ role="option"
190
+ :ref="`option-${String(index)}`"
191
+ @mousedown="handleSelect($event, option)"
192
+ class="group relative cursor-pointer select-none py-2 text-gray-900 hover:bg-indigo-700 hover:text-white"
193
+ :class="[
194
+ option.isDisabled ? 'pointer-events-none opacity-50' : '',
195
+ optionClasses,
196
+ addCheckBox ? 'pr-2 pl-2 ' : 'pr-9 pl-3',
197
+ ]"
198
+ >
199
+ <span class="flex w-full items-center justify-between">
200
+ <div
201
+ class="flex items-center"
202
+ :class="addCheckBox ? 'w-5/6' : 'w-auto'"
203
+ >
204
+ <div v-if="option.showImage" class="flex-shrink-0">
205
+ <c-avatar
206
+ v-if="option.photo"
207
+ size="extraextrasmall"
208
+ :image="option.photo"
209
+ :rounded="true"
210
+ ></c-avatar>
211
+ <c-avatar
212
+ v-else
213
+ size="extraextrasmall"
214
+ :nameInitials="option.initials"
215
+ :rounded="true"
216
+ :isDynamicallyColored="coloredAvatars"
217
+ ></c-avatar>
218
+ </div>
219
+ <c-icon
220
+ class="flex-none"
221
+ v-if="option.showIcon && option.icon"
222
+ :class="option.icon.class"
223
+ :name="option.icon.name"
224
+ :type="option.icon.type"
225
+ >
226
+ </c-icon>
227
+ <span
228
+ :class="[
229
+ option.photo || option.initials ? 'ml-3' : 'text-left',
230
+ addCheckBox ? 'ml-2 mr-2 overflow-hidden' : '',
231
+ ]"
232
+ class="list-options block break-words font-normal"
233
+ >{{ option[renderOptionName] }}
234
+ </span>
235
+ </div>
236
+ <div
237
+ v-if="addCheckBox"
238
+ class="flex w-1/6 items-center justify-end"
239
+ >
240
+ <div class="flex h-5 items-center">
241
+ <input
242
+ type="checkbox"
243
+ name="staff"
244
+ class="pointer-events-none h-4 w-4 cursor-pointer rounded border-gray-300 text-indigo-600 focus:ring-indigo-500 disabled:opacity-50"
245
+ :checked="selectAll ? true : isChecked(option)"
246
+ />
247
+ </div>
248
+ </div>
249
+ </span>
250
+
251
+ <span
252
+ class="absolute inset-y-0 right-0 flex items-center pr-4 text-indigo-600"
253
+ v-show="showSelectedValue"
254
+ >
255
+ <c-icon
256
+ id="list-icon"
257
+ name="check"
258
+ type="solid"
259
+ class="h-5 w-5"
260
+ ></c-icon>
261
+ </span>
262
+ </li>
263
+ </ul>
264
+ </div>
265
+ </transition>
266
+ </div>
267
+ <p
268
+ v-if="helpText && isValidate == true"
269
+ class="mt-1 text-left text-sm text-gray-500"
270
+ >
271
+ {{ helpText }}
272
+ </p>
273
+ <!-- validation error message -->
274
+ <p v-if="!isValidate" class="mt-2 text-left text-sm text-red-600">
275
+ {{ errorMessage }}
276
+ </p>
277
+ </div>
278
+ </template>
279
+ <script>
280
+ import CIcon from "../CIcon/CIcon.vue";
281
+ import CAvatar from "../CAvatar/CAvatar.vue";
282
+
283
+ import { isNumber } from "lodash";
284
+ export default {
285
+ name: "CSelect",
286
+ components: { CIcon, CAvatar },
287
+ props: {
288
+ // label of selectpicker
289
+ label: {
290
+ type: String,
291
+ },
292
+ // action button of selectpicker
293
+ actionBtn: {
294
+ type: String,
295
+ default: null,
296
+ },
297
+ // placeholder in selectpicker
298
+ placeholder: {
299
+ type: String,
300
+ },
301
+ // list to render in dropdown
302
+ options: {
303
+ type: Array,
304
+ required: true,
305
+ },
306
+ // show the avatars with different colors
307
+ coloredAvatars: {
308
+ type: Boolean,
309
+ },
310
+ // text below dropdown to describe more about the field
311
+ helpText: {
312
+ type: String,
313
+ },
314
+ // style input field
315
+ inputStyle: {
316
+ type: String,
317
+ },
318
+ // text adjacent to label of dropdown to provide hint about field
319
+ hint: { type: String },
320
+ // to show if image is present along with dropdown option
321
+ showImage: { type: Boolean },
322
+ // whether the select field is mandatory or not
323
+ isRequired: {
324
+ type: Boolean,
325
+ },
326
+ // validation is passed or not
327
+ isValidate: { type: Boolean, default: true },
328
+ // will truncate the text in input field
329
+ selectedOptionStyles: {
330
+ type: String,
331
+ },
332
+ // validation error message
333
+ errorMessage: {
334
+ type: String,
335
+ },
336
+ // perform action on first option in dropdown
337
+ addAction: { type: Object },
338
+ // icons in dropdown list
339
+ icon: { type: Object },
340
+ // value to set as default option in dropdown
341
+ value: { type: [Object, String, Array], default: null },
342
+ // type of dropdown - gray,tertiary or default
343
+ type: {
344
+ type: String,
345
+ },
346
+ // name of the field in array to that contains text to render in dropdown
347
+ renderOptionName: {
348
+ type: String,
349
+ default: "option",
350
+ },
351
+ // whether to disable the selectpicker
352
+ isDisabled: {
353
+ type: Boolean,
354
+ default: false,
355
+ },
356
+ inputClasses: {
357
+ type: String,
358
+ default: "",
359
+ },
360
+ optionClasses: {
361
+ type: String,
362
+ default: "",
363
+ },
364
+ // to display the dropdown modal from bottom to top (absolute, bottom-full)
365
+ dropDownToTop: {
366
+ type: String,
367
+ default: "",
368
+ },
369
+ // to display the dropdown modal from bottom to top (absolute, bottom-full)
370
+ dropDownToTop2: {
371
+ type: String,
372
+ default: "",
373
+ },
374
+ // customised width for the dropdown
375
+ customWidth: {
376
+ type: String,
377
+ default: null,
378
+ },
379
+ customBorderRadius: {
380
+ type: String,
381
+ default: "rounded-md",
382
+ },
383
+ addCheckBox: {
384
+ type: Boolean,
385
+ default: false,
386
+ },
387
+ selectAll: {
388
+ type: Boolean,
389
+ default: false,
390
+ },
391
+ },
392
+ data() {
393
+ return {
394
+ toggleDropdown: false,
395
+ selectedValue: null,
396
+ showSelectedValue: false,
397
+ showFocus: false,
398
+ selectSearch: null,
399
+ renderOptions: this.options,
400
+ selectedValuesArray: [],
401
+ };
402
+ },
403
+ computed: {
404
+ classes() {
405
+ return {
406
+ "text-gray-900 border border-gray-200 hover:bg-gray-200 bg-gray-100 focus:ring-2 focus:border-gray-200 focus:ring-gray-200 focus:ring-offset-2 shadow-sm":
407
+ this.type == "gray",
408
+ "bg-white border border-gray-200 hover:bg-indigo-100 text-indigo-600 hover:text-indigo-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-200":
409
+ this.type == "tertiary",
410
+ "border border-gray-300 focus:ring-indigo-500 focus:border-indigo-500 bg-white shadow-sm focus:ring-1":
411
+ this.type == null,
412
+ };
413
+ },
414
+ },
415
+ methods: {
416
+ handleSelect(event, option) {
417
+ this.selectSearch = null;
418
+ this.selectedValue = option[this.renderOptionName];
419
+ if (this.addCheckBox) {
420
+ if (this.getIndex(option) == -1) {
421
+ this.selectedValuesArray = [...this.selectedValuesArray, option];
422
+ } else if (this.selectedValuesArray.length == 1) {
423
+ this.selectedValuesArray = [option];
424
+ } else {
425
+ this.selectedValuesArray = this.selectedValuesArray.filter(
426
+ (item) => option.id !== item.id
427
+ );
428
+ }
429
+ this.$emit("onChangeChecked", this.selectedValuesArray);
430
+ }
431
+
432
+ this.$emit("onChangeValue", option);
433
+ if (!this.addCheckBox) {
434
+ this.toggleDropdown = false;
435
+ }
436
+ this.type === "tertiary" ? (this.showFocus = false) : "";
437
+ this.renderOptions = this.options;
438
+ },
439
+ actionEvent(event) {
440
+ this.$emit("listAction", event);
441
+ },
442
+ actionBtnEvent(event) {
443
+ this.$emit("listAction", event);
444
+ },
445
+ handleElementBlur() {
446
+ this.toggleDropdown = false;
447
+ if (this.addCheckBox) {
448
+ this.$emit("onClickOutside", this.selectedValuesArray);
449
+ }
450
+ this.selectSearch = null;
451
+ this.renderOptions = this.options;
452
+ },
453
+ //this prevents the blur to be called when the user clicks on the scrollbar
454
+ handlePreventBlur(event) {
455
+ event.preventDefault();
456
+ },
457
+ // close() {
458
+ // console.log("Close");
459
+ // this.selectSearch = null;
460
+ // this.toggleDropdown = false;
461
+ // this.type === "tertiary" ? (this.showFocus = false) : "";
462
+ // this.renderOptions = this.options;
463
+ // },
464
+ search() {
465
+ this.selectedValue = null;
466
+ if (!this.selectSearch || this.selectSearch == "") {
467
+ this.renderOptions = this.options;
468
+ return;
469
+ }
470
+ let options = [...this.options];
471
+ this.renderOptions = options.filter((option) => {
472
+ isNumber(option[this.renderOptionName])
473
+ ? (option[this.renderOptionName] =
474
+ option[this.renderOptionName].toString())
475
+ : "";
476
+ return option[this.renderOptionName]
477
+ .toLowerCase()
478
+ .includes(this.selectSearch.toLowerCase());
479
+ });
480
+
481
+ if (this.renderOptions.length === 0) {
482
+ console.log("Search ", this.selectSearch);
483
+ this.$emit("search-term", this.selectSearch);
484
+ }
485
+ },
486
+ async scrollOptionIntoView(refName) {
487
+ await this.$nextTick();
488
+ this.$refs[refName][0].scrollIntoView({
489
+ behavior: "smooth",
490
+ block: "nearest", //changed due to pop up issue in main menu
491
+ });
492
+ },
493
+ getIndex(option) {
494
+ return this.selectedValuesArray.findIndex((item) => item.id == option.id);
495
+ },
496
+ isChecked(option) {
497
+ return this.selectedValuesArray.findIndex(
498
+ (item) => item.id == option.id
499
+ ) == -1
500
+ ? false
501
+ : true;
502
+ },
503
+ },
504
+ watch: {
505
+ value() {
506
+ this.selectedValue =
507
+ this.value !== null && this.value[this.renderOptionName]
508
+ ? this.value[this.renderOptionName]
509
+ : this.value;
510
+ if (this.addCheckBox) {
511
+ this.selectedValuesArray = this.value ? this.value : [];
512
+ }
513
+ },
514
+ options() {
515
+ this.renderOptions = this.options;
516
+ },
517
+ toggleDropdown(newValue) {
518
+ if (newValue) {
519
+ let index = this.renderOptions.findIndex(
520
+ (option) => option[this.renderOptionName] === this.selectedValue
521
+ );
522
+ if (index !== -1) {
523
+ let refName = `option-${String(index)}`;
524
+ this.scrollOptionIntoView(refName);
525
+ }
526
+ }
527
+ },
528
+ },
529
+ mounted() {
530
+ this.selectedValue =
531
+ this.value !== null && this.value[this.renderOptionName]
532
+ ? this.value[this.renderOptionName]
533
+ : this.value;
534
+ if (this.addCheckBox) {
535
+ this.selectedValuesArray = this.value ? this.value : [];
536
+ }
537
+ },
538
+ };
539
+ </script>