@coreui/vue-pro 4.1.3 → 4.3.0-beta.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 (64) hide show
  1. package/README.md +1 -1
  2. package/dist/components/button/CButton.d.ts +29 -2
  3. package/dist/components/calendar/CCalendar.d.ts +185 -0
  4. package/dist/components/calendar/index.d.ts +6 -0
  5. package/dist/components/date-picker/CDatePicker.d.ts +406 -0
  6. package/dist/components/date-picker/index.d.ts +6 -0
  7. package/dist/components/date-range-picker/CDateRangePicker.d.ts +480 -0
  8. package/dist/components/date-range-picker/index.d.ts +6 -0
  9. package/dist/components/dropdown/CDropdown.d.ts +25 -0
  10. package/dist/components/dropdown/CDropdownToggle.d.ts +35 -1
  11. package/dist/components/index.d.ts +5 -0
  12. package/dist/components/multi-select/CMultiSelect.d.ts +2 -2
  13. package/dist/components/picker/CPicker.d.ts +11 -0
  14. package/dist/components/picker/index.d.ts +6 -0
  15. package/dist/components/popover/CPopover.d.ts +1 -1
  16. package/dist/components/sidebar/CSidebar.d.ts +1 -1
  17. package/dist/components/smart-table/CSmartTable.d.ts +1 -1
  18. package/dist/components/smart-table/CSmartTableBody.d.ts +0 -11
  19. package/dist/components/smart-table/CSmartTableHead.d.ts +1 -1
  20. package/dist/components/time-picker/CTimePicker.d.ts +10 -0
  21. package/dist/components/time-picker/CTimePickerRollCol.d.ts +27 -0
  22. package/dist/components/time-picker/index.d.ts +6 -0
  23. package/dist/components/toast/CToast.d.ts +1 -1
  24. package/dist/index.es.js +3021 -915
  25. package/dist/index.es.js.map +1 -1
  26. package/dist/index.js +3029 -913
  27. package/dist/index.js.map +1 -1
  28. package/dist/utils/calendar.d.ts +21 -0
  29. package/dist/utils/time.d.ts +17 -0
  30. package/package.json +9 -9
  31. package/src/components/accordion/CAccordionButton.ts +1 -0
  32. package/src/components/accordion/__tests__/__snapshots__/CAccordionButton.spec.ts.snap +1 -1
  33. package/src/components/accordion/__tests__/__snapshots__/CAccordionHeader.spec.ts.snap +1 -1
  34. package/src/components/button/CButton.ts +30 -1
  35. package/src/components/button/__tests__/__snapshots__/CButton.spec.ts.snap +1 -1
  36. package/src/components/calendar/CCalendar.ts +546 -0
  37. package/src/components/calendar/index.ts +10 -0
  38. package/src/components/close-button/CCloseButton.ts +4 -1
  39. package/src/components/date-picker/CDatePicker.ts +243 -0
  40. package/src/components/date-picker/index.ts +10 -0
  41. package/src/components/date-range-picker/CDateRangePicker.ts +635 -0
  42. package/src/components/date-range-picker/index.ts +10 -0
  43. package/src/components/dropdown/CDropdown.ts +48 -49
  44. package/src/components/dropdown/CDropdownMenu.ts +52 -7
  45. package/src/components/dropdown/CDropdownToggle.ts +93 -29
  46. package/src/components/dropdown/__tests__/CDropdownMenu.spec.ts +7 -7
  47. package/src/components/dropdown/__tests__/CDropdownToggle.spec.ts +4 -5
  48. package/src/components/dropdown/__tests__/__snapshots__/CDropdownToggle.spec.ts.snap +2 -2
  49. package/src/components/form/CFormCheck.ts +2 -1
  50. package/src/components/form/CFormSwitch.ts +1 -7
  51. package/src/components/form/__tests__/__snapshots__/CFormCheck.spec.ts.snap +2 -8
  52. package/src/components/index.ts +5 -0
  53. package/src/components/modal/__tests__/__snapshots__/CModal.spec.ts.snap +2 -1
  54. package/src/components/picker/CPicker.ts +220 -0
  55. package/src/components/picker/index.ts +10 -0
  56. package/src/components/sidebar/__tests__/__snapshots__/CSidebar.spec.ts.snap +8 -2
  57. package/src/components/smart-table/CSmartTable.ts +2 -3
  58. package/src/components/smart-table/CSmartTableBody.ts +0 -5
  59. package/src/components/time-picker/CTimePicker.ts +410 -0
  60. package/src/components/time-picker/CTimePickerRollCol.ts +58 -0
  61. package/src/components/time-picker/index.ts +10 -0
  62. package/src/components/toast/__tests__/__snapshots__/CToastClose.spec.ts.snap +1 -1
  63. package/src/utils/calendar.ts +193 -0
  64. package/src/utils/time.ts +58 -0
