@coreui/react-pro 4.8.0-alpha.3 → 4.9.0-next.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.
- package/README.md +1 -1
- package/dist/components/calendar/index.d.ts +2 -0
- package/dist/components/calendar/utils.d.ts +23 -0
- package/dist/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +2 -2
- package/dist/components/element-cover/CElementCover.d.ts +3 -7
- package/dist/components/element-cover/index.d.ts +2 -0
- package/dist/components/form/CFormInput.d.ts +1 -1
- package/dist/components/form/CFormSwitch.d.ts +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/nav/CNavGroup.d.ts +4 -4
- package/dist/components/offcanvas/COffcanvas.d.ts +8 -2
- package/dist/components/sidebar/CSidebar.d.ts +4 -4
- package/dist/components/smart-table/CSmartTableBody.d.ts +6 -5
- package/dist/components/smart-table/CSmartTableHead.d.ts +6 -3
- package/dist/components/smart-table/CSmartTableInterface.d.ts +46 -109
- package/dist/components/smart-table/types.d.ts +53 -0
- package/dist/components/smart-table/utils.d.ts +16 -0
- package/dist/components/table/CTable.d.ts +5 -5
- package/dist/components/time-picker/types.d.ts +15 -0
- package/dist/components/time-picker/utils.d.ts +23 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useForkedRef.d.ts +7 -0
- package/dist/hooks/useStateWithCallback.d.ts +2 -0
- package/dist/index.es.js +1246 -1865
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1246 -1863
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/isInViewport.d.ts +2 -0
- package/dist/utils/isObjectInArray.d.ts +2 -0
- package/package.json +14 -14
- package/src/components/accordion/CAccordionBody.tsx +1 -1
- package/src/components/alert/CAlert.tsx +1 -1
- package/src/components/backdrop/CBackdrop.tsx +1 -1
- package/src/components/calendar/CCalendar.tsx +351 -240
- package/src/components/calendar/index.ts +3 -0
- package/src/{utils/calendar.ts → components/calendar/utils.ts} +1 -1
- package/src/components/carousel/CCarousel.tsx +4 -4
- package/src/components/carousel/CCarouselItem.tsx +1 -1
- package/src/components/collapse/CCollapse.tsx +1 -1
- package/src/components/date-picker/CDatePicker.tsx +1 -1
- package/src/components/date-range-picker/CDateRangePicker.tsx +3 -3
- package/src/components/dropdown/CDropdown.tsx +1 -1
- package/src/components/dropdown/CDropdownToggle.tsx +1 -1
- package/src/components/element-cover/CElementCover.tsx +19 -25
- package/src/components/element-cover/index.ts +3 -0
- package/src/components/form/CFormCheck.tsx +1 -1
- package/src/components/form/CFormControlWrapper.tsx +14 -20
- package/src/components/form/CFormInput.tsx +1 -1
- package/src/components/form/CFormSwitch.tsx +1 -1
- package/src/components/grid/CCol.tsx +4 -0
- package/src/components/index.ts +2 -0
- package/src/components/modal/CModal.tsx +1 -1
- package/src/components/nav/CNavGroup.tsx +4 -4
- package/src/components/nav/CNavLink.tsx +2 -1
- package/src/components/offcanvas/COffcanvas.tsx +36 -18
- package/src/components/sidebar/CSidebar.tsx +10 -10
- package/src/components/smart-table/CSmartTable.tsx +279 -259
- package/src/components/smart-table/CSmartTableBody.tsx +31 -41
- package/src/components/smart-table/CSmartTableCleaner.tsx +1 -1
- package/src/components/smart-table/CSmartTableFilter.tsx +1 -3
- package/src/components/smart-table/CSmartTableHead.tsx +53 -103
- package/src/components/smart-table/CSmartTableInterface.tsx +57 -120
- package/src/components/smart-table/CSmartTableItemsPerPageSelector.tsx +1 -2
- package/src/components/smart-table/types.tsx +65 -0
- package/src/components/smart-table/utils.tsx +199 -0
- package/src/components/table/CTable.tsx +12 -9
- package/src/components/tabs/CTabPane.tsx +1 -1
- package/src/components/time-picker/CTimePicker.tsx +50 -23
- package/src/components/time-picker/CTimePickerRollCol.tsx +1 -1
- package/src/components/time-picker/types.ts +15 -0
- package/src/{utils/time.ts → components/time-picker/utils.ts} +43 -2
- package/src/components/toast/CToast.tsx +1 -1
- package/src/components/virtual-scroller/CVirtualScroller.tsx +1 -1
- package/src/{utils/hooks → hooks}/index.ts +0 -0
- package/src/{utils/hooks → hooks}/useForkedRef.ts +0 -0
- package/src/{utils/hooks → hooks}/useStateWithCallback.ts +0 -0
- package/src/utils/index.ts +3 -2
- package/src/utils/isInViewport.ts +11 -0
- package/src/utils/isObjectInArray.ts +14 -0
- package/src/utils/isVisible.ts +0 -11
|
@@ -4,22 +4,21 @@ import classNames from 'classnames'
|
|
|
4
4
|
|
|
5
5
|
import { CFormInput, CFormSelect, CInputGroup, CInputGroupText } from '../form'
|
|
6
6
|
import { CFormControlWrapper, CFormControlWrapperProps } from '../form/CFormControlWrapper'
|
|
7
|
+
import { CPicker, CPickerProps } from './../picker/CPicker'
|
|
7
8
|
|
|
8
9
|
import { CTimePickerRollCol } from './CTimePickerRollCol'
|
|
9
|
-
import { CPicker, CPickerProps } from './../picker/CPicker'
|
|
10
10
|
import {
|
|
11
11
|
convert12hTo24h,
|
|
12
12
|
convertTimeToDate,
|
|
13
13
|
getAmPm,
|
|
14
|
-
|
|
15
|
-
getListOfMinutes,
|
|
16
|
-
getListOfSeconds,
|
|
14
|
+
getLocalizedTimePartials,
|
|
17
15
|
getSelectedHour,
|
|
18
16
|
getSelectedMinutes,
|
|
19
17
|
getSelectedSeconds,
|
|
20
|
-
isAmPm,
|
|
21
18
|
isValidTime,
|
|
22
|
-
} from '
|
|
19
|
+
} from './utils'
|
|
20
|
+
|
|
21
|
+
import type { LocalizedTimePartials } from './types'
|
|
23
22
|
|
|
24
23
|
export interface CTimePickerProps
|
|
25
24
|
extends Omit<CFormControlWrapperProps, 'floatingLabel'>,
|
|
@@ -121,6 +120,17 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
121
120
|
const [_ampm, setAmPm] = useState<'am' | 'pm'>(date ? getAmPm(new Date(date), locale) : 'am')
|
|
122
121
|
const [_visible, setVisible] = useState(visible)
|
|
123
122
|
|
|
123
|
+
const [localizedTimePartials, setLocalizedTimePartials] = useState<LocalizedTimePartials>({
|
|
124
|
+
listOfHours: [],
|
|
125
|
+
listOfMinutes: [],
|
|
126
|
+
listOfSeconds: [],
|
|
127
|
+
hour12: false,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
setLocalizedTimePartials(getLocalizedTimePartials(locale, ampm))
|
|
132
|
+
}, [date])
|
|
133
|
+
|
|
124
134
|
useEffect(() => {
|
|
125
135
|
setDate(convertTimeToDate(time))
|
|
126
136
|
}, [time])
|
|
@@ -129,7 +139,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
129
139
|
if (inputRef.current) {
|
|
130
140
|
inputRef.current.value = date
|
|
131
141
|
? date.toLocaleTimeString(locale, {
|
|
132
|
-
hour12:
|
|
142
|
+
hour12: localizedTimePartials && localizedTimePartials.hour12,
|
|
133
143
|
...(!seconds && { timeStyle: 'short' }),
|
|
134
144
|
})
|
|
135
145
|
: ''
|
|
@@ -157,7 +167,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
157
167
|
}
|
|
158
168
|
|
|
159
169
|
if (set === 'hours') {
|
|
160
|
-
if (
|
|
170
|
+
if (localizedTimePartials && localizedTimePartials.hour12) {
|
|
161
171
|
_date.setHours(convert12hTo24h(_ampm, parseInt(value)))
|
|
162
172
|
} else {
|
|
163
173
|
_date.setHours(parseInt(value))
|
|
@@ -224,12 +234,15 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
224
234
|
<span className="time-picker-inline-icon" />
|
|
225
235
|
<CFormSelect
|
|
226
236
|
disabled={disabled}
|
|
227
|
-
options={
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
237
|
+
options={
|
|
238
|
+
localizedTimePartials &&
|
|
239
|
+
localizedTimePartials.listOfHours?.map((option) => {
|
|
240
|
+
return {
|
|
241
|
+
value: option.value.toString(),
|
|
242
|
+
label: option.label,
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
}
|
|
233
246
|
onChange={(event: React.ChangeEvent<HTMLSelectElement>) =>
|
|
234
247
|
handleTimeChange('hours', event.target.value)
|
|
235
248
|
}
|
|
@@ -238,8 +251,15 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
238
251
|
<>:</>
|
|
239
252
|
<CFormSelect
|
|
240
253
|
disabled={disabled}
|
|
241
|
-
|
|
242
|
-
|
|
254
|
+
options={
|
|
255
|
+
localizedTimePartials &&
|
|
256
|
+
localizedTimePartials.listOfMinutes.map((option) => {
|
|
257
|
+
return {
|
|
258
|
+
value: option.value.toString(),
|
|
259
|
+
label: option.label,
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
}
|
|
243
263
|
onChange={(event: React.ChangeEvent<HTMLSelectElement>) =>
|
|
244
264
|
handleTimeChange('minutes', event.target.value)
|
|
245
265
|
}
|
|
@@ -250,8 +270,15 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
250
270
|
<>:</>
|
|
251
271
|
<CFormSelect
|
|
252
272
|
disabled={disabled}
|
|
253
|
-
|
|
254
|
-
|
|
273
|
+
options={
|
|
274
|
+
localizedTimePartials &&
|
|
275
|
+
localizedTimePartials.listOfSeconds.map((option) => {
|
|
276
|
+
return {
|
|
277
|
+
value: option.value.toString(),
|
|
278
|
+
label: option.label,
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
}
|
|
255
282
|
onChange={(event: React.ChangeEvent<HTMLSelectElement>) =>
|
|
256
283
|
handleTimeChange('seconds', event.target.value)
|
|
257
284
|
}
|
|
@@ -259,7 +286,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
259
286
|
/>
|
|
260
287
|
</>
|
|
261
288
|
)}
|
|
262
|
-
{
|
|
289
|
+
{localizedTimePartials && localizedTimePartials.hour12 && (
|
|
263
290
|
<CFormSelect
|
|
264
291
|
disabled={disabled}
|
|
265
292
|
options={[
|
|
@@ -279,23 +306,23 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
279
306
|
const TimePickerRoll = () => (
|
|
280
307
|
<>
|
|
281
308
|
<CTimePickerRollCol
|
|
282
|
-
elements={
|
|
309
|
+
elements={localizedTimePartials && localizedTimePartials.listOfHours}
|
|
283
310
|
onClick={(index: number) => handleTimeChange('hours', index.toString())}
|
|
284
311
|
selected={getSelectedHour(date, locale, ampm)}
|
|
285
312
|
/>
|
|
286
313
|
<CTimePickerRollCol
|
|
287
|
-
elements={
|
|
314
|
+
elements={localizedTimePartials && localizedTimePartials.listOfMinutes}
|
|
288
315
|
onClick={(index: number) => handleTimeChange('minutes', index.toString())}
|
|
289
316
|
selected={getSelectedMinutes(date)}
|
|
290
317
|
/>
|
|
291
318
|
{seconds && (
|
|
292
319
|
<CTimePickerRollCol
|
|
293
|
-
elements={
|
|
320
|
+
elements={localizedTimePartials && localizedTimePartials.listOfSeconds}
|
|
294
321
|
onClick={(index: number) => handleTimeChange('seconds', index.toString())}
|
|
295
322
|
selected={getSelectedSeconds(date)}
|
|
296
323
|
/>
|
|
297
324
|
)}
|
|
298
|
-
{
|
|
325
|
+
{localizedTimePartials && localizedTimePartials.hour12 && (
|
|
299
326
|
<CTimePickerRollCol
|
|
300
327
|
elements={[
|
|
301
328
|
{ value: 'am', label: 'AM' },
|
|
@@ -2,7 +2,7 @@ import React, { forwardRef, useEffect, useRef } from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
|
-
import { useForkedRef } from '../../
|
|
5
|
+
import { useForkedRef } from '../../hooks'
|
|
6
6
|
|
|
7
7
|
export interface Element {
|
|
8
8
|
value: number | string
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { LocalizedTimePartials } from './types'
|
|
2
|
+
|
|
1
3
|
export const convert12hTo24h = (abbr: 'am' | 'pm', hour: number) => {
|
|
2
4
|
if (abbr === 'am' && hour === 12) {
|
|
3
5
|
return 0
|
|
@@ -26,6 +28,7 @@ export const getAmPm = (date: Date, locale: string) => {
|
|
|
26
28
|
return date.getHours() >= 12 ? 'pm' : 'am'
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
// TODO: clean-up
|
|
29
32
|
export const getListOfHours = (locale: string, ampm: 'auto' | boolean = 'auto') =>
|
|
30
33
|
Array.from({ length: (ampm === 'auto' && isAmPm(locale)) || ampm === true ? 12 : 24 }, (_, i) => {
|
|
31
34
|
return {
|
|
@@ -36,6 +39,7 @@ export const getListOfHours = (locale: string, ampm: 'auto' | boolean = 'auto')
|
|
|
36
39
|
}
|
|
37
40
|
})
|
|
38
41
|
|
|
42
|
+
// TODO: clean-up
|
|
39
43
|
export const getListOfMinutes = (locale: string, valueAsString = false) =>
|
|
40
44
|
Array.from({ length: 60 }, (_, i) => {
|
|
41
45
|
const d = new Date()
|
|
@@ -47,10 +51,11 @@ export const getListOfMinutes = (locale: string, valueAsString = false) =>
|
|
|
47
51
|
minute: '2-digit',
|
|
48
52
|
second: '2-digit',
|
|
49
53
|
})
|
|
50
|
-
.split(/[^A-Za-z0-9]/)[0],
|
|
54
|
+
.split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
|
|
51
55
|
}
|
|
52
56
|
})
|
|
53
57
|
|
|
58
|
+
// TODO: clean-up
|
|
54
59
|
export const getListOfSeconds = (locale: string, valueAsString = false) =>
|
|
55
60
|
Array.from({ length: 60 }, (_, i) => {
|
|
56
61
|
const d = new Date()
|
|
@@ -62,10 +67,46 @@ export const getListOfSeconds = (locale: string, valueAsString = false) =>
|
|
|
62
67
|
minute: '2-digit',
|
|
63
68
|
second: '2-digit',
|
|
64
69
|
})
|
|
65
|
-
.split(/[^A-Za-z0-9]/)[
|
|
70
|
+
.split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
export const getLocalizedTimePartials = (
|
|
75
|
+
locale: string,
|
|
76
|
+
ampm: 'auto' | boolean = 'auto',
|
|
77
|
+
): LocalizedTimePartials => {
|
|
78
|
+
const date = new Date()
|
|
79
|
+
const hour12 = ['am', 'AM', 'pm', 'PM'].some((el) => date.toLocaleString(locale).includes(el))
|
|
80
|
+
const listOfHours = Array.from(
|
|
81
|
+
{ length: (ampm === 'auto' && hour12) || ampm === true ? 12 : 24 },
|
|
82
|
+
(_, i) => {
|
|
83
|
+
return {
|
|
84
|
+
value: (ampm === 'auto' && hour12) || ampm === true ? i + 1 : i,
|
|
85
|
+
label: ((ampm === 'auto' && hour12) || ampm === true ? i + 1 : i).toLocaleString(locale),
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
)
|
|
89
|
+
const listOfMinutesSeconds = Array.from({ length: 60 }, (_, i) => {
|
|
90
|
+
date.setMinutes(i)
|
|
91
|
+
return {
|
|
92
|
+
value: i,
|
|
93
|
+
label: date
|
|
94
|
+
.toLocaleTimeString(locale, {
|
|
95
|
+
minute: '2-digit',
|
|
96
|
+
second: '2-digit',
|
|
97
|
+
})
|
|
98
|
+
.split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
|
|
66
99
|
}
|
|
67
100
|
})
|
|
68
101
|
|
|
102
|
+
return {
|
|
103
|
+
listOfHours,
|
|
104
|
+
listOfMinutes: listOfMinutesSeconds,
|
|
105
|
+
listOfSeconds: listOfMinutesSeconds,
|
|
106
|
+
hour12,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
69
110
|
export const getSelectedHour = (
|
|
70
111
|
date: Date | null,
|
|
71
112
|
locale: string,
|
|
@@ -12,7 +12,7 @@ import classNames from 'classnames'
|
|
|
12
12
|
|
|
13
13
|
import { Colors, colorPropType } from '../Types'
|
|
14
14
|
|
|
15
|
-
import { useForkedRef } from '../../
|
|
15
|
+
import { useForkedRef } from '../../hooks'
|
|
16
16
|
|
|
17
17
|
export interface CToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
18
18
|
/**
|
|
@@ -2,7 +2,7 @@ import React, { forwardRef, HTMLAttributes, UIEvent, useEffect, useRef, useState
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
|
-
import { useForkedRef } from '../../
|
|
5
|
+
import { useForkedRef } from '../../hooks'
|
|
6
6
|
|
|
7
7
|
export interface CVirtualScrollerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onScroll'> {
|
|
8
8
|
/**
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import getNextSibling from './getNextSibling'
|
|
2
2
|
import getPreviousSibling from './getPreviousSibling'
|
|
3
|
-
import
|
|
3
|
+
import isInViewport from './isInViewport'
|
|
4
|
+
import isObjectInArray from './isObjectInArray'
|
|
4
5
|
|
|
5
|
-
export { getNextSibling, getPreviousSibling,
|
|
6
|
+
export { getNextSibling, getPreviousSibling, isInViewport, isObjectInArray }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const isInViewport = (element: HTMLElement) => {
|
|
2
|
+
const rect = element.getBoundingClientRect()
|
|
3
|
+
return (
|
|
4
|
+
Math.floor(rect.top) >= 0 &&
|
|
5
|
+
Math.floor(rect.left) >= 0 &&
|
|
6
|
+
Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
7
|
+
Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth)
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default isInViewport
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const isObjectInArray = <T>(array: T[], item: T, ignore: string[] = []) =>
|
|
2
|
+
array.some((_item: T) => {
|
|
3
|
+
let result = true
|
|
4
|
+
for (const key in item) {
|
|
5
|
+
if (!ignore.includes(key) && item[key] !== _item[key]) {
|
|
6
|
+
result = false
|
|
7
|
+
break
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return result
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export default isObjectInArray
|
package/src/utils/isVisible.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|