@coreui/react-pro 4.1.3 → 4.2.0-beta.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.
- package/README.md +1 -1
- package/dist/components/calendar/CCalendar.d.ts +106 -0
- package/dist/components/calendar/CCalendar.utils.d.ts +21 -0
- package/dist/components/datepicker/CDatePicker.d.ts +13 -0
- package/dist/components/daterangepicker/CDateRangePicker.d.ts +65 -0
- package/dist/components/dropdown/CDropdown.d.ts +10 -1
- package/dist/components/dropdown/CDropdownToggle.d.ts +4 -0
- package/dist/components/dropdown/CDropdownToggleCustom.d.ts +15 -0
- package/dist/components/picker/CPicker.d.ts +78 -0
- package/dist/components/smart-table/CSmartTableInterface.d.ts +0 -9
- package/dist/components/timepicker/CTimePicker.d.ts +45 -0
- package/dist/components/timepicker/CTimePicker.utils.d.ts +17 -0
- package/dist/components/timepicker/CTimePickerRollCol.d.ts +11 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.es.js +2568 -718
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +2849 -995
- package/dist/index.js.map +1 -1
- package/dist/utils/calendar.d.ts +21 -0
- package/dist/utils/time.d.ts +17 -0
- package/package.json +11 -8
- package/src/components/accordion/CAccordionButton.tsx +2 -1
- package/src/components/accordion/__tests__/__snapshots__/CAccordionButton.spec.tsx.snap +2 -0
- package/src/components/accordion/__tests__/__snapshots__/CAccordionHeader.spec.tsx.snap +2 -0
- package/src/components/calendar/CCalendar.tsx +528 -0
- package/src/components/calendar/__tests__/CCalendar.spec.tsx +9 -0
- package/src/components/calendar/__tests__/__snapshots__/CCalendar.spec.tsx.snap +573 -0
- package/src/components/datepicker/CDatePicker.tsx +50 -0
- package/src/components/datepicker/__tests__/CDatePicker.spec.tsx +9 -0
- package/src/components/datepicker/__tests__/__snapshots__/CDatePicker.spec.tsx.snap +617 -0
- package/src/components/daterangepicker/CDateRangePicker.tsx +427 -0
- package/src/components/daterangepicker/__tests__/CDateRangePicker.spec.tsx +9 -0
- package/src/components/daterangepicker/__tests__/__snapshots__/CDateRangePicker.spec.tsx.snap +1201 -0
- package/src/components/dropdown/CDropdown.tsx +19 -24
- package/src/components/dropdown/CDropdownMenu.tsx +57 -3
- package/src/components/dropdown/CDropdownToggle.tsx +28 -5
- package/src/components/picker/CPicker.tsx +207 -0
- package/src/components/picker/__tests__/CPicker.spec.tsx +9 -0
- package/src/components/picker/__tests__/__snapshots__/CPicker.spec.tsx.snap +23 -0
- package/src/components/smart-table/CSmartTable.tsx +44 -96
- package/src/components/smart-table/CSmartTableCleaner.tsx +3 -16
- package/src/components/smart-table/CSmartTableInterface.tsx +0 -9
- package/src/components/timepicker/CTimePicker.tsx +320 -0
- package/src/components/timepicker/CTimePickerRollCol.tsx +63 -0
- package/src/components/timepicker/__tests__/CTimePicker.spec.tsx +9 -0
- package/src/index.ts +8 -0
- package/src/utils/calendar.ts +193 -0
- package/src/utils/time.ts +58 -0
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { CBreadcrumbItem } from './components/breadcrumb/CBreadcrumbItem'
|
|
|
15
15
|
import { CButton } from './components/button/CButton'
|
|
16
16
|
import { CButtonGroup } from './components/button-group/CButtonGroup'
|
|
17
17
|
import { CButtonToolbar } from './components/button-group/CButtonToolbar'
|
|
18
|
+
import { CCalendar } from './components/calendar/CCalendar'
|
|
18
19
|
import { CCallout } from './components/callout/CCallout'
|
|
19
20
|
import { CCard } from './components/card/CCard'
|
|
20
21
|
import { CCardBody } from './components/card/CCardBody'
|
|
@@ -32,6 +33,8 @@ import { CCarouselCaption } from './components/carousel/CCarouselCaption'
|
|
|
32
33
|
import { CCarouselItem } from './components/carousel/CCarouselItem'
|
|
33
34
|
import { CCollapse } from './components/collapse/CCollapse'
|
|
34
35
|
import { CCloseButton } from './components/close-button/CCloseButton'
|
|
36
|
+
import { CDatePicker } from './components/datepicker/CDatePicker'
|
|
37
|
+
import { CDateRangePicker } from './components/daterangepicker/CDateRangePicker'
|
|
35
38
|
import { CDropdown } from './components/dropdown/CDropdown'
|
|
36
39
|
import { CDropdownDivider } from './components/dropdown/CDropdownDivider'
|
|
37
40
|
import { CDropdownHeader } from './components/dropdown/CDropdownHeader'
|
|
@@ -115,6 +118,7 @@ import { CTableHeaderCell } from './components/table/CTableHeaderCell'
|
|
|
115
118
|
import { CTableRow } from './components/table/CTableRow'
|
|
116
119
|
import { CTabContent } from './components/tabs/CTabContent'
|
|
117
120
|
import { CTabPane } from './components/tabs/CTabPane'
|
|
121
|
+
import { CTimePicker } from './components/timepicker/CTimePicker'
|
|
118
122
|
import { CToast } from './components/toast/CToast'
|
|
119
123
|
import { CToastBody } from './components/toast/CToastBody'
|
|
120
124
|
import { CToastClose } from './components/toast/CToastClose'
|
|
@@ -140,6 +144,7 @@ export {
|
|
|
140
144
|
CButton,
|
|
141
145
|
CButtonGroup,
|
|
142
146
|
CButtonToolbar,
|
|
147
|
+
CCalendar,
|
|
143
148
|
CCallout,
|
|
144
149
|
CCard,
|
|
145
150
|
CCardBody,
|
|
@@ -156,6 +161,8 @@ export {
|
|
|
156
161
|
CCarouselItem,
|
|
157
162
|
CCloseButton,
|
|
158
163
|
CCollapse,
|
|
164
|
+
CDatePicker,
|
|
165
|
+
CDateRangePicker,
|
|
159
166
|
CDropdown,
|
|
160
167
|
CDropdownDivider,
|
|
161
168
|
CDropdownHeader,
|
|
@@ -240,6 +247,7 @@ export {
|
|
|
240
247
|
CTableRow,
|
|
241
248
|
CTabContent,
|
|
242
249
|
CTabPane,
|
|
250
|
+
CTimePicker,
|
|
243
251
|
CToast,
|
|
244
252
|
CToastBody,
|
|
245
253
|
CToastClose,
|
|
@@ -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
|
+
}
|