@coreui/vue-pro 4.10.4 → 5.0.0-alpha.1

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 (79) hide show
  1. package/README.md +1 -1
  2. package/dist/components/calendar/CCalendar.d.ts +58 -32
  3. package/dist/components/calendar/utils.d.ts +11 -4
  4. package/dist/components/close-button/CCloseButton.d.ts +9 -0
  5. package/dist/components/date-picker/CDatePicker.d.ts +89 -0
  6. package/dist/components/date-range-picker/CDateRangePicker.d.ts +89 -0
  7. package/dist/components/dropdown/CDropdown.d.ts +13 -28
  8. package/dist/components/dropdown/CDropdownToggle.d.ts +19 -9
  9. package/dist/components/dropdown/types.d.ts +15 -0
  10. package/dist/components/dropdown/utils.d.ts +6 -0
  11. package/dist/components/form/CFormInput.d.ts +6 -18
  12. package/dist/components/modal/CModal.d.ts +19 -0
  13. package/dist/components/multi-select/CMultiSelect.d.ts +1 -1
  14. package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
  15. package/dist/components/multi-select/types.d.ts +2 -2
  16. package/dist/components/multi-select/utils.d.ts +2 -2
  17. package/dist/components/offcanvas/COffcanvas.d.ts +9 -0
  18. package/dist/components/progress/CProgress.d.ts +102 -3
  19. package/dist/components/progress/CProgressStacked.d.ts +10 -0
  20. package/dist/components/progress/index.d.ts +2 -1
  21. package/dist/components/smart-table/CSmartTable.d.ts +0 -4
  22. package/dist/components/smart-table/CSmartTableBody.d.ts +12 -1
  23. package/dist/components/smart-table/types.d.ts +2 -2
  24. package/dist/components/smart-table/utils.d.ts +4 -2
  25. package/dist/composables/index.d.ts +3 -1
  26. package/dist/composables/useDebouncedCallback.d.ts +1 -0
  27. package/dist/index.es.js +1142 -2823
  28. package/dist/index.es.js.map +1 -1
  29. package/dist/index.js +1143 -2821
  30. package/dist/index.js.map +1 -1
  31. package/package.json +14 -14
  32. package/src/components/breadcrumb/CBreadcrumb.ts +1 -0
  33. package/src/components/button/CButton.ts +5 -5
  34. package/src/components/calendar/CCalendar.ts +444 -179
  35. package/src/components/calendar/utils.ts +93 -55
  36. package/src/components/carousel/CCarousel.ts +2 -5
  37. package/src/components/close-button/CCloseButton.ts +5 -0
  38. package/src/components/date-picker/CDatePicker.ts +43 -0
  39. package/src/components/date-range-picker/CDateRangePicker.ts +140 -126
  40. package/src/components/date-range-picker/utils.ts +2 -2
  41. package/src/components/dropdown/CDropdown.ts +23 -43
  42. package/src/components/dropdown/CDropdownMenu.ts +4 -19
  43. package/src/components/dropdown/CDropdownToggle.ts +44 -38
  44. package/src/components/dropdown/types.ts +11 -0
  45. package/src/components/dropdown/utils.ts +71 -0
  46. package/src/components/form/CFormCheck.ts +1 -1
  47. package/src/components/modal/CModal.ts +15 -1
  48. package/src/components/multi-select/CMultiSelect.ts +68 -62
  49. package/src/components/multi-select/CMultiSelectOptions.ts +1 -1
  50. package/src/components/multi-select/CMultiSelectSelection.ts +14 -13
  51. package/src/components/multi-select/types.ts +2 -2
  52. package/src/components/multi-select/utils.ts +5 -5
  53. package/src/components/navbar/CNavbar.ts +1 -1
  54. package/src/components/offcanvas/COffcanvas.ts +6 -0
  55. package/src/components/picker/CPicker.ts +7 -22
  56. package/src/components/progress/CProgress.ts +67 -9
  57. package/src/components/progress/CProgressBar.ts +4 -6
  58. package/src/components/progress/CProgressStacked.ts +19 -0
  59. package/src/components/progress/index.ts +3 -1
  60. package/src/components/sidebar/CSidebar.ts +1 -1
  61. package/src/components/smart-table/CSmartTable.ts +17 -12
  62. package/src/components/smart-table/CSmartTableBody.ts +30 -31
  63. package/src/components/smart-table/CSmartTableHead.ts +34 -11
  64. package/src/components/smart-table/types.ts +2 -2
  65. package/src/components/smart-table/utils.ts +41 -5
  66. package/src/components/time-picker/CTimePicker.ts +34 -63
  67. package/src/components/tooltip/CTooltip.ts +1 -1
  68. package/src/components/widgets/CWidgetStatsA.ts +1 -3
  69. package/src/components/widgets/CWidgetStatsB.ts +2 -4
  70. package/src/components/widgets/CWidgetStatsC.ts +2 -2
  71. package/src/components/widgets/CWidgetStatsD.ts +1 -1
  72. package/src/components/widgets/CWidgetStatsE.ts +1 -1
  73. package/src/components/widgets/CWidgetStatsF.ts +1 -1
  74. package/src/components/widgets/__tests__/__snapshots__/CWidgetStatsE.spec.ts.snap +1 -1
  75. package/src/composables/index.ts +3 -1
  76. package/src/composables/useColorModes.ts +63 -0
  77. package/src/composables/useDebouncedCallback.ts +16 -0
  78. package/src/utils/getRTLPlacement.ts +1 -1
  79. package/src/utils/isObjectInArray.ts +1 -1
