@loomhq/lens 10.62.0 → 10.63.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.
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { getColorValue, getFocusRing } from '../../utilities';
|
|
13
|
-
import React from 'react';
|
|
13
|
+
import React, { useRef } from 'react';
|
|
14
14
|
import styled from '@emotion/styled';
|
|
15
15
|
const sizes = {
|
|
16
16
|
medium: {
|
|
@@ -115,10 +115,17 @@ const SwitchBox = styled.div `
|
|
|
115
115
|
const Switch = (_a) => {
|
|
116
116
|
var { isActive, isDisabled, onChange, size = 'medium', ariaLabelledby, ariaLabel } = _a, props = __rest(_a, ["isActive", "isDisabled", "onChange", "size", "ariaLabelledby", "ariaLabel"]);
|
|
117
117
|
if (ariaLabelledby && ariaLabel) {
|
|
118
|
-
throw new Error('ariaLabelledby and ariaLabel serve the same purpose and therefore cannot be used at the same time. Choose the one that best suites your needs.
|
|
118
|
+
throw new Error('ariaLabelledby and ariaLabel serve the same purpose and therefore cannot be used at the same time. Choose the one that best suites your needs.');
|
|
119
119
|
}
|
|
120
|
+
const ref = useRef(null);
|
|
121
|
+
const toggleSwitch = () => {
|
|
122
|
+
if (!ref.current || isActive) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
ref.current.checked = !ref.current.checked;
|
|
126
|
+
};
|
|
120
127
|
return (React.createElement(SwitchWrapper, null,
|
|
121
|
-
React.createElement(SwitchInput, Object.assign({}, props, { role: "switch", type: "checkbox", checked: isActive, disabled: isDisabled, onChange: onChange, switchSize: size, "aria-labelledby": ariaLabelledby, "aria-label": ariaLabel, "aria-checked": isActive })),
|
|
122
|
-
React.createElement(SwitchBox, { className: "SwitchBox", isDisabled: isDisabled, isActive: isActive, switchSize: size })));
|
|
128
|
+
React.createElement(SwitchInput, Object.assign({}, props, { role: "switch", type: "checkbox", ref: ref, checked: isActive, disabled: isDisabled, onChange: onChange, switchSize: size, "aria-labelledby": ariaLabelledby, "aria-label": ariaLabel, "aria-checked": isActive })),
|
|
129
|
+
React.createElement(SwitchBox, { className: "SwitchBox", isDisabled: isDisabled, isActive: isActive, switchSize: size, onClick: toggleSwitch })));
|
|
123
130
|
};
|
|
124
131
|
export default Switch;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
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
|
+
declare const ShortcutWrapper: import("@emotion/styled-base").StyledComponent<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Pick<React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement>, keyof React.HTMLAttributes<HTMLDivElement>>, object>;
|
|
5
|
+
export declare const ShortcutBox: ({ children, }: React.ComponentProps<typeof ShortcutWrapper>) => JSX.Element;
|
|
4
6
|
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, dynamicPosition, ...rest }: TooltipProps) => JSX.Element;
|
|
7
|
+
declare const Tooltip: ({ children, content, shortcut, placement, keepOpen, triggerOffset, maxWidth, isInline, isDisabled, container, tabIndex, zIndex, verticalAlign, delay, dynamicPosition, ...rest }: TooltipProps) => JSX.Element;
|
|
6
8
|
export declare const availablePlacements: string[];
|
|
7
9
|
declare type TooltipBoxProps = {
|
|
8
10
|
children?: React.ReactNode;
|
|
@@ -16,6 +18,7 @@ declare type TooltipProps = {
|
|
|
16
18
|
children?: React.ReactNode;
|
|
17
19
|
container?: HTMLElement | (() => HTMLElement) | string;
|
|
18
20
|
content?: React.ReactNode;
|
|
21
|
+
shortcut?: [];
|
|
19
22
|
isDisabled?: boolean;
|
|
20
23
|
isInline?: boolean;
|
|
21
24
|
keepOpen?: boolean;
|
|
@@ -10,6 +10,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React, { useState, useRef, useEffect } from 'react';
|
|
13
|
+
import Arrange from '../arrange/arrange';
|
|
14
|
+
import Text from '../text/text';
|
|
13
15
|
import { getColorValue, getFontWeight, getRadius, getShadow, getSize, getTextSize, u, } from '../../utilities';
|
|
14
16
|
import { useHover, useLayer, mergeRefs, useMousePositionAsTrigger, } from 'react-laag';
|
|
15
17
|
import ResizeObserver from 'resize-observer-polyfill';
|
|
@@ -34,8 +36,8 @@ const tooltipMinHeight = 4;
|
|
|
34
36
|
const textHeight = textSizes.small.fontSize * textSizes.small.lineHeight;
|
|
35
37
|
const tooltipYPadding = (tooltipMinHeight - textHeight) / 2;
|
|
36
38
|
const TooltipBoxWrapper = styled.div `
|
|
37
|
-
background-color: ${getColorValue('
|
|
38
|
-
color: ${getColorValue('
|
|
39
|
+
background-color: ${getColorValue('background')};
|
|
40
|
+
color: ${getColorValue('body')};
|
|
39
41
|
${getRadius('large')};
|
|
40
42
|
${getFontWeight('medium')};
|
|
41
43
|
${getTextSize('small')};
|
|
@@ -45,9 +47,19 @@ const TooltipBoxWrapper = styled.div `
|
|
|
45
47
|
padding: ${u(tooltipYPadding)} ${u(1.5)};
|
|
46
48
|
z-index: ${props => props.zIndex};
|
|
47
49
|
`;
|
|
50
|
+
const ShortcutWrapper = styled.div `
|
|
51
|
+
background-color: ${getColorValue('backgroundActive')};
|
|
52
|
+
border-radius: 3px;
|
|
53
|
+
color: ${getColorValue('grey3')};
|
|
54
|
+
${getFontWeight('medium')};
|
|
55
|
+
${getTextSize('small')};
|
|
56
|
+
padding-left: ${u(0.5)};
|
|
57
|
+
padding-right: ${u(0.5)};
|
|
58
|
+
`;
|
|
59
|
+
export const ShortcutBox = ({ children, }) => (React.createElement(ShortcutWrapper, null, children));
|
|
48
60
|
export const TooltipBox = (_a) => {
|
|
49
61
|
var { children, maxWidth, onMouseEnter, onMouseLeave, layerProps, zIndex } = _a, rest = __rest(_a, ["children", "maxWidth", "onMouseEnter", "onMouseLeave", "layerProps", "zIndex"]);
|
|
50
|
-
return (React.createElement(TooltipBoxWrapper, Object.assign({ maxWidth: maxWidth, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, zIndex: zIndex }, layerProps, rest), children));
|
|
62
|
+
return (React.createElement(TooltipBoxWrapper, Object.assign({ "data-lens-theme": "dark", maxWidth: maxWidth, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, zIndex: zIndex }, layerProps, rest), children));
|
|
51
63
|
};
|
|
52
64
|
const TooltipChildren = styled.div `
|
|
53
65
|
display: ${props => (props.isInline ? 'inline-block' : 'block')};
|
|
@@ -70,7 +82,7 @@ function getInitialDelaySpeed(delay) {
|
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
const Tooltip = (_a) => {
|
|
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"]);
|
|
85
|
+
var { children, content, shortcut, 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", "shortcut", "placement", "keepOpen", "triggerOffset", "maxWidth", "isInline", "isDisabled", "container", "tabIndex", "zIndex", "verticalAlign", "delay", "dynamicPosition"]);
|
|
74
86
|
const [show, hoverProps] = useHover({
|
|
75
87
|
delayEnter: getInitialDelaySpeed(delay),
|
|
76
88
|
delayLeave: 200,
|
|
@@ -142,7 +154,10 @@ const Tooltip = (_a) => {
|
|
|
142
154
|
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),
|
|
143
155
|
isOpen &&
|
|
144
156
|
renderLayer(React.createElement("div", Object.assign({}, layerProps, { style: Object.assign(Object.assign({}, layerProps.style), { zIndex }) }),
|
|
145
|
-
React.createElement(TooltipBox, Object.assign({ maxWidth: maxWidth, onMouseEnter: () => setIsOverTooltip(true), onMouseLeave: () => setIsOverTooltip(false) }, rest),
|
|
157
|
+
React.createElement(TooltipBox, Object.assign({ maxWidth: maxWidth, onMouseEnter: () => setIsOverTooltip(true), onMouseLeave: () => setIsOverTooltip(false) }, rest),
|
|
158
|
+
React.createElement(Arrange, { gap: "small" },
|
|
159
|
+
React.createElement(Text, { size: "small", fontWeight: "medium" }, content),
|
|
160
|
+
shortcut && (React.createElement(Arrange, { gap: "xsmall" }, shortcut.map((char, index) => (React.createElement(ShortcutBox, { key: index }, char)))))))))));
|
|
146
161
|
};
|
|
147
162
|
export const availablePlacements = Object.keys(placements);
|
|
148
163
|
export default Tooltip;
|