-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.tsx
78 lines (68 loc) · 1.61 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* External dependencies
*/
import classnames from 'classnames';
import type { Ref, ForwardedRef } from 'react';
/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import Label from './label';
import type { Axis, Position } from './utils';
import { useResizeLabel, POSITIONS } from './utils';
import { Root } from './styles/resize-tooltip.styles';
type ResizeTooltipProps = React.ComponentProps< typeof Root > & {
'aria-hidden'?: boolean;
axis?: Axis;
className?: string;
fadeTimeout?: number;
isVisible?: boolean;
labelRef?: Ref< HTMLDivElement >;
onResize?: Parameters< typeof useResizeLabel >[ 0 ][ 'onResize' ];
position?: Position;
showPx?: boolean;
zIndex?: number;
};
const noop = () => {};
function ResizeTooltip(
{
axis,
className,
fadeTimeout = 180,
isVisible = true,
labelRef,
onResize = noop,
position = POSITIONS.bottom,
showPx = true,
zIndex = 1000,
...props
}: ResizeTooltipProps,
ref: ForwardedRef< HTMLDivElement >
): JSX.Element | null {
const { label, resizeListener } = useResizeLabel( {
axis,
fadeTimeout,
onResize,
showPx,
position,
} );
if ( ! isVisible ) return null;
const classes = classnames( 'components-resize-tooltip', className );
return (
<Root aria-hidden="true" className={ classes } ref={ ref } { ...props }>
{ resizeListener }
<Label
aria-hidden={ props[ 'aria-hidden' ] }
label={ label }
position={ position }
ref={ labelRef }
zIndex={ zIndex }
/>
</Root>
);
}
const ForwardedComponent = forwardRef( ResizeTooltip );
export default ForwardedComponent;