@swan-io/lake 7.1.4 → 7.2.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 +1 -1
- package/src/components/LakeCopyButton.d.ts +4 -3
- package/src/components/LakeCopyButton.js +2 -2
- package/src/components/LakeTooltip.d.ts +1 -0
- package/src/components/LakeTooltip.js +5 -2
- package/src/components/Tick.d.ts +8 -0
- package/src/components/Tick.js +26 -0
- 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
|
};
|
|
@@ -21,5 +21,6 @@ export type TooltipRef = {
|
|
|
21
21
|
export declare const LakeTooltip: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<TooltipRef>>;
|
|
22
22
|
export declare const InformationTooltip: import("react").ForwardRefExoticComponent<{
|
|
23
23
|
text: string;
|
|
24
|
+
icon?: "lake-building-bank" | "lake-calendar-arrow-swap" | "lake-call" | "lake-card" | "lake-card-add" | "lake-card-filled" | "lake-card-one-off" | "lake-card-physical" | "lake-card-recurring" | "lake-card-single-use" | "lake-card-virtual" | "lake-check" | "lake-chevron-double" | "lake-clipboard-bullet" | "lake-clock" | "lake-clock-arrow-swap" | "lake-close" | "lake-compass" | "lake-currencies" | "lake-delivery-grouped" | "lake-delivery-individual" | "lake-denied" | "lake-document-csv" | "lake-document-jpg" | "lake-document-pdf" | "lake-document-png" | "lake-document-xls" | "lake-email" | "lake-eraser" | "lake-error" | "lake-face-id" | "lake-fingerprint" | "lake-id-card" | "lake-inbox-empty" | "lake-key" | "lake-lock-closed" | "lake-menu" | "lake-people" | "lake-person-arrow-swap" | "lake-person-support" | "lake-phone" | "lake-receipt" | "lake-settings" | "lake-shield" | "lake-signature" | "lake-transfer" | "lake-warning" | "lake-world-map" | "add-circle-filled" | "add-circle-regular" | "add-filled" | "approvals-app-filled" | "apps-list-filled" | "apps-list-regular" | "arrow-counterclockwise-filled" | "arrow-clockwise-filled" | "arrow-down-filled" | "arrow-down-regular" | "arrow-download-filled" | "arrow-left-filled" | "arrow-left-regular" | "arrow-right-filled" | "arrow-right-regular" | "arrow-swap-filled" | "arrow-swap-regular" | "arrow-up-filled" | "arrow-up-regular" | "arrow-upload-filled" | "arrow-upload-regular" | "beaker-filled" | "beaker-regular" | "board-filled" | "board-regular" | "box-regular" | "building-bank-filled" | "building-bank-regular" | "building-filled" | "building-multiple-regular" | "building-regular" | "building-shop-regular" | "calendar-ltr-regular" | "cart-regular" | "chat-help-filled" | "chat-help-regular" | "check-filled" | "check-regular" | "checkmark-circle-regular" | "checkmark-filled" | "checkmark-starburst-regular" | "checkmark-starburst-filled" | "chevron-down-filled" | "chevron-left-filled" | "chevron-right-filled" | "chevron-up-down-regular" | "chevron-up-filled" | "clipboard-search-regular" | "clock-filled" | "clock-regular" | "cloud-sync-filled" | "cloud-sync-regular" | "code-filled" | "code-regular" | "color-regular" | "comment-note-regular" | "copy-filled" | "copy-regular" | "cursor-click-regular" | "database-filled" | "database-regular" | "delete-filled" | "delete-regular" | "desktop-regular" | "device-meeting-room-regular" | "dismiss-circle-regular" | "dismiss-filled" | "dismiss-regular" | "document-regular" | "earth-regular" | "edit-filled" | "edit-regular" | "error-circle-filled" | "error-circle-regular" | "eye-filled" | "eye-off-filled" | "eye-regular" | "eye-off-regular" | "filter-filled" | "flag-filled" | "flag-regular" | "flash-filled" | "flash-regular" | "form-new-filled" | "form-new-regular" | "hand-right-regular" | "image-add-filled" | "image-add-regular" | "image-filled" | "image-regular" | "info-filled" | "info-regular" | "key-regular" | "link-filled" | "live-filled" | "live-regular" | "lock-closed-filled" | "lock-closed-regular" | "lock-open-filled" | "lock-open-regular" | "mail-filled" | "mail-regular" | "money-calculator-regular" | "money-calculator-filled" | "money-regular" | "money-filled" | "more-horizontal-filled" | "more-vertical-filled" | "open-filled" | "open-regular" | "options-regular" | "paint-brush-filled" | "paint-brush-regular" | "panel-left-filled" | "panel-left-regular" | "panel-left-contract-filled" | "panel-left-contract-regular" | "panel-left-expand-filled" | "panel-left-expand-regular" | "pause-regular" | "payment-filled" | "payment-regular" | "people-add-regular" | "people-community-filled" | "people-community-regular" | "people-filled" | "people-regular" | "people-team-regular" | "person-accounts-filled" | "person-accounts-regular" | "person-add-regular" | "person-call-filled" | "person-call-regular" | "person-filled" | "person-lock-regular" | "person-regular" | "phone-filled" | "phone-regular" | "pin-regular" | "play-filled" | "play-regular" | "preview-link-filled" | "qr-code-regular" | "question-circle-regular" | "receipt-money-filled" | "receipt-money-regular" | "rocket-regular" | "search-filled" | "send-filled" | "send-regular" | "settings-filled" | "settings-regular" | "shield-checkmark-filled" | "shield-checkmark-regular" | "shield-error-regular" | "shield-regular" | "sign-out-regular" | "signature-filled" | "signature-regular" | "subtract-circle-filled" | "subtract-circle-regular" | "target-arrow-regular" | "task-list-square-ltr-filled" | "task-list-square-ltr-regular" | "warning-filled" | "warning-regular" | "window-dev-tools-filled" | "window-dev-tools-regular" | undefined;
|
|
24
25
|
} & import("react").RefAttributes<TooltipRef>>;
|
|
25
26
|
export {};
|
|
@@ -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")
|
|
@@ -120,4 +123,4 @@ const Tooltip = memo(forwardRef(({ children, content, describedBy, matchReferenc
|
|
|
120
123
|
.with("right", () => "end")
|
|
121
124
|
.exhaustive(), style: [styles.arrowBar, styles.arrowBarBottom], 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] }) }) }))] }));
|
|
122
125
|
}));
|
|
123
|
-
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:
|
|
126
|
+
export const InformationTooltip = forwardRef(({ text, icon = "info-regular" }, 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: icon, size: 24, color: colors.gray[900] }) }) })));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ColorValue, StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
type Props = {
|
|
3
|
+
style?: StyleProp<ViewStyle>;
|
|
4
|
+
color: ColorValue;
|
|
5
|
+
size?: "small" | "medium" | "large";
|
|
6
|
+
};
|
|
7
|
+
export declare const Tick: ({ color, style, size }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { match } from "ts-pattern";
|
|
4
|
+
import { radii, spacings } from "../constants/design";
|
|
5
|
+
export const Tick = ({ color, style, size = "medium" }) => (_jsx(View, { style: [
|
|
6
|
+
{
|
|
7
|
+
backgroundColor: color,
|
|
8
|
+
...match(size)
|
|
9
|
+
.with("small", () => ({
|
|
10
|
+
width: spacings[8],
|
|
11
|
+
height: spacings[8],
|
|
12
|
+
borderRadius: radii[4],
|
|
13
|
+
}))
|
|
14
|
+
.with("large", () => ({
|
|
15
|
+
width: spacings[16],
|
|
16
|
+
height: spacings[16],
|
|
17
|
+
borderRadius: radii[8],
|
|
18
|
+
}))
|
|
19
|
+
.otherwise(() => ({
|
|
20
|
+
width: spacings[12],
|
|
21
|
+
height: spacings[12],
|
|
22
|
+
borderRadius: radii[6],
|
|
23
|
+
})),
|
|
24
|
+
},
|
|
25
|
+
style,
|
|
26
|
+
] }));
|
|
@@ -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?: Error;
|
|
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?: Error;
|
|
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;
|