@@ -1,3 +1,32 @@
1
+ export const convertIsoWeekToDate = (isoWeek: string) => {
2
+ const [year, week] = isoWeek.split(/w/i)
3
+ // Get date for 4th of January for year
4
+ const date = new Date(Number(year), 0, 4)
5
+ // Get previous Monday, add 7 days for each week after first
6
+ date.setDate(date.getDate() - (date.getDay() || 7) + 1 + (Number(week) - 1) * 7)
7
+ return date
8
+ }
9
+
10
+ export const convertToDateObject = (
11
+ date: Date | string | null,
12
+ selectionType?: 'day' | 'week' | 'month' | 'year',
13
+ ) => {
14
+ // TODO: clean-up ?
15
+ // if (date === null) {
16
+ // return null
17
+ // }
18
+
19
+ if (date instanceof Date) {
20
+ return date
21
+ }
22
+
23
+ if (selectionType === 'week') {
24
+ return convertIsoWeekToDate(date as string)
25
+ }
26
+
27
+ return new Date(Date.parse(date))
28
+ }
29
+
1
30
  export const convertToLocalDate = (d: Date, locale: string, options = {}) =>
2
31
  d.toLocaleDateString(locale, options)
3
32
 
@@ -6,59 +35,53 @@ export const convertToLocalTime = (d: Date, locale: string, options = {}) =>
6
35
 
7
36
  export const createGroupsInArray = <T>(arr: T[], numberOfGroups: number): T[][] => {
8
37
  const perGroup = Math.ceil(arr.length / numberOfGroups)
9
- return new Array(numberOfGroups)
38
+ return Array.from({ length: numberOfGroups })
10
39
  .fill('')
11
40
  .map((_, i) => arr.slice(i * perGroup, (i + 1) * perGroup))
12
41
  }
13
42
 
43
+ export const getCalendarDate = (calendarDate: Date, order: number, view: 'days' | 'months' | 'years') => {
44
+ if (order !== 0 && view === 'days') {
45
+ return new Date(Date.UTC(calendarDate.getFullYear(), calendarDate.getMonth() + order, 1))
46
+ }
47
+
48
+ if (order !== 0 && view === 'months') {
49
+ return new Date(Date.UTC(calendarDate.getFullYear() + order, calendarDate.getMonth(), 1))
50
+ }
51
+
52
+ if (order !== 0 && view === 'years') {
53
+ return new Date(Date.UTC(calendarDate.getFullYear() + (12 * order), calendarDate.getMonth(), 1))
54
+ }
55
+
56
+ return calendarDate
57
+ }
58
+
14
59
  export const getCurrentYear = () => new Date().getFullYear()
15
60
 
16
61
  export const getCurrentMonth = () => new Date().getMonth()
17
62
 
