@coreui/vue-pro 4.6.0 → 4.7.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.
Files changed (58) hide show
  1. package/dist/components/Types.d.ts +5 -5
  2. package/dist/components/date-picker/CDatePicker.d.ts +2 -1
  3. package/dist/components/date-range-picker/CDateRangePicker.d.ts +31 -1
  4. package/dist/components/form/CFormInput.d.ts +166 -1
  5. package/dist/components/form/CFormSelect.d.ts +1 -1
  6. package/dist/components/grid/CCol.d.ts +3 -3
  7. package/dist/components/grid/CRow.d.ts +1 -1
  8. package/dist/components/index.d.ts +1 -0
  9. package/dist/components/multi-select/CMultiSelect.d.ts +12 -4
  10. package/dist/components/multi-select/CMultiSelectOptions.d.ts +11 -0
  11. package/dist/components/multi-select/CMultiSelectSelection.d.ts +3 -3
  12. package/dist/components/pagination/index.d.ts +1 -2
  13. package/dist/components/picker/CPicker.d.ts +1 -1
  14. package/dist/components/popover/CPopover.d.ts +1 -1
  15. package/dist/components/smart-pagination/CSmartPagination.d.ts +257 -0
  16. package/dist/components/smart-pagination/index.d.ts +6 -0
  17. package/dist/components/smart-table/CSmartTable.d.ts +6 -4
  18. package/dist/components/smart-table/CSmartTableFilter.d.ts +2 -2
  19. package/dist/components/smart-table/CSmartTableHead.d.ts +2 -2
  20. package/dist/components/smart-table/CSmartTableInterface.d.ts +4 -1
  21. package/dist/components/table/CTable.d.ts +1 -1
  22. package/dist/components/table/CTableCaption.d.ts +2 -8
  23. package/dist/components/time-picker/CTimePicker.d.ts +2 -1
  24. package/dist/components/tooltip/CTooltip.d.ts +1 -1
  25. package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
  26. package/dist/index.es.js +877 -682
  27. package/dist/index.es.js.map +1 -1
  28. package/dist/index.js +876 -680
  29. package/dist/index.js.map +1 -1
  30. package/dist/utils/getNextSibling.d.ts +2 -0
  31. package/dist/utils/getPreviousSibling.d.ts +2 -0
  32. package/dist/utils/index.d.ts +4 -0
  33. package/dist/utils/isVisible.d.ts +2 -0
  34. package/dist/utils/time.d.ts +2 -2
  35. package/package.json +1 -1
  36. package/src/components/carousel/CCarousel.ts +1 -9
  37. package/src/components/date-picker/CDatePicker.ts +11 -2
  38. package/src/components/date-range-picker/CDateRangePicker.ts +54 -0
  39. package/src/components/form/CFormInput.ts +2 -0
  40. package/src/components/index.ts +1 -0
  41. package/src/components/loading-button/CLoadingButton.ts +1 -2
  42. package/src/components/multi-select/CMultiSelect.ts +125 -103
  43. package/src/components/multi-select/CMultiSelectOptions.ts +48 -10
  44. package/src/components/multi-select/CMultiSelectSelection.ts +1 -1
  45. package/src/components/pagination/index.ts +1 -3
  46. package/src/components/sidebar/CSidebar.ts +2 -10
  47. package/src/components/{pagination → smart-pagination}/CSmartPagination.ts +1 -2
  48. package/src/components/smart-pagination/index.ts +10 -0
  49. package/src/components/smart-table/CSmartTable.ts +10 -5
  50. package/src/components/smart-table/CSmartTableInterface.ts +4 -0
  51. package/src/components/table/CTableCaption.ts +0 -1
  52. package/src/components/time-picker/CTimePicker.ts +73 -20
  53. package/src/components/time-picker/CTimePickerRollCol.ts +9 -0
  54. package/src/utils/getNextSibling.ts +18 -0
  55. package/src/utils/getPreviousSibling.ts +18 -0
  56. package/src/utils/index.ts +5 -0
  57. package/src/utils/isVisible.ts +11 -0
  58. package/src/utils/time.ts +14 -6
@@ -1,19 +1,11 @@
1
1
  import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from 'vue'
2
2
  import { CBackdrop } from '../backdrop'
3
3
 
4
+ import { isVisible } from './../../utils'
5
+
4
6
  const isOnMobile = (element: HTMLDivElement) =>