@@ -0,0 +1,58 @@
1
+ import { defineComponent, h, onUpdated, PropType, ref } from 'vue'
2
+
3
+ export interface Element {
4
+ value: number | string
5
+ label: number | string
6
+ }
7
+
8
+ const CTimePickerRollCol = defineComponent({
9
+ name: 'CTimePickerRollCol',
10
+ props: {
11
+ elements: {
12
+ type: Array as PropType<Element[]>,
13
+ required: true,
14
+ },
15
+ selected: {
16
+ type: [Number, String],
17
+ },
18
+ },
19
+ emits: ['click'],
20
+ setup(props, { emit }) {
21
+ const init = ref(true)
22
+ const colRef = ref<HTMLDivElement>()
23
+
24
+ onUpdated(() => {
25
+ const nodeEl = colRef.value?.querySelector('.selected')
26
+ if (nodeEl && nodeEl instanceof HTMLElement) {
27
+ colRef.value?.scrollTo({
28
+ top: nodeEl.offsetTop,
29
+ behavior: init.value ? 'auto' : 'smooth',
30
+ })
31
+ }
32
+ init.value = false
33
+ })
34
+
35
+ return () =>
36
+ h(
37
+ 'div',
38
+ { class: 'time-picker-roll-col', ref: colRef },
39
+ props.elements.map((element) => {
40
+ return h(
41
+ 'div',
42
+ {
43
+ class: [
44
+ 'time-picker-roll-cell',
45
+ {
46
+ selected: element.value === props.selected,
47
+ },
48
+ ],
49
+ onClick: () => emit('click', element.value),
50
+ role: 'button',
51
+ },
52
+ element.label,
53
+ )
54
+ }),
55
+ )
56
+ },
57
+ })
58
+ export { CTimePickerRollCol }
@@ -0,0 +1,10 @@
1
+ import { App } from 'vue'
2
+ import { CTimePicker } from './CTimePicker'
3
+
4
+ const CTimePickerPlugin = {
5
+ install: (app: App): void => {
6
+ app.component(CTimePicker.name, CTimePicker)
7
+ },
8
+ }
9
+
10
+ export { CTimePicker, CTimePickerPlugin }
@@ -1,5 +1,5 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Customize CToastClose component renders correctly 1`] = `"<button class=\\"btn btn-undefined\\">Default slot</button>"`;
3
+ exports[`Customize CToastClose component renders correctly 1`] = `"<button class=\\"btn btn-undefined\\" type=\\"button\\">Default slot</button>"`;
4
4
 
5
5
  exports[`Loads and display CToastClose component renders correctly 1`] = `"<button class=\\"btn btn-close\\" aria-label=\\"Close\\"></button>"`;
@@ -0,0 +1,193 @@
1
+ export const convertToLocalDate = (d: Date, locale: string, options = {}) =>
2
+ d.toLocaleDateString(locale, options)
3
+
4
+ export const convertToLocalTime = (d: Date, locale: string, options = {}) =>
5
+ d.toLocaleTimeString(locale, options)
6
+
7
+ export const createGroupsInArray = (arr: any[], numberOfGroups: number) => {
8
+ const perGroup = Math.ceil(arr.length / numberOfGroups)
9
+ return new Array(numberOfGroups)
10
+ .fill('')
11
+ .map((_, i) => arr.slice(i * perGroup, (i + 1) * perGroup))
12
+ }
13
+
14
+ export const getCurrentYear = () => new Date().getFullYear()
15
+
16
+ export const getCurrentMonth = () => new Date().getMonth()
17
+
18
+ export const getMonthName = (month: number, locale: string) => {
19
+ const d = new Date()
20
+ d.setDate(1)
21
+ d.setMonth(month)
22
+ return d.toLocaleString(locale, { month: 'long' })
23
+ }
24
+
25
+ export const getMonthsNames = (locale: string) => {
26
+ const months = []
27
+ const d = new Date()
28
+ d.setDate(1)
29
+
30
+ for (let i = 0; i < 12; i++) {
31
+ d.setMonth(i)
32
+ months.push(d.toLocaleString(locale, { month: 'short' }))
33
+ }
34
+
35
+ return months
36
+ }
37
+
38
+ export const getYears = (year: number) => {
39
+ const years = []
40
+ for (let _year = year - 6; _year < year + 6; _year++) {
41
+ years.push(_year)
42
+ }
43
+
44
+ return years
45
+ }
46
+
47
+ const getLeadingDays = (year: number, month: number, firstDayOfWeek: number) => {
48
+ // 0: sunday
49
+ // 1: monday
50
+ const dates = []
51
+ const d = new Date(year, month)
52
+ const y = d.getFullYear()
53
+ const m = d.getMonth()
54
+ const firstWeekday = new Date(y, m, 1).getDay()
55
+ let leadingDays = 6 - (6 - firstWeekday) - firstDayOfWeek
56
+
57
+ if (firstDayOfWeek) {
58
+ leadingDays = leadingDays < 0 ? 7 + leadingDays : leadingDays
59
+ }
60
+
61
+ for (let i = leadingDays * -1; i < 0; i++) {
62
+ dates.push({
63
+ date: new Date(y, m, i + 1),
64
+ month: 'previous',
65
+ })
66
+ }
67
+
68
+ return dates
69
+ }
70
+
71
+ const getMonthDays = (year: number, month: number) => {
72
+ const dates = []
73
+ const lastDay = new Date(year, month + 1, 0).getDate()
74
+ for (let i = 1; i <= lastDay; i++) {
75
+ dates.push({
76
+ date: new Date(year, month, i),
77
+ month: 'current',
78
+ })
79
+ }
80
+ return dates
81
+ }
82
+
83
+ const getTrailingDays = (
84
+ year: number,
85
+ month: number,
86
+ leadingDays: { date: Date; month: string }[],
87
+ monthDays: { date: Date; month: string }[],
88
+ ) => {
89
+ const dates = []
90
+ const days = 42 - (leadingDays.length + monthDays.length)
91
+ for (let i = 1; i <= days; i++) {
92
+ dates.push({
93
+ date: new Date(year, month + 1, i),
94
+ month: 'next',
95
+ })
96
+ }
97
+ return dates
98
+ }
99
+
100
+ export const getMonthDetails = (year: number, month: number, firstDayOfWeek: number) => {
101
+ const daysPrevMonth = getLeadingDays(year, month, firstDayOfWeek)
102
+ const daysThisMonth = getMonthDays(year, month)
103
+ const daysNextMonth = getTrailingDays(year, month, daysPrevMonth, daysThisMonth)
104
+ const days = [...daysPrevMonth, ...daysThisMonth, ...daysNextMonth]
105
+
106
+ const weeks: { date: Date; month: string }[][] = []
107
+
108
+ days.forEach((day, index) => {
109
+ if (index % 7 === 0 || weeks.length === 0) {
110
+ weeks.push([])
111
+ }
112
+ weeks[weeks.length - 1].push(day)
113
+ })
114
+
115
+ return weeks
116
+ }
117
+
118
+ export const isDateDisabled = (
119
+ date: Date,
120
+ min?: Date | null,
121
+ max?: Date | null,
122
+ dates?: Date[] | Date[][],
123
+ ) => {
124
+ let disabled
125
+ if (dates) {
126
+ dates.forEach((_date: Date | Date[]) => {
127
+ if (Array.isArray(_date)) {
128
+ if (isDateInRange(date, _date[0], _date[1])) {
129
+ disabled = true
130
+ }
131
+ }
132
+ if (_date instanceof Date) {
133
+ if (isSameDateAs(date, _date)) {
134
+ disabled = true
135
+ }
136
+ }
137
+ })
138
+ }
139
+ if (min && date < min) {
140
+ disabled = true
141
+ }
142
+
143
+ if (max && date > max) {
144
+ disabled = true
145
+ }
146
+ return disabled
147
+ }
148
+
149
+ export const isDateInRange = (date: Date, start: Date | null, end: Date | null) => {
150
+ return start && end && start <= date && date <= end
151
+ }
152
+
153
+ export const isDateSelected = (date: Date, start: Date | null, end: Date | null) => {
154
+ return (start && isSameDateAs(start, date)) || (end && isSameDateAs(end, date))
155
+ }
156
+
157
+ export const isEndDate = (date: Date, start: Date | null, end: Date | null) => {
158
+ return start && end && isSameDateAs(end, date) && start < end
159
+ }
160
+
161
+ export const isLastDayOfMonth = (date: Date) => {
162
+ const test = new Date(date.getTime())
163
+ const month = test.getMonth()
164
+
165
+ test.setDate(test.getDate() + 1)
166
+ return test.getMonth() !== month
167
+ }
168
+
169
+ export const isSameDateAs = (date: Date, date2: Date) => {
170
+ return (
171
+ date.getDate() == date2.getDate() &&
172
+ date.getMonth() == date2.getMonth() &&
173
+ date.getFullYear() == date2.getFullYear()
174
+ )
175
+ }
176
+
177
+ export const isStartDate = (date: Date, start: Date | null, end: Date | null) => {
178
+ return start && end && isSameDateAs(start, date) && start < end
179
+ }
180
+
181
+ export const isToday = (date: Date) => {
182
+ const today = new Date()
183
+ return (
184
+ date.getDate() == today.getDate() &&
185
+ date.getMonth() == today.getMonth() &&
186
+ date.getFullYear() == today.getFullYear()
187
+ )
188
+ }
189
+
190
+ export const isValidDate = (date: string) => {
191
+ const d = new Date(date)
192
+ return d instanceof Date && d.getTime()
193
+ }
@@ -0,0 +1,58 @@
1
+ export const convert12hTo24h = (abbr: 'am' | 'pm', hour: number) => {
2
+ if (abbr === 'am' && hour === 12) {
3
+ return 0
4
+ }
5
+ if (abbr === 'am') {
6
+ return hour
7
+ }
8
+ if (abbr === 'pm' && hour === 12) {
9
+ return 12
10
+ }
11
+ return hour + 12
12
+ }
13
+
14
+ export const convert24hTo12h = (hour: number) => hour % 12 || 12
15
+
16
+ export const convertTimeToDate = (time: Date | string | null | undefined) =>
17
+ time ? (time instanceof Date ? new Date(time) : new Date(`1970-01-01 ${time}`)) : null
18
+
19
+ export const getAmPm = (date: Date, locale: string) => {
20
+ if (date.toLocaleTimeString(locale).includes('AM')) {
21
+ return 'am'
22
+ }
23
+ if (date.toLocaleTimeString(locale).includes('PM')) {
24
+ return 'pm'
25
+ }
26
+ return date.getHours() >= 12 ? 'pm' : 'am'
27
+ }
28
+
29
+ export const getListOfHours = (locale: string) =>
30
+ Array.from({ length: isAmPm(locale) ? 12 : 24 }, (_, i) => {
31
+ return {
32
+ value: isAmPm(locale) ? i + 1 : i,
33
+ label: (isAmPm(locale) ? i + 1 : i).toLocaleString(locale),
34
+ }
35
+ })
36
+
37
+ export const getMinutesOrSeconds = (locale: string) =>
38
+ Array.from({ length: 60 }, (_, i) => {
39
+ return {
40
+ value: i,
41
+ label: i.toLocaleString(locale).padStart(2, (0).toLocaleString(locale)),
42
+ }
43
+ })
44
+
45
+ export const getSelectedHour = (date: Date | null, locale: string) =>
46
+ date ? (isAmPm(locale) ? convert24hTo12h(date.getHours()) : date.getHours()) : ''
47
+
48
+ export const getSelectedMinutes = (date: Date | null) => (date ? date.getMinutes() : '')
49
+
50
+ export const getSelectedSeconds = (date: Date | null) => (date ? date.getSeconds() : '')
51
+
52
+ export const isAmPm = (locale: string) =>
53
+ ['am', 'AM', 'pm', 'PM'].some((el) => new Date().toLocaleString(locale).includes(el))
54
+
55
+ export const isValidTime = (time: string) => {
56
+ const d = new Date(`1970-01-01 ${time}`)
57
+ return d instanceof Date && d.getTime()
58
+ }