11/*
2- *
32 * Tooltip
4- *
3+
4+ * use custom animation Globally at GlobalStyle.ts
55 */
66
77import { FC , ReactNode , useState , useRef , memo } from 'react'
88
9- import type { TTooltipPlacement , TTooltipAnimation } from '@/spec'
9+ import type { TTooltipPlacement } from '@/spec'
1010import { css , buildLog , isDescendant } from '@/utils'
1111import { useOutsideClick } from '@/hooks'
1212
@@ -28,7 +28,6 @@ const log = buildLog('c:Tooltip:index')
2828type TProps = {
2929 children : ReactNode
3030 content : string | ReactNode
31- animation ?: TTooltipAnimation
3231 placement ?: TTooltipPlacement
3332 // more options see: https://atomiks.github.io/tippyjs/all-options/
3433 delay ?: number
@@ -49,7 +48,6 @@ type TProps = {
4948
5049const Tooltip : FC < TProps > = ( {
5150 children,
52- animation = 'scale' ,
5351 noPadding = false ,
5452 onHide,
5553 onShow,
@@ -116,56 +114,34 @@ const Tooltip: FC<TProps> = ({
116114 }
117115 } )
118116
117+ const props = {
118+ ref,
119+ content : PopoverContent ,
120+ placement,
121+ hideOnClick,
122+ zIndex : css . zIndex . popover ,
123+ interactive : true ,
124+ delay : [ delay , 0 ] as [ number , number ] ,
125+ offset : [ 5 , 5 ] as [ number , number ] ,
126+ duration,
127+ trigger,
128+
129+ onHide : ( ) => {
130+ setInstance ( null )
131+ setActive ( false )
132+ onHide ?.( )
133+ } ,
134+ onShow : ( instance ) => {
135+ setInstance ( instance )
136+ setActive ( true )
137+ onShow ?.( )
138+ } ,
139+ }
140+
119141 return ! noPadding ? (
120- < StyledTippy
121- ref = { ref }
122- content = { PopoverContent }
123- placement = { placement }
124- hideOnClick = { hideOnClick }
125- onHide = { ( ) => {
126- setInstance ( null )
127- setActive ( false )
128- onHide ?.( )
129- } }
130- onShow = { ( instance ) => {
131- setInstance ( instance )
132- setActive ( true )
133- onShow ?.( )
134- } }
135- zIndex = { css . zIndex . popover }
136- interactive
137- delay = { delay }
138- duration = { duration }
139- animation = { animation }
140- trigger = { trigger }
141- >
142- { ContentComp }
143- </ StyledTippy >
142+ < StyledTippy { ...props } > { ContentComp } </ StyledTippy >
144143 ) : (
145- < NoPaddingStyledTippy
146- ref = { ref }
147- content = { PopoverContent }
148- placement = { placement }
149- hideOnClick = { hideOnClick }
150- animation = { animation }
151- onHide = { ( instance ) => {
152- setInstance ( instance )
153- setActive ( false )
154- onHide ?.( )
155- } }
156- onShow = { ( instance ) => {
157- setInstance ( instance )
158- setActive ( true )
159- onShow ?.( )
160- } }
161- zIndex = { css . zIndex . popover }
162- interactive
163- delay = { delay }
164- duration = { duration }
165- trigger = { trigger }
166- >
167- { ContentComp }
168- </ NoPaddingStyledTippy >
144+ < NoPaddingStyledTippy { ...props } > { ContentComp } </ NoPaddingStyledTippy >
169145 )
170146}
171147
0 commit comments