@coreui/vue-pro 4.4.2 → 4.6.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 (27) hide show
  1. package/dist/components/calendar/CCalendar.d.ts +41 -3
  2. package/dist/components/date-picker/CDatePicker.d.ts +41 -3
  3. package/dist/components/date-range-picker/CDateRangePicker.d.ts +160 -3
  4. package/dist/components/multi-select/CMultiSelect copy.d.ts +305 -0
  5. package/dist/components/multi-select/CMultiSelect.d.ts +168 -0
  6. package/dist/components/smart-table/CSmartTable.d.ts +2 -2
  7. package/dist/components/smart-table/CSmartTableHead.d.ts +15 -3
  8. package/dist/components/smart-table/CSmartTableInterface.d.ts +1 -1
  9. package/dist/components/table/CTable.d.ts +170 -8
  10. package/dist/components/table/CTableDataCell.d.ts +14 -0
  11. package/dist/index.es.js +1006 -474
  12. package/dist/index.es.js.map +1 -1
  13. package/dist/index.js +1006 -474
  14. package/dist/index.js.map +1 -1
  15. package/package.json +2 -2
  16. package/src/components/calendar/CCalendar.ts +46 -4
  17. package/src/components/date-picker/CDatePicker.ts +33 -1
  18. package/src/components/date-range-picker/CDateRangePicker.ts +286 -170
  19. package/src/components/form/CFormInput.ts +1 -1
  20. package/src/components/multi-select/CMultiSelect.ts +204 -93
  21. package/src/components/smart-table/CSmartTable.ts +22 -21
  22. package/src/components/smart-table/CSmartTableHead.ts +45 -24
  23. package/src/components/smart-table/CSmartTableInterface.ts +1 -1
  24. package/src/components/smart-table/CSmartTableItemsPerPageSelector.ts +1 -1
  25. package/src/components/table/CTable.ts +243 -9
  26. package/src/components/table/CTableDataCell.ts +9 -1
  27. package/src/components/time-picker/CTimePicker.ts +125 -44
@@ -1,6 +1,51 @@
1
- import { defineComponent, h } from 'vue'
1
+ import { computed, defineComponent, h, PropType } from 'vue'
2
2
 
3
3
  import { Color } from '../props'
4
+ import { CTableBody } from './CTableBody'
5
+ import { CTableCaption } from './CTableCaption'
6
+ import { CTableDataCell } from './CTableDataCell'
7
+ import { CTableFoot } from './CTableFoot'
8
+ import { CTableHead } from './CTableHead'
9
+ import { CTableHeaderCell } from './CTableHeaderCell'
10
+ import { CTableRow } from './CTableRow'
11
+
12
+ export interface Column {
13
+ label?: string
14
+ key: string
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ _style?: any
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ _props?: any
19
+ }
20
+
21
+ export interface FooterItem {
22
+ label?: string
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ _props?: any
25
+ }
26
+
27
+ export type Item = {
28
+ [key: string]: number | string | any
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ _props?: any
31
+ }
32
+
33
+ const pretifyName = (name: string) => {
34
+ return name
35
+ .replace(/[-_.]/g, ' ')
36
+ .replace(/ +/g, ' ')
37
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
38
+ .split(' ')
39
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
40
+ .join(' ')
41
+ }
42
+
43
+ const label = (column: Column | string) =>
44
+ typeof column === 'object'
45
+ ? column.label !== undefined
46
+ ? column.label
47
+ : pretifyName(column.key)
48
+ : pretifyName(column)
4
49
 
