@swan-io/lake 6.0.0 → 7.0.1
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/package.json +3 -5
- package/src/components/FixedListViewCells.d.ts +7 -7
- package/src/components/FixedListViewCells.js +1 -1
- package/src/components/LakeCombobox.js +1 -1
- package/src/components/LakeCopyButton.js +1 -1
- package/src/components/LakeTagInput.d.ts +2 -2
- package/src/components/LakeText.d.ts +2 -2
- package/src/components/LakeTextInput.d.ts +2 -2
- package/src/components/LakeTooltip.d.ts +1 -1
- package/src/components/LakeTooltip.js +26 -98
- package/src/components/Popover.d.ts +2 -2
- package/src/components/Popover.js +25 -60
- package/src/components/Pressable.d.ts +2 -2
- package/src/components/QuickActions.js +1 -1
- package/src/components/RightPanel.js +1 -0
- package/src/components/Svg.d.ts +5 -0
- package/src/components/Svg.js +1 -0
- package/src/hooks/useContextualLayer.d.ts +37 -0
- package/src/hooks/useContextualLayer.js +81 -0
- package/src/utils/popper.d.ts +0 -2
- package/src/utils/popper.js +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swan-io/lake",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18.0.0",
|
|
6
6
|
"yarn": "^1.22.0"
|
|
@@ -26,11 +26,10 @@
|
|
|
26
26
|
],
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@popperjs/core": "^2.11.8",
|
|
30
29
|
"@react-three/drei": "^9.99.4",
|
|
31
30
|
"@react-three/fiber": "^8.15.16",
|
|
32
|
-
"@swan-io/boxed": "^2.0
|
|
33
|
-
"@swan-io/chicane": "^
|
|
31
|
+
"@swan-io/boxed": "^2.1.0-beta",
|
|
32
|
+
"@swan-io/chicane": "^2.0.0-rc.0",
|
|
34
33
|
"dayjs": "^1.11.10",
|
|
35
34
|
"polished": "^4.3.1",
|
|
36
35
|
"prism-react-renderer": "^2.3.1",
|
|
@@ -38,7 +37,6 @@
|
|
|
38
37
|
"react-atomic-state": "^2.0.0",
|
|
39
38
|
"react-dom": "^18.2.0",
|
|
40
39
|
"react-native-web": "^0.19.10",
|
|
41
|
-
"react-popper": "^2.3.0",
|
|
42
40
|
"@swan-io/use-form": "^2.0.0-rc.2",
|
|
43
41
|
"rifm": "^0.12.1",
|
|
44
42
|
"three": "^0.161.0",
|
|
@@ -26,7 +26,7 @@ export declare const SimpleTitleCell: ({ isHighlighted, text, tooltip, }: {
|
|
|
26
26
|
hideArrow?: boolean | undefined;
|
|
27
27
|
onHide?: (() => void) | undefined;
|
|
28
28
|
onShow?: (() => void) | undefined;
|
|
29
|
-
placement: "
|
|
29
|
+
placement: "left" | "right" | "center";
|
|
30
30
|
width?: number | undefined;
|
|
31
31
|
togglableOnFocus?: boolean | undefined;
|
|
32
32
|
containerStyle?: import("react-native").StyleProp<import("react-native").ViewStyle>;
|
|
@@ -34,13 +34,13 @@ export declare const SimpleTitleCell: ({ isHighlighted, text, tooltip, }: {
|
|
|
34
34
|
} & import("react").RefAttributes<import("./LakeTooltip").TooltipRef>, "children"> | undefined;
|
|
35
35
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
36
36
|
export declare const SimpleRegularTextCell: ({ variant, text, textAlign, color, }: {
|
|
37
|
-
variant?: "light" | "
|
|
37
|
+
variant?: "light" | "semibold" | "medium" | "regular" | "smallSemibold" | "smallMedium" | "smallRegular" | undefined;
|
|
38
38
|
text: string;
|
|
39
39
|
textAlign?: "left" | "right" | "center" | undefined;
|
|
40
40
|
color?: string | undefined;
|
|
41
41
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
42
42
|
export declare const CopyableRegularTextCell: ({ variant, text, textToCopy, copyWording, copiedWording, tooltip, }: {
|
|
43
|
-
variant?: "light" | "
|
|
43
|
+
variant?: "light" | "semibold" | "medium" | "regular" | "smallSemibold" | "smallMedium" | "smallRegular" | undefined;
|
|
44
44
|
text: string;
|
|
45
45
|
textToCopy?: string | undefined;
|
|
46
46
|
copyWording: string;
|
|
@@ -53,7 +53,7 @@ export declare const CopyableRegularTextCell: ({ variant, text, textToCopy, copy
|
|
|
53
53
|
hideArrow?: boolean | undefined;
|
|
54
54
|
onHide?: (() => void) | undefined;
|
|
55
55
|
onShow?: (() => void) | undefined;
|
|
56
|
-
placement: "
|
|
56
|
+
placement: "left" | "right" | "center";
|
|
57
57
|
width?: number | undefined;
|
|
58
58
|
togglableOnFocus?: boolean | undefined;
|
|
59
59
|
containerStyle?: import("react-native").StyleProp<import("react-native").ViewStyle>;
|
|
@@ -69,13 +69,13 @@ export declare const BalanceCell: ({ value, currency, originalValue, formatCurre
|
|
|
69
69
|
} | undefined;
|
|
70
70
|
formatCurrency: (value: number, currency: string) => string;
|
|
71
71
|
textAlign?: "left" | "right" | "center" | undefined;
|
|
72
|
-
variant?: "light" | "
|
|
72
|
+
variant?: "light" | "semibold" | "medium" | "regular" | "smallSemibold" | "smallMedium" | "smallRegular" | undefined;
|
|
73
73
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
74
74
|
export declare const LinkCell: ({ children, external, onPress, variant, tooltip, }: {
|
|
75
75
|
children: ReactNode;
|
|
76
76
|
onPress: () => void;
|
|
77
77
|
external?: boolean | undefined;
|
|
78
|
-
variant?: "light" | "
|
|
78
|
+
variant?: "light" | "semibold" | "medium" | "regular" | "smallSemibold" | "smallMedium" | "smallRegular" | undefined;
|
|
79
79
|
tooltip?: Omit<{
|
|
80
80
|
children: ReactNode;
|
|
81
81
|
content: ReactNode;
|
|
@@ -84,7 +84,7 @@ export declare const LinkCell: ({ children, external, onPress, variant, tooltip,
|
|
|
84
84
|
hideArrow?: boolean | undefined;
|
|
85
85
|
onHide?: (() => void) | undefined;
|
|
86
86
|
onShow?: (() => void) | undefined;
|
|
87
|
-
placement: "
|
|
87
|
+
placement: "left" | "right" | "center";
|
|
88
88
|
width?: number | undefined;
|
|
89
89
|
togglableOnFocus?: boolean | undefined;
|
|
90
90
|
containerStyle?: import("react-native").StyleProp<import("react-native").ViewStyle>;
|
|
@@ -125,7 +125,7 @@ export const CopyableRegularTextCell = ({ variant = "regular", text, textToCopy,
|
|
|
125
125
|
Clipboard.setString(clipboardText);
|
|
126
126
|
setVisibleState("copied");
|
|
127
127
|
}, [clipboardText]);
|
|
128
|
-
return (_jsxs(View, { style: styles.cell, children: [_jsx(LakeTooltip, { placement: "
|
|
128
|
+
return (_jsxs(View, { style: styles.cell, children: [_jsx(LakeTooltip, { placement: "right", onHide: () => setVisibleState("copy"), togglableOnFocus: true, content: visibleState === "copy" ? copyWording : copiedWording, containerStyle: styles.iconContainer, children: _jsx(Pressable, { role: "button", "aria-label": copyWording, onPress: onPress, style: ({ hovered }) => [styles.icon, hovered && styles.underline], children: ({ hovered }) => (_jsx(Icon, { name: hovered ? "copy-filled" : "copy-regular", color: "currentColor", size: 14 })) }) }), _jsx(Space, { width: 4 }), _jsx(LakeText, { tooltip: tooltip, color: colors.gray[900], style: styles.regularText, variant: variant, children: text })] }));
|
|
129
129
|
};
|
|
130
130
|
// TODO: handle `+` sign properly
|
|
131
131
|
export const BalanceCell = ({ value, currency, originalValue, formatCurrency, textAlign = "right", variant = "medium", }) => {
|
|
@@ -151,7 +151,7 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
151
151
|
setState("dismissed");
|
|
152
152
|
}, 100);
|
|
153
153
|
}, []);
|
|
154
|
-
return (_jsxs(View, { children: [_jsx(LakeTextInput, { containerRef: inputTextRef, style: styles.input, ariaExpanded: state === "opened", ariaControls: state === "opened" ? suggestionsId : "", enterKeyHint: "search", icon: icon, role: "combobox", placeholder: placeholder, value: value, disabled: disabled, error: error, hideErrors: hideErrors, onChangeText: handleChangeText, onChange: onChange, onFocus: handleFocus, onBlur: handleBlur, onKeyPress: handleKeyPress, id: id, readOnly: readOnly }), _jsx(Popover, { id: suggestionsId, role: "listbox", matchReferenceWidth: true, onEscapeKey: dismiss, referenceRef: ref, autoFocus: false, returnFocus: true, visible: state === "opened" && !items.isNotAsked(), underlay: false, forcedMode: "Dropdown",
|
|
154
|
+
return (_jsxs(View, { children: [_jsx(LakeTextInput, { containerRef: inputTextRef, style: styles.input, ariaExpanded: state === "opened", ariaControls: state === "opened" ? suggestionsId : "", enterKeyHint: "search", icon: icon, role: "combobox", placeholder: placeholder, value: value, disabled: disabled, error: error, hideErrors: hideErrors, onChangeText: handleChangeText, onChange: onChange, onFocus: handleFocus, onBlur: handleBlur, onKeyPress: handleKeyPress, id: id, readOnly: readOnly }), _jsx(Popover, { id: suggestionsId, role: "listbox", matchReferenceWidth: true, onEscapeKey: dismiss, referenceRef: ref, autoFocus: false, returnFocus: true, visible: state === "opened" && !items.isNotAsked(), underlay: false, forcedMode: "Dropdown", children: _jsx(View, { style: [styles.list, { maxHeight: itemHeight * nbItemsDisplayed }], children: items.match({
|
|
155
155
|
NotAsked: () => null,
|
|
156
156
|
Loading: () => _jsx(LoadingView, { style: styles.loader }),
|
|
157
157
|
Done: items => items.match({
|
|
@@ -7,7 +7,7 @@ import { Pressable } from "./Pressable";
|
|
|
7
7
|
export const copyButtondefaultSize = 21;
|
|
8
8
|
export const LakeCopyButton = ({ valueToCopy, size = copyButtondefaultSize, copyText, copiedText, }) => {
|
|
9
9
|
const [visibleState, setVisibleState] = useState("copy");
|
|
10
|
-
return (_jsx(LakeTooltip, { describedBy: "copy", placement: "
|
|
10
|
+
return (_jsx(LakeTooltip, { describedBy: "copy", placement: "right", onHide: () => setVisibleState("copy"), togglableOnFocus: true, content: visibleState === "copy" ? copyText : copiedText, children: _jsx(Pressable, { onPress: event => {
|
|
11
11
|
event.stopPropagation();
|
|
12
12
|
event.preventDefault();
|
|
13
13
|
Clipboard.setString(valueToCopy);
|
|
@@ -59,8 +59,8 @@ export declare const LakeTagInput: import("react").ForwardRefExoticComponent<{
|
|
|
59
59
|
role?: import("react-native").WebRole | undefined;
|
|
60
60
|
lang?: string | undefined;
|
|
61
61
|
initialValue?: string | undefined;
|
|
62
|
-
autoComplete?: "name" | "
|
|
63
|
-
enterKeyHint?: "enter" | "search" | "done" | "
|
|
62
|
+
autoComplete?: "name" | "off" | "email" | "tel" | "url" | "additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday" | "bday-day" | "bday-month" | "bday-year" | "cc-additional-name" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "impp" | "language" | "new-password" | "nickname" | "on" | "one-time-code" | "organization" | "organization-title" | "postal-code" | "sex" | "street-address" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-national" | "transaction-amount" | "transaction-currency" | "username" | undefined;
|
|
63
|
+
enterKeyHint?: "enter" | "search" | "done" | "go" | "next" | "send" | "previous" | undefined;
|
|
64
64
|
rows?: number | undefined;
|
|
65
65
|
children?: import("react").ReactNode;
|
|
66
66
|
hitSlop?: import("react-native").Insets | undefined;
|
|
@@ -15,7 +15,7 @@ export declare const LakeText: import("react").ForwardRefExoticComponent<TextPro
|
|
|
15
15
|
children: ReactNode;
|
|
16
16
|
color?: string | undefined;
|
|
17
17
|
userSelect?: TextStyle["userSelect"];
|
|
18
|
-
variant?: "light" | "
|
|
18
|
+
variant?: "light" | "semibold" | "medium" | "regular" | "smallSemibold" | "smallMedium" | "smallRegular" | undefined;
|
|
19
19
|
tooltip?: Omit<{
|
|
20
20
|
children: ReactNode;
|
|
21
21
|
content: ReactNode;
|
|
@@ -24,7 +24,7 @@ export declare const LakeText: import("react").ForwardRefExoticComponent<TextPro
|
|
|
24
24
|
hideArrow?: boolean | undefined;
|
|
25
25
|
onHide?: (() => void) | undefined;
|
|
26
26
|
onShow?: (() => void) | undefined;
|
|
27
|
-
placement: "
|
|
27
|
+
placement: "left" | "right" | "center";
|
|
28
28
|
width?: number | undefined;
|
|
29
29
|
togglableOnFocus?: boolean | undefined;
|
|
30
30
|
containerStyle?: import("react-native").StyleProp<import("react-native").ViewStyle>;
|
|
@@ -72,8 +72,8 @@ export declare const LakeTextInput: import("react").ForwardRefExoticComponent<{
|
|
|
72
72
|
role?: import("react-native").WebRole | undefined;
|
|
73
73
|
lang?: string | undefined;
|
|
74
74
|
initialValue?: string | undefined;
|
|
75
|
-
autoComplete?: "name" | "
|
|
76
|
-
enterKeyHint?: "enter" | "search" | "done" | "
|
|
75
|
+
autoComplete?: "name" | "off" | "email" | "tel" | "url" | "additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday" | "bday-day" | "bday-month" | "bday-year" | "cc-additional-name" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "impp" | "language" | "new-password" | "nickname" | "on" | "one-time-code" | "organization" | "organization-title" | "postal-code" | "sex" | "street-address" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-national" | "transaction-amount" | "transaction-currency" | "username" | undefined;
|
|
76
|
+
enterKeyHint?: "enter" | "search" | "done" | "go" | "next" | "send" | "previous" | undefined;
|
|
77
77
|
rows?: number | undefined;
|
|
78
78
|
readOnly?: boolean | undefined;
|
|
79
79
|
children?: ReactNode;
|
|
@@ -8,7 +8,7 @@ type Props = {
|
|
|
8
8
|
hideArrow?: boolean;
|
|
9
9
|
onHide?: () => void;
|
|
10
10
|
onShow?: () => void;
|
|
11
|
-
placement: "left" | "
|
|
11
|
+
placement: "left" | "right" | "center";
|
|
12
12
|
width?: number;
|
|
13
13
|
togglableOnFocus?: boolean;
|
|
14
14
|
containerStyle?: ViewProps["style"];
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, memo, useEffect, useImperativeHandle,
|
|
2
|
+
import { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState, } from "react";
|
|
3
3
|
import { StyleSheet, View } from "react-native";
|
|
4
|
-
import { usePopper } from "react-popper";
|
|
5
4
|
import { match } from "ts-pattern";
|
|
6
|
-
import { colors, shadows } from "../constants/design";
|
|
5
|
+
import { colors, shadows, spacings } from "../constants/design";
|
|
6
|
+
import { useContextualLayer } from "../hooks/useContextualLayer";
|
|
7
7
|
import { useHover } from "../hooks/useHover";
|
|
8
8
|
import { isNotNullish, isNullishOrEmpty } from "../utils/nullish";
|
|
9
|
-
import { getRootElement
|
|
9
|
+
import { getRootElement } from "../utils/popper";
|
|
10
|
+
import { Box } from "./Box";
|
|
10
11
|
import { Icon } from "./Icon";
|
|
11
12
|
import { LakeText } from "./LakeText";
|
|
12
13
|
import { Portal } from "./Portal";
|
|
14
|
+
import { Polygon, Svg } from "./Svg";
|
|
13
15
|
const { matches: canHover } = window.matchMedia("(hover: hover)");
|
|
14
16
|
const styles = StyleSheet.create({
|
|
15
17
|
base: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
baseTop: {
|
|
19
|
-
marginBottom: 8,
|
|
20
|
-
},
|
|
21
|
-
baseBottom: {
|
|
22
|
-
marginTop: 8,
|
|
23
|
-
},
|
|
24
|
-
baseRight: {
|
|
25
|
-
marginLeft: 8,
|
|
26
|
-
},
|
|
27
|
-
baseLeft: {
|
|
28
|
-
marginRight: 8,
|
|
18
|
+
position: "absolute",
|
|
19
|
+
pointerEvents: "none",
|
|
29
20
|
},
|
|
30
21
|
content: {
|
|
31
22
|
paddingVertical: 12,
|
|
@@ -37,51 +28,13 @@ const styles = StyleSheet.create({
|
|
|
37
28
|
borderColor: colors.gray[900],
|
|
38
29
|
boxShadow: shadows.modal,
|
|
39
30
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
left: 0,
|
|
43
|
-
right: 0,
|
|
44
|
-
margin: "auto",
|
|
45
|
-
width: 14,
|
|
46
|
-
height: 10,
|
|
47
|
-
overflow: "hidden",
|
|
48
|
-
},
|
|
49
|
-
arrowContainerHorizontal: {
|
|
50
|
-
position: "absolute",
|
|
51
|
-
top: 0,
|
|
52
|
-
bottom: 0,
|
|
53
|
-
margin: "auto",
|
|
54
|
-
width: 14,
|
|
55
|
-
height: 10,
|
|
56
|
-
overflow: "hidden",
|
|
57
|
-
},
|
|
58
|
-
arrowContainerTop: {
|
|
59
|
-
bottom: -7,
|
|
60
|
-
},
|
|
61
|
-
arrowContainerBottom: {
|
|
62
|
-
top: -7,
|
|
63
|
-
},
|
|
64
|
-
arrowContainerRight: {
|
|
65
|
-
left: -7,
|
|
66
|
-
},
|
|
67
|
-
arrowContainerLeft: {
|
|
68
|
-
right: -7,
|
|
69
|
-
},
|
|
70
|
-
arrow: {
|
|
71
|
-
position: "relative",
|
|
72
|
-
top: -7,
|
|
73
|
-
height: 14,
|
|
74
|
-
width: 14,
|
|
75
|
-
backgroundColor: colors.gray[900],
|
|
76
|
-
borderWidth: 1,
|
|
77
|
-
borderColor: colors.gray[900],
|
|
78
|
-
transform: "rotate(45deg)",
|
|
31
|
+
arrowBar: {
|
|
32
|
+
paddingHorizontal: spacings[12],
|
|
79
33
|
},
|
|
80
34
|
info: {
|
|
81
35
|
flexGrow: 0,
|
|
82
36
|
},
|
|
83
37
|
});
|
|
84
|
-
const MAX_WIDTH = "calc(100vw - 20px)";
|
|
85
38
|
export const LakeTooltip = forwardRef(({ content, children, ...rest }, forwardedRef) => {
|
|
86
39
|
if (isNullishOrEmpty(content)) {
|
|
87
40
|
return children;
|
|
@@ -89,12 +42,14 @@ export const LakeTooltip = forwardRef(({ content, children, ...rest }, forwarded
|
|
|
89
42
|
return (_jsx(Tooltip, { ref: forwardedRef, content: content, ...rest, children: children }));
|
|
90
43
|
});
|
|
91
44
|
const Tooltip = memo(forwardRef(({ children, content, describedBy, matchReferenceWidth = false, hideArrow = false, onHide, onShow, placement, width, togglableOnFocus = false, containerStyle, disabled = false, }, forwardedRef) => {
|
|
92
|
-
var _a, _b;
|
|
93
|
-
const referenceRef = useRef(null);
|
|
94
|
-
const rootElement = getRootElement(referenceRef.current);
|
|
95
|
-
const [popperElement, setPopperElement] = useState(null);
|
|
96
45
|
const timeoutRef = useRef(0);
|
|
97
46
|
const [visible, setVisible] = useState(false);
|
|
47
|
+
const { referenceRef, position } = useContextualLayer({
|
|
48
|
+
placement,
|
|
49
|
+
visible,
|
|
50
|
+
matchReferenceWidth,
|
|
51
|
+
});
|
|
52
|
+
const rootElement = getRootElement(referenceRef.current);
|
|
98
53
|
useImperativeHandle(forwardedRef, () => ({
|
|
99
54
|
show: () => setVisible(true),
|
|
100
55
|
hide: () => setVisible(false),
|
|
@@ -106,16 +61,6 @@ const Tooltip = memo(forwardRef(({ children, content, describedBy, matchReferenc
|
|
|
106
61
|
setVisible(nextVisible);
|
|
107
62
|
},
|
|
108
63
|
});
|
|
109
|
-
const { attributes, update, styles: popperStyles, state, } = usePopper(referenceRef.current, popperElement, {
|
|
110
|
-
placement,
|
|
111
|
-
modifiers: useMemo(() => [
|
|
112
|
-
{ name: "preventOverflow", enabled: true, options: { padding: 10 } },
|
|
113
|
-
{ name: "flip", enabled: false },
|
|
114
|
-
{ name: "hide", enabled: true },
|
|
115
|
-
{ ...matchReferenceWidthModifier, enabled: matchReferenceWidth },
|
|
116
|
-
], [matchReferenceWidth]),
|
|
117
|
-
});
|
|
118
|
-
const overflowOffset = (_b = (_a = state === null || state === void 0 ? void 0 : state.modifiersData.preventOverflow) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 0;
|
|
119
64
|
useEffect(() => {
|
|
120
65
|
const node = referenceRef.current;
|
|
121
66
|
if (!(node instanceof Element)) {
|
|
@@ -159,31 +104,14 @@ const Tooltip = memo(forwardRef(({ children, content, describedBy, matchReferenc
|
|
|
159
104
|
useEffect(() => {
|
|
160
105
|
return () => clearTimeout(timeoutRef.current);
|
|
161
106
|
}, []);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
(state === null || state === void 0 ? void 0 : state.placement) === "left" && styles.baseLeft,
|
|
172
|
-
], children: [_jsx(View, { style: [styles.content, { width, maxWidth: MAX_WIDTH }], children: typeof content === "string" || typeof content === "number" ? (_jsx(LakeText, { align: "center", color: colors.gray.contrast, children: content })) : (content) }), !hideArrow && (_jsx(View, { role: "none", style: [
|
|
173
|
-
(state === null || state === void 0 ? void 0 : state.placement) === "right" || (state === null || state === void 0 ? void 0 : state.placement) === "left"
|
|
174
|
-
? styles.arrowContainerHorizontal
|
|
175
|
-
: styles.arrowContainer,
|
|
176
|
-
(state === null || state === void 0 ? void 0 : state.placement) === "top" && styles.arrowContainerTop,
|
|
177
|
-
(state === null || state === void 0 ? void 0 : state.placement) === "bottom" && styles.arrowContainerBottom,
|
|
178
|
-
(state === null || state === void 0 ? void 0 : state.placement) === "right" && styles.arrowContainerRight,
|
|
179
|
-
(state === null || state === void 0 ? void 0 : state.placement) === "left" && styles.arrowContainerLeft,
|
|
180
|
-
{
|
|
181
|
-
transform: `translateX(${-overflowOffset}px) rotate(${match(state === null || state === void 0 ? void 0 : state.placement)
|
|
182
|
-
.with("bottom", () => "180deg")
|
|
183
|
-
.with("left", () => "-90deg")
|
|
184
|
-
.with("right", () => "90deg")
|
|
185
|
-
.otherwise(() => "0deg")})`,
|
|
186
|
-
},
|
|
187
|
-
], children: _jsx(View, { style: styles.arrow }) }))] }) }) }))] }));
|
|
107
|
+
return (_jsxs(_Fragment, { children: [_jsx(View, { ref: referenceRef, style: containerStyle, children: children }), isNotNullish(rootElement) && position.isSome() && !disabled && (_jsx(Portal, { container: rootElement, children: _jsx(View, { style: position.get().rootStyle, children: _jsxs(View, { role: "tooltip", "aria-describedby": describedBy, style: [styles.base, position.get().style], children: [position.get().verticalPosition === "bottom" ? (_jsx(Box, { direction: "row", justifyContent: match(position.get().horizontalPosition)
|
|
108
|
+
.with("left", () => "start")
|
|
109
|
+
.with("center", () => "center")
|
|
110
|
+
.with("right", () => "end")
|
|
111
|
+
.exhaustive(), style: styles.arrowBar, children: _jsx(Svg, { width: 16, height: 8, viewBox: "0 0 16 8", children: _jsx(Polygon, { points: "8 0 16 8 0 8", fill: hideArrow ? "transparent" : colors.gray[900] }) }) })) : null, _jsx(View, { style: [styles.content, { width }], children: typeof content === "string" || typeof content === "number" ? (_jsx(LakeText, { align: "center", color: colors.gray.contrast, children: content })) : (content) }), position.get().verticalPosition === "top" ? (_jsx(Box, { direction: "row", justifyContent: match(position.get().horizontalPosition)
|
|
112
|
+
.with("left", () => "start")
|
|
113
|
+
.with("center", () => "center")
|
|
114
|
+
.with("right", () => "end")
|
|
115
|
+
.exhaustive(), style: styles.arrowBar, children: _jsx(Svg, { width: 16, height: 8, viewBox: "0 0 16 8", children: _jsx(Polygon, { points: "8 8 16 0 0 0", fill: hideArrow ? "transparent" : colors.gray[900] }) }) })) : null] }) }) }))] }));
|
|
188
116
|
}));
|
|
189
|
-
export const InformationTooltip = forwardRef(({ text }, forwardedRef) => (_jsx(LakeTooltip, { ref: forwardedRef, describedBy: "copy", placement: "
|
|
117
|
+
export const InformationTooltip = forwardRef(({ text }, forwardedRef) => (_jsx(LakeTooltip, { ref: forwardedRef, describedBy: "copy", placement: "right", togglableOnFocus: true, width: 300, content: text, children: _jsx(View, { style: styles.info, children: _jsx(Icon, { name: "info-regular", size: 24, color: colors.gray[900] }) }) })));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode, RefObject } from "react";
|
|
2
|
+
import { Text, View } from "react-native";
|
|
2
3
|
type Props = {
|
|
3
4
|
children: ReactNode | ((state: {
|
|
4
5
|
mode: "dropdown" | "panel";
|
|
@@ -11,14 +12,13 @@ type Props = {
|
|
|
11
12
|
matchReferenceMinWidth?: boolean;
|
|
12
13
|
onDismiss?: () => void;
|
|
13
14
|
onEscapeKey?: () => void;
|
|
14
|
-
referenceRef: RefObject<
|
|
15
|
+
referenceRef: RefObject<View | Text>;
|
|
15
16
|
returnFocus?: boolean;
|
|
16
17
|
autoFocus?: boolean;
|
|
17
18
|
visible: boolean;
|
|
18
19
|
underlay?: boolean;
|
|
19
20
|
safetyMargin?: number;
|
|
20
21
|
forcedMode?: "Dropdown" | "BottomPanel";
|
|
21
|
-
field?: boolean;
|
|
22
22
|
};
|
|
23
23
|
export declare const VIEWPORT_WIDTH_THRESHOLD = 600;
|
|
24
24
|
export declare const Popover: import("react").NamedExoticComponent<Props>;
|
|
@@ -2,7 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { memo, useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Pressable, ScrollView, StyleSheet, View, } from "react-native";
|
|
4
4
|
import { match, P } from "ts-pattern";
|
|
5
|
-
import { animations, backgroundColor, radii, shadows } from "../constants/design";
|
|
5
|
+
import { animations, backgroundColor, radii, shadows, spacings, } from "../constants/design";
|
|
6
|
+
import { useContextualLayer } from "../hooks/useContextualLayer";
|
|
6
7
|
import { useResponsive } from "../hooks/useResponsive";
|
|
7
8
|
import { noop } from "../utils/function";
|
|
8
9
|
import { BottomPanel } from "./BottomPanel";
|
|
@@ -14,9 +15,6 @@ const styles = StyleSheet.create({
|
|
|
14
15
|
...StyleSheet.absoluteFillObject,
|
|
15
16
|
pointerEvents: "none",
|
|
16
17
|
},
|
|
17
|
-
contents: {
|
|
18
|
-
...StyleSheet.absoluteFillObject,
|
|
19
|
-
},
|
|
20
18
|
defaultCursor: {
|
|
21
19
|
cursor: "default",
|
|
22
20
|
},
|
|
@@ -29,35 +27,26 @@ const styles = StyleSheet.create({
|
|
|
29
27
|
bottom: 0,
|
|
30
28
|
right: 0,
|
|
31
29
|
},
|
|
30
|
+
popoverContainer: {
|
|
31
|
+
position: "absolute",
|
|
32
|
+
display: "flex",
|
|
33
|
+
},
|
|
32
34
|
popover: {
|
|
33
35
|
pointerEvents: "auto",
|
|
34
|
-
position: "absolute",
|
|
35
36
|
display: "flex",
|
|
36
37
|
flexDirection: "column",
|
|
37
38
|
backgroundColor: backgroundColor.accented,
|
|
38
39
|
borderRadius: radii[8],
|
|
39
|
-
marginVertical:
|
|
40
|
+
marginVertical: spacings[8],
|
|
40
41
|
overflow: "hidden",
|
|
41
42
|
boxShadow: shadows.modal,
|
|
43
|
+
flexGrow: 1,
|
|
44
|
+
alignSelf: "stretch",
|
|
42
45
|
},
|
|
43
46
|
popoverContents: {
|
|
44
47
|
alignItems: "stretch",
|
|
45
48
|
},
|
|
46
49
|
});
|
|
47
|
-
const DEFAULT_VIEWPORT_INFORMATION = {
|
|
48
|
-
availableSpaceAbove: 0,
|
|
49
|
-
availableSpaceBelow: 0,
|
|
50
|
-
availableSpaceBefore: 0,
|
|
51
|
-
availableSpaceAfter: 0,
|
|
52
|
-
top: 0,
|
|
53
|
-
bottom: 0,
|
|
54
|
-
left: 0,
|
|
55
|
-
right: 0,
|
|
56
|
-
availableHeight: 0,
|
|
57
|
-
width: 0,
|
|
58
|
-
};
|
|
59
|
-
const FLEX_END = "flex-end";
|
|
60
|
-
const FLEX_START = "flex-start";
|
|
61
50
|
const animation = {
|
|
62
51
|
...animations.fadeAndSlideInFromBottom,
|
|
63
52
|
leave: [
|
|
@@ -66,36 +55,16 @@ const animation = {
|
|
|
66
55
|
],
|
|
67
56
|
};
|
|
68
57
|
export const VIEWPORT_WIDTH_THRESHOLD = 600;
|
|
69
|
-
export const Popover = memo(({ children, id, label, role = "dialog", describedBy, matchReferenceWidth = false, matchReferenceMinWidth = false, onDismiss = noop, onEscapeKey = onDismiss, referenceRef, returnFocus = true, autoFocus = true, visible, underlay = true,
|
|
58
|
+
export const Popover = memo(({ children, id, label, role = "dialog", describedBy, matchReferenceWidth = false, matchReferenceMinWidth = false, onDismiss = noop, onEscapeKey = onDismiss, referenceRef, returnFocus = true, autoFocus = true, visible, underlay = true, forcedMode, }) => {
|
|
70
59
|
const [rootElement, setRootElement] = useState(null);
|
|
71
60
|
const underlayRef = useRef(null);
|
|
72
61
|
const { desktop } = useResponsive(VIEWPORT_WIDTH_THRESHOLD);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const availableSpaceAbove = rect.top;
|
|
80
|
-
const availableSpaceBelow = window.innerHeight - rect.bottom;
|
|
81
|
-
const visualViewportOffsetTop = (_a = window.scrollY) !== null && _a !== void 0 ? _a : 0;
|
|
82
|
-
const visualViewportOffsetLeft = (_b = window.scrollX) !== null && _b !== void 0 ? _b : 0;
|
|
83
|
-
setViewportInformation({
|
|
84
|
-
availableSpaceAbove,
|
|
85
|
-
availableSpaceBelow,
|
|
86
|
-
availableSpaceBefore: rect.left,
|
|
87
|
-
availableSpaceAfter: window.innerWidth - rect.right,
|
|
88
|
-
top: visualViewportOffsetTop + Math.max(rect.bottom, safetyMargin),
|
|
89
|
-
bottom: Math.max(window.innerHeight - rect.top, safetyMargin) - visualViewportOffsetTop,
|
|
90
|
-
left: visualViewportOffsetLeft + Math.max(rect.left, safetyMargin),
|
|
91
|
-
right: Math.max(window.innerWidth - rect.right, safetyMargin) - visualViewportOffsetLeft,
|
|
92
|
-
availableHeight: field || availableSpaceAbove <= availableSpaceBelow
|
|
93
|
-
? window.innerHeight - rect.top - (rect.bottom - rect.top) - 20
|
|
94
|
-
: availableSpaceAbove - 20,
|
|
95
|
-
width: rect.right - rect.left,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}, [safetyMargin, referenceRef, visible, field]);
|
|
62
|
+
const { position } = useContextualLayer({
|
|
63
|
+
referenceRef,
|
|
64
|
+
visible,
|
|
65
|
+
matchReferenceWidth,
|
|
66
|
+
matchReferenceMinWidth,
|
|
67
|
+
});
|
|
99
68
|
useEffect(() => {
|
|
100
69
|
const element = underlayRef.current;
|
|
101
70
|
if (!visible && element != null) {
|
|
@@ -137,19 +106,15 @@ export const Popover = memo(({ children, id, label, role = "dialog", describedBy
|
|
|
137
106
|
if (mode === "BottomPanel") {
|
|
138
107
|
return (_jsx(BottomPanel, { visible: visible, onPressClose: onDismiss, returnFocus: false, children: typeof children == "function" ? children({ mode: "panel" }) : children }));
|
|
139
108
|
}
|
|
140
|
-
return (_jsxs(Portal, { container: rootElement, children: [visible && underlay ? (_jsx(Pressable, { ref: underlayRef, style: styles.underlay, onPress: onPressUnderlay, "aria-label": "Close" })) : null, _jsx(TransitionView, { style: styles.container, ...animation, children:
|
|
141
|
-
styles.
|
|
142
|
-
(
|
|
143
|
-
!field && availableSpaceAbove > availableSpaceBelow && { bottom },
|
|
144
|
-
availableSpaceBefore <= availableSpaceAfter && { left },
|
|
145
|
-
availableSpaceBefore > availableSpaceAfter && { right },
|
|
146
|
-
matchReferenceMinWidth && { minWidth: width },
|
|
147
|
-
matchReferenceWidth && { width },
|
|
148
|
-
{ maxHeight: field ? undefined : availableHeight },
|
|
149
|
-
], contentContainerStyle: [
|
|
150
|
-
styles.popoverContents,
|
|
109
|
+
return (_jsxs(Portal, { container: rootElement, children: [visible && underlay ? (_jsx(Pressable, { ref: underlayRef, style: styles.underlay, onPress: onPressUnderlay, "aria-label": "Close" })) : null, _jsx(TransitionView, { style: styles.container, ...animation, children: position.isSome() ? (_jsx(View, { style: position.get().rootStyle, children: _jsx(View, { style: [
|
|
110
|
+
styles.popoverContainer,
|
|
111
|
+
position.get().style,
|
|
151
112
|
{
|
|
152
|
-
|
|
113
|
+
alignItems: match(position.get().horizontalPosition)
|
|
114
|
+
.with("left", () => "flex-start")
|
|
115
|
+
.with("center", () => "center")
|
|
116
|
+
.with("right", () => "flex-end")
|
|
117
|
+
.exhaustive(),
|
|
153
118
|
},
|
|
154
|
-
], id: id, role: role, "aria-describedby": describedBy, "aria-label": label, children: _jsx(FocusTrap, { focusLock: true, returnFocus: returnFocus, autoFocus: autoFocus, onEscapeKey: onEscapeKey, onClickOutside: underlay ? undefined : onClickOutside, children: _jsx(Pressable, { tabIndex: -1, onPress: onPress, style: styles.defaultCursor, children: typeof children == "function" ? children({ mode: "dropdown" }) : children }) }) }))
|
|
119
|
+
], children: _jsx(ScrollView, { style: styles.popover, contentContainerStyle: styles.popoverContents, id: id, role: role, "aria-describedby": describedBy, "aria-label": label, children: _jsx(FocusTrap, { focusLock: true, returnFocus: returnFocus, autoFocus: autoFocus, onEscapeKey: onEscapeKey, onClickOutside: underlay ? undefined : onClickOutside, children: _jsx(Pressable, { tabIndex: -1, onPress: onPress, style: styles.defaultCursor, children: typeof children == "function" ? children({ mode: "dropdown" }) : children }) }) }) }) })) : null })] }));
|
|
155
120
|
});
|
|
@@ -190,8 +190,8 @@ export declare const PressableTextInput: FC<{
|
|
|
190
190
|
role?: import("react-native").WebRole | undefined;
|
|
191
191
|
lang?: string | undefined;
|
|
192
192
|
initialValue?: string | undefined;
|
|
193
|
-
autoComplete?: "name" | "
|
|
194
|
-
enterKeyHint?: "enter" | "search" | "done" | "
|
|
193
|
+
autoComplete?: "name" | "off" | "email" | "tel" | "url" | "additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday" | "bday-day" | "bday-month" | "bday-year" | "cc-additional-name" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "impp" | "language" | "new-password" | "nickname" | "on" | "one-time-code" | "organization" | "organization-title" | "postal-code" | "sex" | "street-address" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-national" | "transaction-amount" | "transaction-currency" | "username" | undefined;
|
|
194
|
+
enterKeyHint?: "enter" | "search" | "done" | "go" | "next" | "send" | "previous" | undefined;
|
|
195
195
|
rows?: number | undefined;
|
|
196
196
|
readOnly?: boolean | undefined;
|
|
197
197
|
hitSlop?: import("react-native").Insets | undefined;
|
|
@@ -41,7 +41,7 @@ const styles = StyleSheet.create({
|
|
|
41
41
|
export const QuickActions = ({ actions }) => {
|
|
42
42
|
return (_jsx(View, { style: styles.container, children: actions.map((action, index) => {
|
|
43
43
|
var _a, _b;
|
|
44
|
-
return (_jsx(LakeTooltip, { content: action.tooltipText, placement: "
|
|
44
|
+
return (_jsx(LakeTooltip, { content: action.tooltipText, placement: "right", containerStyle: styles.actionContainer, disabled: action.tooltipDisabled === true || isNullishOrEmpty(action.tooltipText), children: _jsxs(Pressable, { onPress: action.onPress, style: [styles.action, action.disabled === true && styles.disabled], disabled: action.isLoading === true || action.disabled === true, children: [_jsx(View, { style: [
|
|
45
45
|
styles.icon,
|
|
46
46
|
action.backgroundColor != null
|
|
47
47
|
? { backgroundColor: action.backgroundColor, borderColor: action.backgroundColor }
|
package/src/components/Svg.d.ts
CHANGED
|
@@ -110,6 +110,10 @@ type TspanProps = CommonProps & {
|
|
|
110
110
|
x?: number;
|
|
111
111
|
y?: number;
|
|
112
112
|
};
|
|
113
|
+
type PolygonProps = CommonProps & {
|
|
114
|
+
points: string;
|
|
115
|
+
fill?: string;
|
|
116
|
+
};
|
|
113
117
|
export declare const Svg: ({ style, ...props }: SvgProps) => import("react").ReactElement<{
|
|
114
118
|
style: ({
|
|
115
119
|
display: "flex";
|
|
@@ -134,6 +138,7 @@ export declare const Use: (props: UseProps) => import("react").ReactElement<UseP
|
|
|
134
138
|
export declare const Mask: (props: CommonProps) => import("react").ReactElement<CommonProps, string | import("react").JSXElementConstructor<any>>;
|
|
135
139
|
export declare const Text: (props: TextProps) => import("react").ReactElement<TextProps, string | import("react").JSXElementConstructor<any>>;
|
|
136
140
|
export declare const Tspan: (props: TspanProps) => import("react").ReactElement<TspanProps, string | import("react").JSXElementConstructor<any>>;
|
|
141
|
+
export declare const Polygon: (props: PolygonProps) => import("react").ReactElement<PolygonProps, string | import("react").JSXElementConstructor<any>>;
|
|
137
142
|
export declare const Image: (props: ImageProps) => import("react").ReactElement<ImageProps, string | import("react").JSXElementConstructor<any>>;
|
|
138
143
|
export declare const RadialGradient: (props: RadialGradientProps) => import("react").ReactElement<RadialGradientProps, string | import("react").JSXElementConstructor<any>>;
|
|
139
144
|
export declare const Path: (props: PathProps) => import("react").ReactElement<PathProps, string | import("react").JSXElementConstructor<any>>;
|
package/src/components/Svg.js
CHANGED
|
@@ -15,6 +15,7 @@ export const Use = (props) => createElement("use", props);
|
|
|
15
15
|
export const Mask = (props) => createElement("mask", props);
|
|
16
16
|
export const Text = (props) => createElement("text", props);
|
|
17
17
|
export const Tspan = (props) => createElement("tspan", props);
|
|
18
|
+
export const Polygon = (props) => createElement("polygon", props);
|
|
18
19
|
export const Image = (props) => createElement("image", props);
|
|
19
20
|
export const RadialGradient = (props) => createElement("radialGradient", props);
|
|
20
21
|
export const Path = (props) => createElement("path", props);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Option } from "@swan-io/boxed";
|
|
2
|
+
import { MutableRefObject } from "react";
|
|
3
|
+
import { Text, View, ViewStyle } from "react-native";
|
|
4
|
+
export type ElementPosition = {
|
|
5
|
+
availableSpaceAbove: number;
|
|
6
|
+
availableSpaceBelow: number;
|
|
7
|
+
availableSpaceBefore: number;
|
|
8
|
+
availableSpaceAfter: number;
|
|
9
|
+
top: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
left: number;
|
|
12
|
+
right: number;
|
|
13
|
+
availableHeight: number;
|
|
14
|
+
availableWidth: number;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
};
|
|
18
|
+
type Placement = "left" | "center" | "right";
|
|
19
|
+
type Config = {
|
|
20
|
+
placement?: Placement;
|
|
21
|
+
visible: boolean;
|
|
22
|
+
matchReferenceWidth?: boolean;
|
|
23
|
+
matchReferenceMinWidth?: boolean;
|
|
24
|
+
referenceRef?: MutableRefObject<View | Text | null>;
|
|
25
|
+
};
|
|
26
|
+
export type ContextualLayerPosition = {
|
|
27
|
+
rootStyle: ViewStyle;
|
|
28
|
+
style: ViewStyle;
|
|
29
|
+
verticalPosition: "top" | "bottom";
|
|
30
|
+
horizontalPosition: "left" | "center" | "right";
|
|
31
|
+
};
|
|
32
|
+
type ContextualLayerConfig = {
|
|
33
|
+
referenceRef: MutableRefObject<View | Text | null>;
|
|
34
|
+
position: Option<ContextualLayerPosition>;
|
|
35
|
+
};
|
|
36
|
+
export declare const useContextualLayer: ({ placement, visible, matchReferenceWidth, matchReferenceMinWidth, referenceRef: externalReferenceRef, }: Config) => ContextualLayerConfig;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Option } from "@swan-io/boxed";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { match } from "ts-pattern";
|
|
4
|
+
export const useContextualLayer = ({ placement, visible, matchReferenceWidth = false, matchReferenceMinWidth = false, referenceRef: externalReferenceRef, }) => {
|
|
5
|
+
const referenceRef = useRef(null);
|
|
6
|
+
const usedRef = externalReferenceRef !== null && externalReferenceRef !== void 0 ? externalReferenceRef : referenceRef;
|
|
7
|
+
const [position, setPosition] = useState(Option.None());
|
|
8
|
+
const getPosition = useCallback(() => {
|
|
9
|
+
if (usedRef.current == null) {
|
|
10
|
+
return Option.None();
|
|
11
|
+
}
|
|
12
|
+
const element = usedRef.current;
|
|
13
|
+
const rect = element.getBoundingClientRect();
|
|
14
|
+
const viewportHeight = window.innerHeight;
|
|
15
|
+
const viewportWidth = window.innerWidth;
|
|
16
|
+
const availableSpaceAbove = rect.top;
|
|
17
|
+
const availableSpaceBelow = viewportHeight - rect.bottom;
|
|
18
|
+
const availableSpaceBefore = rect.left;
|
|
19
|
+
const availableSpaceAfter = viewportWidth - rect.right;
|
|
20
|
+
const height = rect.bottom - rect.top;
|
|
21
|
+
const width = rect.right - rect.left;
|
|
22
|
+
const inferedPlacement = placement !== null && placement !== void 0 ? placement : (availableSpaceBefore > availableSpaceAfter ? "right" : "left");
|
|
23
|
+
const verticalPosition = availableSpaceAbove > availableSpaceBelow
|
|
24
|
+
? {
|
|
25
|
+
maxHeight: availableSpaceAbove,
|
|
26
|
+
bottom: viewportHeight - rect.top,
|
|
27
|
+
}
|
|
28
|
+
: {
|
|
29
|
+
maxHeight: availableSpaceBelow,
|
|
30
|
+
top: rect.top + height,
|
|
31
|
+
};
|
|
32
|
+
const horizontalPosition = match(inferedPlacement)
|
|
33
|
+
.with("left", () => ({ left: rect.left }))
|
|
34
|
+
.with("right", () => ({ right: window.innerWidth - rect.right }))
|
|
35
|
+
.with("center", () => ({ left: rect.left + width / 2, transform: "translateX(-50%)" }))
|
|
36
|
+
.exhaustive();
|
|
37
|
+
const maxHeight = availableSpaceAbove <= availableSpaceBelow
|
|
38
|
+
? window.innerHeight - rect.top - height
|
|
39
|
+
: availableSpaceAbove;
|
|
40
|
+
const rootStyle = {
|
|
41
|
+
position: "absolute",
|
|
42
|
+
top: window.scrollY,
|
|
43
|
+
left: 0,
|
|
44
|
+
width: "100vw",
|
|
45
|
+
height: "100vh",
|
|
46
|
+
pointerEvents: "none",
|
|
47
|
+
};
|
|
48
|
+
const style = {
|
|
49
|
+
...verticalPosition,
|
|
50
|
+
...horizontalPosition,
|
|
51
|
+
maxHeight,
|
|
52
|
+
...(matchReferenceWidth === true ? { width } : undefined),
|
|
53
|
+
...(matchReferenceMinWidth === true ? { minWidth: width } : undefined),
|
|
54
|
+
pointerEvents: "auto",
|
|
55
|
+
};
|
|
56
|
+
return Option.Some({
|
|
57
|
+
rootStyle,
|
|
58
|
+
horizontalPosition: inferedPlacement,
|
|
59
|
+
verticalPosition: availableSpaceAbove > availableSpaceBelow ? "top" : "bottom",
|
|
60
|
+
style,
|
|
61
|
+
});
|
|
62
|
+
}, [placement, matchReferenceWidth, matchReferenceMinWidth, usedRef]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (visible) {
|
|
65
|
+
setPosition(getPosition());
|
|
66
|
+
const tick = () => {
|
|
67
|
+
setPosition(getPosition());
|
|
68
|
+
animationFrame = requestAnimationFrame(tick);
|
|
69
|
+
};
|
|
70
|
+
let animationFrame = requestAnimationFrame(tick);
|
|
71
|
+
return () => cancelAnimationFrame(animationFrame);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
setPosition(Option.None());
|
|
75
|
+
}
|
|
76
|
+
}, [visible, getPosition]);
|
|
77
|
+
return {
|
|
78
|
+
referenceRef: usedRef,
|
|
79
|
+
position,
|
|
80
|
+
};
|
|
81
|
+
};
|
package/src/utils/popper.d.ts
CHANGED
package/src/utils/popper.js
CHANGED
|
@@ -12,19 +12,3 @@ export const getRootElement = (element) => {
|
|
|
12
12
|
}
|
|
13
13
|
return null;
|
|
14
14
|
};
|
|
15
|
-
export const matchReferenceWidthModifier = {
|
|
16
|
-
name: "matchReferenceWidth",
|
|
17
|
-
requires: ["computeStyles"],
|
|
18
|
-
enabled: false,
|
|
19
|
-
phase: "beforeWrite",
|
|
20
|
-
fn({ state }) {
|
|
21
|
-
if (state.styles.popper) {
|
|
22
|
-
state.styles.popper.width = state.rects.reference.width.toString() + "px";
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
effect({ state }) {
|
|
26
|
-
if (state.elements.reference instanceof HTMLElement) {
|
|
27
|
-
state.elements.popper.style.width = state.elements.reference.offsetWidth.toString() + "px";
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
};
|