5
7
  Boolean(getComputedStyle(element).getPropertyValue('--cui-is-mobile'))
6
8
 
7
- const isVisible = (element: HTMLDivElement) => {
8
- const rect = element.getBoundingClientRect()
9
- return (
10
- rect.top >= 0 &&
11
- rect.left >= 0 &&
12
- rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
13
- rect.right <= (window.innerWidth || document.documentElement.clientWidth)
14
- )
15
- }
16
-
17
9
  const CSidebar = defineComponent({
18
10
  name: 'CSidebar',
19
11
  props: {
@@ -1,7 +1,6 @@
1
1
  import { computed, defineComponent, h, ref, watch } from 'vue'
2
2
 
3
- import { CPagination } from './CPagination'
4
- import { CPaginationItem } from './CPaginationItem'
3
+ import { CPagination, CPaginationItem } from './../pagination'
5
4
 
6
5
  const CSmartPagination = defineComponent({
7
6
  name: 'CSmartPagination',
@@ -0,0 +1,10 @@
1
+ import { App } from 'vue'
2
+ import { CSmartPagination } from './CSmartPagination'
3
+
4
+ const CSmartPaginationPlugin = {
5
+ install: (app: App): void => {
6
+ app.component(CSmartPagination.name, CSmartPagination)
7
+ },
8
+ }
9
+
10
+ export { CSmartPaginationPlugin, CSmartPagination }
@@ -1,7 +1,7 @@
1
1
  import { computed, defineComponent, h, reactive, ref, PropType, watch, onMounted } from 'vue'
2
2
 
3
- import { CSmartPagination } from '../pagination/CSmartPagination'
4
3
  import { CElementCover } from '../element-cover/CElementCover'
4
+ import { CSmartPagination } from '../smart-pagination/CSmartPagination'
5
5
 
6
6
  import { CTable } from '../table/CTable'
7
7
 
@@ -21,6 +21,7 @@ import {
21
21
  ColumnFilterValue,
22
22
  Item,
23
23
  ItemsPerPageSelect,
24
+ Pagination,
24
25
  Sorter,
25
26
  SorterValue,
26
27
  TableFilter,
@@ -133,6 +134,7 @@ const CSmartTable = defineComponent({
133
134
  */
134
135
  itemsPerPage: {
135
136
  type: Number,
137
+ default: 10,
136
138
  required: false,
137
139
  },
138
140
  /**
@@ -181,7 +183,7 @@ const CSmartTable = defineComponent({
181
183
  * Enables default pagination. Set to true for default setup or pass an object with additional CPagination props. Default pagination will always have the computed number of pages that cannot be changed. The number of pages is generated based on the number of passed items and 'itemsPerPage' prop. If this restriction is an obstacle, you can make external CPagination instead.
182
184
  */
183
185
  pagination: {
184
- type: Boolean,
186
+ type: [Boolean, Object] as PropType<boolean | Pagination>,
185
187
  required: false,
186
188
  },
187
189
  /**
@@ -789,12 +791,15 @@ const CSmartTable = defineComponent({
789
791
  {
790
792
  class: 'col',
791
793
  },
792
- props.pagination && numberOfPages.value > 1
794
+ (props.pagination && numberOfPages.value > 1) || props.paginationProps
793
795
  ? h(CSmartPagination, {
794
- ...props.paginationProps,
795
796
  pages: numberOfPages.value,
796
797
  activePage: activePage.value,
797
- onActivePageChange: handleActivePageChange,
798
+ ...props.paginationProps,
799
+ onActivePageChange: (page) =>
800
+ typeof props.pagination === 'object' && props.pagination.external
801
+ ? emit('activePageChange', page)
802
+ : handleActivePageChange(page),
798
803
  })
799
804
  : '',
800
805
  ),
@@ -38,6 +38,10 @@ export interface ItemsPerPageSelect {
38
38
  values?: Array<number>
39
39
  }
40
40
 
41
+ export interface Pagination {
42
+ external?: boolean
43
+ }
44
+
41
45
  export interface Sorter {
42
46
  resetable?: boolean
43
47
  external?: boolean
@@ -2,7 +2,6 @@ import { defineComponent, h } from 'vue'
2
2
 
3
3
  const CTableCaption = defineComponent({
4
4
  name: 'CTableCaption',
5
- props: {},
6
5
  setup(_, { slots }) {
7
6
  return () => h('caption', {}, slots.default && slots.default())
8
7
  },
@@ -25,6 +25,24 @@ const CTimePicker = defineComponent({
25
25
  name: 'CTimePicker',
26
26
  props: {
27
27
  ...CPicker.props,
28
+ /**
29
+ * Set if the component should use the 12/24 hour format. If `true` forces the interface to a 12-hour format. If `false` forces the interface into a 24-hour format. If `auto` the current locale will determine the 12 or 24-hour interface by default locales.
30
+ *
31
+ * @since 4.7.0
32
+ */
33
+ ampm: {
34
+ type: [Boolean, String],
35
+ default: 'auto',
36
+ validator: (value: boolean | string) => {
37
+ if (typeof value == 'string') {
38
+ return ['auto'].includes(value)
39
+ }
40
+ if (typeof value == 'boolean') {
41
+ return true
42
+ }
43
+ return false
44
+ },
45
+ },
28
46
  /**
29
47
  * Toggle visibility or set the content of cancel button.
30
48
  */
@@ -178,6 +196,15 @@ const CTimePicker = defineComponent({
178
196
  type: String,
179
197
  default: 'Select time',
180
198
  },
199
+ /**
200
+ * Show seconds.
201
+ *
202
+ * @since 4.7.0
203
+ */
204
+ seconds: {
205
+ type: Boolean,
206
+ default: true,
207
+ },
181
208
  /**
182
209
  * Size the component small or large.
183
210
  *
@@ -228,6 +255,10 @@ const CTimePicker = defineComponent({
228
255
  return ['roll', 'select'].includes(value)
229
256
  },
230
257
  },
258
+ /**
259
+ * Toggle the visibility of the component.
260
+ */
261
+ visible: Boolean,
231
262
  },
232
263
  emits: [
233
264
  /**
@@ -242,8 +273,15 @@ const CTimePicker = defineComponent({
242
273
  * Callback fired when the component requests to be shown.
243
274
  */
244
275
  'show',
276
+ /**
277
+ * Callback fired when the time changed.
278
+ *
279
+ * @since 4.7.0
280
+ */
281
+ 'update:time',
245
282
  ],
246
283
  setup(props, { emit, attrs, slots }) {
284
+ const visible = ref(props.visible)
247
285
  const date = ref<Date | null>(convertTimeToDate(props.time))
248
286
  const initialDate = ref<Date | null>(null)
249
287
  const ampm = ref<'am' | 'pm'>(date.value ? getAmPm(new Date(date.value), props.locale) : 'am')
@@ -264,6 +302,8 @@ const CTimePicker = defineComponent({
264
302
  const handleClear = (event: Event) => {
265
303
  event.stopPropagation()
266
304
  date.value = null
305
+ emit('change', null)
306
+ emit('update:time', null)
267
307
  }
268
308
 
269
309
  const handleTimeChange = (set: 'hours' | 'minutes' | 'seconds' | 'toggle', value: string) => {
@@ -279,7 +319,7 @@ const CTimePicker = defineComponent({
279
319
  }
280
320
 
281
321
  if (set === 'hours') {
282
- if (isAmPm(props.locale)) {
322
+ if ((props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm) {
283
323
  _date.setHours(convert12hTo24h(ampm.value, parseInt(value)))
284
324
  } else {
285
325
  _date.setHours(parseInt(value))
@@ -295,7 +335,8 @@ const CTimePicker = defineComponent({
295
335
  }
296
336
 
297
337
  date.value = new Date(_date)
298
- emit('change', _date.toTimeString(), _date.toLocaleTimeString(), _date)
338
+ emit('change', _date.toTimeString(), _date.toLocaleTimeString(props.locale), _date)
339
+ emit('update:time', _date.toLocaleTimeString(props.locale))
299
340
  }
300
341
 
301
342
  const InputGroup = () =>
@@ -310,7 +351,13 @@ const CTimePicker = defineComponent({
310
351
  },
311
352
  placeholder: props.placeholder,
312
353
  readonly: props.inputReadOnly,
313
- value: date.value ? date.value.toLocaleTimeString(props.locale) : '',
354
+ value: date.value
355
+ ? date.value.toLocaleTimeString(props.locale, {
356
+ hour12:
357
+ (props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm ? true : false,
358
+ ...(!props.seconds && { timeStyle: 'short' }),
359
+ })
360
+ : '',
314
361
  }),
315
362
  (props.indicator || props.cleaner) &&
316
363
  h(CInputGroupText, {}, () => [
@@ -361,15 +408,16 @@ const CTimePicker = defineComponent({
361
408
  handleTimeChange('minutes', (event.target as HTMLSelectElement).value),
362
409
  ...(date.value && { value: getSelectedMinutes(date.value) }),
363
410
  }),
364
- ':',
365
- // @ts-expect-error the getListOfMinutes function returns corect type
366
- h(CFormSelect, {
367
- disabled: props.disabled,
368
- options: getListOfSeconds(props.locale, true),
369
- onChange: (event: Event) =>
370
- handleTimeChange('seconds', (event.target as HTMLSelectElement).value),
371
- ...(date.value && { value: getSelectedSeconds(date.value) }),
372
- }),
411
+ props.seconds && ':',
412
+ props.seconds &&
413
+ // @ts-expect-error the getListOfMinutes function returns corect type
414
+ h(CFormSelect, {
415
+ disabled: props.disabled,
416
+ options: getListOfSeconds(props.locale, true),
417
+ onChange: (event: Event) =>
418
+ handleTimeChange('seconds', (event.target as HTMLSelectElement).value),
419
+ ...(date.value && { value: getSelectedSeconds(date.value) }),
420
+ }),
373
421
  isAmPm(props.locale) &&
374
422
  h(CFormSelect, {
375
423
  disabled: props.disabled,
@@ -384,21 +432,22 @@ const CTimePicker = defineComponent({
384
432
 
385
433
  const TimePickerRoll = () => [
386
434
  h(CTimePickerRollCol, {
387
- elements: getListOfHours(props.locale),
435
+ elements: getListOfHours(props.locale, props.ampm),
388
436
  onClick: (index: number) => handleTimeChange('hours', index.toString()),
389
- selected: getSelectedHour(date.value, props.locale),
437
+ selected: getSelectedHour(date.value, props.locale, props.ampm),
390
438
  }),
391
439
  h(CTimePickerRollCol, {
392
440
  elements: getListOfMinutes(props.locale),
393
441
  onClick: (index: number) => handleTimeChange('minutes', index.toString()),
394
442
  selected: getSelectedMinutes(date.value),
395
443
  }),
396
- h(CTimePickerRollCol, {
397
- elements: getListOfSeconds(props.locale),
398
- onClick: (index: number) => handleTimeChange('seconds', index.toString()),
399
- selected: getSelectedSeconds(date.value),
400
- }),
401
- isAmPm(props.locale) &&
444
+ props.seconds &&
445
+ h(CTimePickerRollCol, {
446
+ elements: getListOfSeconds(props.locale),
447
+ onClick: (index: number) => handleTimeChange('seconds', index.toString()),
448
+ selected: getSelectedSeconds(date.value),
449
+ }),
450
+ ((props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm) &&
402
451
  h(CTimePickerRollCol, {
403
452
  elements: [
404
453
  { value: 'am', label: 'AM' },
@@ -445,8 +494,10 @@ const CTimePicker = defineComponent({
445
494
  if (initialDate.value) {
446
495
  date.value = new Date(initialDate.value)
447
496
  }
497
+ visible.value = false
448
498
  },
449
499
  onHide: () => {
500
+ visible.value = false
450
501
  emit('hide')
451
502
  },
452
503
  onShow: () => {
@@ -454,8 +505,10 @@ const CTimePicker = defineComponent({
454
505
  initialDate.value = new Date(date.value)
455
506
  }
456
507
 
508
+ visible.value = true
457
509
  emit('show')
458
510
  },
511
+ visible: visible.value,
459
512
  },
460
513
  {
461
514
  ...(slots.cancelButton && {
@@ -32,6 +32,13 @@ const CTimePickerRollCol = defineComponent({
32
32
  init.value = false
33
33
  })
34
34
 
35
+ const handleKeyDown = (event: KeyboardEvent, value: number | string) => {
36
+ if (event.code === 'Space' || event.key === 'Enter') {
37
+ event.preventDefault()
38
+ emit('click', value)
39
+ }
40
+ }
41
+
35
42
  return () =>
36
43
  h(
37
44
  'div',
@@ -47,7 +54,9 @@ const CTimePickerRollCol = defineComponent({
47
54
  },
48
55
  ],
49
56
  onClick: () => emit('click', element.value),
57
+ onKeydown: (event: KeyboardEvent) => handleKeyDown(event, element.value),
50
58
  role: 'button',
59
+ tabindex: 0,
51
60
  },
52
61
  element.label,
53
62
  )
@@ -0,0 +1,18 @@
1
+ const getNextSibling = (elem: HTMLElement, selector?: string) => {
2
+ // Get the next sibling element
3
+ let sibling = elem.nextElementSibling
4
+
5
+ // If there's no selector, return the first sibling
6
+ if (!selector) return sibling
7
+
8
+ // If the sibling matches our selector, use it
9
+ // If not, jump to the next sibling and continue the loop
10
+ while (sibling) {
11
+ if (sibling.matches(selector)) return sibling
12
+ sibling = sibling.nextElementSibling
13
+ }
14
+
15
+ return
16
+ }
17
+
18
+ export default getNextSibling
@@ -0,0 +1,18 @@
1
+ const getPreviousSibling = (elem: HTMLElement, selector?: string) => {
2
+ // Get the next sibling element
3
+ let sibling = elem.previousElementSibling
4
+
5
+ // If there's no selector, return the first sibling
6
+ if (!selector) return sibling
7
+
8
+ // If the sibling matches our selector, use it
9
+ // If not, jump to the next sibling and continue the loop
10
+ while (sibling) {
11
+ if (sibling.matches(selector)) return sibling
12
+ sibling = sibling.previousElementSibling
13
+ }
14
+
15
+ return
16
+ }
17
+
18
+ export default getPreviousSibling
@@ -0,0 +1,5 @@
1
+ import getNextSibling from './getNextSibling'
2
+ import getPreviousSibling from './getPreviousSibling'
3
+ import isVisible from './isVisible'
4
+
5
+ export { getNextSibling, getPreviousSibling, isVisible }
@@ -0,0 +1,11 @@
1
+ const isVisible = (element: HTMLElement) => {
2
+ const rect = element.getBoundingClientRect()
3
+ return (
4
+ rect.top >= 0 &&
5
+ rect.left >= 0 &&
6
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
7
+ rect.right <= (window.innerWidth || document.documentElement.clientWidth)
8
+ )
9
+ }
10
+
11
+ export default isVisible
package/src/utils/time.ts CHANGED
@@ -26,11 +26,11 @@ export const getAmPm = (date: Date, locale: string) => {
26
26
  return date.getHours() >= 12 ? 'pm' : 'am'
27
27
  }
28
28
 
29
- export const getListOfHours = (locale: string) =>
30
- Array.from({ length: isAmPm(locale) ? 12 : 24 }, (_, i) => {
29
+ export const getListOfHours = (locale: string, ampm: 'auto' | boolean = 'auto') =>
30
+ Array.from({ length: (ampm === 'auto' && isAmPm(locale)) || ampm ? 12 : 24 }, (_, i) => {
31
31
  return {
32
- value: isAmPm(locale) ? i + 1 : i,
33
- label: (isAmPm(locale) ? i + 1 : i).toLocaleString(locale),
32
+ value: (ampm === 'auto' && isAmPm(locale)) || ampm ? i + 1 : i,
33
+ label: ((ampm === 'auto' && isAmPm(locale)) || ampm ? i + 1 : i).toLocaleString(locale),
34
34
  }
35
35
  })
36
36
 
@@ -68,8 +68,16 @@ export const getListOfSeconds = (locale: string, valueAsString = false) =>
68
68
  }
69
69
  })
70
70
 
71
- export const getSelectedHour = (date: Date | null, locale: string) =>
72
- date ? (isAmPm(locale) ? convert24hTo12h(date.getHours()) : date.getHours()) : ''
71
+ export const getSelectedHour = (
72
+ date: Date | null,
73
+ locale: string,
74
+ ampm: 'auto' | boolean = 'auto',
75
+ ) =>
76
+ date
77
+ ? (ampm === 'auto' && isAmPm(locale)) || ampm
78
+ ? convert24hTo12h(date.getHours())
79
+ : date.getHours()
80
+ : ''
73
81
 
74
82
  export const getSelectedMinutes = (date: Date | null) => (date ? date.getMinutes() : '')
75
83