-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathindex.jsx
More file actions
87 lines (81 loc) · 2.3 KB
/
index.jsx
File metadata and controls
87 lines (81 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2025, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import PropTypes from 'prop-types'
import {Tooltip as ChakraTooltip} from '@chakra-ui/react'
const Tooltip = React.forwardRef(
(
{
children,
content,
placement = 'top',
showArrow = true,
disabled = false,
openDelay = 500,
closeDelay = 500,
contentProps,
positioning
},
ref
) => {
if (disabled || !content) {
return children
}
const positioningConfig = positioning || {}
const finalPositioning = {
placement,
...positioningConfig
}
return (
<ChakraTooltip.Root
openDelay={openDelay}
closeDelay={closeDelay}
positioning={finalPositioning}
>
<ChakraTooltip.Trigger asChild ref={ref}>
{children}
</ChakraTooltip.Trigger>
<ChakraTooltip.Positioner>
<ChakraTooltip.Content {...contentProps}>
{showArrow && (
<ChakraTooltip.Arrow>
<ChakraTooltip.ArrowTip />
</ChakraTooltip.Arrow>
)}
{content}
</ChakraTooltip.Content>
</ChakraTooltip.Positioner>
</ChakraTooltip.Root>
)
}
)
Tooltip.displayName = 'Tooltip'
Tooltip.propTypes = {
children: PropTypes.node.isRequired,
content: PropTypes.node,
placement: PropTypes.oneOf([
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'left',
'left-start',
'left-end',
'right',
'right-start',
'right-end'
]),
showArrow: PropTypes.bool,
disabled: PropTypes.bool,
openDelay: PropTypes.number,
closeDelay: PropTypes.number,
contentProps: PropTypes.object,
positioning: PropTypes.object
}
export default Tooltip