Skip to content

Commit 3d36c5c

Browse files
committed
refactor: CTooltip: limit main props to essential
1 parent fc2af86 commit 3d36c5c

File tree

1 file changed

+17
-42
lines changed

1 file changed

+17
-42
lines changed

src/CTooltip.js

+17-42
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,39 @@
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'
33
import tippy from 'tippy.js'
4-
import 'tippy.js/dist/tippy.css';
4+
import 'tippy.js/dist/tippy.css'
55
import { renderToString } from 'react-dom/server'
66

7-
// TODO: reference to tippy instance as a prop? possibility of components as a content?
8-
97
//component - CoreUI / CTooltip
10-
const generateKey = () => Math.random().toString(36).substr(2)
11-
128
const CTooltip = props=>{
139

1410
let {
1511
//
1612
children,
17-
allowHTML,
1813
content,
19-
delay,
20-
duration,
21-
hideOnClick,
2214
interactive,
23-
offset,
2415
placement,
25-
showOnCreate,
2616
trigger,
2717
advancedOptions
28-
} = props;
18+
} = props
2919

3020
const computedContent = useCallback(
3121
() => typeof content === 'string' ? content : renderToString(content),
3222
[content]
33-
);
23+
)
3424

3525
const config = {
36-
allowHTML,
26+
allowHTML: true,
3727
content: computedContent,
38-
delay,
39-
duration,
40-
hideOnClick,
4128
interactive,
42-
offset,
4329
placement,
44-
showOnCreate,
4530
trigger,
4631
...advancedOptions
4732
}
4833

49-
const key = useState(generateKey())[0]
34+
const key = useState(Math.random().toString(36).substr(2))[0]
5035
const instance = useRef()
51-
36+
5237
useEffect(() => {
5338
if (instance.current) {
5439
instance.current.setProps(config)
@@ -70,39 +55,29 @@ const CTooltip = props=>{
7055
})
7156
}
7257
</>
73-
);
74-
58+
)
7559
}
7660

7761
CTooltip.propTypes = {
78-
allowHTML: PropTypes.bool,
79-
config: PropTypes.object,
8062
children: PropTypes.node,
8163
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]),
8564
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+
]),
9071
trigger: PropTypes.string,
9172
advancedOptions: PropTypes.object
9273
}
9374

9475
CTooltip.defaultProps = {
95-
allowHTML: false,
9676
content: '',
97-
delay: 0,
98-
duration: [300, 250],
99-
hideOnClick: true,
10077
interactive: false,
101-
offset: [0, 10],
10278
placement: 'top',
103-
showOnCreate: false,
10479
trigger: 'mouseenter focus',
10580
advancedOptions: {}
106-
};
81+
}
10782

108-
export default CTooltip;
83+
export default CTooltip

0 commit comments

Comments
 (0)