@loomhq/lens 10.58.2 → 10.60.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.
- package/dist/components/tooltip/tooltip.d.ts +2 -1
- package/dist/components/tooltip/tooltip.js +10 -3
- package/dist/css-utilities/rules.d.ts +4 -4
- package/dist/hooks/use-prefer-reduced-motion.d.ts +1 -0
- package/dist/hooks/use-prefer-reduced-motion.js +17 -0
- package/dist/utilities/case.d.ts +1 -1
- package/dist/utilities/case.js +1 -1
- package/dist/utilities/color.d.ts +4 -3
- package/dist/utilities/color.js +1 -1
- package/dist/utilities/index.d.ts +5 -5
- package/package.json +1 -1
|
@@ -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)))));
|
|
@@ -106,7 +106,7 @@ export const displayRules: {
|
|
|
106
106
|
selector: string;
|
|
107
107
|
declarations: {
|
|
108
108
|
property: string;
|
|
109
|
-
value:
|
|
109
|
+
value: string;
|
|
110
110
|
}[];
|
|
111
111
|
}[];
|
|
112
112
|
export const flexWrapRules: {
|
|
@@ -129,7 +129,7 @@ export const flexItemRules: {
|
|
|
129
129
|
modifier: string;
|
|
130
130
|
declarations: {
|
|
131
131
|
property: string;
|
|
132
|
-
value:
|
|
132
|
+
value: string;
|
|
133
133
|
}[];
|
|
134
134
|
}[];
|
|
135
135
|
export const JustifyContentRules: {
|
|
@@ -137,7 +137,7 @@ export const JustifyContentRules: {
|
|
|
137
137
|
modifier: string;
|
|
138
138
|
declarations: {
|
|
139
139
|
property: string;
|
|
140
|
-
value:
|
|
140
|
+
value: string;
|
|
141
141
|
}[];
|
|
142
142
|
}[];
|
|
143
143
|
export const growRules: {
|
|
@@ -161,7 +161,7 @@ export const alignSelfRules: {
|
|
|
161
161
|
modifier: string;
|
|
162
162
|
declarations: {
|
|
163
163
|
property: string;
|
|
164
|
-
value:
|
|
164
|
+
value: string;
|
|
165
165
|
}[];
|
|
166
166
|
}[];
|
|
167
167
|
export const overflowRules: {
|
|
@@ -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
|
+
}
|
package/dist/utilities/case.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const pascalCaseToKebabCase: (string: string) => string;
|
package/dist/utilities/case.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
import { hslaColors } from '../colors';
|
|
2
|
+
export declare const getColorAlpha: (color: keyof typeof hslaColors, alpha: number) => string;
|
|
3
|
+
export declare const getColorScale: (color: keyof typeof hslaColors, scaleType: string, scaleIncrement: number) => string;
|
|
4
|
+
export declare const getColorValue: (color?: string) => string | undefined;
|
package/dist/utilities/color.js
CHANGED
|
@@ -13,7 +13,7 @@ export const getColorScale = (color, scaleType, scaleIncrement) => {
|
|
|
13
13
|
};
|
|
14
14
|
return `hsla(${hslaColors[color].h},${hslaColors[color].s}%,${Math.round(scaledValue())}%,${hslaColors[color].a})`;
|
|
15
15
|
};
|
|
16
|
-
export const getColorValue = color => {
|
|
16
|
+
export const getColorValue = (color) => {
|
|
17
17
|
if (color) {
|
|
18
18
|
if (color in hslaColors || color in themeColors.light) {
|
|
19
19
|
return `var(--lns-color-${color})`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './color';
|
|
2
|
+
export * from './responsive';
|
|
3
|
+
export * from './size';
|
|
4
|
+
export * from './styles';
|
|
5
|
+
export * from './case';
|