@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
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { CSSTransition } from 'react-transition-group'
|
|
5
5
|
|
|
6
|
-
import { useForkedRef } from '../../
|
|
6
|
+
import { useForkedRef } from '../../hooks'
|
|
7
7
|
|
|
8
8
|
export interface CCollapseProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
9
|
/**
|
|
@@ -23,7 +23,7 @@ export interface CDatePickerProps
|
|
|
23
23
|
* The id global attribute defines an identifier (ID) that must be unique in the whole document.
|
|
24
24
|
*
|
|
25
25
|
* The name attribute for the input element is generated based on the `id` property:
|
|
26
|
-
* - {id}-date
|
|
26
|
+
* - \{id\}-date
|
|
27
27
|
*/
|
|
28
28
|
id?: string
|
|
29
29
|
/**
|
|
@@ -12,7 +12,7 @@ import { CFormControlWrapper, CFormControlWrapperProps } from '../form/CFormCont
|
|
|
12
12
|
import { CPicker, CPickerProps } from '../picker/CPicker'
|
|
13
13
|
import { CTimePicker } from '../time-picker/CTimePicker'
|
|
14
14
|
|
|
15
|
-
import { getLocalDateFromString } from '
|
|
15
|
+
import { getLocalDateFromString } from '../calendar/utils'
|
|
16
16
|
|
|
17
17
|
import { Colors } from '../Types'
|
|
18
18
|
export interface CDateRangePickerProps
|
|
@@ -46,8 +46,8 @@ export interface CDateRangePickerProps
|
|
|
46
46
|
* The id global attribute defines an identifier (ID) that must be unique in the whole document.
|
|
47
47
|
*
|
|
48
48
|
* The name attributes for input elements are generated based on the `id` property:
|
|
49
|
-
* - {id}-start-date
|
|
50
|
-
* - {id}-end-date
|
|
49
|
+
* - \{id\}-start-date
|
|
50
|
+
* - \{id\}-end-date
|
|
51
51
|
*/
|
|
52
52
|
id?: string
|
|
53
53
|
/**
|
|
@@ -13,7 +13,7 @@ import classNames from 'classnames'
|
|
|
13
13
|
import { Manager } from 'react-popper'
|
|
14
14
|
|
|
15
15
|
import { Placements, placementPropType } from '../Types'
|
|
16
|
-
import { useForkedRef } from '../../
|
|
16
|
+
import { useForkedRef } from '../../hooks'
|
|
17
17
|
|
|
18
18
|
export type Directions = 'start' | 'end'
|
|
19
19
|
|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { Reference } from 'react-popper'
|
|
5
5
|
|
|
6
|
-
import { useForkedRef } from '../../
|
|
6
|
+
import { useForkedRef } from '../../hooks'
|
|
7
7
|
|
|
8
8
|
import { Triggers, triggerPropType } from '../Types'
|
|
9
9
|
|
|
@@ -9,26 +9,22 @@ import React, {
|
|
|
9
9
|
} from 'react'
|
|
10
10
|
import classNames from 'classnames'
|
|
11
11
|
|
|
12
|
-
import { useForkedRef } from '../../
|
|
12
|
+
import { useForkedRef } from '../../hooks'
|
|
13
13
|
import { CSpinner } from '../spinner/CSpinner'
|
|
14
14
|
|
|
15
15
|
interface CElementCoverProps extends HTMLAttributes<HTMLDivElement> {
|
|
16
16
|
/**
|
|
17
|
-
* A string of all className you want applied to the base component.
|
|
17
|
+
* A string of all className you want applied to the base component.
|
|
18
18
|
*/
|
|
19
19
|
className?: string
|
|
20
20
|
/**
|
|
21
21
|
* Array of custom boundaries. Use to create custom cover area (instead of parent element area). Area is defined by four sides: 'top', 'bottom', 'right', 'left'. If side is not defined by any custom boundary it is equal to parent element boundary. Each custom boundary is object with keys:
|
|
22
22
|
* - sides (array) - select boundaries of element to define boundaries. Sides names: 'top', 'bottom', 'right', 'left'.
|
|
23
|
-
* - query (string) - query used to get element which define boundaries. Search will be done only inside parent element, by parent.querySelector(query) function.
|
|
24
|
-
*
|
|
25
|
-
* @type {sides: string[], query: string}[]
|
|
23
|
+
* - query (string) - query used to get element which define boundaries. Search will be done only inside parent element, by parent.querySelector(query) function.
|
|
26
24
|
*/
|
|
27
|
-
boundaries?: { sides: string[]; query: string }[]
|
|
25
|
+
boundaries?: { sides: string[]; query: string }[]
|
|
28
26
|
/**
|
|
29
|
-
* Opacity of the cover.
|
|
30
|
-
*
|
|
31
|
-
* @type number
|
|
27
|
+
* Opacity of the cover.
|
|
32
28
|
*/
|
|
33
29
|
opacity?: number
|
|
34
30
|
}
|
|
@@ -36,17 +32,18 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
|
|
|
36
32
|
({ children, className, boundaries, opacity = 0.4, ...rest }, ref) => {
|
|
37
33
|
const elementCoverRef = useRef<HTMLDivElement>(null)
|
|
38
34
|
const forkedRef = useForkedRef(ref, elementCoverRef)
|
|
39
|
-
|
|
40
35
|
const [customBoundaries, setCustomBoundaries] = useState({})
|
|
41
36
|
|
|
42
37
|
const getCustomBoundaries = () => {
|
|
43
38
|
if (!elementCoverRef || !elementCoverRef.current || !boundaries) {
|
|
44
39
|
return {}
|
|
45
40
|
}
|
|
41
|
+
|
|
46
42
|
const parent = elementCoverRef.current.parentElement
|
|
47
43
|
if (!parent) {
|
|
48
44
|
return {}
|
|
49
45
|
}
|
|
46
|
+
|
|
50
47
|
const parentCoords = parent.getBoundingClientRect()
|
|
51
48
|
const customBoundaries = {}
|
|
52
49
|
boundaries.forEach(({ sides, query }) => {
|
|
@@ -54,6 +51,7 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
|
|
|
54
51
|
if (!element || !sides) {
|
|
55
52
|
return
|
|
56
53
|
}
|
|
54
|
+
|
|
57
55
|
const coords = element.getBoundingClientRect()
|
|
58
56
|
sides.forEach((side) => {
|
|
59
57
|
const sideMargin = Math.abs(coords[side] - parentCoords[side])
|
|
@@ -67,8 +65,6 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
|
|
|
67
65
|
setCustomBoundaries(getCustomBoundaries())
|
|
68
66
|
}, [JSON.stringify(getCustomBoundaries())])
|
|
69
67
|
|
|
70
|
-
//render
|
|
71
|
-
|
|
72
68
|
const classes = classNames(className)
|
|
73
69
|
|
|
74
70
|
const containerCoords = {
|
|
@@ -82,23 +78,21 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
|
|
|
82
78
|
const coverStyles: CSSProperties = {
|
|
83
79
|
...containerCoords,
|
|
84
80
|
position: 'absolute',
|
|
85
|
-
backgroundColor: `
|
|
81
|
+
backgroundColor: `rgba(255,255,255,${opacity})`,
|
|
86
82
|
}
|
|
87
83
|
|
|
88
84
|
return (
|
|
89
85
|
<div className={classes} style={coverStyles} {...rest} ref={forkedRef}>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
</div>
|
|
101
|
-
)}
|
|
86
|
+
<div
|
|
87
|
+
style={{
|
|
88
|
+
position: 'absolute',
|
|
89
|
+
top: '50%',
|
|
90
|
+
left: '50%',
|
|
91
|
+
transform: 'translateX(-50%) translateY(-50%)',
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
{children || <CSpinner variant="grow" color="primary" />}
|
|
95
|
+
</div>
|
|
102
96
|
</div>
|
|
103
97
|
)
|
|
104
98
|
},
|
|
@@ -2,7 +2,7 @@ import React, { forwardRef, InputHTMLAttributes, ReactNode, useEffect, useRef }
|
|
|
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
|
import { Colors, Shapes } from '../Types'
|
|
7
7
|
|
|
8
8
|
import { CFormControlValidation, CFormControlValidationProps } from './CFormControlValidation'
|
|
@@ -57,37 +57,31 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
|
|
|
57
57
|
tooltipFeedback,
|
|
58
58
|
valid,
|
|
59
59
|
}) => {
|
|
60
|
+
const formControlValidation = () => (
|
|
61
|
+
<CFormControlValidation
|
|
62
|
+
describedby={describedby}
|
|
63
|
+
feedback={feedback}
|
|
64
|
+
feedbackInvalid={feedbackInvalid}
|
|
65
|
+
feedbackValid={feedbackValid}
|
|
66
|
+
floatingLabel={floatingLabel}
|
|
67
|
+
invalid={invalid}
|
|
68
|
+
tooltipFeedback={tooltipFeedback}
|
|
69
|
+
valid={valid}
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
60
72
|
return floatingLabel ? (
|
|
61
73
|
<CFormFloating className={floatingClassName}>
|
|
62
74
|
{children}
|
|
63
75
|
<CFormLabel htmlFor={id}>{label || floatingLabel}</CFormLabel>
|
|
64
76
|
{text && <CFormText id={describedby}>{text}</CFormText>}
|
|
65
|
-
|
|
66
|
-
describedby={describedby}
|
|
67
|
-
feedback={feedback}
|
|
68
|
-
feedbackInvalid={feedbackInvalid}
|
|
69
|
-
feedbackValid={feedbackValid}
|
|
70
|
-
floatingLabel={floatingLabel}
|
|
71
|
-
invalid={invalid}
|
|
72
|
-
tooltipFeedback={tooltipFeedback}
|
|
73
|
-
valid={valid}
|
|
74
|
-
/>
|
|
77
|
+
{formControlValidation()}
|
|
75
78
|
</CFormFloating>
|
|
76
79
|
) : (
|
|
77
80
|
<>
|
|
78
81
|
{label && <CFormLabel htmlFor={id}>{label}</CFormLabel>}
|
|
79
82
|
{children}
|
|
80
83
|
{text && <CFormText id={describedby}>{text}</CFormText>}
|
|
81
|
-
|
|
82
|
-
describedby={describedby}
|
|
83
|
-
feedback={feedback}
|
|
84
|
-
feedbackInvalid={feedbackInvalid}
|
|
85
|
-
feedbackValid={feedbackValid}
|
|
86
|
-
floatingLabel={floatingLabel}
|
|
87
|
-
invalid={invalid}
|
|
88
|
-
tooltipFeedback={tooltipFeedback}
|
|
89
|
-
valid={valid}
|
|
90
|
-
/>
|
|
84
|
+
{formControlValidation()}
|
|
91
85
|
</>
|
|
92
86
|
)
|
|
93
87
|
}
|
|
@@ -26,7 +26,7 @@ export interface CFormInputProps
|
|
|
26
26
|
*/
|
|
27
27
|
onChange?: ChangeEventHandler<HTMLInputElement>
|
|
28
28
|
/**
|
|
29
|
-
* Render the component styled as plain text. Removes the default form field styling and preserve the correct margin and padding. Recommend to use only along side `readonly
|
|
29
|
+
* Render the component styled as plain text. Removes the default form field styling and preserve the correct margin and padding. Recommend to use only along side `readonly`.
|
|
30
30
|
*/
|
|
31
31
|
plainText?: boolean
|
|
32
32
|
/**
|
|
@@ -22,7 +22,7 @@ export interface CFormSwitchProps extends Omit<InputHTMLAttributes<HTMLInputElem
|
|
|
22
22
|
*/
|
|
23
23
|
label?: string | ReactNode
|
|
24
24
|
/**
|
|
25
|
-
* Size the component large or extra large. Works only with `switch
|
|
25
|
+
* Size the component large or extra large. Works only with `switch`.
|
|
26
26
|
*/
|
|
27
27
|
size?: 'lg' | 'xl'
|
|
28
28
|
/**
|
package/src/components/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './collapse'
|
|
|
14
14
|
export * from './date-picker'
|
|
15
15
|
export * from './date-range-picker'
|
|
16
16
|
export * from './dropdown'
|
|
17
|
+
export * from './element-cover'
|
|
17
18
|
export * from './footer'
|
|
18
19
|
export * from './form'
|
|
19
20
|
export * from './grid'
|
|
@@ -40,4 +41,5 @@ export * from './tabs'
|
|
|
40
41
|
export * from './time-picker'
|
|
41
42
|
export * from './toast'
|
|
42
43
|
export * from './tooltip'
|
|
44
|
+
export * from './virtual-scroller'
|
|
43
45
|
export * from './widgets'
|
|
@@ -13,7 +13,7 @@ import PropTypes from 'prop-types'
|
|
|
13
13
|
import classNames from 'classnames'
|
|
14
14
|
import { Transition } from 'react-transition-group'
|
|
15
15
|
|
|
16
|
-
import { useForkedRef } from '../../
|
|
16
|
+
import { useForkedRef } from '../../hooks'
|
|
17
17
|
|
|
18
18
|
import { CBackdrop } from '../backdrop/CBackdrop'
|
|
19
19
|
import { CModalContent } from './CModalContent'
|
|
@@ -15,19 +15,19 @@ import { CNavContext } from '../sidebar/CSidebarNav'
|
|
|
15
15
|
export interface CNavGroupProps {
|
|
16
16
|
children?: ReactNode
|
|
17
17
|
/**
|
|
18
|
-
* A string of all className you want applied to the component.
|
|
18
|
+
* A string of all className you want applied to the component.
|
|
19
19
|
*/
|
|
20
20
|
className?: string
|
|
21
21
|
/**
|
|
22
|
-
* Make nav group more compact by cutting all `padding` in half.
|
|
22
|
+
* Make nav group more compact by cutting all `padding` in half.
|
|
23
23
|
*/
|
|
24
24
|
compact?: boolean
|
|
25
25
|
/**
|
|
26
|
-
* Set group toggler label.
|
|
26
|
+
* Set group toggler label.
|
|
27
27
|
*/
|
|
28
28
|
toggler?: string | ReactNode
|
|
29
29
|
/**
|
|
30
|
-
* Show nav group items.
|
|
30
|
+
* Show nav group items.
|
|
31
31
|
*/
|
|
32
32
|
visible?: boolean
|
|
33
33
|
/**
|
|
@@ -2,10 +2,11 @@ import React, { ElementType, forwardRef, useContext, useEffect, useRef } from 'r
|
|
|
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
|
import { CNavContext } from '../sidebar/CSidebarNav'
|
|
8
8
|
import { CLinkProps, CLink } from '../link/CLink'
|
|
9
|
+
|
|
9
10
|
export interface CNavLinkProps extends Omit<CLinkProps, 'idx'> {
|
|
10
11
|
/**
|
|
11
12
|
* Toggle the active state for the component.
|
|
@@ -4,20 +4,20 @@ import { createPortal } from 'react-dom'
|
|
|
4
4
|
import { Transition } from 'react-transition-group'
|
|
5
5
|
import classNames from 'classnames'
|
|
6
6
|
|
|
7
|
-
import { useForkedRef } from '../../
|
|
7
|
+
import { useForkedRef } from '../../hooks'
|
|
8
8
|
import { CBackdrop } from '../backdrop/CBackdrop'
|
|
9
9
|
|
|
10
10
|
export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
|
|
11
11
|
/**
|
|
12
12
|
* Apply a backdrop on body while offcanvas is open.
|
|
13
13
|
*/
|
|
14
|
-
backdrop?: boolean
|
|
14
|
+
backdrop?: boolean | 'static'
|
|
15
15
|
/**
|
|
16
16
|
* A string of all className you want applied to the base component.
|
|
17
17
|
*/
|
|
18
18
|
className?: string
|
|
19
19
|
/**
|
|
20
|
-
* Closes the offcanvas when escape key is pressed
|
|
20
|
+
* Closes the offcanvas when escape key is pressed.
|
|
21
21
|
*/
|
|
22
22
|
keyboard?: boolean
|
|
23
23
|
/**
|
|
@@ -36,6 +36,12 @@ export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
36
36
|
* Generates modal using createPortal.
|
|
37
37
|
*/
|
|
38
38
|
portal?: boolean
|
|
39
|
+
/**
|
|
40
|
+
* Responsive offcanvas property hide content outside the viewport from a specified breakpoint and down.
|
|
41
|
+
*
|
|
42
|
+
* @since 4.6.0
|
|
43
|
+
*/
|
|
44
|
+
responsive?: boolean | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
|
|
39
45
|
/**
|
|
40
46
|
* Allow body scrolling while offcanvas is open
|
|
41
47
|
*/
|
|
@@ -56,7 +62,8 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
56
62
|
onHide,
|
|
57
63
|
onShow,
|
|
58
64
|
placement,
|
|
59
|
-
portal =
|
|
65
|
+
portal = false,
|
|
66
|
+
responsive = true,
|
|
60
67
|
scroll = false,
|
|
61
68
|
visible = false,
|
|
62
69
|
...rest
|
|
@@ -86,26 +93,34 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
86
93
|
}
|
|
87
94
|
}, [_visible])
|
|
88
95
|
|
|
96
|
+
const getTransitionClass = (state: string) => {
|
|
97
|
+
return state === 'entering'
|
|
98
|
+
? 'showing'
|
|
99
|
+
: state === 'entered'
|
|
100
|
+
? 'show'
|
|
101
|
+
: state === 'exiting'
|
|
102
|
+
? 'show hiding'
|
|
103
|
+
: ''
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
const _className = classNames(
|
|
90
|
-
'offcanvas',
|
|
91
107
|
{
|
|
108
|
+
[`offcanvas${typeof responsive !== 'boolean' ? '-' + responsive : ''}`]: responsive,
|
|
92
109
|
[`offcanvas-${placement}`]: placement,
|
|
93
|
-
show: _visible,
|
|
94
110
|
},
|
|
95
111
|
className,
|
|
96
112
|
)
|
|
97
113
|
|
|
98
|
-
const transitionStyles = {
|
|
99
|
-
entering: { visibility: 'visible' },
|
|
100
|
-
entered: { visibility: 'visible' },
|
|
101
|
-
exiting: { visibility: 'visible' },
|
|
102
|
-
exited: { visibility: 'hidden' },
|
|
103
|
-
}
|
|
104
|
-
|
|
105
114
|
const handleDismiss = () => {
|
|
106
115
|
setVisible(false)
|
|
107
116
|
}
|
|
108
117
|
|
|
118
|
+
const handleBackdropDismiss = () => {
|
|
119
|
+
if (backdrop !== 'static') {
|
|
120
|
+
setVisible(false)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
const handleKeyDown = useCallback(
|
|
110
125
|
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
111
126
|
if (event.key === 'Escape' && keyboard) {
|
|
@@ -119,9 +134,8 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
119
134
|
return (
|
|
120
135
|
<>
|
|
121
136
|
<div
|
|
122
|
-
className={_className}
|
|
137
|
+
className={classNames(_className, getTransitionClass(state))}
|
|
123
138
|
role="dialog"
|
|
124
|
-
style={{ ...transitionStyles[state] }}
|
|
125
139
|
tabIndex={-1}
|
|
126
140
|
onKeyDown={handleKeyDown}
|
|
127
141
|
{...rest}
|
|
@@ -154,7 +168,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
154
168
|
createPortal(
|
|
155
169
|
<CBackdrop
|
|
156
170
|
className="offcanvas-backdrop"
|
|
157
|
-
onClick={
|
|
171
|
+
onClick={handleBackdropDismiss}
|
|
158
172
|
visible={_visible}
|
|
159
173
|
/>,
|
|
160
174
|
document.body,
|
|
@@ -162,7 +176,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
162
176
|
: backdrop && (
|
|
163
177
|
<CBackdrop
|
|
164
178
|
className="offcanvas-backdrop"
|
|
165
|
-
onClick={
|
|
179
|
+
onClick={handleBackdropDismiss}
|
|
166
180
|
visible={_visible}
|
|
167
181
|
/>
|
|
168
182
|
)}
|
|
@@ -172,7 +186,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
172
186
|
)
|
|
173
187
|
|
|
174
188
|
COffcanvas.propTypes = {
|
|
175
|
-
backdrop: PropTypes.bool,
|
|
189
|
+
backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf<'static'>(['static'])]),
|
|
176
190
|
children: PropTypes.node,
|
|
177
191
|
className: PropTypes.string,
|
|
178
192
|
keyboard: PropTypes.bool,
|
|
@@ -181,6 +195,10 @@ COffcanvas.propTypes = {
|
|
|
181
195
|
placement: PropTypes.oneOf<'start' | 'end' | 'top' | 'bottom'>(['start', 'end', 'top', 'bottom'])
|
|
182
196
|
.isRequired,
|
|
183
197
|
portal: PropTypes.bool,
|
|
198
|
+
responsive: PropTypes.oneOfType([
|
|
199
|
+
PropTypes.bool,
|
|
200
|
+
PropTypes.oneOf<'sm' | 'md' | 'lg' | 'xl' | 'xxl'>(['sm', 'md', 'lg', 'xl', 'xxl']),
|
|
201
|
+
]),
|
|
184
202
|
scroll: PropTypes.bool,
|
|
185
203
|
visible: PropTypes.bool,
|
|
186
204
|
}
|
|
@@ -3,8 +3,8 @@ import { createPortal } from 'react-dom'
|
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
import classNames from 'classnames'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import { useForkedRef } from '../../
|
|
6
|
+
import { isInViewport } from '../../utils'
|
|
7
|
+
import { useForkedRef } from '../../hooks'
|
|
8
8
|
import { CBackdrop } from '../backdrop/CBackdrop'
|
|
9
9
|
|
|
10
10
|
export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
|
|
@@ -13,13 +13,13 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
13
13
|
*/
|
|
14
14
|
className?: string
|
|
15
15
|
/**
|
|
16
|
-
* Sets if the color of text should be colored for a light or dark dark background.
|
|
16
|
+
* Sets if the color of text should be colored for a light or dark dark background.
|
|
17
17
|
*
|
|
18
18
|
* @type 'dark' | 'light'
|
|
19
19
|
*/
|
|
20
20
|
colorScheme?: 'dark' | 'light'
|
|
21
21
|
/**
|
|
22
|
-
* Make sidebar narrow.
|
|
22
|
+
* Make sidebar narrow.
|
|
23
23
|
*/
|
|
24
24
|
narrow?: boolean
|
|
25
25
|
/**
|
|
@@ -39,12 +39,12 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
39
39
|
*/
|
|
40
40
|
overlaid?: boolean
|
|
41
41
|
/**
|
|
42
|
-
* Components placement, there’s no default placement.
|
|
42
|
+
* Components placement, there’s no default placement.
|
|
43
43
|
* @type 'start' | 'end'
|
|
44
44
|
*/
|
|
45
45
|
placement?: 'start' | 'end'
|
|
46
46
|
/**
|
|
47
|
-
* Place sidebar in non-static positions.
|
|
47
|
+
* Place sidebar in non-static positions.
|
|
48
48
|
*/
|
|
49
49
|
position?: 'fixed' | 'sticky'
|
|
50
50
|
/**
|
|
@@ -108,7 +108,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
108
108
|
|
|
109
109
|
useEffect(() => {
|
|
110
110
|
sidebarRef.current && setMobile(isOnMobile(sidebarRef.current))
|
|
111
|
-
sidebarRef.current && setInViewport(
|
|
111
|
+
sidebarRef.current && setInViewport(isInViewport(sidebarRef.current))
|
|
112
112
|
|
|
113
113
|
window.addEventListener('resize', () => handleResize())
|
|
114
114
|
window.addEventListener('mouseup', handleClickOutside)
|
|
@@ -116,7 +116,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
116
116
|
|
|
117
117
|
sidebarRef.current?.addEventListener('mouseup', handleOnClick)
|
|
118
118
|
sidebarRef.current?.addEventListener('transitionend', () => {
|
|
119
|
-
sidebarRef.current && setInViewport(
|
|
119
|
+
sidebarRef.current && setInViewport(isInViewport(sidebarRef.current))
|
|
120
120
|
})
|
|
121
121
|
|
|
122
122
|
return () => {
|
|
@@ -126,7 +126,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
126
126
|
|
|
127
127
|
sidebarRef.current?.removeEventListener('mouseup', handleOnClick)
|
|
128
128
|
sidebarRef.current?.removeEventListener('transitionend', () => {
|
|
129
|
-
sidebarRef.current && setInViewport(
|
|
129
|
+
sidebarRef.current && setInViewport(isInViewport(sidebarRef.current))
|
|
130
130
|
})
|
|
131
131
|
}
|
|
132
132
|
})
|
|
@@ -137,7 +137,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
137
137
|
|
|
138
138
|
const handleResize = () => {
|
|
139
139
|
sidebarRef.current && setMobile(isOnMobile(sidebarRef.current))
|
|
140
|
-
sidebarRef.current && setInViewport(
|
|
140
|
+
sidebarRef.current && setInViewport(isInViewport(sidebarRef.current))
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
const handleKeyup = (event: Event) => {
|