@coreui/react-pro 5.10.0 → 5.12.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/cjs/components/accordion/CAccordionBody.js +2 -2
- package/dist/cjs/components/accordion/CAccordionBody.js.map +1 -1
- package/dist/cjs/components/accordion/CAccordionButton.js +2 -2
- package/dist/cjs/components/accordion/CAccordionButton.js.map +1 -1
- package/dist/cjs/components/accordion/CAccordionItem.d.ts +5 -0
- package/dist/cjs/components/accordion/CAccordionItem.js +7 -4
- package/dist/cjs/components/accordion/CAccordionItem.js.map +1 -1
- package/dist/cjs/components/badge/CBadge.js +1 -1
- package/dist/cjs/components/badge/CBadge.js.map +1 -1
- package/dist/cjs/components/calendar/CCalendar.d.ts +57 -44
- package/dist/cjs/components/calendar/CCalendar.js +51 -187
- package/dist/cjs/components/calendar/CCalendar.js.map +1 -1
- package/dist/cjs/components/calendar/CCalendarNavigation.d.ts +21 -0
- package/dist/cjs/components/calendar/CCalendarNavigation.js +23 -0
- package/dist/cjs/components/calendar/CCalendarNavigation.js.map +1 -0
- package/dist/cjs/components/calendar/CCalendarPanel.d.ts +28 -0
- package/dist/cjs/components/calendar/CCalendarPanel.js +149 -0
- package/dist/cjs/components/calendar/CCalendarPanel.js.map +1 -0
- package/dist/cjs/components/calendar/types.d.ts +3 -0
- package/dist/cjs/components/calendar/utils.d.ts +175 -18
- package/dist/cjs/components/calendar/utils.js +312 -43
- package/dist/cjs/components/calendar/utils.js.map +1 -1
- package/dist/cjs/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/cjs/components/date-range-picker/CDateRangePicker.d.ts +2 -2
- package/dist/cjs/components/date-range-picker/CDateRangePicker.js +0 -2
- package/dist/cjs/components/date-range-picker/CDateRangePicker.js.map +1 -1
- package/dist/cjs/components/date-range-picker/utils.d.ts +16 -0
- package/dist/cjs/components/date-range-picker/utils.js +18 -2
- package/dist/cjs/components/date-range-picker/utils.js.map +1 -1
- package/dist/cjs/components/dropdown/CDropdown.d.ts +77 -20
- package/dist/cjs/components/dropdown/CDropdown.js +6 -3
- package/dist/cjs/components/dropdown/CDropdown.js.map +1 -1
- package/dist/cjs/components/dropdown/CDropdownMenu.js +1 -1
- package/dist/cjs/components/dropdown/CDropdownMenu.js.map +1 -1
- package/dist/cjs/components/dropdown/CDropdownToggle.js +1 -1
- package/dist/cjs/components/dropdown/CDropdownToggle.js.map +1 -1
- package/dist/cjs/components/modal/CModal.js +0 -1
- package/dist/cjs/components/modal/CModal.js.map +1 -1
- package/dist/cjs/components/nav/CNavGroup.js +1 -1
- package/dist/cjs/components/nav/CNavGroup.js.map +1 -1
- package/dist/cjs/components/popover/CPopover.d.ts +75 -20
- package/dist/cjs/components/popover/CPopover.js +8 -21
- package/dist/cjs/components/popover/CPopover.js.map +1 -1
- package/dist/cjs/components/progress/CProgress.d.ts +1 -1
- package/dist/cjs/components/range-slider/CRangeSlider.js +6 -2
- package/dist/cjs/components/range-slider/CRangeSlider.js.map +1 -1
- package/dist/cjs/components/sidebar/CSidebar.d.ts +7 -2
- package/dist/cjs/components/sidebar/CSidebar.js +7 -6
- package/dist/cjs/components/sidebar/CSidebar.js.map +1 -1
- package/dist/cjs/components/smart-pagination/CSmartPagination.d.ts +4 -12
- package/dist/cjs/components/smart-pagination/CSmartPagination.js.map +1 -1
- package/dist/cjs/components/smart-table/CSmartTableHead.js +12 -25
- package/dist/cjs/components/smart-table/CSmartTableHead.js.map +1 -1
- package/dist/cjs/components/smart-table/types.d.ts +1 -1
- package/dist/cjs/components/time-picker/CTimePicker.d.ts +1 -1
- package/dist/cjs/components/time-picker/CTimePicker.js.map +1 -1
- package/dist/cjs/components/time-picker/types.d.ts +5 -0
- package/dist/cjs/components/time-picker/utils.d.ts +8 -11
- package/dist/cjs/components/time-picker/utils.js +8 -4
- package/dist/cjs/components/time-picker/utils.js.map +1 -1
- package/dist/cjs/components/tooltip/CTooltip.d.ts +67 -15
- package/dist/cjs/components/tooltip/CTooltip.js +8 -21
- package/dist/cjs/components/tooltip/CTooltip.js.map +1 -1
- package/dist/cjs/hooks/index.d.ts +2 -1
- package/dist/cjs/hooks/useClipboard.d.ts +12 -0
- package/dist/cjs/hooks/useClipboard.js +54 -0
- package/dist/cjs/hooks/useClipboard.js.map +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node_modules/react-device-detect/dist/lib.js +1 -1
- package/dist/cjs/node_modules/react-device-detect/dist/lib.js.map +1 -1
- package/dist/cjs/node_modules/tslib/tslib.es6.js +40 -0
- package/dist/cjs/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +2 -1
- package/dist/cjs/utils/mergeClassNames.d.ts +2 -0
- package/dist/esm/components/accordion/CAccordionBody.js +2 -2
- package/dist/esm/components/accordion/CAccordionBody.js.map +1 -1
- package/dist/esm/components/accordion/CAccordionButton.js +2 -2
- package/dist/esm/components/accordion/CAccordionButton.js.map +1 -1
- package/dist/esm/components/accordion/CAccordionItem.d.ts +5 -0
- package/dist/esm/components/accordion/CAccordionItem.js +8 -5
- package/dist/esm/components/accordion/CAccordionItem.js.map +1 -1
- package/dist/esm/components/badge/CBadge.js +1 -1
- package/dist/esm/components/badge/CBadge.js.map +1 -1
- package/dist/esm/components/calendar/CCalendar.d.ts +57 -44
- package/dist/esm/components/calendar/CCalendar.js +52 -188
- package/dist/esm/components/calendar/CCalendar.js.map +1 -1
- package/dist/esm/components/calendar/CCalendarNavigation.d.ts +21 -0
- package/dist/esm/components/calendar/CCalendarNavigation.js +21 -0
- package/dist/esm/components/calendar/CCalendarNavigation.js.map +1 -0
- package/dist/esm/components/calendar/CCalendarPanel.d.ts +28 -0
- package/dist/esm/components/calendar/CCalendarPanel.js +147 -0
- package/dist/esm/components/calendar/CCalendarPanel.js.map +1 -0
- package/dist/esm/components/calendar/types.d.ts +3 -0
- package/dist/esm/components/calendar/utils.d.ts +175 -18
- package/dist/esm/components/calendar/utils.js +306 -44
- package/dist/esm/components/calendar/utils.js.map +1 -1
- package/dist/esm/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/esm/components/date-range-picker/CDateRangePicker.d.ts +2 -2
- package/dist/esm/components/date-range-picker/CDateRangePicker.js +0 -2
- package/dist/esm/components/date-range-picker/CDateRangePicker.js.map +1 -1
- package/dist/esm/components/date-range-picker/utils.d.ts +16 -0
- package/dist/esm/components/date-range-picker/utils.js +18 -2
- package/dist/esm/components/date-range-picker/utils.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdown.d.ts +77 -20
- package/dist/esm/components/dropdown/CDropdown.js +6 -3
- package/dist/esm/components/dropdown/CDropdown.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdownMenu.js +1 -1
- package/dist/esm/components/dropdown/CDropdownMenu.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdownToggle.js +1 -1
- package/dist/esm/components/dropdown/CDropdownToggle.js.map +1 -1
- package/dist/esm/components/modal/CModal.js +0 -1
- package/dist/esm/components/modal/CModal.js.map +1 -1
- package/dist/esm/components/nav/CNavGroup.js +1 -1
- package/dist/esm/components/nav/CNavGroup.js.map +1 -1
- package/dist/esm/components/popover/CPopover.d.ts +75 -20
- package/dist/esm/components/popover/CPopover.js +8 -21
- package/dist/esm/components/popover/CPopover.js.map +1 -1
- package/dist/esm/components/progress/CProgress.d.ts +1 -1
- package/dist/esm/components/range-slider/CRangeSlider.js +6 -2
- package/dist/esm/components/range-slider/CRangeSlider.js.map +1 -1
- package/dist/esm/components/sidebar/CSidebar.d.ts +7 -2
- package/dist/esm/components/sidebar/CSidebar.js +7 -6
- package/dist/esm/components/sidebar/CSidebar.js.map +1 -1
- package/dist/esm/components/smart-pagination/CSmartPagination.d.ts +4 -12
- package/dist/esm/components/smart-pagination/CSmartPagination.js.map +1 -1
- package/dist/esm/components/smart-table/CSmartTableHead.js +13 -26
- package/dist/esm/components/smart-table/CSmartTableHead.js.map +1 -1
- package/dist/esm/components/smart-table/types.d.ts +1 -1
- package/dist/esm/components/time-picker/CTimePicker.d.ts +1 -1
- package/dist/esm/components/time-picker/CTimePicker.js.map +1 -1
- package/dist/esm/components/time-picker/types.d.ts +5 -0
- package/dist/esm/components/time-picker/utils.d.ts +8 -11
- package/dist/esm/components/time-picker/utils.js +8 -4
- package/dist/esm/components/time-picker/utils.js.map +1 -1
- package/dist/esm/components/tooltip/CTooltip.d.ts +67 -15
- package/dist/esm/components/tooltip/CTooltip.js +8 -21
- package/dist/esm/components/tooltip/CTooltip.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +2 -1
- package/dist/esm/hooks/useClipboard.d.ts +12 -0
- package/dist/esm/hooks/useClipboard.js +52 -0
- package/dist/esm/hooks/useClipboard.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node_modules/react-device-detect/dist/lib.js +1 -1
- package/dist/esm/node_modules/react-device-detect/dist/lib.js.map +1 -1
- package/dist/esm/node_modules/tslib/tslib.es6.js +39 -1
- package/dist/esm/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/esm/utils/index.d.ts +2 -1
- package/dist/esm/utils/mergeClassNames.d.ts +2 -0
- package/package.json +12 -10
- package/src/components/accordion/CAccordionBody.tsx +3 -3
- package/src/components/accordion/CAccordionButton.tsx +3 -2
- package/src/components/accordion/CAccordionItem.tsx +14 -5
- package/src/components/accordion/__tests__/__snapshots__/CAccordionButton.spec.tsx.snap +0 -2
- package/src/components/accordion/__tests__/__snapshots__/CAccordionHeader.spec.tsx.snap +0 -2
- package/src/components/badge/CBadge.tsx +1 -1
- package/src/components/calendar/CCalendar.tsx +154 -489
- package/src/components/calendar/CCalendarNavigation.tsx +120 -0
- package/src/components/calendar/CCalendarPanel.tsx +306 -0
- package/src/components/calendar/types.ts +5 -0
- package/src/components/calendar/utils.ts +414 -109
- package/src/components/carousel/__tests__/CCarousel.spec.tsx +1 -2
- package/src/components/date-picker/CDatePicker.tsx +1 -1
- package/src/components/date-range-picker/CDateRangePicker.tsx +2 -4
- package/src/components/date-range-picker/utils.ts +23 -3
- package/src/components/dropdown/CDropdown.tsx +106 -26
- package/src/components/dropdown/CDropdownMenu.tsx +0 -1
- package/src/components/dropdown/CDropdownToggle.tsx +1 -1
- package/src/components/dropdown/__tests__/CDropdown.spec.tsx +43 -19
- package/src/components/modal/CModal.tsx +0 -2
- package/src/components/modal/__tests__/CModal.spec.tsx +33 -25
- package/src/components/nav/CNavGroup.tsx +5 -1
- package/src/components/nav/__tests__/__snapshots__/CNavGroup.spec.tsx.snap +4 -1
- package/src/components/popover/CPopover.tsx +103 -43
- package/src/components/popover/__tests__/CPopover.spec.tsx +1 -1
- package/src/components/popover/__tests__/__snapshots__/CPopover.spec.tsx.snap +2 -3
- package/src/components/progress/CProgress.tsx +1 -1
- package/src/components/range-slider/CRangeSlider.tsx +7 -2
- package/src/components/sidebar/CSidebar.tsx +15 -5
- package/src/components/smart-pagination/CSmartPagination.tsx +4 -12
- package/src/components/smart-table/CSmartTableHead.tsx +10 -34
- package/src/components/smart-table/types.ts +7 -1
- package/src/components/time-picker/CTimePicker.tsx +3 -3
- package/src/components/time-picker/types.ts +7 -0
- package/src/components/time-picker/utils.ts +15 -13
- package/src/components/tooltip/CTooltip.tsx +94 -38
- package/src/components/tooltip/__tests__/__snapshots__/CTooltip.spec.tsx.snap +0 -1
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useClipboard.ts +38 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/mergeClassNames.ts +25 -0
|
@@ -9,6 +9,7 @@ import React, {
|
|
|
9
9
|
} from 'react'
|
|
10
10
|
import classNames from 'classnames'
|
|
11
11
|
import PropTypes from 'prop-types'
|
|
12
|
+
import type { Options } from '@popperjs/core'
|
|
12
13
|
|
|
13
14
|
import { CConditionalPortal } from '../conditional-portal'
|
|
14
15
|
import { useForkedRef, usePopper } from '../../hooks'
|
|
@@ -18,65 +19,132 @@ import { executeAfterTransition, getRTLPlacement } from '../../utils'
|
|
|
18
19
|
|
|
19
20
|
export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'content'> {
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
+
* Adds a fade transition animation to the React Popover.
|
|
22
23
|
*
|
|
23
24
|
* @since 4.9.0
|
|
24
25
|
*/
|
|
25
26
|
animation?: boolean
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
29
|
+
* Custom class name(s) for additional styling.
|
|
28
30
|
*/
|
|
29
31
|
className?: string
|
|
32
|
+
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
34
|
+
* Defines the container element to which the React Popover is appended.
|
|
35
|
+
* Accepts:
|
|
36
|
+
* - A DOM element (`HTMLElement` or `DocumentFragment`)
|
|
37
|
+
* - A function that returns a single element
|
|
38
|
+
* - `null` (defaults to `document.body`)
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* <CPopover container={document.getElementById('my-container')}>...</CPopover>
|
|
32
42
|
*
|
|
43
|
+
* @default document.body
|
|
33
44
|
* @since 4.11.0
|
|
34
45
|
*/
|
|
35
46
|
container?: DocumentFragment | Element | (() => DocumentFragment | Element | null) | null
|
|
47
|
+
|
|
36
48
|
/**
|
|
37
|
-
*
|
|
49
|
+
* Main content of the React Popover. It can be a string or any valid React node.
|
|
38
50
|
*/
|
|
39
51
|
content: ReactNode | string
|
|
52
|
+
|
|
40
53
|
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
54
|
+
* Delay (in milliseconds) before showing or hiding the React Popover.
|
|
55
|
+
* - If a number is provided, that delay applies to both "show" and "hide".
|
|
56
|
+
* - If an object is provided, use separate values for "show" and "hide".
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Delays 300ms on both show and hide
|
|
60
|
+
* <CPopover delay={300}>...</CPopover>
|
|
61
|
+
*
|
|
62
|
+
* // Delays 500ms on show and 100ms on hide
|
|
63
|
+
* <CPopover delay={{ show: 500, hide: 100 }}>...</CPopover>
|
|
46
64
|
*
|
|
47
65
|
* @since 4.9.0
|
|
48
66
|
*/
|
|
49
67
|
delay?: number | { show: number; hide: number }
|
|
68
|
+
|
|
50
69
|
/**
|
|
51
|
-
*
|
|
70
|
+
* Specifies the fallback placements when the preferred `placement` cannot be met.
|
|
52
71
|
*
|
|
72
|
+
* @type 'top', 'right', 'bottom', 'left' | ('top', 'right', 'bottom', 'left')[]
|
|
53
73
|
* @since 4.9.0
|
|
54
74
|
*/
|
|
55
75
|
fallbackPlacements?: Placements | Placements[]
|
|
76
|
+
|
|
56
77
|
/**
|
|
57
|
-
*
|
|
78
|
+
* Offset of the React Popover relative to its toggle element, in the form `[x, y]`.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Offset the menu 0px in X and 10px in Y direction
|
|
82
|
+
* <CPopover offset={[0, 10]}>...</CPopover>
|
|
83
|
+
*
|
|
84
|
+
* // Offset the menu 5px in both X and Y direction
|
|
85
|
+
* <CPopover offset={[5, 5]}>...</CPopover>
|
|
86
|
+
*/
|
|
87
|
+
offset?: [number, number]
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Invoked when the React Popover is about to hide.
|
|
58
91
|
*/
|
|
59
92
|
onHide?: () => void
|
|
93
|
+
|
|
60
94
|
/**
|
|
61
|
-
*
|
|
95
|
+
* Invoked when the React Popover is about to show.
|
|
62
96
|
*/
|
|
63
97
|
onShow?: () => void
|
|
98
|
+
|
|
64
99
|
/**
|
|
65
|
-
*
|
|
100
|
+
* Placement of the React Popover. Popper.js may override this based on available space.
|
|
66
101
|
*/
|
|
67
|
-
|
|
102
|
+
placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left'
|
|
103
|
+
|
|
68
104
|
/**
|
|
69
|
-
*
|
|
105
|
+
* Allows customization of the Popper.js configuration for the React Popover.
|
|
106
|
+
* Can be an object or a function returning a modified configuration.
|
|
107
|
+
* [Learn more](https://popper.js.org/docs/v2/constructors/#options)
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* <CPopover
|
|
111
|
+
* popperConfig={(defaultConfig) => ({
|
|
112
|
+
* ...defaultConfig,
|
|
113
|
+
* strategy: 'fixed',
|
|
114
|
+
* modifiers: [
|
|
115
|
+
* ...defaultConfig.modifiers,
|
|
116
|
+
* { name: 'computeStyles', options: { adaptive: false } },
|
|
117
|
+
* ],
|
|
118
|
+
* })}
|
|
119
|
+
* >...</CPopover>
|
|
70
120
|
*
|
|
71
|
-
* @
|
|
121
|
+
* @since 5.5.0
|
|
72
122
|
*/
|
|
73
|
-
|
|
123
|
+
popperConfig?: Partial<Options> | ((defaultPopperConfig: Partial<Options>) => Partial<Options>)
|
|
124
|
+
|
|
74
125
|
/**
|
|
75
|
-
*
|
|
126
|
+
* Title for the React Popover header. Can be a string or any valid React node.
|
|
76
127
|
*/
|
|
77
|
-
|
|
128
|
+
title?: ReactNode | string
|
|
129
|
+
|
|
78
130
|
/**
|
|
79
|
-
*
|
|
131
|
+
* Determines which events trigger the visibility of the React Popover. Can be a single trigger or an array of triggers.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* // Hover-only popover
|
|
135
|
+
* <CPopover trigger="hover">...</CPopover>
|
|
136
|
+
*
|
|
137
|
+
* // Hover + click combined
|
|
138
|
+
* <CPopover trigger={['hover', 'click']}>...</CPopover>
|
|
139
|
+
*
|
|
140
|
+
* @type 'hover' | 'focus' | 'click' | ('hover' | 'focus' | 'click')[]
|
|
141
|
+
*/
|
|
142
|
+
trigger?: Triggers | Triggers[]
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Controls the visibility of the React Popover.
|
|
146
|
+
* - `true` shows the popover.
|
|
147
|
+
* - `false` hides the popover.
|
|
80
148
|
*/
|
|
81
149
|
visible?: boolean
|
|
82
150
|
}
|
|
@@ -95,12 +163,13 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
95
163
|
onHide,
|
|
96
164
|
onShow,
|
|
97
165
|
placement = 'top',
|
|
166
|
+
popperConfig,
|
|
98
167
|
title,
|
|
99
168
|
trigger = 'click',
|
|
100
169
|
visible,
|
|
101
170
|
...rest
|
|
102
171
|
},
|
|
103
|
-
ref
|
|
172
|
+
ref
|
|
104
173
|
) => {
|
|
105
174
|
const popoverRef = useRef<HTMLDivElement>(null)
|
|
106
175
|
const togglerRef = useRef(null)
|
|
@@ -114,30 +183,20 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
114
183
|
|
|
115
184
|
const _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay
|
|
116
185
|
|
|
117
|
-
const
|
|
186
|
+
const defaultPopperConfig: Partial<Options> = {
|
|
118
187
|
modifiers: [
|
|
119
|
-
{
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
element: '.popover-arrow',
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
name: 'flip',
|
|
127
|
-
options: {
|
|
128
|
-
fallbackPlacements: fallbackPlacements,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: 'offset',
|
|
133
|
-
options: {
|
|
134
|
-
offset: offset,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
188
|
+
{ name: 'arrow', options: { element: '.popover-arrow' } },
|
|
189
|
+
{ name: 'flip', options: { fallbackPlacements } },
|
|
190
|
+
{ name: 'offset', options: { offset } },
|
|
137
191
|
],
|
|
138
192
|
placement: getRTLPlacement(placement, togglerRef.current),
|
|
139
193
|
}
|
|
140
194
|
|
|
195
|
+
const computedPopperConfig: Partial<Options> = {
|
|
196
|
+
...defaultPopperConfig,
|
|
197
|
+
...(typeof popperConfig === 'function' ? popperConfig(defaultPopperConfig) : popperConfig),
|
|
198
|
+
}
|
|
199
|
+
|
|
141
200
|
useEffect(() => {
|
|
142
201
|
if (visible) {
|
|
143
202
|
handleShow()
|
|
@@ -149,7 +208,7 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
149
208
|
|
|
150
209
|
useEffect(() => {
|
|
151
210
|
if (mounted && togglerRef.current && popoverRef.current) {
|
|
152
|
-
initPopper(togglerRef.current, popoverRef.current,
|
|
211
|
+
initPopper(togglerRef.current, popoverRef.current, computedPopperConfig)
|
|
153
212
|
setTimeout(() => {
|
|
154
213
|
setVisible(true)
|
|
155
214
|
}, _delay.show)
|
|
@@ -215,7 +274,7 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
215
274
|
fade: animation,
|
|
216
275
|
show: _visible,
|
|
217
276
|
},
|
|
218
|
-
className
|
|
277
|
+
className
|
|
219
278
|
)}
|
|
220
279
|
id={id}
|
|
221
280
|
ref={forkedRef}
|
|
@@ -230,7 +289,7 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
230
289
|
</CConditionalPortal>
|
|
231
290
|
</>
|
|
232
291
|
)
|
|
233
|
-
}
|
|
292
|
+
}
|
|
234
293
|
)
|
|
235
294
|
|
|
236
295
|
CPopover.propTypes = {
|
|
@@ -251,6 +310,7 @@ CPopover.propTypes = {
|
|
|
251
310
|
onHide: PropTypes.func,
|
|
252
311
|
onShow: PropTypes.func,
|
|
253
312
|
placement: PropTypes.oneOf(['auto', 'top', 'right', 'bottom', 'left']),
|
|
313
|
+
popperConfig: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
254
314
|
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
255
315
|
trigger: triggerPropType,
|
|
256
316
|
visible: PropTypes.bool,
|
|
@@ -31,7 +31,7 @@ test('CPopover customize', async () => {
|
|
|
31
31
|
expect(container).toMatchSnapshot()
|
|
32
32
|
let arrLength = container.getElementsByClassName('popover').length
|
|
33
33
|
expect(arrLength).toBe(1)
|
|
34
|
-
arrLength = container.getElementsByClassName('bs-popover-
|
|
34
|
+
arrLength = container.getElementsByClassName('bs-popover-auto').length
|
|
35
35
|
expect(arrLength).toBe(1)
|
|
36
36
|
arrLength = container.getElementsByClassName('popover-arrow').length
|
|
37
37
|
expect(arrLength).toBe(1)
|
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
exports[`CPopover customize 1`] = `
|
|
4
4
|
<body>
|
|
5
5
|
<button
|
|
6
|
-
aria-describedby="popover744956"
|
|
7
6
|
class="btn btn-primary"
|
|
8
7
|
type="button"
|
|
9
8
|
>
|
|
10
9
|
Test
|
|
11
10
|
</button>
|
|
12
11
|
<div
|
|
13
|
-
class="popover bs-popover-auto fade
|
|
14
|
-
id="
|
|
12
|
+
class="popover bs-popover-auto fade"
|
|
13
|
+
id="popover:r1:"
|
|
15
14
|
role="tooltip"
|
|
16
15
|
style="position: absolute; left: 0px; top: 0px; margin: 0px;"
|
|
17
16
|
>
|
|
@@ -207,7 +207,12 @@ export const CRangeSlider = forwardRef<HTMLDivElement, CRangeSliderProps>(
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
const handleInputsContainerMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
210
|
-
if (trackRef.current === null || event.button !== 0) {
|
|
210
|
+
if (trackRef.current === null || event.button !== 0 || disabled) {
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const target = event.target as HTMLDivElement | HTMLInputElement
|
|
215
|
+
if (!(target instanceof HTMLInputElement) && target !== trackRef.current) {
|
|
211
216
|
return
|
|
212
217
|
}
|
|
213
218
|
|
|
@@ -237,7 +242,7 @@ export const CRangeSlider = forwardRef<HTMLDivElement, CRangeSliderProps>(
|
|
|
237
242
|
}
|
|
238
243
|
|
|
239
244
|
const handleMouseMove = (event: MouseEvent) => {
|
|
240
|
-
if (!isDragging || trackRef.current === null) {
|
|
245
|
+
if (!isDragging || trackRef.current === null || disabled) {
|
|
241
246
|
return
|
|
242
247
|
}
|
|
243
248
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef, HTMLAttributes, useEffect, useRef, useState } from 'react'
|
|
1
|
+
import React, { ElementType, forwardRef, HTMLAttributes, useEffect, useRef, useState } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
import classNames from 'classnames'
|
|
@@ -7,8 +7,13 @@ import { CBackdrop } from '../backdrop'
|
|
|
7
7
|
|
|
8
8
|
import { isInViewport } from '../../utils'
|
|
9
9
|
import { useForkedRef } from '../../hooks'
|
|
10
|
+
import { PolymorphicRefForwardingComponent } from '../../helpers'
|
|
10
11
|
|
|
11
12
|
export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
|
|
13
|
+
/**
|
|
14
|
+
* Component used for the root node. Either a string to use a HTML element or a component.
|
|
15
|
+
*/
|
|
16
|
+
as?: ElementType
|
|
12
17
|
/**
|
|
13
18
|
* A string of all className you want applied to the component.
|
|
14
19
|
*/
|
|
@@ -65,10 +70,14 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
65
70
|
const isOnMobile = (element: HTMLDivElement) =>
|
|
66
71
|
Boolean(getComputedStyle(element).getPropertyValue('--cui-is-mobile'))
|
|
67
72
|
|
|
68
|
-
export const CSidebar
|
|
73
|
+
export const CSidebar: PolymorphicRefForwardingComponent<'div', CSidebarProps> = forwardRef<
|
|
74
|
+
HTMLDivElement,
|
|
75
|
+
CSidebarProps
|
|
76
|
+
>(
|
|
69
77
|
(
|
|
70
78
|
{
|
|
71
79
|
children,
|
|
80
|
+
as: Component = 'div',
|
|
72
81
|
className,
|
|
73
82
|
colorScheme,
|
|
74
83
|
narrow,
|
|
@@ -183,7 +192,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
183
192
|
|
|
184
193
|
return (
|
|
185
194
|
<>
|
|
186
|
-
<
|
|
195
|
+
<Component
|
|
187
196
|
className={classNames(
|
|
188
197
|
'sidebar',
|
|
189
198
|
{
|
|
@@ -203,7 +212,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
203
212
|
ref={forkedRef}
|
|
204
213
|
>
|
|
205
214
|
{children}
|
|
206
|
-
</
|
|
215
|
+
</Component>
|
|
207
216
|
{typeof window !== 'undefined' &&
|
|
208
217
|
mobile &&
|
|
209
218
|
createPortal(
|
|
@@ -216,6 +225,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
216
225
|
)
|
|
217
226
|
|
|
218
227
|
CSidebar.propTypes = {
|
|
228
|
+
as: PropTypes.elementType,
|
|
219
229
|
children: PropTypes.node,
|
|
220
230
|
className: PropTypes.string,
|
|
221
231
|
colorScheme: PropTypes.oneOf(['dark', 'light']),
|
|
@@ -231,4 +241,4 @@ CSidebar.propTypes = {
|
|
|
231
241
|
visible: PropTypes.bool,
|
|
232
242
|
}
|
|
233
243
|
|
|
234
|
-
CSidebar.displayName = 'CSidebar'
|
|
244
|
+
CSidebar.displayName = 'CSidebar'
|
|
@@ -26,27 +26,19 @@ export interface CSmartPaginationProps extends HTMLAttributes<HTMLUListElement>
|
|
|
26
26
|
*/
|
|
27
27
|
doubleArrows?: boolean
|
|
28
28
|
/**
|
|
29
|
-
* The content of
|
|
30
|
-
*
|
|
31
|
-
* @default '<React.Fragment>«</React.Fragment>''
|
|
29
|
+
* The content of `firstButton` button.
|
|
32
30
|
*/
|
|
33
31
|
firstButton?: ReactNode | string
|
|
34
32
|
/**
|
|
35
|
-
* The content of
|
|
36
|
-
*
|
|
37
|
-
* @default '<React.Fragment>‹</React.Fragment>'
|
|
33
|
+
* The content of `previousButton` button.
|
|
38
34
|
*/
|
|
39
35
|
previousButton?: ReactNode | string
|
|
40
36
|
/**
|
|
41
|
-
* The content of
|
|
42
|
-
*
|
|
43
|
-
* @default '<React.Fragment>›</React.Fragment>''
|
|
37
|
+
* The content of `nextButton` button.
|
|
44
38
|
*/
|
|
45
39
|
nextButton?: ReactNode | string
|
|
46
40
|
/**
|
|
47
|
-
* The content of
|
|
48
|
-
*
|
|
49
|
-
* @default '<React.Fragment>»</React.Fragment>'
|
|
41
|
+
* The content of `lastButton` button.
|
|
50
42
|
*/
|
|
51
43
|
lastButton?: ReactNode | string
|
|
52
44
|
/**
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
ElementType,
|
|
3
|
-
forwardRef,
|
|
4
|
-
ReactNode,
|
|
5
|
-
useEffect,
|
|
6
|
-
useMemo,
|
|
7
|
-
useRef,
|
|
8
|
-
useState,
|
|
9
|
-
} from 'react'
|
|
1
|
+
import React, { ElementType, forwardRef, ReactNode, useMemo, useRef } from 'react'
|
|
10
2
|
import PropTypes from 'prop-types'
|
|
11
3
|
|
|
12
4
|
import { CFormCheck, CFormInput } from '../form'
|
|
@@ -76,27 +68,9 @@ export const CSmartTableHead: PolymorphicRefForwardingComponent<'thead', CSmartT
|
|
|
76
68
|
ref,
|
|
77
69
|
) => {
|
|
78
70
|
const selectAllcheckboxRef = useRef<HTMLInputElement>(null)
|
|
79
|
-
const [refresh, setRefresh] = useState(false)
|
|
80
|
-
|
|
81
71
|
const _columns = useMemo(() => getColumns(columns), [columns])
|
|
82
72
|
const groups = useMemo(() => getColumnGroups(columns), [columns])
|
|
83
73
|
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
if (columnFilterState && Object.keys(columnFilterState).length === 0) {
|
|
86
|
-
setRefresh(true)
|
|
87
|
-
}
|
|
88
|
-
}, [columnFilterState])
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
setRefresh(true)
|
|
92
|
-
}, [items])
|
|
93
|
-
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (setRefresh) {
|
|
96
|
-
setRefresh(false)
|
|
97
|
-
}
|
|
98
|
-
}, [refresh])
|
|
99
|
-
|
|
100
74
|
const columnSorterIcon = (column: Column | string) => {
|
|
101
75
|
if (getColumnSorterState(getColumnKey(column), sorterState) === 0) {
|
|
102
76
|
return <span className="opacity-25 float-end me-1">{sortingIcon}</span>
|
|
@@ -161,18 +135,18 @@ export const CSmartTableHead: PolymorphicRefForwardingComponent<'thead', CSmartT
|
|
|
161
135
|
{...(isSortable && {
|
|
162
136
|
onClick: () => handleSort && handleSort(getColumnKey(column), index),
|
|
163
137
|
onKeyDown: (event) => {
|
|
164
|
-
if (event.key === 'Enter') {
|
|
165
|
-
handleSort
|
|
138
|
+
if (event.key === 'Enter' && handleSort) {
|
|
139
|
+
handleSort(getColumnKey(column), index)
|
|
166
140
|
}
|
|
167
141
|
|
|
168
|
-
if (event.key === 'ArrowUp') {
|
|
142
|
+
if (event.key === 'ArrowUp' && handleSort) {
|
|
169
143
|
event.preventDefault()
|
|
170
|
-
handleSort
|
|
144
|
+
handleSort(getColumnKey(column), index, 'asc')
|
|
171
145
|
}
|
|
172
146
|
|
|
173
|
-
if (event.key === 'ArrowDown') {
|
|
147
|
+
if (event.key === 'ArrowDown' && handleSort) {
|
|
174
148
|
event.preventDefault()
|
|
175
|
-
handleSort
|
|
149
|
+
handleSort(getColumnKey(column), index, 'desc')
|
|
176
150
|
}
|
|
177
151
|
},
|
|
178
152
|
tabIndex: 0,
|
|
@@ -198,12 +172,14 @@ export const CSmartTableHead: PolymorphicRefForwardingComponent<'thead', CSmartT
|
|
|
198
172
|
: true
|
|
199
173
|
) ? (
|
|
200
174
|
typeof column !== 'string' && typeof column.filter === 'function' ? (
|
|
201
|
-
!refresh &&
|
|
202
175
|
column.filter(
|
|
203
176
|
getColumnValues(items, getColumnKey(column)),
|
|
204
177
|
(value: any) =>
|
|
205
178
|
handleOnCustomFilterChange &&
|
|
206
179
|
handleOnCustomFilterChange(getColumnKey(column), value),
|
|
180
|
+
columnFilterState && columnFilterState[getColumnKey(column)]
|
|
181
|
+
? columnFilterState[getColumnKey(column)]
|
|
182
|
+
: undefined
|
|
207
183
|
)
|
|
208
184
|
) : (
|
|
209
185
|
<CFormInput
|
|
@@ -6,7 +6,13 @@ import { CTableRowProps } from '../table/CTableRow'
|
|
|
6
6
|
|
|
7
7
|
export type Column = {
|
|
8
8
|
children?: Column[]
|
|
9
|
-
filter?:
|
|
9
|
+
filter?:
|
|
10
|
+
| boolean
|
|
11
|
+
| ((
|
|
12
|
+
values: any[],
|
|
13
|
+
onChange: (value: any) => void,
|
|
14
|
+
state: ColumnFilterValue | undefined
|
|
15
|
+
) => ReactNode)
|
|
10
16
|
group?: string
|
|
11
17
|
key: string
|
|
12
18
|
label?: string
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from './utils'
|
|
20
20
|
|
|
21
21
|
import { Colors } from '../../types'
|
|
22
|
-
import type { LocalizedTimePartials } from './types'
|
|
22
|
+
import type { AmPm, LocalizedTimePartials } from './types'
|
|
23
23
|
import { useDebouncedCallback } from '../../hooks'
|
|
24
24
|
|
|
25
25
|
export interface CTimePickerProps
|
|
@@ -139,7 +139,7 @@ export interface CTimePickerProps
|
|
|
139
139
|
*
|
|
140
140
|
* @since 4.8.0
|
|
141
141
|
*/
|
|
142
|
-
seconds?: boolean | number[] | ((second: number) =>
|
|
142
|
+
seconds?: boolean | number[] | ((second: number) => boolean)
|
|
143
143
|
/**
|
|
144
144
|
* Size the component small or large.
|
|
145
145
|
*/
|
|
@@ -208,7 +208,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
|
|
|
208
208
|
const [date, setDate] = useState<Date | null>(convertTimeToDate(time))
|
|
209
209
|
const [initialDate, setInitialDate] = useState<Date | null>(null)
|
|
210
210
|
const [isValid, setIsValid] = useState(valid ?? (invalid === true ? false : undefined))
|
|
211
|
-
const [_ampm, setAmPm] = useState<
|
|
211
|
+
const [_ampm, setAmPm] = useState<AmPm>(date ? getAmPm(new Date(date), locale) : 'am')
|
|
212
212
|
const [_visible, setVisible] = useState(visible)
|
|
213
213
|
|
|
214
214
|
const [localizedTimePartials, setLocalizedTimePartials] = useState<LocalizedTimePartials>({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LocalizedTimePartials } from './types'
|
|
1
|
+
import type { AmPm, FormattedPartial, LocalizedTimePartials } from './types'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Converts a 12-hour time format to a 24-hour time format.
|
|
@@ -6,7 +6,7 @@ import type { LocalizedTimePartials } from './types'
|
|
|
6
6
|
* @param {number} hour The hour to be converted.
|
|
7
7
|
* @returns {number} The hour in 24-hour format.
|
|
8
8
|
*/
|
|
9
|
-
export const convert12hTo24h = (abbr:
|
|
9
|
+
export const convert12hTo24h = (abbr: AmPm, hour: number): number => {
|
|
10
10
|
if (abbr === 'am' && hour === 12) {
|
|
11
11
|
return 0
|
|
12
12
|
}
|
|
@@ -27,14 +27,14 @@ export const convert12hTo24h = (abbr: 'am' | 'pm', hour: number) => {
|
|
|
27
27
|
* @param {number} hour The hour to be converted.
|
|
28
28
|
* @returns {number} The hour in 12-hour format.
|
|
29
29
|
*/
|
|
30
|
-
export const convert24hTo12h = (hour: number) => hour % 12 || 12
|
|
30
|
+
export const convert24hTo12h = (hour: number): number => hour % 12 || 12
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Converts a time input into a Date object.
|
|
34
34
|
* @param {Date | string | null | undefined} time The time input to be converted.
|
|
35
35
|
* @returns {Date | null} The converted Date object or null if the input is falsy.
|
|
36
36
|
*/
|
|
37
|
-
export const convertTimeToDate = (time: Date | string | null | undefined) =>
|
|
37
|
+
export const convertTimeToDate = (time: Date | string | null | undefined): Date | null =>
|
|
38
38
|
time ? (time instanceof Date ? time : new Date(`1970-01-01 ${time}`)) : null
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -43,7 +43,7 @@ export const convertTimeToDate = (time: Date | string | null | undefined) =>
|
|
|
43
43
|
* @param {string} locale The locale to use for formatting.
|
|
44
44
|
* @returns {string} 'am' or 'pm' based on the given date and locale.
|
|
45
45
|
*/
|
|
46
|
-
export const getAmPm = (date: Date, locale: string) => {
|
|
46
|
+
export const getAmPm = (date: Date, locale: string): AmPm => {
|
|
47
47
|
if (date.toLocaleTimeString(locale).includes('AM')) {
|
|
48
48
|
return 'am'
|
|
49
49
|
}
|
|
@@ -66,7 +66,7 @@ export const formatTimePartials = (
|
|
|
66
66
|
values: number[],
|
|
67
67
|
locale: string,
|
|
68
68
|
partial: 'hour' | 'minute' | 'second',
|
|
69
|
-
) => {
|
|
69
|
+
): FormattedPartial[] => {
|
|
70
70
|
const date = new Date()
|
|
71
71
|
|
|
72
72
|
const formatter = new Intl.DateTimeFormat(locale, {
|
|
@@ -155,7 +155,7 @@ export const getSelectedHour = (
|
|
|
155
155
|
date: Date | null,
|
|
156
156
|
locale: string,
|
|
157
157
|
ampm: 'auto' | boolean = 'auto',
|
|
158
|
-
) =>
|
|
158
|
+
): number | string =>
|
|
159
159
|
date
|
|
160
160
|
? ((ampm === 'auto' && isAmPm(locale)) || ampm === true
|
|
161
161
|
? convert24hTo12h(date.getHours())
|
|
@@ -167,21 +167,23 @@ export const getSelectedHour = (
|
|
|
167
167
|
* @param {Date | null} date The date object from which to extract the minutes. If null, the function returns an empty string.
|
|
168
168
|
* @returns {string | number} The minutes from the date or an empty string if the date is null.
|
|
169
169
|
*/
|
|
170
|
-
export const getSelectedMinutes = (date: Date | null)
|
|
170
|
+
export const getSelectedMinutes = (date: Date | null): number | string =>
|
|
171
|
+
date ? date.getMinutes() : ''
|
|
171
172
|
|
|
172
173
|
/**
|
|
173
174
|
* Gets the selected seconds from a date object.
|
|
174
175
|
* @param {Date | null} date The date object from which to extract the seconds. If null, the function returns an empty string.
|
|
175
176
|
* @returns {string | number} The seconds from the date or an empty string if the date is null.
|
|
176
177
|
*/
|
|
177
|
-
export const getSelectedSeconds = (date: Date | null)
|
|
178
|
+
export const getSelectedSeconds = (date: Date | null): number | string =>
|
|
179
|
+
date ? date.getSeconds() : ''
|
|
178
180
|
|
|
179
181
|
/**
|
|
180
182
|
* Determines if the given locale uses AM/PM format.
|
|
181
183
|
* @param {string} locale The locale to check.
|
|
182
184
|
* @returns {boolean} True if the locale uses AM/PM format, otherwise false.
|
|
183
185
|
*/
|
|
184
|
-
export const isAmPm = (locale: string) =>
|
|
186
|
+
export const isAmPm = (locale: string): boolean =>
|
|
185
187
|
['am', 'AM', 'pm', 'PM'].some((el) => new Date().toLocaleString(locale).includes(el))
|
|
186
188
|
|
|
187
189
|
/**
|
|
@@ -189,7 +191,7 @@ export const isAmPm = (locale: string) =>
|
|
|
189
191
|
* @param {string} time The time string to validate.
|
|
190
192
|
* @returns {boolean} True if the string is a valid time, otherwise false.
|
|
191
193
|
*/
|
|
192
|
-
export const isValidTime = (time: string) => {
|
|
193
|
-
const d = new Date(`1970-01-
|
|
194
|
-
return d instanceof Date && d.getTime()
|
|
194
|
+
export const isValidTime = (time: string): boolean => {
|
|
195
|
+
const d = new Date(`1970-01-01T${time}`)
|
|
196
|
+
return d instanceof Date && !Number.isNaN(d.getTime())
|
|
195
197
|
}
|