@@ -7,28 +7,9 @@ import {invariant} from '../utils/invariant'
7
7
import styled from 'styled-components'
8
8
import { get } from '../constants'
9
9
import { useOnEscapePress } from '../hooks/useOnEscapePress'
10
+ import { ComponentProps } from '../utils/types'
10
11
11
- export type TooltipProps = {
12
- direction ?: 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'
13
- text ?: string
14
- noDelay ?: boolean
15
- align ?: 'left' | 'right'
16
- wrap ?: boolean
17
- type ?: 'label' | 'description'
18
- 'aria-label' ?: React . AriaAttributes [ 'aria-label' ]
19
- } & SxProp
20
-
21
- export type TriggerPropsType = {
22
- 'aria-describedby' ?: string
23
- 'aria-labelledby' ?: string
24
- 'aria-label' ?: string
25
- onBlur ?: React . FocusEventHandler
26
- onFocus ?: React . FocusEventHandler
27
- onMouseEnter ?: React . MouseEventHandler
28
- ref ?: React . RefObject < HTMLElement >
29
- }
30
-
31
- const TooltipEL = styled . div < TooltipProps > `
12
+ const StyledTooltip = styled . div `
32
13
// tooltip element itself
33
14
position: absolute;
34
15
z-index: 1000000;
@@ -294,7 +275,30 @@ const TooltipEL = styled.div<TooltipProps>`
294
275
${ sx } ;
295
276
`
296
277
297
- export const Tooltip : React . FC < React . PropsWithChildren < TooltipProps > > = ( {
278
+ export type TooltipProps = React . PropsWithChildren <
279
+ {
280
+ direction ?: 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'
281
+ text ?: string
282
+ noDelay ?: boolean
283
+ align ?: 'left' | 'right'
284
+ wrap ?: boolean
285
+ type ?: 'label' | 'description'
286
+ 'aria-label' ?: React . AriaAttributes [ 'aria-label' ]
287
+ } & SxProp &
288
+ ComponentProps < typeof StyledTooltip >
289
+ >
290
+
291
+ export type TriggerPropsType = {
292
+ 'aria-describedby' ?: string
293
+ 'aria-labelledby' ?: string
294
+ 'aria-label' ?: string
295
+ onBlur ?: React . FocusEventHandler
296
+ onFocus ?: React . FocusEventHandler
297
+ onMouseEnter ?: React . MouseEventHandler
298
+ ref ?: React . RefObject < HTMLElement >
299
+ }
300
+
301
+ export const Tooltip = ( {
298
302
direction = 'n' ,
299
303
// used for description type
300
304
text,
@@ -306,7 +310,7 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = ({
306
310
type = 'label' ,
307
311
children,
308
312
...rest
309
- } ) => {
313
+ } : TooltipProps ) => {
310
314
const id = useId ( )
311
315
const triggerRef = useRef < HTMLElement > ( null )
312
316
const child = Children . only ( children )
@@ -376,7 +380,7 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = ({
376
380
child . props . onMouseEnter ?.( event )
377
381
} ,
378
382
} ) }
379
- < TooltipEL
383
+ < StyledTooltip
380
384
data-direction = { direction }
381
385
data-state = { open ? 'open' : undefined }
382
386
data-align = { align }
@@ -390,7 +394,7 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = ({
390
394
id = { id }
391
395
>
392
396
{ text ?? label }
393
- </ TooltipEL >
397
+ </ StyledTooltip >
394
398
</ Box >
395
399
)
396
400
}
0 commit comments