1
- import React , { FC , ReactNode , useRef , useState } from 'react'
1
+ import React , { FC , HTMLAttributes , ReactNode , useEffect , useRef , useState } from 'react'
2
2
import { createPortal } from 'react-dom'
3
-
4
3
import classNames from 'classnames'
5
4
import PropTypes from 'prop-types'
6
5
import { usePopper } from 'react-popper'
7
6
import { Transition } from 'react-transition-group'
8
7
9
8
import { Triggers , triggerPropType } from '../Types'
10
9
11
- export interface CTooltipProps {
12
- // TODO: find solution to not use any
13
- children : any
10
+ export interface CTooltipProps extends HTMLAttributes < HTMLDivElement > {
11
+ /**
12
+ * A string of all className you want applied to the component.
13
+ */
14
+ className ?: string
14
15
/**
15
16
* Content node for your component.
16
17
*/
@@ -45,6 +46,7 @@ export interface CTooltipProps {
45
46
46
47
export const CTooltip : FC < CTooltipProps > = ( {
47
48
children,
49
+ className,
48
50
content,
49
51
offset = [ 0 , 0 ] ,
50
52
onHide,
@@ -73,6 +75,10 @@ export const CTooltip: FC<CTooltipProps> = ({
73
75
placement : placement ,
74
76
} )
75
77
78
+ useEffect ( ( ) => {
79
+ setVisible ( visible )
80
+ } , [ visible ] )
81
+
76
82
const getTransitionClass = ( state : string ) => {
77
83
return state === 'entering'
78
84
? 'fade'
@@ -85,7 +91,7 @@ export const CTooltip: FC<CTooltipProps> = ({
85
91
86
92
return (
87
93
< >
88
- { React . cloneElement ( children , {
94
+ { React . cloneElement ( children as React . ReactElement < any > , {
89
95
ref : setReferenceElement ,
90
96
...( ( trigger === 'click' || trigger . includes ( 'click' ) ) && {
91
97
onClick : ( ) => setVisible ( ! _visible ) ,
@@ -121,6 +127,7 @@ export const CTooltip: FC<CTooltipProps> = ({
121
127
`tooltip bs-tooltip-${
122
128
placement === 'left' ? 'start' : placement === 'right' ? 'end' : placement
123
129
} `,
130
+ className ,
124
131
transitionClass ,
125
132
) }
126
133
ref = { setPopperElement }
@@ -142,7 +149,7 @@ export const CTooltip: FC<CTooltipProps> = ({
142
149
}
143
150
144
151
CTooltip . propTypes = {
145
- children : PropTypes . any ,
152
+ children : PropTypes . node ,
146
153
content : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) ,
147
154
offset : PropTypes . any , // TODO: find good proptype
148
155
onHide : PropTypes . func ,
0 commit comments