@coreui/react-pro 4.9.0-next.1 → 4.10.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/conditional-portal/CConditionalPortal.d.ts +12 -0
- package/dist/components/conditional-portal/index.d.ts +2 -0
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +6 -0
- package/dist/components/form/CFormCheck.d.ts +7 -1
- package/dist/components/form/CFormSwitch.d.ts +6 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/table/CTableResponsiveWrapper.d.ts +0 -1
- package/dist/components/time-picker/CTimePicker.d.ts +6 -0
- package/dist/index.es.js +507 -728
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +506 -726
- package/dist/index.js.map +1 -1
- package/package.json +11 -6
- package/src/components/accordion/CAccordion.tsx +7 -3
- package/src/components/accordion/CAccordionBody.tsx +1 -2
- package/src/components/accordion/CAccordionButton.tsx +1 -3
- package/src/components/accordion/CAccordionHeader.tsx +1 -3
- package/src/components/accordion/CAccordionItem.tsx +2 -4
- package/src/components/accordion/__tests__/__snapshots__/CAccordionBody.spec.tsx.snap +2 -2
- package/src/components/alert/CAlert.tsx +19 -27
- package/src/components/alert/CAlertHeading.tsx +1 -3
- package/src/components/alert/CAlertLink.tsx +1 -3
- package/src/components/alert/__tests__/__snapshots__/CAlert.spec.tsx.snap +1 -1
- package/src/components/avatar/CAvatar.tsx +14 -11
- package/src/components/backdrop/CBackdrop.tsx +9 -12
- package/src/components/badge/CBadge.tsx +19 -17
- package/src/components/breadcrumb/CBreadcrumb.tsx +1 -2
- package/src/components/breadcrumb/CBreadcrumbItem.tsx +12 -8
- package/src/components/button/CButton.tsx +7 -9
- package/src/components/button-group/CButtonGroup.tsx +9 -7
- package/src/components/button-group/CButtonToolbar.tsx +1 -3
- package/src/components/calendar/utils.ts +7 -9
- package/src/components/callout/CCallout.tsx +11 -9
- package/src/components/card/CCard.tsx +12 -10
- package/src/components/card/CCardBody.tsx +1 -3
- package/src/components/card/CCardFooter.tsx +1 -3
- package/src/components/card/CCardGroup.tsx +1 -3
- package/src/components/card/CCardHeader.tsx +1 -3
- package/src/components/card/CCardImage.tsx +5 -3
- package/src/components/card/CCardImageOverlay.tsx +1 -3
- package/src/components/card/CCardLink.tsx +1 -3
- package/src/components/card/CCardSubtitle.tsx +1 -3
- package/src/components/card/CCardText.tsx +1 -3
- package/src/components/card/CCardTitle.tsx +1 -3
- package/src/components/carousel/CCarousel.tsx +8 -8
- package/src/components/carousel/CCarouselCaption.tsx +1 -3
- package/src/components/carousel/CCarouselItem.tsx +11 -9
- package/src/components/close-button/CCloseButton.tsx +9 -10
- package/src/components/collapse/CCollapse.tsx +8 -20
- package/src/components/collapse/__tests__/CCollapse.spec.tsx +2 -3
- package/src/components/conditional-portal/CConditionalPortal.tsx +29 -0
- package/src/components/conditional-portal/index.ts +3 -0
- package/src/components/date-range-picker/CDateRangePicker.tsx +19 -11
- package/src/components/date-range-picker/utils.ts +2 -2
- package/src/components/dropdown/CDropdown.tsx +35 -30
- package/src/components/dropdown/CDropdownDivider.tsx +1 -3
- package/src/components/dropdown/CDropdownHeader.tsx +1 -3
- package/src/components/dropdown/CDropdownItem.tsx +6 -3
- package/src/components/dropdown/CDropdownItemPlain.tsx +1 -3
- package/src/components/dropdown/CDropdownMenu.tsx +27 -31
- package/src/components/dropdown/CDropdownToggle.tsx +29 -23
- package/src/components/dropdown/__tests__/CDropdown.spec.tsx +2 -4
- package/src/components/dropdown/__tests__/__snapshots__/CDropdown.spec.tsx.snap +1 -1
- package/src/components/footer/CFooter.tsx +5 -3
- package/src/components/form/CForm.tsx +5 -2
- package/src/components/form/CFormCheck.tsx +87 -63
- package/src/components/form/CFormControlWrapper.tsx +3 -3
- package/src/components/form/CFormFeedback.tsx +11 -8
- package/src/components/form/CFormFloating.tsx +1 -2
- package/src/components/form/CFormInput.tsx +10 -12
- package/src/components/form/CFormLabel.tsx +1 -2
- package/src/components/form/CFormRange.tsx +1 -2
- package/src/components/form/CFormSelect.tsx +15 -10
- package/src/components/form/CFormSwitch.tsx +31 -20
- package/src/components/form/CFormText.tsx +1 -2
- package/src/components/form/CFormTextarea.tsx +13 -9
- package/src/components/form/CInputGroup.tsx +11 -8
- package/src/components/form/CInputGroupText.tsx +1 -2
- package/src/components/form/__tests__/CFormRange.spec.tsx +1 -1
- package/src/components/form/__tests__/__snapshots__/CForm.spec.tsx.snap +2 -6
- package/src/components/form/__tests__/__snapshots__/CFormRange.spec.tsx.snap +2 -2
- package/src/components/grid/CCol.tsx +8 -6
- package/src/components/grid/CContainer.tsx +8 -6
- package/src/components/grid/CRow.tsx +4 -3
- package/src/components/header/CHeader.tsx +12 -13
- package/src/components/header/CHeaderBrand.tsx +1 -3
- package/src/components/header/CHeaderBrand.tsx~HEAD +1 -3
- package/src/components/header/CHeaderDivider.tsx +1 -3
- package/src/components/header/CHeaderNav.tsx +6 -3
- package/src/components/header/CHeaderText.tsx +1 -3
- package/src/components/header/CHeaderToggler.tsx +2 -4
- package/src/components/image/CImage.tsx +17 -10
- package/src/components/image/__tests__/__snapshots__/CImage.spec.tsx.snap +1 -3
- package/src/components/index.ts +1 -0
- package/src/components/link/CLink.tsx +2 -4
- package/src/components/list-group/CListGroup.tsx +11 -10
- package/src/components/list-group/CListGroupItem.tsx +13 -12
- package/src/components/loading-button/CLoadingButton.tsx +1 -3
- package/src/components/modal/CModal.tsx +55 -70
- package/src/components/modal/CModalBody.tsx +1 -3
- package/src/components/modal/CModalContent.tsx +1 -3
- package/src/components/modal/CModalDialog.tsx +16 -14
- package/src/components/modal/CModalFooter.tsx +1 -3
- package/src/components/modal/CModalHeader.tsx +1 -2
- package/src/components/modal/CModalTitle.tsx +1 -3
- package/src/components/modal/__tests__/CModal.spec.tsx +19 -20
- package/src/components/multi-select/CMultiSelect.tsx +19 -19
- package/src/components/multi-select/utils.ts +3 -3
- package/src/components/nav/CNav.tsx +13 -10
- package/src/components/nav/CNavGroup.tsx +1 -3
- package/src/components/nav/CNavGroupItems.tsx +1 -2
- package/src/components/nav/CNavItem.tsx +8 -10
- package/src/components/nav/CNavLink.tsx +1 -2
- package/src/components/nav/CNavTitle.tsx +1 -2
- package/src/components/navbar/CNavbar.tsx +21 -22
- package/src/components/navbar/CNavbarBrand.tsx +2 -3
- package/src/components/navbar/CNavbarNav.tsx +6 -3
- package/src/components/navbar/CNavbarText.tsx +1 -3
- package/src/components/navbar/CNavbarToggler.tsx +2 -4
- package/src/components/offcanvas/COffcanvas.tsx +39 -66
- package/src/components/offcanvas/COffcanvasBody.tsx +1 -3
- package/src/components/offcanvas/COffcanvasHeader.tsx +1 -3
- package/src/components/offcanvas/COffcanvasTitle.tsx +1 -3
- package/src/components/offcanvas/__tests__/COffcanvas.spec.tsx +7 -2
- package/src/components/offcanvas/__tests__/__snapshots__/COffcanvas.spec.tsx.snap +9 -4
- package/src/components/pagination/CPagination.tsx +12 -9
- package/src/components/pagination/CPaginationItem.tsx +12 -11
- package/src/components/pagination/__tests__/CPagination.spec.tsx +3 -3
- package/src/components/pagination/__tests__/CPaginationItem.spec.tsx +3 -3
- package/src/components/picker/CPicker.tsx +6 -6
- package/src/components/placeholder/CPlaceholder.tsx +13 -11
- package/src/components/popover/CPopover.tsx +22 -33
- package/src/components/progress/CProgress.tsx +12 -10
- package/src/components/progress/CProgressBar.tsx +9 -11
- package/src/components/sidebar/CSidebar.tsx +20 -18
- package/src/components/sidebar/CSidebarBrand.tsx +1 -2
- package/src/components/sidebar/CSidebarFooter.tsx +1 -2
- package/src/components/sidebar/CSidebarHeader.tsx +1 -2
- package/src/components/sidebar/CSidebarNav.tsx +2 -2
- package/src/components/sidebar/CSidebarToggler.tsx +1 -2
- package/src/components/smart-pagination/CSmartPagination.tsx +22 -20
- package/src/components/smart-table/CSmartTable.tsx +4 -8
- package/src/components/smart-table/utils.ts +3 -4
- package/src/components/spinner/CSpinner.tsx +11 -8
- package/src/components/table/CTable.tsx +20 -18
- package/src/components/table/CTableBody.tsx +12 -8
- package/src/components/table/CTableDataCell.tsx +14 -10
- package/src/components/table/CTableFoot.tsx +12 -8
- package/src/components/table/CTableHead.tsx +12 -8
- package/src/components/table/CTableHeaderCell.tsx +12 -8
- package/src/components/table/CTableResponsiveWrapper.tsx +2 -3
- package/src/components/table/CTableRow.tsx +14 -10
- package/src/components/table/__tests__/__snapshots__/CTable.spec.tsx.snap +1 -5
- package/src/components/table/utils.ts +2 -7
- package/src/components/tabs/CTabContent.tsx +1 -2
- package/src/components/tabs/CTabPane.tsx +17 -20
- package/src/components/tabs/__tests__/CTabPane.spec.tsx +2 -5
- package/src/components/tabs/__tests__/__snapshots__/CTabPane.spec.tsx.snap +1 -1
- package/src/components/time-picker/CTimePicker.tsx +21 -14
- package/src/components/toast/CToast.tsx +29 -42
- package/src/components/toast/CToastBody.tsx +1 -2
- package/src/components/toast/CToastClose.tsx +3 -1
- package/src/components/toast/CToastHeader.tsx +1 -2
- package/src/components/toast/CToaster.tsx +26 -26
- package/src/components/toast/__tests__/CToast.spec.tsx +2 -1
- package/src/components/toast/__tests__/__snapshots__/CToast.spec.tsx.snap +1 -66
- package/src/components/tooltip/CTooltip.tsx +21 -32
- package/src/components/virtual-scroller/CVirtualScroller.tsx +4 -6
- package/src/components/widgets/CWidgetStatsA.tsx +8 -6
- package/src/components/widgets/CWidgetStatsD.tsx +9 -10
- package/src/components/widgets/CWidgetStatsE.tsx +1 -3
- package/src/components/widgets/CWidgetStatsF.tsx +1 -4
- package/dist/components/Types.d.ts +0 -14
- package/dist/components/multi-select/CMultiSelectCleaner.d.ts +0 -2
- package/dist/components/multi-select/CMultiSelectSearchInput.d.ts +0 -5
- package/dist/components/pagination/CSmartPagination.d.ts +0 -80
- package/dist/components/time-picker/CTimePicker copy.d.ts +0 -46
- package/dist/utils/calendar.d.ts +0 -23
- package/dist/utils/getNextSibling.d.ts +0 -2
- package/dist/utils/getPreviousSibling.d.ts +0 -2
- package/dist/utils/hooks/index.d.ts +0 -3
- package/dist/utils/hooks/useForkedRef.d.ts +0 -7
- package/dist/utils/hooks/useStateWithCallback.d.ts +0 -2
- package/dist/utils/isVisible.d.ts +0 -2
- package/dist/utils/time.d.ts +0 -21
|
@@ -14,10 +14,8 @@ export interface CCardSubtitleProps extends HTMLAttributes<HTMLHeadingElement> {
|
|
|
14
14
|
}
|
|
15
15
|
export const CCardSubtitle = forwardRef<HTMLHeadingElement, CCardSubtitleProps>(
|
|
16
16
|
({ children, component: Component = 'h6', className, ...rest }, ref) => {
|
|
17
|
-
const _className = classNames('card-subtitle', className)
|
|
18
|
-
|
|
19
17
|
return (
|
|
20
|
-
<Component className={
|
|
18
|
+
<Component className={classNames('card-subtitle', className)} {...rest} ref={ref}>
|
|
21
19
|
{children}
|
|
22
20
|
</Component>
|
|
23
21
|
)
|
|
@@ -15,10 +15,8 @@ export interface CCardTextProps extends HTMLAttributes<HTMLParagraphElement> {
|
|
|
15
15
|
|
|
16
16
|
export const CCardText = forwardRef<HTMLParagraphElement, CCardTextProps>(
|
|
17
17
|
({ children, component: Component = 'p', className, ...rest }, ref) => {
|
|
18
|
-
const _className = classNames('card-text', className)
|
|
19
|
-
|
|
20
18
|
return (
|
|
21
|
-
<Component className={
|
|
19
|
+
<Component className={classNames('card-text', className)} {...rest} ref={ref}>
|
|
22
20
|
{children}
|
|
23
21
|
</Component>
|
|
24
22
|
)
|
|
@@ -15,10 +15,8 @@ export interface CCardTitleProps extends HTMLAttributes<HTMLHeadingElement> {
|
|
|
15
15
|
|
|
16
16
|
export const CCardTitle = forwardRef<HTMLHeadingElement, CCardTitleProps>(
|
|
17
17
|
({ children, component: Component = 'h5', className, ...rest }, ref) => {
|
|
18
|
-
const _className = classNames('card-title', className)
|
|
19
|
-
|
|
20
18
|
return (
|
|
21
|
-
<Component className={
|
|
19
|
+
<Component className={classNames('card-title', className)} {...rest} ref={ref}>
|
|
22
20
|
{children}
|
|
23
21
|
</Component>
|
|
24
22
|
)
|
|
@@ -132,13 +132,6 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
|
|
|
132
132
|
}
|
|
133
133
|
})
|
|
134
134
|
|
|
135
|
-
const _className = classNames(
|
|
136
|
-
'carousel slide',
|
|
137
|
-
transition === 'crossfade' && 'carousel-fade',
|
|
138
|
-
dark && 'carousel-dark',
|
|
139
|
-
className,
|
|
140
|
-
)
|
|
141
|
-
|
|
142
135
|
const cycle = () => {
|
|
143
136
|
_pause()
|
|
144
137
|
if (!wrap && active === itemsNumber - 1) {
|
|
@@ -230,7 +223,14 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
|
|
|
230
223
|
|
|
231
224
|
return (
|
|
232
225
|
<div
|
|
233
|
-
className={
|
|
226
|
+
className={classNames(
|
|
227
|
+
'carousel slide',
|
|
228
|
+
{
|
|
229
|
+
'carousel-dark': dark,
|
|
230
|
+
'carousel-fade': transition === 'crossfade',
|
|
231
|
+
},
|
|
232
|
+
className,
|
|
233
|
+
)}
|
|
234
234
|
onMouseEnter={_pause}
|
|
235
235
|
onMouseLeave={cycle}
|
|
236
236
|
{...(touch && { onTouchStart: handleTouchStart, onTouchMove: handleTouchMove })}
|
|
@@ -11,9 +11,7 @@ export interface CCarouselCaptionProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
11
11
|
|
|
12
12
|
export const CCarouselCaption = forwardRef<HTMLDivElement, CCarouselCaptionProps>(
|
|
13
13
|
({ className, ...rest }, ref) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return <div className={_className} {...rest} ref={ref} />
|
|
14
|
+
return <div className={classNames('carousel-caption', className)} {...rest} ref={ref} />
|
|
17
15
|
},
|
|
18
16
|
)
|
|
19
17
|
|
|
@@ -94,16 +94,18 @@ export const CCarouselItem = forwardRef<HTMLDivElement, CCarouselItemProps>(
|
|
|
94
94
|
}
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
const _className = classNames(
|
|
98
|
-
'carousel-item',
|
|
99
|
-
activeClassName,
|
|
100
|
-
directionClassName,
|
|
101
|
-
orderClassName,
|
|
102
|
-
className,
|
|
103
|
-
)
|
|
104
|
-
|
|
105
97
|
return (
|
|
106
|
-
<div
|
|
98
|
+
<div
|
|
99
|
+
className={classNames(
|
|
100
|
+
'carousel-item',
|
|
101
|
+
activeClassName,
|
|
102
|
+
directionClassName,
|
|
103
|
+
orderClassName,
|
|
104
|
+
className,
|
|
105
|
+
)}
|
|
106
|
+
ref={forkedRef}
|
|
107
|
+
{...rest}
|
|
108
|
+
>
|
|
107
109
|
{children}
|
|
108
110
|
</div>
|
|
109
111
|
)
|
|
@@ -19,19 +19,18 @@ export interface CCloseButtonProps extends HTMLAttributes<HTMLButtonElement> {
|
|
|
19
19
|
|
|
20
20
|
export const CCloseButton = forwardRef<HTMLButtonElement, CCloseButtonProps>(
|
|
21
21
|
({ className, disabled, white, ...rest }, ref) => {
|
|
22
|
-
const _className = classNames(
|
|
23
|
-
'btn',
|
|
24
|
-
'btn-close',
|
|
25
|
-
{
|
|
26
|
-
'btn-close-white': white,
|
|
27
|
-
},
|
|
28
|
-
disabled,
|
|
29
|
-
className,
|
|
30
|
-
)
|
|
31
22
|
return (
|
|
32
23
|
<button
|
|
33
24
|
type="button"
|
|
34
|
-
className={
|
|
25
|
+
className={classNames(
|
|
26
|
+
'btn',
|
|
27
|
+
'btn-close',
|
|
28
|
+
{
|
|
29
|
+
'btn-close-white': white,
|
|
30
|
+
},
|
|
31
|
+
disabled,
|
|
32
|
+
className,
|
|
33
|
+
)}
|
|
35
34
|
aria-label="Close"
|
|
36
35
|
disabled={disabled}
|
|
37
36
|
{...rest}
|
|
@@ -30,20 +30,11 @@ export interface CCollapseProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
30
30
|
|
|
31
31
|
export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
|
|
32
32
|
({ children, className, horizontal, onHide, onShow, visible, ...rest }, ref) => {
|
|
33
|
-
const [height, setHeight] = useState<number>()
|
|
34
|
-
const [width, setWidth] = useState<number>()
|
|
35
33
|
const collapseRef = useRef<HTMLDivElement>(null)
|
|
36
34
|
const forkedRef = useForkedRef(ref, collapseRef)
|
|
37
35
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
? 'collapsing'
|
|
41
|
-
: state === 'entered'
|
|
42
|
-
? 'collapse show'
|
|
43
|
-
: state === 'exiting'
|
|
44
|
-
? 'collapsing'
|
|
45
|
-
: 'collapse'
|
|
46
|
-
}
|
|
36
|
+
const [height, setHeight] = useState<number>()
|
|
37
|
+
const [width, setWidth] = useState<number>()
|
|
47
38
|
|
|
48
39
|
const onEntering = () => {
|
|
49
40
|
onShow && onShow()
|
|
@@ -88,13 +79,6 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
|
|
|
88
79
|
setHeight(0)
|
|
89
80
|
}
|
|
90
81
|
|
|
91
|
-
const _className = classNames(
|
|
92
|
-
{
|
|
93
|
-
'collapse-horizontal': horizontal,
|
|
94
|
-
},
|
|
95
|
-
className,
|
|
96
|
-
)
|
|
97
|
-
|
|
98
82
|
return (
|
|
99
83
|
<CSSTransition
|
|
100
84
|
in={visible}
|
|
@@ -107,12 +91,16 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
|
|
|
107
91
|
timeout={350}
|
|
108
92
|
>
|
|
109
93
|
{(state) => {
|
|
110
|
-
const transitionClass = getTransitionClass(state)
|
|
111
94
|
const currentHeight = height === 0 ? null : { height }
|
|
112
95
|
const currentWidth = width === 0 ? null : { width }
|
|
113
96
|
return (
|
|
114
97
|
<div
|
|
115
|
-
className={classNames(
|
|
98
|
+
className={classNames(className, {
|
|
99
|
+
'collapse-horizontal': horizontal,
|
|
100
|
+
collapsing: state === 'entering' || state === 'exiting',
|
|
101
|
+
'collapse show': state === 'entered',
|
|
102
|
+
collapse: state === 'exited',
|
|
103
|
+
})}
|
|
116
104
|
style={{ ...currentHeight, ...currentWidth }}
|
|
117
105
|
{...rest}
|
|
118
106
|
ref={forkedRef}
|
|
@@ -15,7 +15,6 @@ test('CCollapse customize', async () => {
|
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
test('CCollapse use case test', async () => {
|
|
18
|
-
jest.useFakeTimers()
|
|
19
18
|
const { rerender } = render(<CCollapse visible={false}>Test</CCollapse>)
|
|
20
19
|
expect(screen.getByText('Test')).toHaveClass('collapse')
|
|
21
20
|
expect(screen.getByText('Test')).not.toHaveClass('show')
|
|
@@ -24,7 +23,7 @@ test('CCollapse use case test', async () => {
|
|
|
24
23
|
expect(screen.getByText('Test')).not.toHaveClass('collapse')
|
|
25
24
|
expect(screen.getByText('Test')).not.toHaveClass('show')
|
|
26
25
|
expect(screen.getByText('Test')).toHaveClass('collapsing')
|
|
27
|
-
|
|
26
|
+
await new Promise((r) => setTimeout(r, 1000))
|
|
28
27
|
expect(screen.getByText('Test')).toHaveClass('collapse')
|
|
29
28
|
expect(screen.getByText('Test')).toHaveClass('show')
|
|
30
29
|
expect(screen.getByText('Test')).not.toHaveClass('collapsing')
|
|
@@ -32,7 +31,7 @@ test('CCollapse use case test', async () => {
|
|
|
32
31
|
expect(screen.getByText('Test')).not.toHaveClass('collapse')
|
|
33
32
|
expect(screen.getByText('Test')).not.toHaveClass('show')
|
|
34
33
|
expect(screen.getByText('Test')).toHaveClass('collapsing')
|
|
35
|
-
|
|
34
|
+
await new Promise((r) => setTimeout(r, 1000))
|
|
36
35
|
expect(screen.getByText('Test')).toHaveClass('collapse')
|
|
37
36
|
expect(screen.getByText('Test')).not.toHaveClass('show')
|
|
38
37
|
expect(screen.getByText('Test')).not.toHaveClass('collapsing')
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { FC, ReactNode } from 'react'
|
|
2
|
+
import { createPortal } from 'react-dom'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
|
|
5
|
+
export interface CConditionalPortalProps {
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
children: ReactNode
|
|
10
|
+
/**
|
|
11
|
+
* Render some children into a different part of the DOM
|
|
12
|
+
*/
|
|
13
|
+
portal: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const CConditionalPortal: FC<CConditionalPortalProps> = ({ children, portal }) => {
|
|
17
|
+
return typeof window !== 'undefined' && portal ? (
|
|
18
|
+
createPortal(children, document.body)
|
|
19
|
+
) : (
|
|
20
|
+
<>{children}</>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
CConditionalPortal.propTypes = {
|
|
25
|
+
children: PropTypes.node,
|
|
26
|
+
portal: PropTypes.bool.isRequired,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
CConditionalPortal.displayName = 'CConditionalPortal'
|
|
@@ -84,6 +84,12 @@ export interface CDateRangePickerProps
|
|
|
84
84
|
* Set the ranges button variant to an outlined button or a ghost button.
|
|
85
85
|
*/
|
|
86
86
|
rangesButtonsVariant?: 'outline' | 'ghost'
|
|
87
|
+
/**
|
|
88
|
+
* When present, it specifies that date must be filled out before submitting the form.
|
|
89
|
+
*
|
|
90
|
+
* @since 4.10.0
|
|
91
|
+
*/
|
|
92
|
+
required?: boolean
|
|
87
93
|
/**
|
|
88
94
|
* Default icon or character character that separates two dates.
|
|
89
95
|
*/
|
|
@@ -159,6 +165,7 @@ export const CDateRangePicker = forwardRef<HTMLDivElement | HTMLLIElement, CDate
|
|
|
159
165
|
rangesButtonsColor = 'secondary',
|
|
160
166
|
rangesButtonsSize,
|
|
161
167
|
rangesButtonsVariant = 'ghost',
|
|
168
|
+
required,
|
|
162
169
|
separator = true,
|
|
163
170
|
size,
|
|
164
171
|
startDate,
|
|
@@ -304,15 +311,6 @@ export const CDateRangePicker = forwardRef<HTMLDivElement | HTMLLIElement, CDate
|
|
|
304
311
|
setEndDate(null)
|
|
305
312
|
}
|
|
306
313
|
|
|
307
|
-
const _className = classNames(
|
|
308
|
-
'date-picker',
|
|
309
|
-
{
|
|
310
|
-
'is-invalid': invalid,
|
|
311
|
-
'is-valid': valid,
|
|
312
|
-
},
|
|
313
|
-
className,
|
|
314
|
-
)
|
|
315
|
-
|
|
316
314
|
const InputGroup = () => (
|
|
317
315
|
<CInputGroup className="picker-input-group" size={size}>
|
|
318
316
|
<CFormInput
|
|
@@ -325,6 +323,7 @@ export const CDateRangePicker = forwardRef<HTMLDivElement | HTMLLIElement, CDate
|
|
|
325
323
|
{...(id && { name: range ? `${id}-start-date` : `${id}-date` })}
|
|
326
324
|
placeholder={Array.isArray(placeholder) ? placeholder[0] : placeholder}
|
|
327
325
|
readOnly={inputReadOnly || typeof format === 'string'}
|
|
326
|
+
required={required}
|
|
328
327
|
onChange={(event) => {
|
|
329
328
|
const date = getLocalDateFromString(event.target.value, locale, timepicker)
|
|
330
329
|
if (date instanceof Date && date.getTime()) {
|
|
@@ -355,6 +354,7 @@ export const CDateRangePicker = forwardRef<HTMLDivElement | HTMLLIElement, CDate
|
|
|
355
354
|
{...(id && { name: `${id}-end-date` })}
|
|
356
355
|
placeholder={placeholder[1]}
|
|
357
356
|
readOnly={inputReadOnly || typeof format === 'string'}
|
|
357
|
+
required={required}
|
|
358
358
|
onChange={(event) => {
|
|
359
359
|
const date = getLocalDateFromString(event.target.value, locale, timepicker)
|
|
360
360
|
if (date instanceof Date && date.getTime()) {
|
|
@@ -409,7 +409,14 @@ export const CDateRangePicker = forwardRef<HTMLDivElement | HTMLLIElement, CDate
|
|
|
409
409
|
valid={valid}
|
|
410
410
|
>
|
|
411
411
|
<CPicker
|
|
412
|
-
className={
|
|
412
|
+
className={classNames(
|
|
413
|
+
'date-picker',
|
|
414
|
+
{
|
|
415
|
+
'is-invalid': invalid,
|
|
416
|
+
'is-valid': valid,
|
|
417
|
+
},
|
|
418
|
+
className,
|
|
419
|
+
)}
|
|
413
420
|
disabled={disabled}
|
|
414
421
|
footer={footer || timepicker}
|
|
415
422
|
footerContent={
|
|
@@ -431,7 +438,7 @@ export const CDateRangePicker = forwardRef<HTMLDivElement | HTMLLIElement, CDate
|
|
|
431
438
|
)
|
|
432
439
|
}
|
|
433
440
|
id={id}
|
|
434
|
-
toggler={toggler
|
|
441
|
+
toggler={toggler ?? InputGroup()}
|
|
435
442
|
onCancel={() => {
|
|
436
443
|
handleStartDateChange(initialStartDate)
|
|
437
444
|
handleEndDateChange(initialEndDate)
|
|
@@ -567,6 +574,7 @@ CDateRangePicker.propTypes = {
|
|
|
567
574
|
rangesButtonsColor: CButton.propTypes?.color,
|
|
568
575
|
rangesButtonsSize: CButton.propTypes?.size,
|
|
569
576
|
rangesButtonsVariant: CButton.propTypes?.variant,
|
|
577
|
+
required: PropTypes.bool,
|
|
570
578
|
separator: PropTypes.oneOfType([PropTypes.bool, PropTypes.node]),
|
|
571
579
|
size: PropTypes.oneOf(['sm', 'lg']),
|
|
572
580
|
timepicker: PropTypes.bool,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const getLocalDateFromString = (string: string, locale: string, time?: boolean) => {
|
|
2
|
-
if (!isNaN(Date.parse(string))) {
|
|
2
|
+
if (!Number.isNaN(Date.parse(string))) {
|
|
3
3
|
return new Date(Date.parse(string))
|
|
4
4
|
}
|
|
5
5
|
|
|
@@ -19,7 +19,7 @@ export const getLocalDateFromString = (string: string, locale: string, time?: bo
|
|
|
19
19
|
.replace('PM', '(?<ampm>[A-Z]{2})')
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const rgx = RegExp(`${regex}`)
|
|
22
|
+
const rgx = new RegExp(`${regex}`)
|
|
23
23
|
const partials = string.match(rgx)
|
|
24
24
|
|
|
25
25
|
if (partials === null) return
|
|
@@ -3,6 +3,7 @@ import React, {
|
|
|
3
3
|
ElementType,
|
|
4
4
|
forwardRef,
|
|
5
5
|
HTMLAttributes,
|
|
6
|
+
ReactNode,
|
|
6
7
|
RefObject,
|
|
7
8
|
useEffect,
|
|
8
9
|
useRef,
|
|
@@ -87,6 +88,16 @@ export interface CDropdownProps extends HTMLAttributes<HTMLDivElement | HTMLLIEl
|
|
|
87
88
|
visible?: boolean
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
const PopperManagerWrapper = ({
|
|
92
|
+
children,
|
|
93
|
+
popper,
|
|
94
|
+
}: {
|
|
95
|
+
children: ReactNode
|
|
96
|
+
popper: boolean
|
|
97
|
+
}) => {
|
|
98
|
+
return popper ? <Manager>{children}</Manager> : <>{children}</>
|
|
99
|
+
}
|
|
100
|
+
|
|
90
101
|
interface ContextProps extends CDropdownProps {
|
|
91
102
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
103
|
dropdownToggleRef: RefObject<any> | undefined
|
|
@@ -115,10 +126,10 @@ export const CDropdown = forwardRef<HTMLDivElement | HTMLLIElement, CDropdownPro
|
|
|
115
126
|
},
|
|
116
127
|
ref,
|
|
117
128
|
) => {
|
|
118
|
-
const [_visible, setVisible] = useState(visible)
|
|
119
129
|
const dropdownRef = useRef<HTMLDivElement>(null)
|
|
120
130
|
const dropdownToggleRef = useRef(null)
|
|
121
131
|
const forkedRef = useForkedRef(ref, dropdownRef)
|
|
132
|
+
const [_visible, setVisible] = useState(visible)
|
|
122
133
|
|
|
123
134
|
const Component = variant === 'nav-item' ? 'li' : component
|
|
124
135
|
|
|
@@ -140,19 +151,6 @@ export const CDropdown = forwardRef<HTMLDivElement | HTMLLIElement, CDropdownPro
|
|
|
140
151
|
setVisible,
|
|
141
152
|
}
|
|
142
153
|
|
|
143
|
-
const _className = classNames(
|
|
144
|
-
variant === 'nav-item' ? 'nav-item dropdown' : variant,
|
|
145
|
-
{
|
|
146
|
-
show: _visible,
|
|
147
|
-
},
|
|
148
|
-
direction === 'center'
|
|
149
|
-
? 'dropdown-center'
|
|
150
|
-
: direction === 'dropup-center'
|
|
151
|
-
? 'dropup dropup-center'
|
|
152
|
-
: direction,
|
|
153
|
-
className,
|
|
154
|
-
)
|
|
155
|
-
|
|
156
154
|
useEffect(() => {
|
|
157
155
|
setVisible(visible)
|
|
158
156
|
}, [visible])
|
|
@@ -162,23 +160,30 @@ export const CDropdown = forwardRef<HTMLDivElement | HTMLLIElement, CDropdownPro
|
|
|
162
160
|
!_visible && onHide && onHide()
|
|
163
161
|
}, [_visible])
|
|
164
162
|
|
|
165
|
-
|
|
166
|
-
return variant === 'input-group' ? (
|
|
167
|
-
<>{children}</>
|
|
168
|
-
) : (
|
|
169
|
-
<Component className={_className} {...rest} ref={forkedRef}>
|
|
170
|
-
{children}
|
|
171
|
-
</Component>
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return popper ? (
|
|
176
|
-
<CDropdownContext.Provider value={contextValues}>
|
|
177
|
-
<Manager>{dropdownContent()}</Manager>
|
|
178
|
-
</CDropdownContext.Provider>
|
|
179
|
-
) : (
|
|
163
|
+
return (
|
|
180
164
|
<CDropdownContext.Provider value={contextValues}>
|
|
181
|
-
{
|
|
165
|
+
<PopperManagerWrapper popper={popper}>
|
|
166
|
+
{variant === 'input-group' ? (
|
|
167
|
+
<>{children}</>
|
|
168
|
+
) : (
|
|
169
|
+
<Component
|
|
170
|
+
className={classNames(
|
|
171
|
+
variant === 'nav-item' ? 'nav-item dropdown' : variant,
|
|
172
|
+
{
|
|
173
|
+
'dropdown-center': direction === 'center',
|
|
174
|
+
'dropup dropup-center': direction === 'dropup-center',
|
|
175
|
+
direction: direction && direction !== 'center' && direction !== 'dropup-center',
|
|
176
|
+
show: _visible,
|
|
177
|
+
},
|
|
178
|
+
className,
|
|
179
|
+
)}
|
|
180
|
+
{...rest}
|
|
181
|
+
ref={forkedRef}
|
|
182
|
+
>
|
|
183
|
+
{children}
|
|
184
|
+
</Component>
|
|
185
|
+
)}
|
|
186
|
+
</PopperManagerWrapper>
|
|
182
187
|
</CDropdownContext.Provider>
|
|
183
188
|
)
|
|
184
189
|
},
|
|
@@ -11,9 +11,7 @@ export interface CDropdownDividerProps extends HTMLAttributes<HTMLHRElement> {
|
|
|
11
11
|
|
|
12
12
|
export const CDropdownDivider = forwardRef<HTMLHRElement, CDropdownDividerProps>(
|
|
13
13
|
({ className, ...rest }, ref) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return <hr className={_className} {...rest} ref={ref} />
|
|
14
|
+
return <hr className={classNames('dropdown-divider', className)} {...rest} ref={ref} />
|
|
17
15
|
},
|
|
18
16
|
)
|
|
19
17
|
|
|
@@ -15,10 +15,8 @@ export interface CDropdownHeaderProps extends HTMLAttributes<HTMLHeadingElement>
|
|
|
15
15
|
|
|
16
16
|
export const CDropdownHeader = forwardRef<HTMLHeadingElement, CDropdownHeaderProps>(
|
|
17
17
|
({ children, className, component: Component = 'h6', ...rest }, ref) => {
|
|
18
|
-
const _className = classNames('dropdown-header', className)
|
|
19
|
-
|
|
20
18
|
return (
|
|
21
|
-
<Component className={
|
|
19
|
+
<Component className={classNames('dropdown-header', className)} {...rest} ref={ref}>
|
|
22
20
|
{children}
|
|
23
21
|
</Component>
|
|
24
22
|
)
|
|
@@ -17,10 +17,13 @@ export interface CDropdownItemProps extends CLinkProps {
|
|
|
17
17
|
|
|
18
18
|
export const CDropdownItem = forwardRef<HTMLButtonElement | HTMLAnchorElement, CDropdownItemProps>(
|
|
19
19
|
({ children, className, component = 'a', ...rest }, ref) => {
|
|
20
|
-
const _className = classNames('dropdown-item', className)
|
|
21
|
-
|
|
22
20
|
return (
|
|
23
|
-
<CLink
|
|
21
|
+
<CLink
|
|
22
|
+
className={classNames('dropdown-item', className)}
|
|
23
|
+
component={component}
|
|
24
|
+
{...rest}
|
|
25
|
+
ref={ref}
|
|
26
|
+
>
|
|
24
27
|
{children}
|
|
25
28
|
</CLink>
|
|
26
29
|
)
|
|
@@ -15,10 +15,8 @@ export interface CDropdownItemPlainProps extends HTMLAttributes<HTMLSpanElement>
|
|
|
15
15
|
|
|
16
16
|
export const CDropdownItemPlain = forwardRef<HTMLSpanElement, CDropdownItemPlainProps>(
|
|
17
17
|
({ children, className, component: Component = 'span', ...rest }, ref) => {
|
|
18
|
-
const _className = classNames('dropdown-item-text', className)
|
|
19
|
-
|
|
20
18
|
return (
|
|
21
|
-
<Component className={
|
|
19
|
+
<Component className={classNames('dropdown-item-text', className)} {...rest} ref={ref}>
|
|
22
20
|
{children}
|
|
23
21
|
</Component>
|
|
24
22
|
)
|
|
@@ -126,39 +126,35 @@ export const CDropdownMenu: FC<CDropdownMenuProps> = ({
|
|
|
126
126
|
return classNames
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
const dropdownMenuComponent = (style?: React.CSSProperties, ref?: React.Ref<HTMLDivElement>) => (
|
|
130
|
+
<Component
|
|
131
|
+
className={classNames(
|
|
132
|
+
'dropdown-menu',
|
|
133
|
+
{
|
|
134
|
+
'dropdown-menu-dark': dark,
|
|
135
|
+
show: visible,
|
|
136
|
+
},
|
|
137
|
+
alignment && alignmentClassNames(alignment),
|
|
138
|
+
className,
|
|
139
|
+
)}
|
|
140
|
+
ref={ref}
|
|
141
|
+
style={style}
|
|
142
|
+
role="menu"
|
|
143
|
+
aria-hidden={!visible}
|
|
144
|
+
{...(!popper && { 'data-coreui-popper': 'static' })}
|
|
145
|
+
{...rest}
|
|
146
|
+
>
|
|
147
|
+
{Component === 'ul'
|
|
148
|
+
? React.Children.map(children, (child, index) => {
|
|
149
|
+
if (React.isValidElement(child)) {
|
|
150
|
+
return <li key={index}>{React.cloneElement(child)}</li>
|
|
151
|
+
}
|
|
152
|
+
return
|
|
153
|
+
})
|
|
154
|
+
: children}
|
|
155
|
+
</Component>
|
|
137
156
|
)
|
|
138
157
|
|
|
139
|
-
const dropdownMenuComponent = (style?: React.CSSProperties, ref?: React.Ref<HTMLDivElement>) => {
|
|
140
|
-
return (
|
|
141
|
-
<Component
|
|
142
|
-
className={_className}
|
|
143
|
-
ref={ref}
|
|
144
|
-
style={style}
|
|
145
|
-
role="menu"
|
|
146
|
-
aria-hidden={!visible}
|
|
147
|
-
{...(!popper && { 'data-coreui-popper': 'static' })}
|
|
148
|
-
{...rest}
|
|
149
|
-
>
|
|
150
|
-
{Component === 'ul'
|
|
151
|
-
? React.Children.map(children, (child, index) => {
|
|
152
|
-
if (React.isValidElement(child)) {
|
|
153
|
-
return <li key={index}>{React.cloneElement(child)}</li>
|
|
154
|
-
}
|
|
155
|
-
return
|
|
156
|
-
})
|
|
157
|
-
: children}
|
|
158
|
-
</Component>
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
158
|
return popper && visible ? (
|
|
163
159
|
<Popper innerRef={dropdownMenuRef} placement={_placement}>
|
|
164
160
|
{({ ref, style }) => dropdownMenuComponent(style, ref)}
|
|
@@ -42,14 +42,6 @@ export const CDropdownToggle: FC<CDropdownToggleProps> = ({
|
|
|
42
42
|
...rest
|
|
43
43
|
}) => {
|
|
44
44
|
const { dropdownToggleRef, popper, variant, visible, setVisible } = useContext(CDropdownContext)
|
|
45
|
-
const _className = classNames(
|
|
46
|
-
{
|
|
47
|
-
'dropdown-toggle': caret,
|
|
48
|
-
'dropdown-toggle-split': split,
|
|
49
|
-
'nav-link': variant === 'nav-item',
|
|
50
|
-
},
|
|
51
|
-
className,
|
|
52
|
-
)
|
|
53
45
|
|
|
54
46
|
const triggers = {
|
|
55
47
|
...((trigger === 'click' || trigger.includes('click')) && {
|
|
@@ -65,28 +57,42 @@ export const CDropdownToggle: FC<CDropdownToggleProps> = ({
|
|
|
65
57
|
}
|
|
66
58
|
|
|
67
59
|
const togglerProps = {
|
|
68
|
-
className:
|
|
60
|
+
className: classNames(
|
|
61
|
+
{
|
|
62
|
+
'dropdown-toggle': caret,
|
|
63
|
+
'dropdown-toggle-split': split,
|
|
64
|
+
'nav-link': variant === 'nav-item',
|
|
65
|
+
},
|
|
66
|
+
className,
|
|
67
|
+
),
|
|
69
68
|
'aria-expanded': visible,
|
|
70
69
|
...(!rest.disabled && { ...triggers }),
|
|
71
|
-
...triggers,
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
// We use any because Toggler can be `a` as well as `button`.
|
|
75
73
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
74
|
const Toggler = (ref?: React.Ref<any>) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
75
|
+
if (custom && React.isValidElement(children)) {
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{React.cloneElement(children as React.ReactElement<any>, {
|
|
79
|
+
'aria-expanded': visible,
|
|
80
|
+
...(!rest.disabled && { ...triggers }),
|
|
81
|
+
ref: useForkedRef(ref, dropdownToggleRef),
|
|
82
|
+
})}
|
|
83
|
+
</>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (variant === 'nav-item') {
|
|
88
|
+
return (
|
|
89
|
+
<a href="#" {...togglerProps} ref={useForkedRef(ref, dropdownToggleRef)}>
|
|
90
|
+
{children}
|
|
91
|
+
</a>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (
|
|
90
96
|
<CButton
|
|
91
97
|
type="button"
|
|
92
98
|
{...togglerProps}
|