1
- import React , { useState , useEffect , useRef , useCallback } from 'react' ;
2
- import PropTypes from 'prop-types' ;
1
+ import React , { useState , useEffect , useRef , useCallback } from 'react'
2
+ import PropTypes from 'prop-types'
3
3
import tippy from 'tippy.js'
4
- import 'tippy.js/dist/tippy.css' ;
4
+ import 'tippy.js/dist/tippy.css'
5
5
import { renderToString } from 'react-dom/server'
6
6
7
- // TODO: reference to tippy instance as a prop? possibility of components as a content?
8
-
9
7
//component - CoreUI / CTooltip
10
- const generateKey = ( ) => Math . random ( ) . toString ( 36 ) . substr ( 2 )
11
-
12
8
const CTooltip = props => {
13
9
14
10
let {
15
11
//
16
12
children,
17
- allowHTML,
18
13
content,
19
- delay,
20
- duration,
21
- hideOnClick,
22
14
interactive,
23
- offset,
24
15
placement,
25
- showOnCreate,
26
16
trigger,
27
17
advancedOptions
28
- } = props ;
18
+ } = props
29
19
30
20
const computedContent = useCallback (
31
21
( ) => typeof content === 'string' ? content : renderToString ( content ) ,
32
22
[ content ]
33
- ) ;
23
+ )
34
24
35
25
const config = {
36
- allowHTML,
26
+ allowHTML : true ,
37
27
content : computedContent ,
38
- delay,
39
- duration,
40
- hideOnClick,
41
28
interactive,
42
- offset,
43
29
placement,
44
- showOnCreate,
45
30
trigger,
46
31
...advancedOptions
47
32
}
48
33
49
- const key = useState ( generateKey ( ) ) [ 0 ]
34
+ const key = useState ( Math . random ( ) . toString ( 36 ) . substr ( 2 ) ) [ 0 ]
50
35
const instance = useRef ( )
51
-
36
+
52
37
useEffect ( ( ) => {
53
38
if ( instance . current ) {
54
39
instance . current . setProps ( config )
@@ -70,39 +55,29 @@ const CTooltip = props=>{
70
55
} )
71
56
}
72
57
</ >
73
- ) ;
74
-
58
+ )
75
59
}
76
60
77
61
CTooltip . propTypes = {
78
- allowHTML : PropTypes . bool ,
79
- config : PropTypes . object ,
80
62
children : PropTypes . node ,
81
63
content : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) ,
82
- delay : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . array ] ) ,
83
- duration : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . array ] ) ,
84
- hideOnClick : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . string ] ) ,
85
64
interactive : PropTypes . bool ,
86
- offset : PropTypes . array ,
87
- //TODO posible positions check
88
- placement : PropTypes . string ,
89
- showOnCreate : PropTypes . bool ,
65
+ placement : PropTypes . oneOf ( [
66
+ '' , 'top-end' , 'top' , 'top-start' ,
67
+ 'bottom-end' , 'bottom' , 'bottom-start' ,
68
+ 'right-start' , 'right' , 'right-end' ,
69
+ 'left-start' , 'left' , 'left-end'
70
+ ] ) ,
90
71
trigger : PropTypes . string ,
91
72
advancedOptions : PropTypes . object
92
73
}
93
74
94
75
CTooltip . defaultProps = {
95
- allowHTML : false ,
96
76
content : '' ,
97
- delay : 0 ,
98
- duration : [ 300 , 250 ] ,
99
- hideOnClick : true ,
100
77
interactive : false ,
101
- offset : [ 0 , 10 ] ,
102
78
placement : 'top' ,
103
- showOnCreate : false ,
104
79
trigger : 'mouseenter focus' ,
105
80
advancedOptions : { }
106
- } ;
81
+ }
107
82
108
- export default CTooltip ;
83
+ export default CTooltip
0 commit comments