@loomhq/lens 10.58.2 → 10.59.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 const Tooltip: ({ children, content, placement, keepOpen, triggerOffset, maxWidth, isInline, isDisabled, container, tabIndex, zIndex, verticalAlign, delay, ...rest }: TooltipProps) => JSX.Element;
|
|
5
|
+
declare const Tooltip: ({ children, content, placement, keepOpen, triggerOffset, maxWidth, isInline, isDisabled, container, tabIndex, zIndex, verticalAlign, delay, dynamicPosition, ...rest }: TooltipProps) => JSX.Element;
|
|
6
6
|
export declare const availablePlacements: string[];
|
|
7
7
|
declare type TooltipBoxProps = {
|
|
8
8
|
children?: React.ReactNode;
|
|
@@ -21,6 +21,7 @@ declare type TooltipProps = {
|
|
|
21
21
|
keepOpen?: boolean;
|
|
22
22
|
maxWidth?: number | string | [];
|
|
23
23
|
placement?: 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight' | 'leftTop' | 'leftCenter' | 'leftBottom' | 'rightTop' | 'rightCenter' | 'rightBottom';
|
|
24
|
+
dynamicPosition?: boolean;
|
|
24
25
|
triggerOffset?: number;
|
|
25
26
|
verticalAlign?: string;
|
|
26
27
|
zIndex?: number;
|
|
@@ -11,10 +11,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import React, { useState, useRef, useEffect } from 'react';
|
|
13
13
|
import { getColorValue, getFontWeight, getRadius, getShadow, getSize, getTextSize, u, } from '../../utilities';
|
|
14
|
-
import { useHover, useLayer, mergeRefs } from 'react-laag';
|
|
14
|
+
import { useHover, useLayer, mergeRefs, useMousePositionAsTrigger, } 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 { usePrefersReducedMotion } from '../../hooks/use-prefer-reduced-motion';
|
|
18
19
|
const placements = {
|
|
19
20
|
topLeft: 'top-start',
|
|
20
21
|
topCenter: 'top-center',
|
|
@@ -69,15 +70,20 @@ function getInitialDelaySpeed(delay) {
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
const Tooltip = (_a) => {
|
|
72
|
-
var { children, content, placement = 'topCenter', keepOpen, triggerOffset = 4, maxWidth = 26, isInline = true, isDisabled, container, tabIndex = 0, zIndex = 1100, verticalAlign = 'middle', delay = 'immediate' } = _a, rest = __rest(_a, ["children", "content", "placement", "keepOpen", "triggerOffset", "maxWidth", "isInline", "isDisabled", "container", "tabIndex", "zIndex", "verticalAlign", "delay"]);
|
|
73
|
+
var { children, content, placement = 'topCenter', keepOpen, triggerOffset = 4, maxWidth = 26, isInline = true, isDisabled, container, tabIndex = 0, zIndex = 1100, verticalAlign = 'middle', delay = 'immediate', dynamicPosition = false } = _a, rest = __rest(_a, ["children", "content", "placement", "keepOpen", "triggerOffset", "maxWidth", "isInline", "isDisabled", "container", "tabIndex", "zIndex", "verticalAlign", "delay", "dynamicPosition"]);
|
|
73
74
|
const [show, hoverProps] = useHover({
|
|
74
75
|
delayEnter: getInitialDelaySpeed(delay),
|
|
75
76
|
delayLeave: 200,
|
|
76
77
|
});
|
|
78
|
+
const { handleMouseEvent, trigger, parentRef } = useMousePositionAsTrigger({
|
|
79
|
+
enabled: show,
|
|
80
|
+
});
|
|
77
81
|
const [isOverTooltip, setIsOverTooltip] = useState(false);
|
|
78
82
|
const [isOpen, setIsOpen] = useState(false);
|
|
79
83
|
const focusRef = useRef();
|
|
80
84
|
const isTooltipDisabled = !content || isDisabled;
|
|
85
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
86
|
+
const allowTrackMousePosition = dynamicPosition && !prefersReducedMotion;
|
|
81
87
|
// show the tooltip if a user has focused or hovered on it AND it is not disabled
|
|
82
88
|
useEffect(() => {
|
|
83
89
|
const keepTooltipOpenOnHover = isOverTooltip && keepOpen;
|
|
@@ -130,9 +136,10 @@ const Tooltip = (_a) => {
|
|
|
130
136
|
triggerOffset,
|
|
131
137
|
container,
|
|
132
138
|
auto: true,
|
|
139
|
+
trigger: allowTrackMousePosition ? trigger : null,
|
|
133
140
|
});
|
|
134
141
|
return (React.createElement(React.Fragment, null,
|
|
135
|
-
React.createElement(TooltipChildren, Object.assign({}, triggerProps, hoverProps, { onFocus: handleFocus, onBlur: handleBlur, isInline: isInline, verticalAlign: verticalAlign, tabIndex: isTooltipDisabled ? -1 : tabIndex, ref: mergeRefs(triggerProps.ref, focusRef) }), children),
|
|
142
|
+
React.createElement(TooltipChildren, Object.assign({}, triggerProps, hoverProps, { onFocus: handleFocus, onBlur: handleBlur, isInline: isInline, verticalAlign: verticalAlign, tabIndex: isTooltipDisabled ? -1 : tabIndex, ref: mergeRefs(triggerProps.ref, focusRef, parentRef), onMouseMove: allowTrackMousePosition ? handleMouseEvent : null }), children),
|
|
136
143
|
isOpen &&
|
|
137
144
|
renderLayer(React.createElement("div", Object.assign({}, layerProps, { style: Object.assign(Object.assign({}, layerProps.style), { zIndex }) }),
|
|
138
145
|
React.createElement(TooltipBox, Object.assign({ maxWidth: maxWidth, onMouseEnter: () => setIsOverTooltip(true), onMouseLeave: () => setIsOverTooltip(false) }, rest), content)))));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function usePrefersReducedMotion(): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
const QUERY = '(prefers-reduced-motion: no-preference)';
|
|
3
|
+
export function usePrefersReducedMotion() {
|
|
4
|
+
const [prefersReducedMotion, setPrefersReducedMotion] = useState(true);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const mediaQueryList = window.matchMedia(QUERY);
|
|
7
|
+
setPrefersReducedMotion(!window.matchMedia(QUERY).matches);
|
|
8
|
+
const listener = event => {
|
|
9
|
+
setPrefersReducedMotion(!event.matches);
|
|
10
|
+
};
|
|
11
|
+
mediaQueryList.addEventListener('toggle motion', listener);
|
|
12
|
+
return () => {
|
|
13
|
+
mediaQueryList.removeEventListener('toggle motion', listener);
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
return prefersReducedMotion;
|
|
17
|
+
}
|