@coreui/react-pro 4.13.1 → 4.14.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/date-range-picker/CDateRangePicker.d.ts +18 -0
- package/dist/components/popover/CPopover.d.ts +2 -2
- package/dist/components/tooltip/CTooltip.d.ts +2 -2
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useDebouncedCallback.d.ts +1 -0
- package/dist/hooks/useIsVisible.d.ts +2 -0
- package/dist/index.es.js +97 -61
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +97 -59
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/date-range-picker/CDateRangePicker.tsx +45 -21
- package/src/components/popover/CPopover.tsx +126 -117
- package/src/components/time-picker/CTimePicker.tsx +34 -34
- package/src/components/time-picker/CTimePickerRollCol.tsx +7 -4
- package/src/components/tooltip/CTooltip.tsx +131 -114
- package/src/hooks/index.ts +3 -1
- package/src/hooks/useDebouncedCallback.ts +18 -0
- package/src/hooks/useIsVisible.ts +14 -0
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
HTMLAttributes,
|
|
4
|
+
ReactNode,
|
|
5
|
+
useRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react'
|
|
2
9
|
import { createPortal } from 'react-dom'
|
|
3
10
|
import classNames from 'classnames'
|
|
4
11
|
import PropTypes from 'prop-types'
|
|
5
12
|
import { Transition } from 'react-transition-group'
|
|
6
13
|
|
|
7
|
-
import { usePopper } from '../../hooks'
|
|
14
|
+
import { useForkedRef, usePopper } from '../../hooks'
|
|
8
15
|
import { fallbackPlacementsPropType, triggerPropType } from '../../props'
|
|
9
16
|
import type { Placements, Triggers } from '../../types'
|
|
10
17
|
import { getRTLPlacement, getTransitionDurationFromElement } from '../../utils'
|
|
@@ -64,129 +71,139 @@ export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'con
|
|
|
64
71
|
visible?: boolean
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
export const CTooltip
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
|
|
75
|
+
(
|
|
76
|
+
{
|
|
77
|
+
children,
|
|
78
|
+
animation = true,
|
|
79
|
+
className,
|
|
80
|
+
content,
|
|
81
|
+
delay = 0,
|
|
82
|
+
fallbackPlacements = ['top', 'right', 'bottom', 'left'],
|
|
83
|
+
offset = [0, 6],
|
|
84
|
+
onHide,
|
|
85
|
+
onShow,
|
|
86
|
+
placement = 'top',
|
|
87
|
+
trigger = ['hover', 'focus'],
|
|
88
|
+
visible,
|
|
89
|
+
...rest
|
|
90
|
+
},
|
|
91
|
+
ref,
|
|
92
|
+
) => {
|
|
93
|
+
const tooltipRef = useRef(null)
|
|
94
|
+
const togglerRef = useRef(null)
|
|
95
|
+
const forkedRef = useForkedRef(ref, tooltipRef)
|
|
86
96
|
|
|
87
|
-
|
|
97
|
+
const { initPopper, destroyPopper } = usePopper()
|
|
98
|
+
const [_visible, setVisible] = useState(visible)
|
|
88
99
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
const _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay
|
|
101
|
+
|
|
102
|
+
const popperConfig = {
|
|
103
|
+
modifiers: [
|
|
104
|
+
{
|
|
105
|
+
name: 'arrow',
|
|
106
|
+
options: {
|
|
107
|
+
element: '.tooltip-arrow',
|
|
108
|
+
},
|
|
95
109
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
{
|
|
111
|
+
name: 'flip',
|
|
112
|
+
options: {
|
|
113
|
+
fallbackPlacements: fallbackPlacements,
|
|
114
|
+
},
|
|
101
115
|
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
116
|
+
{
|
|
117
|
+
name: 'offset',
|
|
118
|
+
options: {
|
|
119
|
+
offset: offset,
|
|
120
|
+
},
|
|
107
121
|
},
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
122
|
+
],
|
|
123
|
+
placement: getRTLPlacement(placement, togglerRef.current),
|
|
124
|
+
}
|
|
112
125
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
setVisible(visible)
|
|
128
|
+
}, [visible])
|
|
116
129
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (_visible && togglerRef.current && tooltipRef.current) {
|
|
132
|
+
initPopper(togglerRef.current, tooltipRef.current, popperConfig)
|
|
133
|
+
}
|
|
121
134
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
return () => {
|
|
136
|
+
destroyPopper()
|
|
137
|
+
}
|
|
138
|
+
}, [_visible])
|
|
126
139
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
const toggleVisible = (visible: boolean) => {
|
|
141
|
+
if (visible) {
|
|
142
|
+
setTimeout(() => setVisible(true), _delay.show)
|
|
143
|
+
return
|
|
144
|
+
}
|
|
132
145
|
|
|
133
|
-
|
|
134
|
-
|
|
146
|
+
setTimeout(() => setVisible(false), _delay.hide)
|
|
147
|
+
}
|
|
135
148
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
149
|
+
return (
|
|
150
|
+
<>
|
|
151
|
+
{React.cloneElement(children as React.ReactElement<any>, {
|
|
152
|
+
ref: togglerRef,
|
|
153
|
+
...((trigger === 'click' || trigger.includes('click')) && {
|
|
154
|
+
onClick: () => toggleVisible(!_visible),
|
|
155
|
+
}),
|
|
156
|
+
...((trigger === 'focus' || trigger.includes('focus')) && {
|
|
157
|
+
onFocus: () => toggleVisible(true),
|
|
158
|
+
onBlur: () => toggleVisible(false),
|
|
159
|
+
}),
|
|
160
|
+
...((trigger === 'hover' || trigger.includes('hover')) && {
|
|
161
|
+
onMouseEnter: () => toggleVisible(true),
|
|
162
|
+
onMouseLeave: () => toggleVisible(false),
|
|
163
|
+
}),
|
|
164
|
+
})}
|
|
165
|
+
{typeof window !== 'undefined' &&
|
|
166
|
+
createPortal(
|
|
167
|
+
<Transition
|
|
168
|
+
in={_visible}
|
|
169
|
+
mountOnEnter
|
|
170
|
+
nodeRef={tooltipRef}
|
|
171
|
+
onEnter={onShow}
|
|
172
|
+
onExit={onHide}
|
|
173
|
+
timeout={{
|
|
174
|
+
enter: 0,
|
|
175
|
+
exit: tooltipRef.current
|
|
176
|
+
? getTransitionDurationFromElement(tooltipRef.current) + 50
|
|
177
|
+
: 200,
|
|
178
|
+
}}
|
|
179
|
+
unmountOnExit
|
|
180
|
+
>
|
|
181
|
+
{(state) => (
|
|
182
|
+
<div
|
|
183
|
+
className={classNames(
|
|
184
|
+
'tooltip',
|
|
185
|
+
'bs-tooltip-auto',
|
|
186
|
+
{
|
|
187
|
+
fade: animation,
|
|
188
|
+
show: state === 'entered',
|
|
189
|
+
},
|
|
190
|
+
className,
|
|
191
|
+
)}
|
|
192
|
+
ref={forkedRef}
|
|
193
|
+
role="tooltip"
|
|
194
|
+
{...rest}
|
|
195
|
+
>
|
|
196
|
+
<div className="tooltip-arrow"></div>
|
|
197
|
+
<div className="tooltip-inner">{content}</div>
|
|
198
|
+
</div>
|
|
199
|
+
)}
|
|
200
|
+
</Transition>,
|
|
201
|
+
document.body,
|
|
202
|
+
)}
|
|
203
|
+
</>
|
|
204
|
+
)
|
|
205
|
+
},
|
|
206
|
+
)
|
|
190
207
|
|
|
191
208
|
CTooltip.propTypes = {
|
|
192
209
|
animation: PropTypes.bool,
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { useDebouncedCallback } from './useDebouncedCallback'
|
|
1
2
|
import { useForkedRef } from './useForkedRef'
|
|
3
|
+
import { useIsVisible } from './useIsVisible'
|
|
2
4
|
import { usePopper } from './usePopper'
|
|
3
5
|
import { useStateWithCallback } from './useStateWithCallback'
|
|
4
6
|
|
|
5
|
-
export { useForkedRef, usePopper, useStateWithCallback }
|
|
7
|
+
export { useDebouncedCallback, useForkedRef, useIsVisible, usePopper, useStateWithCallback }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useRef, useCallback, } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useDebouncedCallback = <F extends Function>(callback: F, delay: number) => {
|
|
4
|
+
const timeout = useRef<ReturnType<typeof setTimeout>>()
|
|
5
|
+
|
|
6
|
+
return useCallback(
|
|
7
|
+
(...args: any[]) => {
|
|
8
|
+
const handler = () => {
|
|
9
|
+
clearTimeout(timeout.current)
|
|
10
|
+
callback(...args)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
clearTimeout(timeout.current)
|
|
14
|
+
timeout.current = setTimeout(handler, delay)
|
|
15
|
+
},
|
|
16
|
+
[callback, delay],
|
|
17
|
+
)
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RefObject, useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useIsVisible = (ref: RefObject<HTMLElement>) => {
|
|
4
|
+
const [isIntersecting, setIntersecting] = useState(false)
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const observer = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting))
|
|
8
|
+
|
|
9
|
+
ref.current && observer.observe(ref.current)
|
|
10
|
+
return () => observer.disconnect()
|
|
11
|
+
}, [])
|
|
12
|
+
|
|
13
|
+
return isIntersecting
|
|
14
|
+
}
|