@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,61 +19,124 @@ import { executeAfterTransition, getRTLPlacement } from '../../utils'
|
|
|
18
19
|
|
|
19
20
|
export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'content'> {
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
+
* Enables or disables the CSS fade transition for the React Tooltip.
|
|
22
23
|
*
|
|
23
24
|
* @since 4.9.0
|
|
24
25
|
*/
|
|
25
26
|
animation?: boolean
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
29
|
+
* Adds a custom class name to the React Tooltip container. Useful for overriding default styles or applying additional design choices.
|
|
28
30
|
*/
|
|
29
31
|
className?: string
|
|
32
|
+
|
|
30
33
|
/**
|
|
31
|
-
* Appends the
|
|
34
|
+
* Appends the React Tooltip to a specific element instead of the default `document.body`. You may pass:
|
|
35
|
+
* - A DOM element (`HTMLElement` or `DocumentFragment`)
|
|
36
|
+
* - A function that returns a single element
|
|
37
|
+
* - `null`
|
|
32
38
|
*
|
|
39
|
+
* @example
|
|
40
|
+
* <CTooltip container={document.getElementById('my-container')}>...</CTooltip>
|
|
41
|
+
*
|
|
42
|
+
* @default document.body
|
|
33
43
|
* @since 4.11.0
|
|
34
44
|
*/
|
|
35
45
|
container?: DocumentFragment | Element | (() => DocumentFragment | Element | null) | null
|
|
46
|
+
|
|
36
47
|
/**
|
|
37
|
-
* Content
|
|
48
|
+
* Content to be displayed within the React Tooltip. Can be a string or any valid React node.
|
|
38
49
|
*/
|
|
39
50
|
content: ReactNode | string
|
|
51
|
+
|
|
40
52
|
/**
|
|
41
|
-
* The delay
|
|
53
|
+
* The delay (in milliseconds) before showing or hiding the React Tooltip.
|
|
54
|
+
* - If provided as a number, the delay is applied to both "show" and "hide".
|
|
55
|
+
* - If provided as an object, it should have distinct "show" and "hide" values.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Delays 300ms on both show and hide
|
|
59
|
+
* <CTooltip delay={300}>...</CTooltip>
|
|
60
|
+
*
|
|
61
|
+
* // Delays 500ms on show and 100ms on hide
|
|
62
|
+
* <CTooltip delay={{ show: 500, hide: 100 }}>...</CTooltip>
|
|
42
63
|
*
|
|
43
64
|
* @since 4.9.0
|
|
44
65
|
*/
|
|
45
66
|
delay?: number | { show: number; hide: number }
|
|
67
|
+
|
|
46
68
|
/**
|
|
47
|
-
*
|
|
69
|
+
* Array of fallback placements for the React Tooltip to use when the preferred placement cannot be achieved. These placements are tried in order.
|
|
48
70
|
*
|
|
71
|
+
* @type 'top', 'right', 'bottom', 'left' | ('top', 'right', 'bottom', 'left')[]
|
|
49
72
|
* @since 4.9.0
|
|
50
73
|
*/
|
|
51
74
|
fallbackPlacements?: Placements | Placements[]
|
|
75
|
+
|
|
52
76
|
/**
|
|
53
|
-
*
|
|
77
|
+
* Adjusts the offset of the React Tooltip relative to its target. Expects a tuple `[x-axis, y-axis]`.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* // Offset the menu 0px in X and 10px in Y direction
|
|
81
|
+
* <CTooltip offset={[0, 10]}>...</CTooltip>
|
|
82
|
+
*
|
|
83
|
+
* // Offset the menu 5px in both X and Y direction
|
|
84
|
+
* <CTooltip offset={[5, 5]}>...</CTooltip>
|
|
54
85
|
*/
|
|
55
86
|
offset?: [number, number]
|
|
87
|
+
|
|
56
88
|
/**
|
|
57
|
-
* Callback fired
|
|
89
|
+
* Callback fired immediately after the React Tooltip is hidden.
|
|
58
90
|
*/
|
|
59
91
|
onHide?: () => void
|
|
92
|
+
|
|
60
93
|
/**
|
|
61
|
-
* Callback fired
|
|
94
|
+
* Callback fired immediately after the React Tooltip is shown.
|
|
62
95
|
*/
|
|
63
96
|
onShow?: () => void
|
|
97
|
+
|
|
64
98
|
/**
|
|
65
|
-
*
|
|
99
|
+
* Initial placement of the React Tooltip. Note that Popper.js modifiers may alter this placement automatically if there's insufficient space in the chosen position.
|
|
100
|
+
*/
|
|
101
|
+
placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left'
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Customize the Popper.js configuration used to position the React Tooltip. Pass either an object or a function returning a modified config. [Learn more](https://popper.js.org/docs/v2/constructors/#options)
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* <CTooltip
|
|
108
|
+
* popperConfig={(defaultConfig) => ({
|
|
109
|
+
* ...defaultConfig,
|
|
110
|
+
* strategy: 'fixed',
|
|
111
|
+
* modifiers: [
|
|
112
|
+
* ...defaultConfig.modifiers,
|
|
113
|
+
* { name: 'computeStyles', options: { adaptive: false } },
|
|
114
|
+
* ],
|
|
115
|
+
* })}
|
|
116
|
+
* >...</CTooltip>
|
|
66
117
|
*
|
|
67
|
-
* @
|
|
118
|
+
* @since 5.5.0
|
|
68
119
|
*/
|
|
69
|
-
|
|
120
|
+
popperConfig?: Partial<Options> | ((defaultPopperConfig: Partial<Options>) => Partial<Options>)
|
|
121
|
+
|
|
70
122
|
/**
|
|
71
|
-
*
|
|
123
|
+
* Determines the events that toggle the visibility of the React Tooltip. Can be a single trigger or an array of triggers.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // Hover-only tooltip
|
|
127
|
+
* <CTooltip trigger="hover">...</CTooltip>
|
|
128
|
+
*
|
|
129
|
+
* // Hover + click combined
|
|
130
|
+
* <CTooltip trigger={['hover', 'click']}>...</CTooltip>
|
|
131
|
+
*
|
|
132
|
+
* @type 'hover' | 'focus' | 'click' | ('hover' | 'focus' | 'click')[]
|
|
72
133
|
*/
|
|
73
|
-
|
|
134
|
+
trigger?: Triggers | Triggers[]
|
|
135
|
+
|
|
74
136
|
/**
|
|
75
|
-
*
|
|
137
|
+
* Controls the visibility of the React Tooltip.
|
|
138
|
+
* - `true` to show the tooltip.
|
|
139
|
+
* - `false` to hide the tooltip.
|
|
76
140
|
*/
|
|
77
141
|
visible?: boolean
|
|
78
142
|
}
|
|
@@ -91,11 +155,12 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
91
155
|
onHide,
|
|
92
156
|
onShow,
|
|
93
157
|
placement = 'top',
|
|
158
|
+
popperConfig,
|
|
94
159
|
trigger = ['hover', 'focus'],
|
|
95
160
|
visible,
|
|
96
161
|
...rest
|
|
97
162
|
},
|
|
98
|
-
ref
|
|
163
|
+
ref
|
|
99
164
|
) => {
|
|
100
165
|
const tooltipRef = useRef<HTMLDivElement>(null)
|
|
101
166
|
const togglerRef = useRef(null)
|
|
@@ -109,30 +174,20 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
109
174
|
|
|
110
175
|
const _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay
|
|
111
176
|
|
|
112
|
-
const
|
|
177
|
+
const defaultPopperConfig: Partial<Options> = {
|
|
113
178
|
modifiers: [
|
|
114
|
-
{
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
element: '.tooltip-arrow',
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
name: 'flip',
|
|
122
|
-
options: {
|
|
123
|
-
fallbackPlacements: fallbackPlacements,
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
name: 'offset',
|
|
128
|
-
options: {
|
|
129
|
-
offset: offset,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
179
|
+
{ name: 'arrow', options: { element: '.tooltip-arrow' } },
|
|
180
|
+
{ name: 'flip', options: { fallbackPlacements } },
|
|
181
|
+
{ name: 'offset', options: { offset } },
|
|
132
182
|
],
|
|
133
183
|
placement: getRTLPlacement(placement, togglerRef.current),
|
|
134
184
|
}
|
|
135
185
|
|
|
186
|
+
const computedPopperConfig: Partial<Options> = {
|
|
187
|
+
...defaultPopperConfig,
|
|
188
|
+
...(typeof popperConfig === 'function' ? popperConfig(defaultPopperConfig) : popperConfig),
|
|
189
|
+
}
|
|
190
|
+
|
|
136
191
|
useEffect(() => {
|
|
137
192
|
if (visible) {
|
|
138
193
|
handleShow()
|
|
@@ -144,7 +199,7 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
144
199
|
|
|
145
200
|
useEffect(() => {
|
|
146
201
|
if (mounted && togglerRef.current && tooltipRef.current) {
|
|
147
|
-
initPopper(togglerRef.current, tooltipRef.current,
|
|
202
|
+
initPopper(togglerRef.current, tooltipRef.current, computedPopperConfig)
|
|
148
203
|
setTimeout(() => {
|
|
149
204
|
setVisible(true)
|
|
150
205
|
}, _delay.show)
|
|
@@ -214,7 +269,7 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
214
269
|
fade: animation,
|
|
215
270
|
show: _visible,
|
|
216
271
|
},
|
|
217
|
-
className
|
|
272
|
+
className
|
|
218
273
|
)}
|
|
219
274
|
id={id}
|
|
220
275
|
ref={forkedRef}
|
|
@@ -228,7 +283,7 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
228
283
|
</CConditionalPortal>
|
|
229
284
|
</>
|
|
230
285
|
)
|
|
231
|
-
}
|
|
286
|
+
}
|
|
232
287
|
)
|
|
233
288
|
|
|
234
289
|
CTooltip.propTypes = {
|
|
@@ -248,6 +303,7 @@ CTooltip.propTypes = {
|
|
|
248
303
|
onHide: PropTypes.func,
|
|
249
304
|
onShow: PropTypes.func,
|
|
250
305
|
placement: PropTypes.oneOf(['auto', 'top', 'right', 'bottom', 'left']),
|
|
306
|
+
popperConfig: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
251
307
|
trigger: triggerPropType,
|
|
252
308
|
visible: PropTypes.bool,
|
|
253
309
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useClipboard } from './useClipboard'
|
|
1
2
|
import { useColorModes } from './useColorModes'
|
|
2
3
|
import { useDebounce } from './useDebounce'
|
|
3
4
|
import { useDebouncedCallback } from './useDebouncedCallback'
|
|
@@ -8,6 +9,7 @@ import { usePopper } from './usePopper'
|
|
|
8
9
|
import { useStateWithCallback } from './useStateWithCallback'
|
|
9
10
|
|
|
10
11
|
export {
|
|
12
|
+
useClipboard,
|
|
11
13
|
useColorModes,
|
|
12
14
|
useDebounce,
|
|
13
15
|
useDebouncedCallback,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* useClipboard Hook
|
|
5
|
+
*
|
|
6
|
+
* Provides functionality to copy text to the clipboard and track the copy status.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object containing the copy function, copy status, and any error encountered.
|
|
9
|
+
*/
|
|
10
|
+
export const useClipboard = () => {
|
|
11
|
+
const [isCopied, setIsCopied] = useState<boolean>(false)
|
|
12
|
+
const [error, setError] = useState<Error | null>(null)
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Copies the provided text to the clipboard.
|
|
16
|
+
*
|
|
17
|
+
* @param text - The text to be copied to the clipboard.
|
|
18
|
+
*/
|
|
19
|
+
const copy = useCallback(async (text: string) => {
|
|
20
|
+
if (!navigator?.clipboard) {
|
|
21
|
+
setError(new Error('Clipboard API is not available'))
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await navigator.clipboard.writeText(text)
|
|
27
|
+
setIsCopied(true)
|
|
28
|
+
setError(null)
|
|
29
|
+
// Reset the isCopied state after 2 seconds
|
|
30
|
+
setTimeout(() => setIsCopied(false), 2000)
|
|
31
|
+
} catch (_error) {
|
|
32
|
+
setError(_error as Error)
|
|
33
|
+
setIsCopied(false)
|
|
34
|
+
}
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
return { copy, isCopied, error }
|
|
38
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import isEqual from './isEqual'
|
|
|
6
6
|
import isInViewport from './isInViewport'
|
|
7
7
|
import isObjectInArray from './isObjectInArray'
|
|
8
8
|
import isRTL from './isRTL'
|
|
9
|
+
import mergeClassNames from './mergeClassNames'
|
|
9
10
|
|
|
10
11
|
export {
|
|
11
12
|
executeAfterTransition,
|
|
@@ -16,4 +17,5 @@ export {
|
|
|
16
17
|
isInViewport,
|
|
17
18
|
isObjectInArray,
|
|
18
19
|
isRTL,
|
|
20
|
+
mergeClassNames,
|
|
19
21
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const mergeClassNames = <T extends object>(
|
|
2
|
+
defaultClassNames: T,
|
|
3
|
+
customClassNames?: Partial<T>,
|
|
4
|
+
): T => {
|
|
5
|
+
if (customClassNames === undefined || typeof customClassNames !== 'object') {
|
|
6
|
+
return defaultClassNames
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const classNames: T = { ...defaultClassNames }
|
|
10
|
+
|
|
11
|
+
for (const key in customClassNames) {
|
|
12
|
+
if (customClassNames.hasOwnProperty(key)) {
|
|
13
|
+
const typedKey = key as keyof T
|
|
14
|
+
const customClassName = customClassNames[typedKey]?.toString()
|
|
15
|
+
|
|
16
|
+
classNames[typedKey] = customClassName?.startsWith('!')
|
|
17
|
+
? (customClassName.slice(1).trim() as T[keyof T])
|
|
18
|
+
: (`${classNames[typedKey]} ${customClassName}`.trim() as T[keyof T])
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return classNames
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default mergeClassNames
|