@coreui/react 5.3.0 → 5.4.1
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/breadcrumb/CBreadcrumbItem.d.ts +9 -2
- package/dist/cjs/components/breadcrumb/CBreadcrumbItem.js +2 -2
- package/dist/cjs/components/breadcrumb/CBreadcrumbItem.js.map +1 -1
- package/dist/cjs/components/form/CFormSelect.d.ts +1 -0
- package/dist/cjs/components/form/CFormSelect.js.map +1 -1
- package/dist/cjs/components/grid/CRow.js +1 -1
- package/dist/cjs/components/grid/CRow.js.map +1 -1
- package/dist/cjs/components/list-group/CListGroup.js +4 -3
- package/dist/cjs/components/list-group/CListGroup.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.js +47 -42
- package/dist/cjs/components/popover/CPopover.js.map +1 -1
- package/dist/cjs/components/tabs/CTab.d.ts +4 -0
- package/dist/cjs/components/tabs/CTab.js +1 -0
- package/dist/cjs/components/tabs/CTab.js.map +1 -1
- package/dist/cjs/components/toast/CToast.d.ts +1 -1
- package/dist/cjs/components/toast/CToast.js +6 -3
- package/dist/cjs/components/toast/CToast.js.map +1 -1
- package/dist/cjs/components/toast/CToaster.js +1 -1
- package/dist/cjs/components/toast/CToaster.js.map +1 -1
- package/dist/cjs/components/tooltip/CTooltip.js +47 -42
- package/dist/cjs/components/tooltip/CTooltip.js.map +1 -1
- package/dist/esm/components/breadcrumb/CBreadcrumbItem.d.ts +9 -2
- package/dist/esm/components/breadcrumb/CBreadcrumbItem.js +2 -2
- package/dist/esm/components/breadcrumb/CBreadcrumbItem.js.map +1 -1
- package/dist/esm/components/form/CFormSelect.d.ts +1 -0
- package/dist/esm/components/form/CFormSelect.js.map +1 -1
- package/dist/esm/components/grid/CRow.js +2 -2
- package/dist/esm/components/grid/CRow.js.map +1 -1
- package/dist/esm/components/list-group/CListGroup.js +4 -3
- package/dist/esm/components/list-group/CListGroup.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.js +48 -43
- package/dist/esm/components/popover/CPopover.js.map +1 -1
- package/dist/esm/components/tabs/CTab.d.ts +4 -0
- package/dist/esm/components/tabs/CTab.js +1 -0
- package/dist/esm/components/tabs/CTab.js.map +1 -1
- package/dist/esm/components/toast/CToast.d.ts +1 -1
- package/dist/esm/components/toast/CToast.js +6 -3
- package/dist/esm/components/toast/CToast.js.map +1 -1
- package/dist/esm/components/toast/CToaster.js +1 -1
- package/dist/esm/components/toast/CToaster.js.map +1 -1
- package/dist/esm/components/tooltip/CTooltip.js +48 -43
- package/dist/esm/components/tooltip/CTooltip.js.map +1 -1
- package/package.json +15 -15
- package/src/components/breadcrumb/CBreadcrumbItem.tsx +36 -21
- package/src/components/form/CFormSelect.tsx +1 -0
- package/src/components/grid/CRow.tsx +1 -1
- package/src/components/list-group/CListGroup.tsx +2 -1
- package/src/components/nav/CNavGroup.tsx +1 -1
- package/src/components/popover/CPopover.tsx +65 -46
- package/src/components/tabs/CTab.tsx +5 -0
- package/src/components/toast/CToast.tsx +7 -4
- package/src/components/toast/CToaster.tsx +1 -1
- package/src/components/tooltip/CTooltip.tsx +65 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/react",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"description": "UI Components Library for React.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -41,20 +41,20 @@
|
|
|
41
41
|
"test:update": "jest --coverage --updateSnapshot"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@coreui/coreui": "^5.
|
|
44
|
+
"@coreui/coreui": "^5.2.0",
|
|
45
45
|
"@popperjs/core": "^2.11.8",
|
|
46
46
|
"prop-types": "^15.8.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@rollup/plugin-commonjs": "^
|
|
50
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
51
|
-
"@rollup/plugin-typescript": "^
|
|
52
|
-
"@testing-library/jest-dom": "^6.
|
|
53
|
-
"@testing-library/react": "^16.0.
|
|
54
|
-
"@types/jest": "^29.5.
|
|
55
|
-
"@types/react": "18.3.
|
|
56
|
-
"@types/react-dom": "^18.3.
|
|
57
|
-
"@types/react-transition-group": "^4.4.
|
|
49
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
50
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
51
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
|
52
|
+
"@testing-library/jest-dom": "^6.6.2",
|
|
53
|
+
"@testing-library/react": "^16.0.1",
|
|
54
|
+
"@types/jest": "^29.5.14",
|
|
55
|
+
"@types/react": "18.3.12",
|
|
56
|
+
"@types/react-dom": "^18.3.1",
|
|
57
|
+
"@types/react-transition-group": "^4.4.11",
|
|
58
58
|
"classnames": "^2.5.1",
|
|
59
59
|
"cross-env": "^7.0.3",
|
|
60
60
|
"jest": "^29.7.0",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"react": "^18.3.1",
|
|
63
63
|
"react-dom": "^18.3.1",
|
|
64
64
|
"react-transition-group": "^4.4.5",
|
|
65
|
-
"rollup": "^4.
|
|
66
|
-
"ts-jest": "^29.2.
|
|
67
|
-
"tslib": "^2.
|
|
68
|
-
"typescript": "^5.
|
|
65
|
+
"rollup": "^4.24.2",
|
|
66
|
+
"ts-jest": "^29.2.5",
|
|
67
|
+
"tslib": "^2.8.0",
|
|
68
|
+
"typescript": "^5.6.3"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"react": ">=17",
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import React, { forwardRef, HTMLAttributes } from 'react'
|
|
1
|
+
import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
5
|
import { CLink } from '../link/CLink'
|
|
6
6
|
|
|
7
|
+
import { PolymorphicRefForwardingComponent } from '../../helpers'
|
|
8
|
+
|
|
7
9
|
export interface CBreadcrumbItemProps extends HTMLAttributes<HTMLLIElement> {
|
|
8
10
|
/**
|
|
9
11
|
* Toggle the active state for the component.
|
|
10
12
|
*/
|
|
11
13
|
active?: boolean
|
|
14
|
+
/**
|
|
15
|
+
* Component used for the root node. Either a string to use a HTML element or a component.
|
|
16
|
+
*
|
|
17
|
+
* @since 5.4.0
|
|
18
|
+
*/
|
|
19
|
+
as?: ElementType
|
|
12
20
|
/**
|
|
13
21
|
* A string of all className you want applied to the base component.
|
|
14
22
|
*/
|
|
@@ -19,26 +27,33 @@ export interface CBreadcrumbItemProps extends HTMLAttributes<HTMLLIElement> {
|
|
|
19
27
|
href?: string
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
export const CBreadcrumbItem
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
export const CBreadcrumbItem: PolymorphicRefForwardingComponent<'li', CBreadcrumbItemProps> =
|
|
31
|
+
forwardRef<HTMLLIElement, CBreadcrumbItemProps>(
|
|
32
|
+
({ children, active, as, className, href, ...rest }, ref) => {
|
|
33
|
+
return (
|
|
34
|
+
<li
|
|
35
|
+
className={classNames(
|
|
36
|
+
'breadcrumb-item',
|
|
37
|
+
{
|
|
38
|
+
active: active,
|
|
39
|
+
},
|
|
40
|
+
className,
|
|
41
|
+
)}
|
|
42
|
+
{...(active && { 'aria-current': 'page' })}
|
|
43
|
+
{...rest}
|
|
44
|
+
ref={ref}
|
|
45
|
+
>
|
|
46
|
+
{href ? (
|
|
47
|
+
<CLink as={as} href={href}>
|
|
48
|
+
{children}
|
|
49
|
+
</CLink>
|
|
50
|
+
) : (
|
|
51
|
+
children
|
|
52
|
+
)}
|
|
53
|
+
</li>
|
|
54
|
+
)
|
|
55
|
+
},
|
|
56
|
+
)
|
|
42
57
|
|
|
43
58
|
CBreadcrumbItem.propTypes = {
|
|
44
59
|
active: PropTypes.bool,
|
|
@@ -91,7 +91,7 @@ export const CRow = forwardRef<HTMLDivElement, CRowProps>(
|
|
|
91
91
|
})
|
|
92
92
|
|
|
93
93
|
return (
|
|
94
|
-
<div className={classNames('row', repsonsiveClassNames, className)} ref={ref}>
|
|
94
|
+
<div className={classNames('row', repsonsiveClassNames, className)} {...rest} ref={ref}>
|
|
95
95
|
{children}
|
|
96
96
|
</div>
|
|
97
97
|
)
|
|
@@ -32,7 +32,7 @@ export interface CListGroupProps extends HTMLAttributes<HTMLDivElement | HTMLULi
|
|
|
32
32
|
export const CListGroup: PolymorphicRefForwardingComponent<'ul', CListGroupProps> = forwardRef<
|
|
33
33
|
HTMLDivElement | HTMLUListElement,
|
|
34
34
|
CListGroupProps
|
|
35
|
-
>(({ children, as: Component = 'ul', className, flush, layout }, ref) => {
|
|
35
|
+
>(({ children, as: Component = 'ul', className, flush, layout, ...rest }, ref) => {
|
|
36
36
|
return (
|
|
37
37
|
<Component
|
|
38
38
|
className={classNames(
|
|
@@ -43,6 +43,7 @@ export const CListGroup: PolymorphicRefForwardingComponent<'ul', CListGroupProps
|
|
|
43
43
|
},
|
|
44
44
|
className,
|
|
45
45
|
)}
|
|
46
|
+
{...rest}
|
|
46
47
|
ref={ref}
|
|
47
48
|
>
|
|
48
49
|
{children}
|
|
@@ -58,7 +58,7 @@ export const CNavGroup: PolymorphicRefForwardingComponent<'li', CNavGroupProps>
|
|
|
58
58
|
HTMLDivElement | HTMLLIElement,
|
|
59
59
|
CNavGroupProps
|
|
60
60
|
>(({ children, as: Component = 'li', className, compact, idx, toggler, visible, ...rest }, ref) => {
|
|
61
|
-
const [height, setHeight] = useState<number | string>()
|
|
61
|
+
const [height, setHeight] = useState<number | string>(0)
|
|
62
62
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
63
|
const navItemsRef = useRef<any>(null)
|
|
64
64
|
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
HTMLAttributes,
|
|
4
|
+
ReactNode,
|
|
5
|
+
useEffect,
|
|
6
|
+
useId,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react'
|
|
2
10
|
import classNames from 'classnames'
|
|
3
11
|
import PropTypes from 'prop-types'
|
|
4
12
|
|
|
@@ -97,12 +105,13 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
97
105
|
const popoverRef = useRef<HTMLDivElement>(null)
|
|
98
106
|
const togglerRef = useRef(null)
|
|
99
107
|
const forkedRef = useForkedRef(ref, popoverRef)
|
|
100
|
-
const uID = useRef(`popover${Math.floor(Math.random() * 1_000_000)}`)
|
|
101
108
|
|
|
102
|
-
const
|
|
109
|
+
const id = `popover${useId()}`
|
|
103
110
|
const [mounted, setMounted] = useState(false)
|
|
104
111
|
const [_visible, setVisible] = useState(visible)
|
|
105
112
|
|
|
113
|
+
const { initPopper, destroyPopper } = usePopper()
|
|
114
|
+
|
|
106
115
|
const _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay
|
|
107
116
|
|
|
108
117
|
const popperConfig = {
|
|
@@ -130,77 +139,87 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
useEffect(() => {
|
|
133
|
-
|
|
142
|
+
if (visible) {
|
|
143
|
+
handleShow()
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
handleHide()
|
|
134
148
|
}, [visible])
|
|
135
149
|
|
|
136
150
|
useEffect(() => {
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (popoverRef.current) {
|
|
141
|
-
popoverRef.current.classList.remove('fade', 'show')
|
|
142
|
-
destroyPopper()
|
|
143
|
-
}
|
|
144
|
-
|
|
151
|
+
if (mounted && togglerRef.current && popoverRef.current) {
|
|
152
|
+
initPopper(togglerRef.current, popoverRef.current, popperConfig)
|
|
145
153
|
setTimeout(() => {
|
|
146
|
-
|
|
147
|
-
if (animation) {
|
|
148
|
-
popoverRef.current.classList.add('fade')
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
initPopper(togglerRef.current, popoverRef.current, popperConfig)
|
|
152
|
-
popoverRef.current.style.removeProperty('display')
|
|
153
|
-
popoverRef.current.classList.add('show')
|
|
154
|
-
onShow && onShow()
|
|
155
|
-
}
|
|
154
|
+
setVisible(true)
|
|
156
155
|
}, _delay.show)
|
|
156
|
+
|
|
157
|
+
return
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
setMounted(false)
|
|
170
|
-
}, popoverRef.current)
|
|
171
|
-
}
|
|
160
|
+
if (!mounted && togglerRef.current && popoverRef.current) {
|
|
161
|
+
destroyPopper()
|
|
162
|
+
}
|
|
163
|
+
}, [mounted])
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (!_visible && togglerRef.current && popoverRef.current) {
|
|
167
|
+
executeAfterTransition(() => {
|
|
168
|
+
setMounted(false)
|
|
169
|
+
}, popoverRef.current)
|
|
172
170
|
}
|
|
173
171
|
}, [_visible])
|
|
174
172
|
|
|
173
|
+
const handleShow = () => {
|
|
174
|
+
setMounted(true)
|
|
175
|
+
if (onShow) {
|
|
176
|
+
onShow()
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const handleHide = () => {
|
|
181
|
+
setTimeout(() => {
|
|
182
|
+
setVisible(false)
|
|
183
|
+
if (onHide) {
|
|
184
|
+
onHide()
|
|
185
|
+
}
|
|
186
|
+
}, _delay.hide)
|
|
187
|
+
}
|
|
188
|
+
|
|
175
189
|
return (
|
|
176
190
|
<>
|
|
177
191
|
{React.cloneElement(children as React.ReactElement<any>, {
|
|
178
192
|
...(_visible && {
|
|
179
|
-
'aria-describedby':
|
|
193
|
+
'aria-describedby': id,
|
|
180
194
|
}),
|
|
181
195
|
ref: togglerRef,
|
|
182
196
|
...((trigger === 'click' || trigger.includes('click')) && {
|
|
183
|
-
onClick: () =>
|
|
197
|
+
onClick: () => (_visible ? handleHide() : handleShow()),
|
|
184
198
|
}),
|
|
185
199
|
...((trigger === 'focus' || trigger.includes('focus')) && {
|
|
186
|
-
onFocus: () =>
|
|
187
|
-
onBlur: () =>
|
|
200
|
+
onFocus: () => handleShow(),
|
|
201
|
+
onBlur: () => handleHide(),
|
|
188
202
|
}),
|
|
189
203
|
...((trigger === 'hover' || trigger.includes('hover')) && {
|
|
190
|
-
onMouseEnter: () =>
|
|
191
|
-
onMouseLeave: () =>
|
|
204
|
+
onMouseEnter: () => handleShow(),
|
|
205
|
+
onMouseLeave: () => handleHide(),
|
|
192
206
|
}),
|
|
193
207
|
})}
|
|
194
208
|
<CConditionalPortal container={container} portal={true}>
|
|
195
209
|
{mounted && (
|
|
196
210
|
<div
|
|
197
|
-
className={classNames(
|
|
198
|
-
|
|
211
|
+
className={classNames(
|
|
212
|
+
'popover',
|
|
213
|
+
'bs-popover-auto',
|
|
214
|
+
{
|
|
215
|
+
fade: animation,
|
|
216
|
+
show: _visible,
|
|
217
|
+
},
|
|
218
|
+
className,
|
|
219
|
+
)}
|
|
220
|
+
id={id}
|
|
199
221
|
ref={forkedRef}
|
|
200
222
|
role="tooltip"
|
|
201
|
-
style={{
|
|
202
|
-
display: 'none',
|
|
203
|
-
}}
|
|
204
223
|
{...rest}
|
|
205
224
|
>
|
|
206
225
|
<div className="popover-arrow"></div>
|
|
@@ -9,6 +9,10 @@ export interface CTabProps extends HTMLAttributes<HTMLButtonElement> {
|
|
|
9
9
|
* A string of all className you want applied to the base component.
|
|
10
10
|
*/
|
|
11
11
|
className?: string
|
|
12
|
+
/**
|
|
13
|
+
* Toggle the disabled state for the component.
|
|
14
|
+
*/
|
|
15
|
+
disabled?: boolean
|
|
12
16
|
/**
|
|
13
17
|
* Item key.
|
|
14
18
|
*/
|
|
@@ -50,6 +54,7 @@ export const CTab = forwardRef<HTMLButtonElement, CTabProps>(
|
|
|
50
54
|
CTab.propTypes = {
|
|
51
55
|
children: PropTypes.node,
|
|
52
56
|
className: PropTypes.string,
|
|
57
|
+
disabled: PropTypes.bool,
|
|
53
58
|
itemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
54
59
|
}
|
|
55
60
|
|
|
@@ -44,7 +44,7 @@ export interface CToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title
|
|
|
44
44
|
/**
|
|
45
45
|
* @ignore
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
innerKey?: number | string
|
|
48
48
|
/**
|
|
49
49
|
* Callback fired when the component requests to be closed.
|
|
50
50
|
*/
|
|
@@ -76,7 +76,7 @@ export const CToast = forwardRef<HTMLDivElement, CToastProps>(
|
|
|
76
76
|
color,
|
|
77
77
|
delay = 5000,
|
|
78
78
|
index,
|
|
79
|
-
|
|
79
|
+
innerKey,
|
|
80
80
|
visible = false,
|
|
81
81
|
onClose,
|
|
82
82
|
onShow,
|
|
@@ -143,7 +143,7 @@ export const CToast = forwardRef<HTMLDivElement, CToastProps>(
|
|
|
143
143
|
onMouseEnter={() => clearTimeout(timeout.current)}
|
|
144
144
|
onMouseLeave={() => _autohide()}
|
|
145
145
|
{...rest}
|
|
146
|
-
key={
|
|
146
|
+
key={innerKey}
|
|
147
147
|
ref={forkedRef}
|
|
148
148
|
>
|
|
149
149
|
{children}
|
|
@@ -163,7 +163,10 @@ CToast.propTypes = {
|
|
|
163
163
|
color: colorPropType,
|
|
164
164
|
delay: PropTypes.number,
|
|
165
165
|
index: PropTypes.number,
|
|
166
|
-
|
|
166
|
+
innerKey: PropTypes.oneOfType([
|
|
167
|
+
PropTypes.number,
|
|
168
|
+
PropTypes.string
|
|
169
|
+
]),
|
|
167
170
|
onClose: PropTypes.func,
|
|
168
171
|
onShow: PropTypes.func,
|
|
169
172
|
visible: PropTypes.bool,
|
|
@@ -45,7 +45,7 @@ export const CToaster = forwardRef<HTMLDivElement, CToasterProps>(
|
|
|
45
45
|
...state,
|
|
46
46
|
React.cloneElement(push, {
|
|
47
47
|
index: index.current,
|
|
48
|
-
|
|
48
|
+
innerKey: index.current,
|
|
49
49
|
onClose: (index: number) =>
|
|
50
50
|
setToasts((state) => state.filter((i) => i.props.index !== index)),
|
|
51
51
|
}),
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
HTMLAttributes,
|
|
4
|
+
ReactNode,
|
|
5
|
+
useEffect,
|
|
6
|
+
useId,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react'
|
|
2
10
|
import classNames from 'classnames'
|
|
3
11
|
import PropTypes from 'prop-types'
|
|
4
12
|
|
|
@@ -92,12 +100,13 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
92
100
|
const tooltipRef = useRef<HTMLDivElement>(null)
|
|
93
101
|
const togglerRef = useRef(null)
|
|
94
102
|
const forkedRef = useForkedRef(ref, tooltipRef)
|
|
95
|
-
const uID = useRef(`tooltip${Math.floor(Math.random() * 1_000_000)}`)
|
|
96
103
|
|
|
97
|
-
const
|
|
104
|
+
const id = `tooltip${useId()}`
|
|
98
105
|
const [mounted, setMounted] = useState(false)
|
|
99
106
|
const [_visible, setVisible] = useState(visible)
|
|
100
107
|
|
|
108
|
+
const { initPopper, destroyPopper, updatePopper } = usePopper()
|
|
109
|
+
|
|
101
110
|
const _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay
|
|
102
111
|
|
|
103
112
|
const popperConfig = {
|
|
@@ -125,48 +134,53 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
125
134
|
}
|
|
126
135
|
|
|
127
136
|
useEffect(() => {
|
|
128
|
-
|
|
137
|
+
if (visible) {
|
|
138
|
+
handleShow()
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
handleHide()
|
|
129
143
|
}, [visible])
|
|
130
144
|
|
|
131
145
|
useEffect(() => {
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (tooltipRef.current) {
|
|
136
|
-
tooltipRef.current.classList.remove('fade', 'show')
|
|
137
|
-
destroyPopper()
|
|
138
|
-
}
|
|
139
|
-
|
|
146
|
+
if (mounted && togglerRef.current && tooltipRef.current) {
|
|
147
|
+
initPopper(togglerRef.current, tooltipRef.current, popperConfig)
|
|
140
148
|
setTimeout(() => {
|
|
141
|
-
|
|
142
|
-
if (animation) {
|
|
143
|
-
tooltipRef.current.classList.add('fade')
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
initPopper(togglerRef.current, tooltipRef.current, popperConfig)
|
|
147
|
-
tooltipRef.current.style.removeProperty('display')
|
|
148
|
-
tooltipRef.current.classList.add('show')
|
|
149
|
-
onShow && onShow()
|
|
150
|
-
}
|
|
149
|
+
setVisible(true)
|
|
151
150
|
}, _delay.show)
|
|
151
|
+
|
|
152
|
+
return
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
setMounted(false)
|
|
165
|
-
}, tooltipRef.current)
|
|
166
|
-
}
|
|
155
|
+
if (!mounted && togglerRef.current && tooltipRef.current) {
|
|
156
|
+
destroyPopper()
|
|
157
|
+
}
|
|
158
|
+
}, [mounted])
|
|
159
|
+
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (!_visible && togglerRef.current && tooltipRef.current) {
|
|
162
|
+
executeAfterTransition(() => {
|
|
163
|
+
setMounted(false)
|
|
164
|
+
}, tooltipRef.current)
|
|
167
165
|
}
|
|
168
166
|
}, [_visible])
|
|
169
167
|
|
|
168
|
+
const handleShow = () => {
|
|
169
|
+
setMounted(true)
|
|
170
|
+
if (onShow) {
|
|
171
|
+
onShow()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const handleHide = () => {
|
|
176
|
+
setTimeout(() => {
|
|
177
|
+
setVisible(false)
|
|
178
|
+
if (onHide) {
|
|
179
|
+
onHide()
|
|
180
|
+
}
|
|
181
|
+
}, _delay.hide)
|
|
182
|
+
}
|
|
183
|
+
|
|
170
184
|
useEffect(() => {
|
|
171
185
|
updatePopper()
|
|
172
186
|
}, [content])
|
|
@@ -175,31 +189,36 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
|
175
189
|
<>
|
|
176
190
|
{React.cloneElement(children as React.ReactElement<any>, {
|
|
177
191
|
...(_visible && {
|
|
178
|
-
'aria-describedby':
|
|
192
|
+
'aria-describedby': id,
|
|
179
193
|
}),
|
|
180
194
|
ref: togglerRef,
|
|
181
195
|
...((trigger === 'click' || trigger.includes('click')) && {
|
|
182
|
-
onClick: () =>
|
|
196
|
+
onClick: () => (_visible ? handleHide() : handleShow()),
|
|
183
197
|
}),
|
|
184
198
|
...((trigger === 'focus' || trigger.includes('focus')) && {
|
|
185
|
-
onFocus: () =>
|
|
186
|
-
onBlur: () =>
|
|
199
|
+
onFocus: () => handleShow(),
|
|
200
|
+
onBlur: () => handleHide(),
|
|
187
201
|
}),
|
|
188
202
|
...((trigger === 'hover' || trigger.includes('hover')) && {
|
|
189
|
-
onMouseEnter: () =>
|
|
190
|
-
onMouseLeave: () =>
|
|
203
|
+
onMouseEnter: () => handleShow(),
|
|
204
|
+
onMouseLeave: () => handleHide(),
|
|
191
205
|
}),
|
|
192
206
|
})}
|
|
193
207
|
<CConditionalPortal container={container} portal={true}>
|
|
194
208
|
{mounted && (
|
|
195
209
|
<div
|
|
196
|
-
className={classNames(
|
|
197
|
-
|
|
210
|
+
className={classNames(
|
|
211
|
+
'tooltip',
|
|
212
|
+
'bs-tooltip-auto',
|
|
213
|
+
{
|
|
214
|
+
fade: animation,
|
|
215
|
+
show: _visible,
|
|
216
|
+
},
|
|
217
|
+
className,
|
|
218
|
+
)}
|
|
219
|
+
id={id}
|
|
198
220
|
ref={forkedRef}
|
|
199
221
|
role="tooltip"
|
|
200
|
-
style={{
|
|
201
|
-
display: 'none',
|
|
202
|
-
}}
|
|
203
222
|
{...rest}
|
|
204
223
|
>
|
|
205
224
|
<div className="tooltip-arrow"></div>
|