1- import React , { FC , ReactNode , useRef , useState } from 'react'
1+ import React , { FC , HTMLAttributes , ReactNode , useEffect , useRef , useState } from 'react'
22import { createPortal } from 'react-dom'
3-
43import classNames from 'classnames'
54import PropTypes from 'prop-types'
65import { usePopper } from 'react-popper'
76import { Transition } from 'react-transition-group'
87
98import { Triggers , triggerPropType } from '../Types'
109
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
1415 /**
1516 * Content node for your component.
1617 */
@@ -45,6 +46,7 @@ export interface CTooltipProps {
4546
4647export const CTooltip : FC < CTooltipProps > = ( {
4748 children,
49+ className,
4850 content,
4951 offset = [ 0 , 0 ] ,
5052 onHide,
@@ -73,6 +75,10 @@ export const CTooltip: FC<CTooltipProps> = ({
7375 placement : placement ,
7476 } )
7577
78+ useEffect ( ( ) => {
79+ setVisible ( visible )
80+ } , [ visible ] )
81+
7682 const getTransitionClass = ( state : string ) => {
7783 return state === 'entering'
7884 ? 'fade'
@@ -85,7 +91,7 @@ export const CTooltip: FC<CTooltipProps> = ({
8591
8692 return (
8793 < >
88- { React . cloneElement ( children , {
94+ { React . cloneElement ( children as React . ReactElement < any > , {
8995 ref : setReferenceElement ,
9096 ...( ( trigger === 'click' || trigger . includes ( 'click' ) ) && {
9197 onClick : ( ) => setVisible ( ! _visible ) ,
@@ -121,6 +127,7 @@ export const CTooltip: FC<CTooltipProps> = ({
121127 `tooltip bs-tooltip-${
122128 placement === 'left' ? 'start' : placement === 'right' ? 'end' : placement
123129 } `,
130+ className ,
124131 transitionClass ,
125132 ) }
126133 ref = { setPopperElement }
@@ -142,7 +149,7 @@ export const CTooltip: FC<CTooltipProps> = ({
142149}
143150
144151CTooltip . propTypes = {
145- children : PropTypes . any ,
152+ children : PropTypes . node ,
146153 content : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) ,
147154 offset : PropTypes . any , // TODO: find good proptype
148155 onHide : PropTypes . func ,
0 commit comments