@coreui/vue-pro 5.0.0 → 5.1.0

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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/components/calendar/CCalendar.js +4 -7
  3. package/dist/cjs/components/calendar/CCalendar.js.map +1 -1
  4. package/dist/cjs/components/dropdown/utils.js +1 -1
  5. package/dist/cjs/components/dropdown/utils.js.map +1 -1
  6. package/dist/cjs/components/index.d.ts +1 -0
  7. package/dist/cjs/components/index.js +26 -22
  8. package/dist/cjs/components/index.js.map +1 -1
  9. package/dist/cjs/components/multi-select/utils.js +0 -6
  10. package/dist/cjs/components/multi-select/utils.js.map +1 -1
  11. package/dist/cjs/components/rating/CRating.d.ts +132 -0
  12. package/dist/cjs/components/rating/CRating.js +240 -0
  13. package/dist/cjs/components/rating/CRating.js.map +1 -0
  14. package/dist/cjs/components/rating/index.d.ts +6 -0
  15. package/dist/cjs/components/rating/index.js +13 -0
  16. package/dist/cjs/components/rating/index.js.map +1 -0
  17. package/dist/cjs/components/smart-table/CSmartTableBody.js +2 -1
  18. package/dist/cjs/components/smart-table/CSmartTableBody.js.map +1 -1
  19. package/dist/cjs/index.js +32 -28
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/cjs/node_modules/vue-types/dist/vue-types.modern.js +1 -1
  22. package/dist/cjs/node_modules/vue-types/dist/vue-types.modern.js.map +1 -1
  23. package/dist/esm/components/calendar/CCalendar.js +4 -7
  24. package/dist/esm/components/calendar/CCalendar.js.map +1 -1
  25. package/dist/esm/components/dropdown/utils.js +1 -1
  26. package/dist/esm/components/dropdown/utils.js.map +1 -1
  27. package/dist/esm/components/index.d.ts +1 -0
  28. package/dist/esm/components/index.js +2 -0
  29. package/dist/esm/components/index.js.map +1 -1
  30. package/dist/esm/components/multi-select/utils.js +0 -6
  31. package/dist/esm/components/multi-select/utils.js.map +1 -1
  32. package/dist/esm/components/rating/CRating.d.ts +132 -0
  33. package/dist/esm/components/rating/CRating.js +238 -0
  34. package/dist/esm/components/rating/CRating.js.map +1 -0
  35. package/dist/esm/components/rating/index.d.ts +6 -0
  36. package/dist/esm/components/rating/index.js +10 -0
  37. package/dist/esm/components/rating/index.js.map +1 -0
  38. package/dist/esm/components/smart-table/CSmartTableBody.js +3 -2
  39. package/dist/esm/components/smart-table/CSmartTableBody.js.map +1 -1
  40. package/dist/esm/index.js +2 -0
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/node_modules/vue-types/dist/vue-types.modern.js +1 -1
  43. package/dist/esm/node_modules/vue-types/dist/vue-types.modern.js.map +1 -1
  44. package/package.json +7 -7
  45. package/src/components/index.ts +1 -0
  46. package/src/components/rating/CRating.ts +288 -0
  47. package/src/components/rating/index.ts +10 -0
  48. package/src/components/smart-table/CSmartTableBody.ts +3 -1
