@coreui/vue-pro 5.0.0 → 5.1.0-alpha.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.
- package/README.md +1 -1
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +26 -22
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/components/rating/CRating.d.ts +132 -0
- package/dist/cjs/components/rating/CRating.js +240 -0
- package/dist/cjs/components/rating/CRating.js.map +1 -0
- package/dist/cjs/components/rating/index.d.ts +6 -0
- package/dist/cjs/components/rating/index.js +13 -0
- package/dist/cjs/components/rating/index.js.map +1 -0
- package/dist/cjs/components/smart-table/CSmartTableBody.js +2 -1
- package/dist/cjs/components/smart-table/CSmartTableBody.js.map +1 -1
- package/dist/cjs/index.js +32 -28
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/rating/CRating.d.ts +132 -0
- package/dist/esm/components/rating/CRating.js +238 -0
- package/dist/esm/components/rating/CRating.js.map +1 -0
- package/dist/esm/components/rating/index.d.ts +6 -0
- package/dist/esm/components/rating/index.js +10 -0
- package/dist/esm/components/rating/index.js.map +1 -0
- package/dist/esm/components/smart-table/CSmartTableBody.js +3 -2
- package/dist/esm/components/smart-table/CSmartTableBody.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/index.ts +1 -0
- package/src/components/rating/CRating.ts +288 -0
- package/src/components/rating/index.ts +10 -0
- package/src/components/smart-table/CSmartTableBody.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/vue-pro",
|
|
3
|
-
"version": "5.0.0",
|
|
3
|
+
"version": "5.1.0-alpha.0",
|
|
4
4
|
"description": "UI Components Library for Vue.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"test:update": "jest --coverage --updateSnapshot"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@coreui/coreui-pro": "^5.0.0",
|
|
44
|
+
"@coreui/coreui-pro": "^5.1.0-alpha.0",
|
|
45
45
|
"@popperjs/core": "^2.11.8"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
package/src/components/index.ts
CHANGED
|
@@ -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 }
|
|
@@ -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
|
-
|
|
93
|
+
columns.map((column) => {
|
|
92
94
|
const colName = getColumnName(column)
|
|
93
95
|
return props.scopedSlots &&
|
|
94
96
|
props.scopedSlots[colName] &&
|