classcard-ui 0.2.752 → 0.2.753

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 +75 -62
  3. package/dist/classcard-ui.common.js.map +1 -1
  4. package/dist/classcard-ui.umd.js +75 -62
  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 +118 -118
  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 +410 -410
  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 +131 -131
  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 +218 -218
  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 +118 -118
  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 +361 -361
  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 +204 -204
  79. package/src/components/CPagination/index.js +2 -2
  80. package/src/components/CPhoneNumber/CPhoneNumber.vue +89 -89
  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 +341 -340
  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 +537 -537
  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 +297 -297
  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 +45 -45
  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 +103 -103
  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,340 +1,341 @@
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="focus:outline-none relative w-full cursor-pointer rounded-md py-2 pl-3 pr-10 text-left text-sm 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 name="selector" type="solid" class="h-5 w-5 text-gray-400"></c-icon>
76
- </div>
77
- </div>
78
- </div>
79
- <transition
80
- enter-active-class="transition ease-out duration-100"
81
- enter-class="transform opacity-0 scale-95"
82
- enter-to-class="transform opacity-100 scale-100"
83
- leave-active-class="transition ease-in duration-75"
84
- leave-class="transform opacity-100 scale-100"
85
- leave-to-class="transform opacity-0 scale-95"
86
- >
87
- <div
88
- v-if="toggleDropdown && !isDisabled"
89
- class="absolute z-10 mt-1 w-full rounded-md bg-white shadow-lg"
90
- >
91
- <ul
92
- tabindex="-1"
93
- role="listbox"
94
- aria-labelledby="listbox-label"
95
- 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"
96
- >
97
- <li
98
- v-if="addAction"
99
- @mousedown="actionEvent($event)"
100
- class="relative flex cursor-pointer select-none py-2 pl-3 pr-9 text-indigo-500 hover:bg-indigo-100 hover:text-indigo-700"
101
- >
102
- <c-icon
103
- type="outline"
104
- class="mr-1 h-5 w-5 text-indigo-400 group-hover:text-indigo-500"
105
- name="plus"
106
- ></c-icon>
107
- {{ addAction.label }}
108
- </li>
109
- <li
110
- v-for="(option, index) in renderOptions"
111
- :key="index"
112
- id="listbox-option-0"
113
- role="option"
114
- :ref="`option-${String(index)}`"
115
- @mousedown="handleSelect($event, option)"
116
- class="relative cursor-pointer select-none py-2 pl-3 pr-9 text-gray-900 hover:bg-indigo-700 hover:text-white"
117
- :class="[option.isDisabled ? 'pointer-events-none opacity-50' : '', optionClasses]"
118
- >
119
- <span class="flex items-center">
120
- <div v-if="option.showImage">
121
- <c-avatar
122
- v-if="option.photo"
123
- size="extraextrasmall"
124
- :image="option.photo"
125
- :rounded="true"
126
- ></c-avatar>
127
- <c-avatar
128
- v-else
129
- size="extraextrasmall"
130
- :nameInitials="option.initials"
131
- :rounded="true"
132
- :isDynamicallyColored="coloredAvatars"
133
- ></c-avatar>
134
- </div>
135
- <c-icon
136
- class="flex-none"
137
- v-if="option.showIcon && option.icon"
138
- :class="option.icon.class"
139
- :name="option.icon.name"
140
- :type="option.icon.type"
141
- >
142
- </c-icon>
143
- <span
144
- :class="option.photo || option.initials ? 'ml-3' : ''"
145
- class="list-options block break-words font-normal"
146
- >{{ option[renderOptionName] }}
147
- </span>
148
- </span>
149
-
150
- <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-indigo-600">
151
- <c-icon
152
- id="list-icon"
153
- v-show="showSelectedValue"
154
- name="check"
155
- type="solid"
156
- class="h-5 w-5"
157
- ></c-icon>
158
- </span>
159
- </li>
160
- </ul>
161
- </div>
162
- </transition>
163
- <!-- validation error message -->
164
- <p v-if="!isValidate" class="mt-2 text-left text-sm text-red-600">
165
- {{ errorMessage }}
166
- </p>
167
- <p v-if="helpText" class="mt-2 text-sm text-gray-500">
168
- {{ helpText }}
169
- </p>
170
- </div>
171
- </div>
172
- </template>
173
- <script>
174
- import CIcon from "../CIcon/CIcon.vue";
175
- import CAvatar from "../CAvatar/CAvatar.vue";
176
- import { isNumber } from "lodash";
177
- export default {
178
- name: "CSelect",
179
- components: { CIcon, CAvatar },
180
- props: {
181
- // label of selectpicker
182
- label: {
183
- type: String,
184
- },
185
- // placeholder in selectpicker
186
- placeholder: {
187
- type: String,
188
- },
189
- // list to render in dropdown
190
- options: {
191
- type: Array,
192
- required: true,
193
- },
194
- // show the avatars with different colors
195
- coloredAvatars: {
196
- type: Boolean,
197
- },
198
- // text below dropdown to describe more about the field
199
- helpText: {
200
- type: String,
201
- },
202
- // text adjacent to label of dropdown to provide hint about field
203
- hint: { type: String },
204
- // to show if image is present along with dropdown option
205
- showImage: { type: Boolean },
206
- // whether the select field is mandatory or not
207
- isRequired: {
208
- type: Boolean,
209
- },
210
- // validation is passed or not
211
- isValidate: { type: Boolean, default: true },
212
- // will truncate the text in input field
213
- selectedOptionStyles: {
214
- type: String,
215
- },
216
- // validation error message
217
- errorMessage: {
218
- type: String,
219
- },
220
- // perform action on first option in dropdown
221
- addAction: { type: Object },
222
- // icons in dropdown list
223
- icon: { type: Object },
224
- // value to set as default option in dropdown
225
- value: { type: [Object, String], default: null },
226
- // type of dropdown - gray,tertiary or default
227
- type: {
228
- type: String,
229
- },
230
- // name of the field in array to that contains text to render in dropdown
231
- renderOptionName: {
232
- type: String,
233
- default: "option",
234
- },
235
- // whether to disable the selectpicker
236
- isDisabled: {
237
- type: Boolean,
238
- default: false,
239
- },
240
- inputClasses: {
241
- type: String,
242
- default: "",
243
- },
244
- optionClasses: {
245
- type: String,
246
- default: "",
247
- },
248
- },
249
- data() {
250
- return {
251
- toggleDropdown: false,
252
- selectedValue: null,
253
- showSelectedValue: false,
254
- showFocus: false,
255
- selectSearch: null,
256
- renderOptions: this.options,
257
- };
258
- },
259
- computed: {
260
- classes() {
261
- return {
262
- "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":
263
- this.type == "gray",
264
- "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":
265
- this.type == "tertiary",
266
- "border border-gray-300 focus:ring-indigo-500 focus:border-indigo-500 bg-white shadow-sm focus:ring-1":
267
- this.type == null,
268
- };
269
- },
270
- },
271
- methods: {
272
- handleSelect(event, option) {
273
- this.selectSearch = null;
274
- this.selectedValue = option[this.renderOptionName];
275
- this.$emit("onChangeValue", option);
276
- this.toggleDropdown = false;
277
- },
278
- actionEvent(event) {
279
- this.$emit("listAction", event);
280
- },
281
- close() {
282
- this.selectSearch = null;
283
- this.toggleDropdown = false;
284
- this.type === "tertiary" ? (this.showFocus = false) : "";
285
- this.renderOptions = this.options;
286
- },
287
- search() {
288
- this.selectedValue = null;
289
- if (!this.selectSearch || this.selectSearch == "") {
290
- this.renderOptions = this.options;
291
- return;
292
- }
293
- let options = [...this.options];
294
- this.renderOptions = options.filter((option) => {
295
- isNumber(option[this.renderOptionName])
296
- ? (option[this.renderOptionName] = option[this.renderOptionName].toString())
297
- : "";
298
- return option[this.renderOptionName]
299
- .toLowerCase()
300
- .includes(this.selectSearch.toLowerCase());
301
- });
302
- },
303
- async scrollOptionIntoView(refName) {
304
- await this.$nextTick();
305
- this.$refs[refName][0].scrollIntoView({
306
- behavior: "smooth",
307
- block: "nearest", //changed due to pop up issue in main menu
308
- });
309
- },
310
- },
311
- watch: {
312
- value() {
313
- this.selectedValue =
314
- this.value !== null && this.value[this.renderOptionName]
315
- ? this.value[this.renderOptionName]
316
- : this.value;
317
- },
318
- options() {
319
- this.renderOptions = this.options;
320
- },
321
- toggleDropdown(newValue) {
322
- if (newValue) {
323
- let index = this.renderOptions.findIndex(
324
- (option) => option[this.renderOptionName] === this.selectedValue
325
- );
326
- if (index !== -1) {
327
- let refName = `option-${String(index)}`;
328
- this.scrollOptionIntoView(refName);
329
- }
330
- }
331
- },
332
- },
333
- mounted() {
334
- this.selectedValue =
335
- this.value !== null && this.value[this.renderOptionName]
336
- ? this.value[this.renderOptionName]
337
- : this.value;
338
- },
339
- };
340
- </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="focus:outline-none relative w-full cursor-pointer rounded-md py-2 pl-3 pr-10 text-left text-sm 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 name="selector" type="solid" class="h-5 w-5 text-gray-400"></c-icon>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ <transition
80
+ enter-active-class="transition ease-out duration-100"
81
+ enter-class="transform opacity-0 scale-95"
82
+ enter-to-class="transform opacity-100 scale-100"
83
+ leave-active-class="transition ease-in duration-75"
84
+ leave-class="transform opacity-100 scale-100"
85
+ leave-to-class="transform opacity-0 scale-95"
86
+ >
87
+ <div
88
+ v-if="toggleDropdown && !isDisabled"
89
+ class="absolute z-10 mt-1 w-full rounded-md bg-white shadow-lg"
90
+ >
91
+ <ul
92
+ tabindex="-1"
93
+ role="listbox"
94
+ aria-labelledby="listbox-label"
95
+ 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"
96
+ >
97
+ <li
98
+ v-if="addAction"
99
+ @mousedown="actionEvent($event)"
100
+ class="relative flex cursor-pointer select-none py-2 pl-3 pr-9 text-indigo-500 hover:bg-indigo-100 hover:text-indigo-700"
101
+ >
102
+ <c-icon
103
+ type="outline"
104
+ class="mr-1 h-5 w-5 text-indigo-400 group-hover:text-indigo-500"
105
+ name="plus"
106
+ ></c-icon>
107
+ {{ addAction.label }}
108
+ </li>
109
+ <li
110
+ v-for="(option, index) in renderOptions"
111
+ :key="index"
112
+ id="listbox-option-0"
113
+ role="option"
114
+ :ref="`option-${String(index)}`"
115
+ @mousedown="handleSelect($event, option)"
116
+ class="relative cursor-pointer select-none py-2 pl-3 pr-9 text-gray-900 hover:bg-indigo-700 hover:text-white"
117
+ :class="[option.isDisabled ? 'pointer-events-none opacity-50' : '', optionClasses]"
118
+ >
119
+ <span class="flex items-center">
120
+ <div v-if="option.showImage">
121
+ <c-avatar
122
+ v-if="option.photo"
123
+ size="extraextrasmall"
124
+ :image="option.photo"
125
+ :rounded="true"
126
+ ></c-avatar>
127
+ <c-avatar
128
+ v-else
129
+ size="extraextrasmall"
130
+ :nameInitials="option.initials"
131
+ :rounded="true"
132
+ :isDynamicallyColored="coloredAvatars"
133
+ ></c-avatar>
134
+ </div>
135
+ <c-icon
136
+ class="flex-none"
137
+ v-if="option.showIcon && option.icon"
138
+ :class="option.icon.class"
139
+ :name="option.icon.name"
140
+ :type="option.icon.type"
141
+ >
142
+ </c-icon>
143
+ <span
144
+ :class="option.photo || option.initials ? 'ml-3' : ''"
145
+ class="list-options block break-words font-normal"
146
+ >{{ option[renderOptionName] }}
147
+ </span>
148
+ </span>
149
+
150
+ <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-indigo-600">
151
+ <c-icon
152
+ id="list-icon"
153
+ v-show="showSelectedValue"
154
+ name="check"
155
+ type="solid"
156
+ class="h-5 w-5"
157
+ ></c-icon>
158
+ </span>
159
+ </li>
160
+ </ul>
161
+ </div>
162
+ </transition>
163
+ <!-- validation error message -->
164
+ <p v-if="!isValidate" class="mt-2 text-left text-sm text-red-600">
165
+ {{ errorMessage }}
166
+ </p>
167
+ <p v-if="helpText" class="mt-2 text-sm text-gray-500">
168
+ {{ helpText }}
169
+ </p>
170
+ </div>
171
+ </div>
172
+ </template>
173
+ <script>
174
+ import CIcon from "../CIcon/CIcon.vue";
175
+ import CAvatar from "../CAvatar/CAvatar.vue";
176
+ import { isNumber } from "lodash";
177
+ export default {
178
+ name: "CSelect",
179
+ components: { CIcon, CAvatar },
180
+ props: {
181
+ // label of selectpicker
182
+ label: {
183
+ type: String,
184
+ },
185
+ // placeholder in selectpicker
186
+ placeholder: {
187
+ type: String,
188
+ },
189
+ // list to render in dropdown
190
+ options: {
191
+ type: Array,
192
+ required: true,
193
+ },
194
+ // show the avatars with different colors
195
+ coloredAvatars: {
196
+ type: Boolean,
197
+ },
198
+ // text below dropdown to describe more about the field
199
+ helpText: {
200
+ type: String,
201
+ },
202
+ // text adjacent to label of dropdown to provide hint about field
203
+ hint: { type: String },
204
+ // to show if image is present along with dropdown option
205
+ showImage: { type: Boolean },
206
+ // whether the select field is mandatory or not
207
+ isRequired: {
208
+ type: Boolean,
209
+ },
210
+ // validation is passed or not
211
+ isValidate: { type: Boolean, default: true },
212
+ // will truncate the text in input field
213
+ selectedOptionStyles: {
214
+ type: String,
215
+ },
216
+ // validation error message
217
+ errorMessage: {
218
+ type: String,
219
+ },
220
+ // perform action on first option in dropdown
221
+ addAction: { type: Object },
222
+ // icons in dropdown list
223
+ icon: { type: Object },
224
+ // value to set as default option in dropdown
225
+ value: { type: [Object, String], default: null },
226
+ // type of dropdown - gray,tertiary or default
227
+ type: {
228
+ type: String,
229
+ },
230
+ // name of the field in array to that contains text to render in dropdown
231
+ renderOptionName: {
232
+ type: String,
233
+ default: "option",
234
+ },
235
+ // whether to disable the selectpicker
236
+ isDisabled: {
237
+ type: Boolean,
238
+ default: false,
239
+ },
240
+ inputClasses: {
241
+ type: String,
242
+ default: "",
243
+ },
244
+ optionClasses: {
245
+ type: String,
246
+ default: "",
247
+ },
248
+ },
249
+ data() {
250
+ return {
251
+ toggleDropdown: false,
252
+ selectedValue: null,
253
+ showSelectedValue: false,
254
+ showFocus: false,
255
+ selectSearch: null,
256
+ renderOptions: this.options,
257
+ };
258
+ },
259
+ computed: {
260
+ classes() {
261
+ return {
262
+ "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":
263
+ this.type == "gray",
264
+ "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":
265
+ this.type == "tertiary",
266
+ "border border-gray-300 focus:ring-indigo-500 focus:border-indigo-500 bg-white shadow-sm focus:ring-1":
267
+ this.type == null,
268
+ };
269
+ },
270
+ },
271
+ methods: {
272
+ handleSelect(event, option) {
273
+ this.selectSearch = null;
274
+ this.selectedValue = option[this.renderOptionName];
275
+ this.$emit("onChangeValue", option);
276
+ this.toggleDropdown = false;
277
+ },
278
+ actionEvent(event) {
279
+ this.$emit("listAction", event);
280
+ },
281
+ close() {
282
+ this.selectSearch = null;
283
+ this.toggleDropdown = false;
284
+ this.type === "tertiary" ? (this.showFocus = false) : "";
285
+ this.renderOptions = this.options;
286
+ },
287
+ search() {
288
+ this.selectedValue = null;
289
+ if (!this.selectSearch || this.selectSearch == "") {
290
+ this.renderOptions = this.options;
291
+ return;
292
+ }
293
+ let options = [...this.options];
294
+ this.renderOptions = options.filter((option) => {
295
+ isNumber(option[this.renderOptionName])
296
+ ? (option[this.renderOptionName] = option[this.renderOptionName].toString())
297
+ : "";
298
+ return option[this.renderOptionName]
299
+ .toLowerCase()
300
+ .includes(this.selectSearch.toLowerCase());
301
+ });
302
+ this.$emit("search-term", this.selectSearch);
303
+ },
304
+ async scrollOptionIntoView(refName) {
305
+ await this.$nextTick();
306
+ this.$refs[refName][0].scrollIntoView({
307
+ behavior: "smooth",
308
+ block: "nearest", //changed due to pop up issue in main menu
309
+ });
310
+ },
311
+ },
312
+ watch: {
313
+ value() {
314
+ this.selectedValue =
315
+ this.value !== null && this.value[this.renderOptionName]
316
+ ? this.value[this.renderOptionName]
317
+ : this.value;
318
+ },
319
+ options() {
320
+ this.renderOptions = this.options;
321
+ },
322
+ toggleDropdown(newValue) {
323
+ if (newValue) {
324
+ let index = this.renderOptions.findIndex(
325
+ (option) => option[this.renderOptionName] === this.selectedValue
326
+ );
327
+ if (index !== -1) {
328
+ let refName = `option-${String(index)}`;
329
+ this.scrollOptionIntoView(refName);
330
+ }
331
+ }
332
+ },
333
+ },
334
+ mounted() {
335
+ this.selectedValue =
336
+ this.value !== null && this.value[this.renderOptionName]
337
+ ? this.value[this.renderOptionName]
338
+ : this.value;
339
+ },
340
+ };
341
+ </script>