@swan-io/lake 7.2.0 → 7.2.2
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 +1 -1
- package/src/components/LakeCopyButton.d.ts +4 -3
- package/src/components/LakeCopyButton.js +2 -2
- package/src/components/LakeTooltip.js +4 -1
- package/src/components/ToastStack.js +27 -5
- package/src/state/toasts.d.ts +3 -1
- package/src/state/toasts.js +2 -2
- package/src/utils/urql.d.ts +2 -1
- package/src/utils/urql.js +1 -0
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
type Props = {
|
|
2
|
-
|
|
3
|
-
copyText: string;
|
|
2
|
+
color?: string;
|
|
4
3
|
copiedText: string;
|
|
4
|
+
copyText: string;
|
|
5
5
|
size?: number;
|
|
6
|
+
valueToCopy: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const copyButtondefaultSize = 21;
|
|
8
|
-
export declare const LakeCopyButton: ({
|
|
9
|
+
export declare const LakeCopyButton: ({ color, copiedText, copyText, size, valueToCopy, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
9
10
|
export {};
|
|
@@ -5,12 +5,12 @@ import { Icon } from "./Icon";
|
|
|
5
5
|
import { LakeTooltip } from "./LakeTooltip";
|
|
6
6
|
import { Pressable } from "./Pressable";
|
|
7
7
|
export const copyButtondefaultSize = 21;
|
|
8
|
-
export const LakeCopyButton = ({
|
|
8
|
+
export const LakeCopyButton = ({ color, copiedText, copyText, size = copyButtondefaultSize, valueToCopy, }) => {
|
|
9
9
|
const [visibleState, setVisibleState] = useState("copy");
|
|
10
10
|
return (_jsx(LakeTooltip, { describedBy: "copy", 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);
|
|
14
14
|
setVisibleState("copied");
|
|
15
|
-
}, children: _jsx(Icon, { size: size, name: "copy-regular" }) }) }));
|
|
15
|
+
}, children: _jsx(Icon, { color: color, size: size, name: "copy-regular" }) }) }));
|
|
16
16
|
};
|
|
@@ -14,6 +14,9 @@ import { Portal } from "./Portal";
|
|
|
14
14
|
import { Polygon, Svg } from "./Svg";
|
|
15
15
|
const { matches: canHover } = window.matchMedia("(hover: hover)");
|
|
16
16
|
const styles = StyleSheet.create({
|
|
17
|
+
root: {
|
|
18
|
+
zIndex: 1000,
|
|
19
|
+
},
|
|
17
20
|
base: {
|
|
18
21
|
position: "absolute",
|
|
19
22
|
pointerEvents: "none",
|
|
@@ -110,7 +113,7 @@ const Tooltip = memo(forwardRef(({ children, content, describedBy, matchReferenc
|
|
|
110
113
|
useEffect(() => {
|
|
111
114
|
return () => clearTimeout(timeoutRef.current);
|
|
112
115
|
}, []);
|
|
113
|
-
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)
|
|
116
|
+
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, styles.root], 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)
|
|
114
117
|
.with("left", () => "start")
|
|
115
118
|
.with("center", () => "center")
|
|
116
119
|
.with("right", () => "end")
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { t } from "@swan-io/shared-business/src/utils/i18n";
|
|
2
3
|
import { memo, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import { Clipboard, StyleSheet, View } from "react-native";
|
|
4
5
|
import { match } from "ts-pattern";
|
|
5
6
|
import { animations, colors, shadows } from "../constants/design";
|
|
6
7
|
import { hideToast, useToasts } from "../state/toasts";
|
|
7
|
-
import { isNullish } from "../utils/nullish";
|
|
8
|
+
import { isNotNullish, isNotNullishOrEmpty, isNullish } from "../utils/nullish";
|
|
9
|
+
import { isCombinedError } from "../utils/urql";
|
|
8
10
|
import { Box } from "./Box";
|
|
9
11
|
import { Icon } from "./Icon";
|
|
10
12
|
import { LakeText } from "./LakeText";
|
|
13
|
+
import { LakeTooltip } from "./LakeTooltip";
|
|
11
14
|
import { Portal } from "./Portal";
|
|
12
15
|
import { Pressable } from "./Pressable";
|
|
13
16
|
import { Space } from "./Space";
|
|
@@ -52,9 +55,20 @@ const styles = StyleSheet.create({
|
|
|
52
55
|
height: 2,
|
|
53
56
|
transformOrigin: "left",
|
|
54
57
|
},
|
|
58
|
+
copyTooltip: {
|
|
59
|
+
alignSelf: "flex-start",
|
|
60
|
+
},
|
|
61
|
+
copyButton: {
|
|
62
|
+
alignItems: "center",
|
|
63
|
+
flexDirection: "row",
|
|
64
|
+
flexGrow: 1,
|
|
65
|
+
flexShrink: 1,
|
|
66
|
+
},
|
|
55
67
|
});
|
|
56
|
-
const Toast = memo(({ variant, uid, title, description, progress, onClose }) => {
|
|
68
|
+
const Toast = memo(({ variant, uid, title, description, error, progress, onClose }) => {
|
|
57
69
|
const progressBarRef = useRef(null);
|
|
70
|
+
const [visibleState, setVisibleState] = useState("copy");
|
|
71
|
+
const hasDescription = isNotNullishOrEmpty(description);
|
|
58
72
|
const colorVariation = match(variant)
|
|
59
73
|
.returnType()
|
|
60
74
|
.with("success", () => "positive")
|
|
@@ -85,7 +99,15 @@ const Toast = memo(({ variant, uid, title, description, progress, onClose }) =>
|
|
|
85
99
|
.with("error", () => (_jsx(Icon, { name: "dismiss-circle-regular", size: 20, color: colors[colorVariation][700] })))
|
|
86
100
|
.with("info", () => (_jsx(Icon, { name: "info-regular", size: 20, color: colors[colorVariation][700] })))
|
|
87
101
|
.with("warning", () => (_jsx(Icon, { name: "warning-regular", size: 20, color: colors[colorVariation][700] })))
|
|
88
|
-
.exhaustive(), _jsx(Space, { width: 12 }), _jsx(LakeText, { variant: "regular", color: colors[colorVariation][700], children: title })] }),
|
|
102
|
+
.exhaustive(), _jsx(Space, { width: 12 }), _jsx(LakeText, { variant: "regular", color: colors[colorVariation][700], children: title })] }), hasDescription && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 8 }), _jsx(LakeText, { variant: "smallRegular", color: colors.gray[700], children: description })] })), isCombinedError(error) && isNotNullish(error.requestId) ? (_jsxs(_Fragment, { children: [_jsx(Space, { height: hasDescription ? 4 : 8 }), _jsx(LakeTooltip, { describedBy: "copy", onHide: () => setVisibleState("copy"), togglableOnFocus: true, placement: "center", containerStyle: styles.copyTooltip, content: visibleState === "copy"
|
|
103
|
+
? t("copyButton.copyTooltip")
|
|
104
|
+
: t("copyButton.copiedTooltip"), children: _jsxs(Pressable, { style: styles.copyButton, onPress: event => {
|
|
105
|
+
var _a;
|
|
106
|
+
event.stopPropagation();
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
Clipboard.setString((_a = error.requestId) !== null && _a !== void 0 ? _a : "");
|
|
109
|
+
setVisibleState("copied");
|
|
110
|
+
}, children: [_jsx(Icon, { color: colors.gray[700], size: 14, name: "copy-regular" }), _jsx(Space, { width: 4 }), _jsxs(LakeText, { numberOfLines: 1, variant: "smallRegular", color: colors.gray[700], children: ["ID: ", error.requestId] })] }) })] })) : null] }), _jsx(Pressable, { onPress: () => onClose(uid), style: styles.closeButton, children: _jsx(Icon, { name: "lake-close", size: 24, color: colors.gray[500] }) }), progress != null && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 24 }), _jsx(View, { ref: progressBarRef, role: "progressbar", style: [styles.progressBar, { backgroundColor: colors[colorVariation][500] }] })] }))] }) }));
|
|
89
111
|
});
|
|
90
112
|
export const ToastStack = () => {
|
|
91
113
|
const toasts = useToasts();
|
|
@@ -102,5 +124,5 @@ export const ToastStack = () => {
|
|
|
102
124
|
if (rootElement == null) {
|
|
103
125
|
return null;
|
|
104
126
|
}
|
|
105
|
-
return (_jsx(Portal, { container: rootElement, children: _jsx(TransitionGroupView, { style: styles.list, enter: animations.fadeAndSlideInFromRight.enter, leave: animations.fadeAndSlideInFromRight.leave, children: toasts.map(toast => (_jsx(Toast, { uid: toast.uid, variant: toast.variant,
|
|
127
|
+
return (_jsx(Portal, { container: rootElement, children: _jsx(TransitionGroupView, { style: styles.list, enter: animations.fadeAndSlideInFromRight.enter, leave: animations.fadeAndSlideInFromRight.leave, children: toasts.map(toast => (_jsx(Toast, { uid: toast.uid, variant: toast.variant, title: toast.title, description: toast.description, error: toast.error, progress: toast.progress, onClose: hideToast }, toast.uid))) }) }));
|
|
106
128
|
};
|
package/src/state/toasts.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ type ToastContent = {
|
|
|
5
5
|
variant: ToastVariant;
|
|
6
6
|
title: string;
|
|
7
7
|
description?: string;
|
|
8
|
+
error?: unknown;
|
|
8
9
|
autoClose?: boolean;
|
|
9
10
|
};
|
|
10
11
|
type Toast = {
|
|
@@ -12,10 +13,11 @@ type Toast = {
|
|
|
12
13
|
variant: ToastVariant;
|
|
13
14
|
title: string;
|
|
14
15
|
description?: string;
|
|
16
|
+
error?: unknown;
|
|
15
17
|
progress?: Animated.Value;
|
|
16
18
|
timeout?: ControllableTimeout;
|
|
17
19
|
};
|
|
18
20
|
export declare const useToasts: () => Toast[];
|
|
19
21
|
export declare const hideToast: (uid: string) => void;
|
|
20
|
-
export declare const showToast: ({ variant, title, description, autoClose }: ToastContent) => string;
|
|
22
|
+
export declare const showToast: ({ variant, title, description, error, autoClose }: ToastContent) => string;
|
|
21
23
|
export {};
|
package/src/state/toasts.js
CHANGED
|
@@ -13,7 +13,7 @@ export const hideToast = (uid) => {
|
|
|
13
13
|
(_b = toast.progress) === null || _b === void 0 ? void 0 : _b.stopAnimation();
|
|
14
14
|
toasts.set(toasts => toasts.filter(toast => toast.uid !== uid));
|
|
15
15
|
};
|
|
16
|
-
export const showToast = ({ variant, title, description, autoClose }) => {
|
|
16
|
+
export const showToast = ({ variant, title, description, error, autoClose }) => {
|
|
17
17
|
const uid = `${variant} - ${title} - ${description !== null && description !== void 0 ? description : ""}`;
|
|
18
18
|
const toast = toasts.get().find(toast => toast.uid === uid);
|
|
19
19
|
if (toast != null) {
|
|
@@ -58,6 +58,6 @@ export const showToast = ({ variant, title, description, autoClose }) => {
|
|
|
58
58
|
},
|
|
59
59
|
})
|
|
60
60
|
: undefined;
|
|
61
|
-
toasts.set(toasts => [{ uid, variant, title, description, progress, timeout }, ...toasts]);
|
|
61
|
+
toasts.set(toasts => [{ uid, variant, title, description, error, progress, timeout }, ...toasts]);
|
|
62
62
|
return uid;
|
|
63
63
|
};
|
package/src/utils/urql.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Result } from "@swan-io/boxed";
|
|
2
2
|
import { Except, SetRequired } from "type-fest";
|
|
3
|
-
import { AnyVariables, OperationResult, UseQueryArgs, UseQueryResponse, UseQueryState } from "urql";
|
|
3
|
+
import { AnyVariables, CombinedError, OperationResult, UseQueryArgs, UseQueryResponse, UseQueryState } from "urql";
|
|
4
|
+
export declare const isCombinedError: (error: unknown) => error is CombinedError;
|
|
4
5
|
export declare const parseOperationResult: <T>({ error, data }: OperationResult<T>) => T;
|
|
5
6
|
export declare const useQueryWithErrorBoundary: <Data = unknown, Variables extends AnyVariables = AnyVariables>(options: UseQueryArgs<Variables, Data>) => [
|
|
6
7
|
SetRequired<Except<UseQueryState<Data, Variables>, "fetching" | "error">, "data">,
|
package/src/utils/urql.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Result } from "@swan-io/boxed";
|
|
2
2
|
import { CombinedError, useQuery, } from "urql";
|
|
3
3
|
import { isNotNullish, isNullish } from "./nullish";
|
|
4
|
+
export const isCombinedError = (error) => error instanceof CombinedError;
|
|
4
5
|
export const parseOperationResult = ({ error, data }) => {
|
|
5
6
|
if (isNotNullish(error)) {
|
|
6
7
|
throw error;
|