classcard-ui 0.2.705 → 0.2.708

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