5
50
  const CTable = defineComponent({
6
51
  name: 'CTable',
@@ -41,15 +86,39 @@ const CTable = defineComponent({
41
86
  /**
42
87
  * Put the `<caption>` on the top of the table.
43
88
  *
44
- * @values 'top'
89
+ * @values 'top' | string
45
90
  */
46
91
  caption: {
47
92
  type: String,
48
93
  default: undefined,
49
94
  required: false,
50
- validator: (value: string) => {
51
- return value === 'top'
52
- },
95
+ },
96
+ /**
97
+ * Set the text of the table caption and the caption on the top of the table.
98
+ *
99
+ * @since 4.5.0
100
+ */
101
+ captionTop: {
102
+ type: String,
103
+ default: undefined,
104
+ required: false,
105
+ },
106
+ /**
107
+ * Prop for table columns configuration. If prop is not defined, table will display columns based on the first item keys, omitting keys that begins with underscore (e.g. '_props')
108
+ *
109
+ * In columns prop each array item represents one column. Item might be specified in two ways:
110
+ * String: each item define column name equal to item value.
111
+ * Object: item is object with following keys available as column configuration:
112
+ * - key (required)(String) - define column name equal to item key.
113
+ * - label (String) - define visible label of column. If not defined, label will be generated automatically based on column name, by converting kebab-case and snake_case to individual words and capitalization of each word.
114
+ * - _props (Object) - adds classes to all cels in column, ex. _props: { scope: 'col', className: 'custom-class' },
115
+ * - _style (Object) - adds styles to the column header (useful for defining widths)
116
+ *
117
+ * @since 4.5.0
118
+ */
119
+ columns: {
120
+ type: Array as PropType<Column[] | string[]>,
121
+ required: false,
53
122
  },
54
123
  /**
55
124
  * Sets the color context of the component to one of CoreUI’s themed colors.
@@ -57,6 +126,21 @@ const CTable = defineComponent({
57
126
  * @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light', string
58
127
  */
59
128
  color: Color,
129
+ /**
130
+ * Array of objects or strings, where each element represents one cell in the table footer.
131
+ *
132
+ * Example items:
133
+ * ['FooterCell', 'FooterCell', 'FooterCell']
134
+ * or
135
+ * [{ label: 'FooterCell', _props: { color: 'success' }, ...]
136
+ *
137
+ * @since 4.5.0
138
+ */
139
+ footer: {
140
+ type: Array as PropType<FooterItem[]>,
141
+ default: () => [],
142
+ required: false,
143
+ },
60
144
  /**
61
145
  * Enable a hover state on table rows within a `<CTableBody>`.
62
146
  */
@@ -65,10 +149,18 @@ const CTable = defineComponent({
65
149
  required: false,
66
150
  },
67
151
  /**
68
- * Make any table responsive across all viewports or pick a maximum breakpoint with which to have a responsive table up to.
152
+ * Array of objects, where each object represents one item - row in table. Additionally, you can add style classes to each row by passing them by '_props' key and to single cell by '_cellProps'.
69
153
  *
70
- * @values boolean, 'sm', 'md', 'lg', 'xl', 'xxl'
154
+ * Example item:
155
+ * { name: 'John' , age: 12, _props: { color: 'success' }, _cellProps: { age: { className: 'fw-bold'}}}
156
+ *
157
+ * @since 4.5.0
71
158
  */
159
+ items: {
160
+ type: Array as PropType<Item[]>,
161
+ default: () => [],
162
+ required: false,
163
+ },
72
164
  responsive: {
73
165
  type: [Boolean, String],
74
166
  default: undefined,
@@ -106,8 +198,39 @@ const CTable = defineComponent({
106
198
  type: Boolean,
107
199
  required: false,
108
200
  },
201
+ /**
202
+ * Properties that will be passed to the table footer component.
203
+ *
204
+ * Properties to [CTableFoot](#ctablefoot) component.
205
+ * @since 4.5.0
206
+ */
207
+ tableFootProps: {
208
+ type: Object,
209
+ default: undefined,
210
+ required: false,
211
+ },
212
+ /**
213
+ * Properties that will be passed to the table head component.
214
+ *
215
+ * Properties to [CTableHead](#ctablehead) component.
216
+ * @since 4.5.0
217
+ */
218
+ tableHeadProps: {
219
+ type: Object,
220
+ default: undefined,
221
+ required: false,
222
+ },
109
223
  },
110
224
  setup(props, { slots, attrs }) {
225
+ const rawColumnNames = computed(() =>
226
+ props.columns
227
+ ? props.columns.map((column: Column | string) => {
228
+ if (typeof column === 'object') return column.key
229
+ else return column
230
+ })
231
+ : Object.keys(props.items[0] || {}).filter((el) => el.charAt(0) !== '_'),
232
+ )
233
+
111
234
  const table = () =>
112
235
  h(
113
236
  'table',
@@ -116,7 +239,7 @@ const CTable = defineComponent({
116
239
  'table',
117
240
  {
118
241
  [`align-${props.align}`]: props.align,
119
- [`caption-${props.caption}`]: props.caption,
242
+ [`caption-top`]: props.captionTop || props.caption === 'top',
120
243
  [`border-${props.borderColor}`]: props.borderColor,
121
244
  'table-bordered': props.bordered,
122
245
  'table-borderless': props.borderless,
@@ -129,7 +252,118 @@ const CTable = defineComponent({
129
252
  attrs.class,
130
253
  ],
131
254
  },
132
- slots.default && slots.default(),
255
+ {
256
+ default: () => [
257
+ ((props.caption && props.caption !== 'top') || props.captionTop) &&
258
+ h(
259
+ CTableCaption,
260
+ {},
261
+ {
262
+ default: () => props.caption || props.captionTop,
263
+ },
264
+ ),
265
+ props.columns &&
266
+ h(
267
+ CTableHead,
268
+ {
269
+ ...props.tableHeadProps,
270
+ },
271
+ {
272
+ default: () =>
273
+ h(
274
+ CTableRow,
275
+ {},
276
+ {
277
+ default: () => [
278
+ props.columns &&
279
+ props.columns.map((column: Column | string) =>
280
+ h(
281
+ CTableHeaderCell,
282
+ {
283
+ ...(typeof column === 'object' &&
284
+ column._props && { ...column._props }),
285
+ ...(typeof column === 'object' &&
286
+ column._style && { style: { ...column._style } }),
287
+ },
288
+ {
289
+ default: () => label(column),
290
+ },
291
+ ),
292
+ ),
293
+ ],
294
+ },
295
+ ),
296
+ },
297
+ ),
298
+ props.items &&
299
+ h(
300
+ CTableBody,
301
+ {},
302
+ {
303
+ default: () => [
304
+ props.items.map((item: Item) =>
305
+ h(
306
+ CTableRow,
307
+ {
308
+ ...(item._props && { ...item._props }),
309
+ },
310
+ {
311
+ default: () => [
312
+ rawColumnNames.value.map(
313
+ (colName: string) =>
314
+ item[colName] &&
315
+ h(
316
+ CTableDataCell,
317
+ {
318
+ ...(item._cellProps &&
319
+ item._cellProps['all'] && { ...item._cellProps['all'] }),
320
+ ...(item._cellProps &&
321
+ item._cellProps[colName] && { ...item._cellProps[colName] }),
322
+ },
323
+ {
324
+ default: () => item[colName],
325
+ },
326
+ ),
327
+ ),
328
+ ],
329
+ },
330
+ ),
331
+ ),
332
+ ],
333
+ },
334
+ ),
335
+ slots.default && slots.default(),
336
+ props.footer &&
337
+ h(
338
+ CTableFoot,
339
+ {
340
+ ...props.tableFootProps,
341
+ },
342
+ {
343
+ default: () =>
344
+ h(
345
+ CTableRow,
346
+ {},
347
+ {
348
+ default: () => [
349
+ props.footer.map((item: FooterItem | string) =>
350
+ h(
351
+ CTableDataCell,
352
+ {
353
+ ...(typeof item === 'object' && item._props && { ...item._props }),
354
+ },
355
+ {
356
+ default: () => (typeof item === 'object' ? item.label : item),
357
+ },
358
+ ),
359
+ ),
360
+ ],
361
+ },
362
+ ),
363
+ },
364
+ ),
365
+ ],
366
+ },
133
367
  )
134
368
  return () => [
135
369
  props.responsive
@@ -31,11 +31,18 @@ const CTableDataCell = defineComponent({
31
31
  * @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light', string
32
32
  */
33
33
  color: Color,
34
+ /**
35
+ * @ignore
36
+ */
37
+ scope: {
38
+ type: String,
39
+ required: false,
40
+ },
34
41
  },
35
42
  setup(props, { slots }) {
36
43
  return () =>
37
44
  h(
38
- 'td',
45
+ props.scope ? 'th' : 'td',
39
46
  {
40
47
  class: [
41
48
  {
@@ -44,6 +51,7 @@ const CTableDataCell = defineComponent({
44
51
  [`table-${props.color}`]: props.color,
45
52
  },
46
53
  ],
54
+ ...(props.scope && { scope: props.scope }),
47
55
  },
48
56
  slots.default && slots.default(),
49
57
  )
@@ -1,6 +1,7 @@
1
1
  import { defineComponent, h, ref, watch } from 'vue'
2
2
 
3
3
  import { CFormInput, CFormSelect, CInputGroup, CInputGroupText } from '../form/'
4
+ import { CFormControlWrapper } from './../form/CFormControlWrapper'
4
5
  import { CPicker } from '../picker'
5
6
  import { CTimePickerRollCol } from './CTimePickerRollCol'
6
7
 
@@ -110,6 +111,34 @@ const CTimePicker = defineComponent({
110
111
  return ['ghost', 'outline'].includes(value)
111
112
  },
112
113
  },
114
+ /**
115
+ * Provide valuable, actionable feedback.
116
+ *
117
+ * @since 4.6.0
118
+ */
119
+ feedback: {
120
+ type: String,
121
+ },
122
+ /**
123
+ * Provide valuable, actionable feedback.
124
+ *
125
+ * @since 4.6.0
126
+ */
127
+ feedbackInvalid: {
128
+ type: String,
129
+ },
130
+ /**
131
+ * Provide valuable, actionable invalid feedback when using standard HTML form validation which applied two CSS pseudo-classes, `:invalid` and `:valid`.
132
+ *
133
+ * @since 4.6.0
134
+ */
135
+ feedbackValid: {
136
+ type: String,
137
+ },
138
+ /**
139
+ * The id global attribute defines an identifier (ID) that must be unique in the whole document.
140
+ */
141
+ id: String,
113
142
  /**
114
143
  * Toggle visibility or set the content of the input indicator.
115
144
  */
@@ -121,6 +150,20 @@ const CTimePicker = defineComponent({
121
150
  * Toggle the readonly state for the component.
122
151
  */
123
152
  inputReadOnly: Boolean,
153
+ /**
154
+ * Set component validation state to invalid.
155
+ *
156
+ * @since 4.6.0
157
+ */
158
+ invalid: Boolean,
159
+ /**
160
+ * Add a caption for a component.
161
+ *
162
+ * @since 4.6.0
163
+ */
164
+ label: {
165
+ type: String,
166
+ },
124
167
  /**
125
168
  * Sets the default locale for components. If not set, it is inherited from the navigator.language.
126
169
  */
@@ -147,12 +190,32 @@ const CTimePicker = defineComponent({
147
190
  return ['sm', 'lg'].includes(value)
148
191
  },
149
192
  },
193
+ /**
194
+ * Add helper text to the component.
195
+ *
196
+ * @since 4.6.0
197
+ */
198
+ text: {
199
+ type: String,
200
+ },
150
201
  /**
151
202
  * Initial selected time.
152
203
  */
153
204
  time: {
154
205
  type: [Date, String],
155
206
  },
207
+ /**
208
+ * Display validation feedback in a styled tooltip.
209
+ *
210
+ * @since 4.6.0
211
+ */
212
+ tooltipFeedback: Boolean,
213
+ /**
214
+ * Set component validation state to valid.
215
+ *
216
+ * @since 4.6.0
217
+ */
218
+ valid: Boolean,
156
219
  /**
157
220
  * Set the time picker variant to a roll or select.
158
221
  *
@@ -180,7 +243,7 @@ const CTimePicker = defineComponent({
180
243
  */
181
244
  'show',
182
245
  ],
183
- setup(props, { emit, slots }) {
246
+ setup(props, { emit, attrs, slots }) {
184
247
  const date = ref<Date | null>(convertTimeToDate(props.time))
185
248
  const initialDate = ref<Date | null>(null)
186
249
  const ampm = ref<'am' | 'pm'>(date.value ? getAmPm(new Date(date.value), props.locale) : 'am')
@@ -348,56 +411,74 @@ const CTimePicker = defineComponent({
348
411
 
349
412
  return () =>
350
413
  h(
351
- CPicker,
414
+ CFormControlWrapper,
352
415
  {
353
- cancelButton: props.cancelButton,
354
- cancelButtonColor: props.cancelButtonColor,
355
- cancelButtonSize: props.cancelButtonSize,
356
- cancelButtonVariant: props.cancelButtonVariant,
357
- class: 'time-picker',
358
- confirmButton: props.confirmButton,
359
- confirmButtonColor: props.confirmButtonColor,
360
- confirmButtonSize: props.confirmButtonSize,
361
- confirmButtonVariant: props.confirmButtonVariant,
362
- container: props.container,
363
- disabled: props.disabled,
364
- footer: true,
365
- onCancel: () => {
366
- if (initialDate.value) {
367
- date.value = new Date(initialDate.value)
368
- }
369
- },
370
- onHide: () => {
371
- emit('hide')
372
- },
373
- onShow: () => {
374
- if (date.value) {
375
- initialDate.value = new Date(date.value)
376
- }
377
-
378
- emit('show')
379
- },
416
+ describedby: attrs['aria-describedby'],
417
+ feedback: props.feedback,
418
+ feedbackInvalid: props.feedbackInvalid,
419
+ feedbackValid: props.feedbackValid,
420
+ id: props.id,
421
+ invalid: props.invalid,
422
+ label: props.label,
423
+ text: props.text,
424
+ tooltipFeedback: props.tooltipFeedback,
425
+ valid: props.valid,
380
426
  },
381
427
  {
382
- ...(slots.cancelButton && {
383
- cancelButton: () => slots.cancelButton && slots.cancelButton(),
384
- }),
385
- ...(slots.confirmButton && {
386
- confirmButton: () => slots.confirmButton && slots.confirmButton(),
387
- }),
388
- toggler: () => InputGroup(),
389
428
  default: () =>
390
429
  h(
391
- 'div',
430
+ CPicker,
431
+ {
432
+ cancelButton: props.cancelButton,
433
+ cancelButtonColor: props.cancelButtonColor,
434
+ cancelButtonSize: props.cancelButtonSize,
435
+ cancelButtonVariant: props.cancelButtonVariant,
436
+ class: ['time-picker', { 'is-invalid': props.invalid, 'is-valid': props.valid }],
437
+ confirmButton: props.confirmButton,
438
+ confirmButtonColor: props.confirmButtonColor,
439
+ confirmButtonSize: props.confirmButtonSize,
440
+ confirmButtonVariant: props.confirmButtonVariant,
441
+ container: props.container,
442
+ disabled: props.disabled,
443
+ footer: true,
444
+ onCancel: () => {
445
+ if (initialDate.value) {
446
+ date.value = new Date(initialDate.value)
447
+ }
448
+ },
449
+ onHide: () => {
450
+ emit('hide')
451
+ },
452
+ onShow: () => {
453
+ if (date.value) {
454
+ initialDate.value = new Date(date.value)
455
+ }
456
+
457
+ emit('show')
458
+ },
459
+ },
392
460
  {
393
- class: [
394
- 'time-picker-body',
395
- {
396
- ['time-picker-roll']: props.variant === 'roll',
397
- },
398
- ],
461
+ ...(slots.cancelButton && {
462
+ cancelButton: () => slots.cancelButton && slots.cancelButton(),
463
+ }),
464
+ ...(slots.confirmButton && {
465
+ confirmButton: () => slots.confirmButton && slots.confirmButton(),
466
+ }),
467
+ toggler: () => InputGroup(),
468
+ default: () =>
469
+ h(
470
+ 'div',
471
+ {
472
+ class: [
473
+ 'time-picker-body',
474
+ {
475
+ ['time-picker-roll']: props.variant === 'roll',
476
+ },
477
+ ],
478
+ },
479
+ props.variant === 'select' ? TimePickerSelect() : TimePickerRoll(),
480
+ ),
399
481
  },
400
- props.variant === 'select' ? TimePickerSelect() : TimePickerRoll(),
401
482
  ),
402
483
  },
403
484
  )