@loomhq/lens 10.50.0 → 10.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
declare type DelaySpeed = 'immediate' | 'long';
|
|
3
3
|
declare const TooltipBoxWrapper: import("@emotion/styled-base").StyledComponent<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, TooltipBoxProps, object>;
|
|
4
4
|
export declare const TooltipBox: ({ children, maxWidth, onMouseEnter, onMouseLeave, layerProps, zIndex, ...rest }: TooltipBoxProps & React.ComponentProps<typeof TooltipBoxWrapper>) => JSX.Element;
|
|
5
|
-
declare
|
|
5
|
+
declare const Tooltip: ({ children, content, placement, keepOpen, triggerOffset, maxWidth, isInline, isDisabled, container, zIndex, verticalAlign, delay, ...rest }: TooltipProps) => JSX.Element;
|
|
6
6
|
export declare const availablePlacements: string[];
|
|
7
7
|
declare type TooltipBoxProps = {
|
|
8
8
|
children?: React.ReactNode;
|
|
@@ -25,5 +25,6 @@ declare type TooltipProps = {
|
|
|
25
25
|
verticalAlign?: string;
|
|
26
26
|
zIndex?: number;
|
|
27
27
|
delay?: DelaySpeed;
|
|
28
|
+
tabIndex?: number;
|
|
28
29
|
};
|
|
29
30
|
export default Tooltip;
|
|
@@ -9,12 +9,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React, { useState } from 'react';
|
|
12
|
+
import React, { useState, useRef } from 'react';
|
|
13
13
|
import { getColorValue, getFontWeight, getRadius, getShadow, getSize, getTextSize, u, } from '../../utilities';
|
|
14
|
-
import { useHover, useLayer } from 'react-laag';
|
|
14
|
+
import { useHover, useLayer, mergeRefs } from 'react-laag';
|
|
15
15
|
import ResizeObserver from 'resize-observer-polyfill';
|
|
16
16
|
import styled from '@emotion/styled';
|
|
17
17
|
import { textSizes } from '../../variables';
|
|
18
|
+
import useFocusedElement from '../../hooks/use-focused-element';
|
|
18
19
|
const placements = {
|
|
19
20
|
topLeft: 'top-start',
|
|
20
21
|
topCenter: 'top-center',
|
|
@@ -48,7 +49,7 @@ export const TooltipBox = (_a) => {
|
|
|
48
49
|
var { children, maxWidth, onMouseEnter, onMouseLeave, layerProps, zIndex } = _a, rest = __rest(_a, ["children", "maxWidth", "onMouseEnter", "onMouseLeave", "layerProps", "zIndex"]);
|
|
49
50
|
return (React.createElement(TooltipBoxWrapper, Object.assign({ maxWidth: maxWidth, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, zIndex: zIndex }, layerProps, rest), children));
|
|
50
51
|
};
|
|
51
|
-
const TooltipChildren = styled.
|
|
52
|
+
const TooltipChildren = styled.div `
|
|
52
53
|
display: ${props => (props.isInline ? 'inline-block' : 'block')};
|
|
53
54
|
${props => props.verticalAlign && `vertical-align: ${props.verticalAlign}`};
|
|
54
55
|
`;
|
|
@@ -62,14 +63,18 @@ function getInitialDelaySpeed(delay) {
|
|
|
62
63
|
return 200;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
const Tooltip = (_a) => {
|
|
66
67
|
var { children, content, placement = 'topCenter', keepOpen, triggerOffset = 4, maxWidth = 26, isInline = true, isDisabled, container, zIndex = 1100, verticalAlign = 'middle', delay = 'immediate' } = _a, rest = __rest(_a, ["children", "content", "placement", "keepOpen", "triggerOffset", "maxWidth", "isInline", "isDisabled", "container", "zIndex", "verticalAlign", "delay"]);
|
|
67
68
|
const [show, hoverProps] = useHover({
|
|
68
69
|
delayEnter: getInitialDelaySpeed(delay),
|
|
69
70
|
delayLeave: 100,
|
|
70
71
|
});
|
|
71
72
|
const [isOverTooltip, setIsOverTooltip] = useState(false);
|
|
72
|
-
const
|
|
73
|
+
const focusRef = useRef();
|
|
74
|
+
const isFocused = useFocusedElement(focusRef);
|
|
75
|
+
// show the tooltip if a user has focused or hovered on it AND it is not disabled
|
|
76
|
+
const isOpen = (content && (show || (isOverTooltip && keepOpen)) && !isDisabled) ||
|
|
77
|
+
(content && isFocused && !isDisabled);
|
|
73
78
|
const { layerProps, triggerProps, renderLayer } = useLayer({
|
|
74
79
|
isOpen,
|
|
75
80
|
placement: placements[placement],
|
|
@@ -79,10 +84,10 @@ function Tooltip(_a) {
|
|
|
79
84
|
auto: true,
|
|
80
85
|
});
|
|
81
86
|
return (React.createElement(React.Fragment, null,
|
|
82
|
-
React.createElement(TooltipChildren, Object.assign({}, triggerProps, hoverProps, { isInline: isInline, verticalAlign: verticalAlign }), children),
|
|
87
|
+
React.createElement(TooltipChildren, Object.assign({}, triggerProps, hoverProps, { isInline: isInline, verticalAlign: verticalAlign, tabIndex: 0, ref: mergeRefs(triggerProps.ref, focusRef) }), children),
|
|
83
88
|
isOpen &&
|
|
84
89
|
renderLayer(React.createElement("div", Object.assign({}, layerProps, { style: Object.assign(Object.assign({}, layerProps.style), { zIndex }) }),
|
|
85
90
|
React.createElement(TooltipBox, Object.assign({ maxWidth: maxWidth, onMouseEnter: () => setIsOverTooltip(true), onMouseLeave: () => setIsOverTooltip(false) }, rest), content)))));
|
|
86
|
-
}
|
|
91
|
+
};
|
|
87
92
|
export const availablePlacements = Object.keys(placements);
|
|
88
93
|
export default Tooltip;
|