classcard-ui 0.2.989 → 0.2.991

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