18
- export const getLocalDateFromString = (string: string, locale: string, time?: boolean) => {
19
- const date = new Date(2013, 11, 31, 17, 19, 22)
20
- let regex = time ? date.toLocaleString(locale) : date.toLocaleDateString(locale)
21
- regex = regex
22
- .replace('2013', '(?<year>[0-9]{2,4})')
23
- .replace('12', '(?<month>[0-9]{1,2})')
24
- .replace('31', '(?<day>[0-9]{1,2})')
25
-
26
- if (time) {
27
- regex = regex
28
- .replace('5', '(?<hour>[0-9]{1,2})')
29
- .replace('17', '(?<hour>[0-9]{1,2})')
30
- .replace('19', '(?<minute>[0-9]{1,2})')
31
- .replace('22', '(?<second>[0-9]{1,2})')
32
- .replace('PM', '(?<ampm>[A-Z]{2})')
63
+ export const getDateBySelectionType = (
64
+ date: Date | null,
65
+ selectionType: 'day' | 'week' | 'month' | 'year',
66
+ ) => {
67
+ if (date === null) {
68
+ return null
69
+ }
70
+
71
+ if (selectionType === 'week') {
72
+ return `${date.getFullYear()}W${getWeekNumber(date)}`
73
+ }
74
+
75
+ if (selectionType === 'month') {
76
+ const monthNumber = `0${date.getMonth() + 1}`.slice(-2)
77
+ return `${date.getFullYear()}-${monthNumber}`
78
+ }
79
+
80
+ if (selectionType === 'year') {
81
+ return `${date.getFullYear()}`
33
82
  }
34
83
 
35
- const rgx = RegExp(`${regex}`)
36
- const partials = string.match(rgx)
37
-
38
- if (partials === null) return
39
-
40
- const newDate =
41
- partials.groups &&
42
- (time
43
- ? new Date(
44
- Number(partials.groups['year']),
45
- Number(partials.groups['month']) - 1,
46
- Number(partials.groups['day']),
47
- partials.groups['ampm']
48
- ? partials.groups['ampm'] === 'PM'
49
- ? Number(partials.groups['hour']) + 12
50
- : Number(partials.groups['hour'])
51
- : Number(partials.groups['hour']),
52
- Number(partials.groups['minute']),
53
- Number(partials.groups['second']),
54
- )
55
- : new Date(
56
- Number(partials.groups['year']),
57
- Number(partials.groups['month']) - 1,
58
- Number(partials.groups['day']),
59
- ))
60
-
61
- return newDate
84
+ return date
62
85
  }
63
86
 
64
87
  export const getMonthName = (month: number, locale: string) => {
@@ -123,6 +146,7 @@ const getMonthDays = (year: number, month: number) => {
123
146
  month: 'current',
124
147
  })
125
148
  }
149
+
126
150
  return dates
127
151
  }
128
152
 
@@ -140,22 +164,37 @@ const getTrailingDays = (
140
164
  month: 'next',
141
165
  })
142
166
  }
167
+
143
168
  return dates
144
169
  }
145
170
 