@@ -0,0 +1,288 @@
1
+ import { PropType, defineComponent, h, ref, watch, withDirectives } from 'vue'
2
+ import vCTooltip from '../../directives/v-c-tooltip'
3
+
4
+ const CRating = defineComponent({
5
+ name: 'CRating',
6
+ props: {
7
+ /**
8
+ * Enables the clearing upon clicking the selected item again.
9
+ */
10
+ allowClear: Boolean,
11
+ /**
12
+ * Toggle the disabled state for the component.
13
+ */
14
+ disabled: Boolean,
15
+ /**
16
+ * If enabled, only the currently selected icon will be visibly highlighted.
17
+ */
18
+ highlightOnlySelected: Boolean,
19
+ /**
20
+ * Specifies the total number of stars to be displayed in the star rating component. This property determines the scale of the rating, such as out of 5 stars, 10 stars, etc.
21
+ */
22
+ itemCount: {
23
+ type: Number,
24
+ default: 5,
25
+ },
26
+ /**
27
+ * The default name for a value passed using v-model.
28
+ */
29
+ modelValue: Number,
30
+ /**
31
+ * The name attribute of the radio input elements.
32
+ */
33
+ name: String,
34
+ /**
35
+ * Minimum increment value change allowed.
36
+ */
37
+ precision: {
38
+ type: Number,
39
+ default: 1,
40
+ },
41
+ /**
42
+ * Toggle the readonly state for the component.
43
+ */
44
+ readOnly: Boolean,
45
+ /**
46
+ * Size the component small, large, or custom if you define custom icons with custom height.
47
+ *
48
+ * @values 'sm', 'lg', 'custom'
49
+ */
50
+ size: {
51
+ type: String,
52
+ validator: (value: string) => {
53
+ return ['sm', 'lg', 'custom'].includes(value)
54
+ },
55
+ },
56
+ /**
57
+ * Enable tooltips with default values or set specific labels for each icon.
58
+ */
59
+ tooltips: {
60
+ type: [Boolean, Array] as PropType<boolean | string[]>,
61
+ },
62
+ /**
63
+ * The `value` attribute of component.
64
+ * */
65
+ value: Number,
66
+ },
67
+ emits: [
68
+ /**
69
+ * Execute a function when a user changes the selected element.
70
+ *
71
+ * @property {number | null} value
72
+ */
73
+ 'change',
74
+ /**
75
+ * Execute a function when a user hover the element.
76
+ *
77
+ * @property {number | null} value
78
+ */
79
+ 'hover',
80
+ /**
81
+ * Emit the new value whenever there’s a change event.
82
+ */
83
+ 'update:modelValue',
84
+ ],
85
+ setup(props, { slots, emit }) {
86
+ const cleared = ref(false)
87
+ const currentValue = ref((props.modelValue || props.value) ?? null)
88
+ const hoverValue = ref<number | null>(null)
89
+ const tooltipValue = ref<number | null>(null)
90
+ const name = props.name || `name${Math.floor(Math.random() * 1_000_000)}`
91
+ const uid = `id${Math.floor(Math.random() * 1_000_000)}`
92
+
93
+ watch(
94
+ () => props.value,
95
+ () => {
96
+ if (props.value !== undefined) {
97
+ currentValue.value = props.value
98
+ }
99
+ },
100
+ )
101
+
102
+ watch(
103
+ () => props.modelValue,
104
+ () => {
105
+ if (props.modelValue !== undefined) {
106
+ currentValue.value = props.modelValue
107
+ }
108
+ },
109
+ )
110
+
111
+ const handleMouseEnter = (value: number) => {
112
+ if (props.disabled || props.readOnly) {
113
+ return
114
+ }
115
+
116
+ emit('hover', value)
117
+ hoverValue.value = value
118
+ tooltipValue.value = value
119
+ }
120
+
121
+ const handleMouseLeave = () => {
122
+ if (props.disabled || props.readOnly) {
123
+ return
124
+ }
125
+
126
+ emit('hover', null)
127
+ hoverValue.value = null
128
+ }
129
+
130
+ const handleOnChange = (value: number) => {
131
+ if (props.disabled || props.readOnly) {
132
+ return
133
+ }
134
+
135
+ if (cleared.value) {
136
+ cleared.value = false
137
+ return
138
+ }
139
+
140
+ currentValue.value = value
141
+ emit('change', value)
142
+ emit('update:modelValue', value)
143
+ }
144
+
145
+ const handleOnClick = (value: number) => {
146
+ if (props.disabled || props.readOnly) {
147
+ return
148
+ }
149
+
150
+ if (props.allowClear && value === currentValue.value) {
151
+ emit('change', value)
152
+ cleared.value = true
153
+ currentValue.value = null
154
+ hoverValue.value = null
155
+ }
156
+ }
157
+
158
+ return () =>
159
+ h(
160
+ 'div',
161
+ {
162
+ class: [
163
+ 'rating',
164
+ {
165
+ [`rating-${props.size}`]: props.size,
166
+ disabled: props.disabled,
167
+ readonly: props.readOnly,
168
+ },
169
+ ],
170
+ role: 'radiogroup',
171
+ },
172
+ [
173
+ Array.from({ length: props.itemCount }, (_, index) => {
174
+ const numberOfRadios = 1 / props.precision
175
+ return withDirectives(
176
+ h(
177
+ 'div',
178
+ {
179
+ class: 'rating-item',
180
+ },
181
+ [
182
+ Array.from({ length: numberOfRadios }, (_, _index) => {
183
+ const isNotLastItem = _index + 1 < numberOfRadios
184
+ const value =
185
+ numberOfRadios === 1
186
+ ? index + 1
187
+ : index + (_index + 1) * (1 * props.precision)
188
+ const id = `${uid}${value}`
189
+
190
+ const isItemChecked = () => value === currentValue.value
191
+
192
+ const isItemActive = () => {
193
+ if (
194
+ props.highlightOnlySelected
195
+ ? hoverValue.value === value
196
+ : hoverValue.value && hoverValue.value >= value
197
+ ) {
198
+ return true
199
+ }
200
+
201
+ if (
202
+ hoverValue.value === null &&
203
+ (props.highlightOnlySelected
204
+ ? isItemChecked()
205
+ : currentValue.value && currentValue.value >= value)
206
+ ) {
207
+ return true
208
+ }
209
+
210
+ return false
211
+ }
212
+
213
+ return [
214
+ h(
215
+ 'label',
216
+ {
217
+ class: [
218
+ 'rating-item-label',
219
+ {
220
+ active: isItemActive(),
221
+ },
222
+ ],
223
+ for: id,
224
+ onClick: () => handleOnClick(value),
225
+ onMouseenter: () => handleMouseEnter(value),
226
+ onMouseleave: () => handleMouseLeave(),
227
+ ...(isNotLastItem && {
228
+ style: {
229
+ zIndex: 1 / props.precision - _index,
230
+ position: 'absolute',
231
+ width: `${props.precision * (_index + 1) * 100}%`,
232
+ overflow: 'hidden',
233
+ opacity: 0,
234
+ },
235
+ }),
236
+ },
237
+ {
238
+ default: () => [
239
+ slots.icon
240
+ ? h(
241
+ 'div',
242
+ { class: 'rating-item-custom-icon' },
243
+ slots.icon({ value: index + 1 }),
244
+ )
245
+ : h('div', { class: 'rating-item-icon' }),
246
+ slots.activeIcon &&
247
+ h(
248
+ 'div',
249
+ { class: 'rating-item-custom-icon-active' },
250
+ slots.activeIcon({ value: index + 1 }),
251
+ ),
252
+ ],
253
+ },
254
+ ),
255
+ h('input', {
256
+ checked: isItemChecked(),
257
+ class: 'rating-item-input',
258
+ disabled: props.disabled || props.readOnly,
259
+ id: id,
260
+ name: name,
261
+ onBlur: () => handleMouseLeave(),
262
+ onChange: () => handleOnChange(value),
263
+ onFocus: () => handleMouseEnter(value),
264
+ type: 'radio',
265
+ value: value,
266
+ }),
267
+ ]
268
+ }),
269
+ ],
270
+ ),
271
+ props.tooltips
272
+ ? [
273
+ [
274
+ vCTooltip,
275
+ {
276
+ content: Array.isArray(props.tooltips) ? props.tooltips[index] : index + 1,
277
+ placement: 'top',
278
+ },
279
+ ],
280
+ ]
281
+ : [],
282
+ )
283
+ }),
284
+ ],
285
+ )
286
+ },
287
+ })
288
+ export { CRating }
@@ -0,0 +1,10 @@
1
+ import { App } from 'vue'
2
+ import { CRating } from './CRating'
3
+
4
+ const CRatingPlugin = {
5
+ install: (app: App): void => {
6
+ app.component(CRating.name as string, CRating)
7
+ },
8
+ }
9
+
10
+ export { CRating, CRatingPlugin }
@@ -9,6 +9,7 @@ import { ITEM_INTERNAL_KEYS } from './consts'
9
9
  import {
10
10
  getClickedColumnName,
11
11
  getColumnName,
12
+ getColumns,
12
13
  getTableDataCellProps,
13
14
  getTableDataCellStyles,
14
15
  } from './utils'
@@ -45,6 +46,7 @@ const CSmartTableBody = defineComponent({
45
46
  emits: ['rowChecked', 'rowClick'],
46
47
  setup(props, { emit }) {
47
48
  const colspan: number = props.selectable ? props.columns.length + 1 : props.columns.length
49
+ const columns = getColumns(props.columns)
48
50
  return () =>
49
51
  h(
50
52
  CTableBody,
@@ -88,7 +90,7 @@ const CSmartTableBody = defineComponent({
88
90
  },
89
91
  }),
90
92
  ),
91
- props.columns.map((column) => {
93
+ columns.map((column) => {
92
94
  const colName = getColumnName(column)
93
95
  return props.scopedSlots &&
94
96
  props.scopedSlots[colName] &&