171
+ export const getWeekNumber = (date: Date) => {
172
+ const week1 = new Date(date.getFullYear(), 0, 4)
173
+ return (
174
+ 1 +
175
+ Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + ((week1.getDay() + 6) % 7)) / 7)
176
+ )
177
+ }
178
+
146
179
  export const getMonthDetails = (year: number, month: number, firstDayOfWeek: number) => {
147
180
  const daysPrevMonth = getLeadingDays(year, month, firstDayOfWeek)
148
181
  const daysThisMonth = getMonthDays(year, month)
149
182
  const daysNextMonth = getTrailingDays(year, month, daysPrevMonth, daysThisMonth)
150
183
  const days = [...daysPrevMonth, ...daysThisMonth, ...daysNextMonth]
151
-
152
- const weeks: { date: Date; month: string }[][] = []
184
+ const weeks: { weekNumber?: number; days: { date: Date; month: string }[] }[] = []
153
185
 
154
186
  days.forEach((day, index) => {
155
187
  if (index % 7 === 0 || weeks.length === 0) {
156
- weeks.push([])
188
+ weeks.push({
189
+ days: [],
190
+ })
157
191
  }
158
- weeks[weeks.length - 1].push(day)
192
+
193
+ if ((index + 1) % 7 === 0) {
194
+ weeks[weeks.length - 1].weekNumber = getWeekNumber(day.date)
195
+ }
196
+
197
+ weeks[weeks.length - 1].days.push(day)
159
198
  })
160
199
 
161
200
  return weeks
@@ -193,18 +232,16 @@ export const isDateDisabled = (
193
232
  let disabled
194
233
  if (dates) {
195
234
  dates.forEach((_date: Date | Date[]) => {
196
- if (Array.isArray(_date)) {
197
- if (isDateInRange(date, _date[0], _date[1])) {
198
- disabled = true
199
- }
235
+ if (Array.isArray(_date) && isDateInRange(date, _date[0], _date[1])) {
236
+ disabled = true
200
237
  }
201
- if (_date instanceof Date) {
202
- if (isSameDateAs(date, _date)) {
203
- disabled = true
204
- }
238
+
239
+ if (_date instanceof Date && isSameDateAs(date, _date)) {
240
+ disabled = true
205
241
  }
206
242
  })
207
243
  }
244
+
208
245
  if (min && date < min) {
209
246
  disabled = true
210
247
  }
@@ -212,6 +249,7 @@ export const isDateDisabled = (
212
249
  if (max && date > max) {
213
250
  disabled = true
214
251
  }
252
+
215
253
  return disabled
216
254
  }
217
255
 
@@ -185,11 +185,8 @@ const CCarousel = defineComponent({
185
185
  h(
186
186
  'div',
187
187
  {
188
- class: [
189
- 'carousel slide',
190
- props.transition === 'crossfade' && 'carousel-fade',
191
- props.dark && 'carousel-dark',
192
- ],
188
+ class: ['carousel slide', props.transition === 'crossfade' && 'carousel-fade'],
189
+ ...(props.dark && { 'data-coreui-theme': 'dark' }),
193
190
  onmouseover: () => props.pause && pause(),
194
191
  onmouseleave: () => cycle(),
195
192
  ref: carouselRef,
@@ -3,6 +3,10 @@ import { defineComponent, h } from 'vue'
3
3
  export const CCloseButton = defineComponent({
4
4
  name: 'CCloseButton',
5
5
  props: {
6
+ /**
7
+ * Invert the default color.
8
+ */
9
+ dark: Boolean,
6
10
  /**
7
11
  * Toggle the disabled state for the component.
8
12
  */
@@ -39,6 +43,7 @@ export const CCloseButton = defineComponent({
39
43
  ],
40
44
  'aria-label': 'Close',
41
45
  disabled: props.disabled,
46
+ ...(props.dark && { 'data-coreui-theme': 'dark' }),
42
47
  onClick: handleClick,
43
48
  })
44
49
  },
@@ -180,6 +180,27 @@ const CDatePicker = defineComponent({
180
180
  * Toggle the readonly state for the component.
181
181
  */
182
182
  inputReadOnly: Boolean,
183
+ /**
184
+ * Custom function to format the selected date into a string according to a custom format.
185
+ *
186
+ * @since v5.0.0-alpha.4
187
+ */
188
+ inputDateFormat: Function,
189
+ /**
190
+ * Custom function to parse the input value into a valid Date object.
191
+ *
192
+ * @since v5.0.0-alpha.4
193
+ */
194
+ inputDateParse: Function,
195
+ /**
196
+ * Defines the delay (in milliseconds) for the input field's onChange event.
197
+ *
198
+ * @since v5.0.0-alpha.4
199
+ */
200
+ inputOnChangeDelay: {
201
+ type: Number,
202
+ default: 750,
203
+ },
183
204
  /**
184
205
  * Sets the default locale for components. If not set, it is inherited from the navigator.language.
185
206
  */
@@ -225,6 +246,16 @@ const CDatePicker = defineComponent({
225
246
  * @since 4.9.0
226
247
  */
227
248
  selectAdjacementDays: Boolean,
249
+ /**
250
+ * Specify the type of date selection as day, week, month, or year.
251
+ *
252
+ * @since 5.0.0-alpha.1
253
+ */
254
+ selectionType: {
255
+ type: String as PropType<'day' | 'week' | 'month' | 'year'>,
256
+ default: 'day',
257
+ validator: (value: string) => ['day', 'week', 'month', 'year'].includes(value),
258
+ },
228
259
  /**
229
260
  * Set whether to display dates in adjacent months (non-selectable) at the start and end of the current month.
230
261
  *
@@ -234,6 +265,12 @@ const CDatePicker = defineComponent({
234
265
  type: Boolean,
235
266
  default: true,
236
267
  },
268
+ /**
269
+ * Set whether to display week numbers in the calendar.
270
+ *
271
+ * @since 5.0.0-alpha.1
272
+ */
273
+ showWeekNumber: Boolean,
237
274
  /**
238
275
  * Size the component small or large.
239
276
  *
@@ -271,6 +308,12 @@ const CDatePicker = defineComponent({
271
308
  return false
272
309
  },
273
310
  },
311
+ /**
312
+ * Label displayed over week numbers in the calendar.
313
+ *
314
+ * @since 5.0.0-alpha.1
315
+ */
316
+ weekNumbersLabel: String,
274
317
  },
275
318
  emits: [
276
319
  /**