@ledgerhq/lumen-ui-rnative 0.1.63 → 0.1.65
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/module/lib/Components/core/AmountDisplay/AmountDisplay.js +19 -11
- package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.js.map +1 -1
- package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.test.js +113 -4
- package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.test.js.map +1 -1
- package/dist/module/lib/Components/core/BottomSheet/BottomSheet.stories.js +51 -0
- package/dist/module/lib/Components/core/BottomSheet/BottomSheet.stories.js.map +1 -1
- package/dist/module/lib/Components/core/CardButton/CardButton.js +2 -0
- package/dist/module/lib/Components/core/CardButton/CardButton.js.map +1 -1
- package/dist/module/lib/Components/core/CardButton/CardButton.mdx +4 -0
- package/dist/module/lib/Components/core/CardButton/CardButton.stories.js +1 -0
- package/dist/module/lib/Components/core/CardButton/CardButton.stories.js.map +1 -1
- package/dist/module/lib/Components/core/Link/Link.figma.js +2 -1
- package/dist/module/lib/Components/core/Link/Link.figma.js.map +1 -1
- package/dist/module/lib/Components/core/Link/Link.js +5 -3
- package/dist/module/lib/Components/core/Link/Link.js.map +1 -1
- package/dist/module/lib/Components/core/Link/Link.mdx +3 -2
- package/dist/module/lib/Components/core/Link/Link.stories.js +4 -1
- package/dist/module/lib/Components/core/Link/Link.stories.js.map +1 -1
- package/dist/module/lib/Components/core/Link/Link.test.js +2 -2
- package/dist/module/lib/Components/core/Link/Link.test.js.map +1 -1
- package/dist/module/lib/Components/core/MenuList/MenuList.js +93 -7
- package/dist/module/lib/Components/core/MenuList/MenuList.js.map +1 -1
- package/dist/module/lib/Components/core/MenuList/MenuList.mdx +14 -1
- package/dist/module/lib/Components/core/MenuList/MenuList.stories.js +39 -2
- package/dist/module/lib/Components/core/MenuList/MenuList.stories.js.map +1 -1
- package/dist/module/lib/Components/core/MenuList/MenuList.test.js +60 -2
- package/dist/module/lib/Components/core/MenuList/MenuList.test.js.map +1 -1
- package/dist/module/lib/Components/core/SegmentedControl/SegmentedControl.js +1 -1
- package/dist/module/lib/Components/core/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/module/lib/Components/core/Stepper/Stepper.js +76 -30
- package/dist/module/lib/Components/core/Stepper/Stepper.js.map +1 -1
- package/dist/module/lib/Components/core/Stepper/Stepper.mdx +37 -16
- package/dist/module/lib/Components/core/Stepper/Stepper.stories.js +102 -2
- package/dist/module/lib/Components/core/Stepper/Stepper.stories.js.map +1 -1
- package/dist/module/lib/Components/core/Stepper/Stepper.test.js +32 -1
- package/dist/module/lib/Components/core/Stepper/Stepper.test.js.map +1 -1
- package/dist/module/lib/Components/core/Timeline/Timeline.figma.js +83 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.figma.js.map +1 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.js +464 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.js.map +1 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.mdx +49 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.stories.js +289 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.stories.js.map +1 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.test.js +234 -0
- package/dist/module/lib/Components/core/Timeline/Timeline.test.js.map +1 -0
- package/dist/module/lib/Components/core/Timeline/index.js +5 -0
- package/dist/module/lib/Components/core/Timeline/index.js.map +1 -0
- package/dist/module/lib/Components/core/Timeline/types.js +4 -0
- package/dist/module/lib/Components/core/Timeline/types.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/Toast.figma.js +39 -0
- package/dist/module/lib/Components/core/Toast/Toast.figma.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/Toast.js +138 -0
- package/dist/module/lib/Components/core/Toast/Toast.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/Toast.mdx +203 -0
- package/dist/module/lib/Components/core/Toast/Toast.stories.js +238 -0
- package/dist/module/lib/Components/core/Toast/Toast.stories.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/Toast.test.js +203 -0
- package/dist/module/lib/Components/core/Toast/Toast.test.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/Toaster.js +147 -0
- package/dist/module/lib/Components/core/Toast/Toaster.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/Toaster.test.js +732 -0
- package/dist/module/lib/Components/core/Toast/Toaster.test.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js +70 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js +33 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js +224 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js +82 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js +21 -0
- package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/index.js +7 -0
- package/dist/module/lib/Components/core/Toast/index.js.map +1 -0
- package/dist/module/lib/Components/core/Toast/types.js +4 -0
- package/dist/module/lib/Components/core/Toast/types.js.map +1 -0
- package/dist/module/lib/Components/core/index.js +2 -0
- package/dist/module/lib/Components/core/index.js.map +1 -1
- package/dist/typescript/src/lib/Components/core/AmountDisplay/AmountDisplay.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts +2 -0
- package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/Link/Link.d.ts +1 -1
- package/dist/typescript/src/lib/Components/core/Link/Link.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/Link/types.d.ts +1 -1
- package/dist/typescript/src/lib/Components/core/Link/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/MenuList/MenuList.d.ts +12 -2
- package/dist/typescript/src/lib/Components/core/MenuList/MenuList.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/MenuList/types.d.ts +26 -7
- package/dist/typescript/src/lib/Components/core/MenuList/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts +4 -3
- package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts +12 -2
- package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts +56 -0
- package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts +3 -0
- package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts +109 -0
- package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts +24 -0
- package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts +35 -0
- package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts +17 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts +19 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts +14 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts +15 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts +21 -0
- package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/index.d.ts +5 -0
- package/dist/typescript/src/lib/Components/core/Toast/index.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/Toast/types.d.ts +75 -0
- package/dist/typescript/src/lib/Components/core/Toast/types.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/index.d.ts +2 -0
- package/dist/typescript/src/lib/Components/core/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/Components/core/AmountDisplay/AmountDisplay.test.tsx +138 -4
- package/src/lib/Components/core/AmountDisplay/AmountDisplay.tsx +13 -6
- package/src/lib/Components/core/BottomSheet/BottomSheet.stories.tsx +51 -0
- package/src/lib/Components/core/CardButton/CardButton.mdx +4 -0
- package/src/lib/Components/core/CardButton/CardButton.stories.tsx +1 -0
- package/src/lib/Components/core/CardButton/CardButton.tsx +2 -0
- package/src/lib/Components/core/Link/Link.figma.tsx +1 -0
- package/src/lib/Components/core/Link/Link.mdx +3 -2
- package/src/lib/Components/core/Link/Link.stories.tsx +3 -2
- package/src/lib/Components/core/Link/Link.test.tsx +2 -0
- package/src/lib/Components/core/Link/Link.tsx +3 -1
- package/src/lib/Components/core/Link/types.ts +1 -1
- package/src/lib/Components/core/MenuList/MenuList.mdx +14 -1
- package/src/lib/Components/core/MenuList/MenuList.stories.tsx +30 -2
- package/src/lib/Components/core/MenuList/MenuList.test.tsx +72 -2
- package/src/lib/Components/core/MenuList/MenuList.tsx +94 -11
- package/src/lib/Components/core/MenuList/types.ts +29 -7
- package/src/lib/Components/core/SegmentedControl/SegmentedControl.tsx +1 -1
- package/src/lib/Components/core/Stepper/Stepper.mdx +37 -16
- package/src/lib/Components/core/Stepper/Stepper.stories.tsx +50 -2
- package/src/lib/Components/core/Stepper/Stepper.test.tsx +29 -1
- package/src/lib/Components/core/Stepper/Stepper.tsx +73 -32
- package/src/lib/Components/core/Stepper/types.ts +12 -2
- package/src/lib/Components/core/Timeline/Timeline.figma.tsx +79 -0
- package/src/lib/Components/core/Timeline/Timeline.mdx +49 -0
- package/src/lib/Components/core/Timeline/Timeline.stories.tsx +250 -0
- package/src/lib/Components/core/Timeline/Timeline.test.tsx +275 -0
- package/src/lib/Components/core/Timeline/Timeline.tsx +576 -0
- package/src/lib/Components/core/Timeline/index.ts +2 -0
- package/src/lib/Components/core/Timeline/types.ts +124 -0
- package/src/lib/Components/core/Toast/Toast.figma.tsx +36 -0
- package/src/lib/Components/core/Toast/Toast.mdx +203 -0
- package/src/lib/Components/core/Toast/Toast.stories.tsx +260 -0
- package/src/lib/Components/core/Toast/Toast.test.tsx +181 -0
- package/src/lib/Components/core/Toast/Toast.tsx +163 -0
- package/src/lib/Components/core/Toast/Toaster.test.tsx +687 -0
- package/src/lib/Components/core/Toast/Toaster.tsx +157 -0
- package/src/lib/Components/core/Toast/hooks/useToastAccessibility.ts +82 -0
- package/src/lib/Components/core/Toast/hooks/useToastCollapse.ts +38 -0
- package/src/lib/Components/core/Toast/hooks/useToastGesture.ts +83 -0
- package/src/lib/Components/core/Toast/hooks/useToastMotion.ts +71 -0
- package/src/lib/Components/core/Toast/hooks/useToastViewportStyles.ts +45 -0
- package/src/lib/Components/core/Toast/index.ts +4 -0
- package/src/lib/Components/core/Toast/types.ts +94 -0
- package/src/lib/Components/core/index.ts +2 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
4
|
+
import { useStyleSheet } from "../../../../styles/index.js";
|
|
5
|
+
import { Box } from "../../primitives/index.js";
|
|
6
|
+
import { CheckmarkCircleFill, DeleteCircleFill, WarningFill } from "../../symbols/index.js";
|
|
7
|
+
import { Button } from "../Button/index.js";
|
|
8
|
+
import { Spinner } from "../Spinner/index.js";
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const TITLE_MAX_LINES = 5;
|
|
11
|
+
const iconsMap = {
|
|
12
|
+
success: CheckmarkCircleFill,
|
|
13
|
+
warning: WarningFill,
|
|
14
|
+
error: DeleteCircleFill
|
|
15
|
+
};
|
|
16
|
+
const iconColorMap = {
|
|
17
|
+
success: 'successOnInteractive',
|
|
18
|
+
warning: 'warningOnInteractive',
|
|
19
|
+
error: 'errorOnInteractive'
|
|
20
|
+
};
|
|
21
|
+
const useToastStyles = ({
|
|
22
|
+
hasLeading,
|
|
23
|
+
hasAction
|
|
24
|
+
}) => useStyleSheet(t => ({
|
|
25
|
+
root: {
|
|
26
|
+
flexDirection: 'row',
|
|
27
|
+
alignItems: 'flex-start',
|
|
28
|
+
gap: t.spacings.s8,
|
|
29
|
+
minHeight: t.sizes.s56,
|
|
30
|
+
width: '100%',
|
|
31
|
+
borderRadius: t.borderRadius.md,
|
|
32
|
+
backgroundColor: t.colors.bg.interactive,
|
|
33
|
+
paddingVertical: t.spacings.s8,
|
|
34
|
+
paddingRight: t.spacings.s20,
|
|
35
|
+
paddingLeft: hasLeading ? t.spacings.s12 : t.spacings.s16
|
|
36
|
+
},
|
|
37
|
+
iconWrapper: {
|
|
38
|
+
flexShrink: 0,
|
|
39
|
+
paddingTop: t.spacings.s10
|
|
40
|
+
},
|
|
41
|
+
textAction: {
|
|
42
|
+
flexDirection: 'row',
|
|
43
|
+
flexWrap: 'wrap',
|
|
44
|
+
alignItems: 'flex-start',
|
|
45
|
+
columnGap: t.spacings.s8,
|
|
46
|
+
rowGap: t.spacings.s4,
|
|
47
|
+
flexGrow: 1,
|
|
48
|
+
flexShrink: 1,
|
|
49
|
+
flexBasis: 'auto'
|
|
50
|
+
},
|
|
51
|
+
title: StyleSheet.flatten([t.typographies.body2, {
|
|
52
|
+
color: t.colors.text.onInteractive,
|
|
53
|
+
flexShrink: 0,
|
|
54
|
+
flexGrow: 1,
|
|
55
|
+
flexBasis: 'auto',
|
|
56
|
+
paddingTop: t.spacings.s10,
|
|
57
|
+
paddingBottom: hasAction ? undefined : t.spacings.s10,
|
|
58
|
+
paddingRight: t.spacings.s16
|
|
59
|
+
}]),
|
|
60
|
+
actionButton: {
|
|
61
|
+
marginLeft: hasLeading ? -t.spacings.s16 : undefined
|
|
62
|
+
}
|
|
63
|
+
}), [hasLeading, hasAction]);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A single toast item: an inverted surface with a status icon or spinner, a
|
|
67
|
+
* title that wraps up to five lines, and an optional action inline beside
|
|
68
|
+
* the title. When the two cannot share a row, the action wraps onto its own
|
|
69
|
+
* row, under the title's left edge. Dismissal is a swipe gesture, owned by
|
|
70
|
+
* `Toaster` — this component never dismisses itself.
|
|
71
|
+
*
|
|
72
|
+
* This is the presentational piece. For the queue, timing and imperative API,
|
|
73
|
+
* use `Toaster` + `toast`.
|
|
74
|
+
*
|
|
75
|
+
* @see {@link https://ldls-react-native.vercel.app/?path=/docs/rnative-toast--docs Guidelines}
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* import { Toast } from '@ledgerhq/lumen-ui-rnative';
|
|
79
|
+
*
|
|
80
|
+
* <Toast appearance="success" title="Payment done" />
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Loading with an action
|
|
84
|
+
* <Toast loading title="Uploading…" action={{ label: 'Cancel', onAction: () => {} }} />
|
|
85
|
+
*/
|
|
86
|
+
export const Toast = ({
|
|
87
|
+
appearance = 'info',
|
|
88
|
+
loading = false,
|
|
89
|
+
title,
|
|
90
|
+
action,
|
|
91
|
+
style,
|
|
92
|
+
...props
|
|
93
|
+
}) => {
|
|
94
|
+
const hasLeading = loading || appearance !== 'info';
|
|
95
|
+
const styles = useToastStyles({
|
|
96
|
+
hasLeading,
|
|
97
|
+
hasAction: Boolean(action)
|
|
98
|
+
});
|
|
99
|
+
const IconComponent = appearance === 'info' ? null : iconsMap[appearance];
|
|
100
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
101
|
+
style: StyleSheet.flatten([styles.root, style]),
|
|
102
|
+
accessibilityLiveRegion: appearance === 'warning' || appearance === 'error' ? 'assertive' : 'polite',
|
|
103
|
+
...props,
|
|
104
|
+
children: [loading ? /*#__PURE__*/_jsx(View, {
|
|
105
|
+
style: styles.iconWrapper,
|
|
106
|
+
children: /*#__PURE__*/_jsx(Spinner, {
|
|
107
|
+
testID: "toast-spinner",
|
|
108
|
+
size: 20,
|
|
109
|
+
color: "onInteractive"
|
|
110
|
+
})
|
|
111
|
+
}) : IconComponent && /*#__PURE__*/_jsx(View, {
|
|
112
|
+
testID: "toast-icon",
|
|
113
|
+
style: styles.iconWrapper,
|
|
114
|
+
children: /*#__PURE__*/_jsx(IconComponent, {
|
|
115
|
+
size: 20,
|
|
116
|
+
lx: {
|
|
117
|
+
color: iconColorMap[appearance]
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}), /*#__PURE__*/_jsxs(View, {
|
|
121
|
+
testID: "toast-text-action",
|
|
122
|
+
style: styles.textAction,
|
|
123
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
124
|
+
style: styles.title,
|
|
125
|
+
numberOfLines: TITLE_MAX_LINES,
|
|
126
|
+
children: title
|
|
127
|
+
}), action && /*#__PURE__*/_jsx(Button, {
|
|
128
|
+
testID: "toast-action",
|
|
129
|
+
appearance: "base",
|
|
130
|
+
size: "sm",
|
|
131
|
+
onPress: action.onAction,
|
|
132
|
+
style: styles.actionButton,
|
|
133
|
+
children: action.label
|
|
134
|
+
})]
|
|
135
|
+
})]
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=Toast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StyleSheet","Text","View","useStyleSheet","Box","CheckmarkCircleFill","DeleteCircleFill","WarningFill","Button","Spinner","jsx","_jsx","jsxs","_jsxs","TITLE_MAX_LINES","iconsMap","success","warning","error","iconColorMap","useToastStyles","hasLeading","hasAction","t","root","flexDirection","alignItems","gap","spacings","s8","minHeight","sizes","s56","width","borderRadius","md","backgroundColor","colors","bg","interactive","paddingVertical","paddingRight","s20","paddingLeft","s12","s16","iconWrapper","flexShrink","paddingTop","s10","textAction","flexWrap","columnGap","rowGap","s4","flexGrow","flexBasis","title","flatten","typographies","body2","color","text","onInteractive","paddingBottom","undefined","actionButton","marginLeft","Toast","appearance","loading","action","style","props","styles","Boolean","IconComponent","accessibilityLiveRegion","children","testID","size","lx","numberOfLines","onPress","onAction","label"],"sourceRoot":"../../../../../../src","sources":["lib/Components/core/Toast/Toast.tsx"],"mappings":";;AACA,SAASA,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AACrD,SAASC,aAAa,QAAQ,6BAAoB;AAClD,SAASC,GAAG,QAAQ,2BAAkB;AACtC,SACEC,mBAAmB,EACnBC,gBAAgB,EAChBC,WAAW,QACN,wBAAe;AAEtB,SAASC,MAAM,QAAQ,oBAAW;AAClC,SAASC,OAAO,QAAQ,qBAAY;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAKrC,MAAMC,eAAe,GAAG,CAAC;AAEzB,MAAMC,QAA6D,GAAG;EACpEC,OAAO,EAAEX,mBAAmB;EAC5BY,OAAO,EAAEV,WAAW;EACpBW,KAAK,EAAEZ;AACT,CAAC;AAED,MAAMa,YAGL,GAAG;EACFH,OAAO,EAAE,sBAAsB;EAC/BC,OAAO,EAAE,sBAAsB;EAC/BC,KAAK,EAAE;AACT,CAAC;AAED,MAAME,cAAc,GAAGA,CAAC;EACtBC,UAAU;EACVC;AAIF,CAAC,KACCnB,aAAa,CACVoB,CAAC,KAAM;EACNC,IAAI,EAAE;IACJC,a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C;MAAe,CAAE;IAAC,CAC9D,CAAC,GAEPe,aAAa,iBACXjE,IAAA,CAACT,IAAI;MAAC6E,MAAM,EAAC,YAAY;MAACP,KAAK,EAAEE,MAAM,CAAC5B,WAAY;MAAAgC,QAAA,eAClDnE,IAAA,CAACiE,aAAa;QACZI,IAAI,EAAE,EAAG;QACTC,EAAE,EAAE;UAAEpB,KAAK,EAAE1C,YAAY,CAACkD,UAAU;QAAuB;MAAE,CAC9D;IAAC,CACE,CAET,eACDxD,KAAA,CAACX,IAAI;MAAC6E,MAAM,EAAC,mBAAmB;MAACP,KAAK,EAAEE,MAAM,CAACxB,UAAW;MAAA4B,QAAA,gBACxDnE,IAAA,CAACV,IAAI;QAACuE,KAAK,EAAEE,MAAM,CAACjB,KAAM;QAACyB,aAAa,EAAEpE,eAAgB;QAAAgE,QAAA,EACvDrB;MAAK,CACF,CAAC,EACNc,MAAM,iBACL5D,IAAA,CAACH,MAAM;QACLuE,MAAM,EAAC,cAAc;QACrBV,UAAU,EAAC,MAAM;QACjBW,IAAI,EAAC,IAAI;QACTG,OAAO,EAAEZ,MAAM,CAACa,QAAS;QACzBZ,KAAK,EAAEE,MAAM,CAACR,YAAa;QAAAY,QAAA,EAE1BP,MAAM,CAACc;MAAK,CACP,CACT;IAAA,CACG,CAAC;EAAA,CACJ,CAAC;AAEV,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls, Source } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import * as ToastStories from './Toast.stories';
|
|
3
|
+
import {
|
|
4
|
+
CustomTabs,
|
|
5
|
+
Tab,
|
|
6
|
+
SetupNote,
|
|
7
|
+
} from '../../../../../.storybook/components';
|
|
8
|
+
|
|
9
|
+
<Meta title='Core/Toast' of={ToastStories} />
|
|
10
|
+
|
|
11
|
+
# Toast
|
|
12
|
+
|
|
13
|
+
<CustomTabs>
|
|
14
|
+
<Tab label="Overview">
|
|
15
|
+
|
|
16
|
+
## Introduction
|
|
17
|
+
|
|
18
|
+
Toasts are brief, non-blocking messages that confirm an action or surface a
|
|
19
|
+
status. They appear in a queued stack, are timed by status, and can carry a
|
|
20
|
+
single action.
|
|
21
|
+
|
|
22
|
+
Mount `Toaster` once and call `toast` from anywhere — no provider or hook
|
|
23
|
+
required. `Toaster` owns the queue, timing, and placement, and renders each
|
|
24
|
+
item for you. `position`, `maxItems`, `insets`, and `durations` configure that
|
|
25
|
+
queue.
|
|
26
|
+
|
|
27
|
+
> View in [Figma](https://www.figma.com/design/JxaLVMTWirCpU0rsbZ30k7/2.-Components-Library?node-id=21016-59623&m=dev).
|
|
28
|
+
|
|
29
|
+
<Canvas of={ToastStories.Base} />
|
|
30
|
+
<Controls of={ToastStories.Base} />
|
|
31
|
+
|
|
32
|
+
Call `toast` from anywhere. Every method that enqueues a toast returns `{ id }`.
|
|
33
|
+
`info`, `success`, `warning`, and `error` set `appearance` for you.
|
|
34
|
+
`loading` also sets the spinner.
|
|
35
|
+
|
|
36
|
+
- `toast.notify(options)`: enqueues a toast.
|
|
37
|
+
- `toast.info(options)`: info. Auto-dismisses after 5s.
|
|
38
|
+
- `toast.success(options)`: success. Auto-dismisses after 5s.
|
|
39
|
+
- `toast.warning(options)`: warning. Persists until dismissed.
|
|
40
|
+
- `toast.error(options)`: error. Persists until dismissed.
|
|
41
|
+
- `toast.loading(options)`: spinner. Persists until updated or dismissed.
|
|
42
|
+
- `toast.update(id, options)`: patches a live toast. Keeps the same id.
|
|
43
|
+
- `toast.dismiss(id)`: dismisses one toast.
|
|
44
|
+
- `toast.dismissAll()`: dismisses every toast, visible or queued.
|
|
45
|
+
- `toast.promise(promise, options)`: loading, then success or error, on one id.
|
|
46
|
+
|
|
47
|
+
`notify` and the shortcuts take these options:
|
|
48
|
+
|
|
49
|
+
- `title` (required): the message.
|
|
50
|
+
- `appearance`: info, success, warning, or error. Defaults to info.
|
|
51
|
+
- `loading`: replaces the status icon with a spinner. Defaults to false.
|
|
52
|
+
- `duration`: milliseconds for this item. `0` disables auto-dismiss. Defaults
|
|
53
|
+
to the status default.
|
|
54
|
+
- `dismissible`: allows the swipe and the dismiss accessibility action.
|
|
55
|
+
Defaults to true.
|
|
56
|
+
- `action`: `{ label, onAction }`. Pressing it does not dismiss the toast.
|
|
57
|
+
|
|
58
|
+
`toast.promise` takes `{ loading, success, error }` instead. `success` and
|
|
59
|
+
`error` may be the next state, or a function of the result.
|
|
60
|
+
|
|
61
|
+
### Appearance
|
|
62
|
+
|
|
63
|
+
Appearance drives the leading icon and the default timing:
|
|
64
|
+
|
|
65
|
+
- **info** (default): general confirmation. Auto-dismisses after 5s.
|
|
66
|
+
- **success**: positive outcome. Auto-dismisses after 5s.
|
|
67
|
+
- **warning**: caution. Persists until dismissed.
|
|
68
|
+
- **error**: failure. Persists until dismissed.
|
|
69
|
+
- **loading**: `toast.loading` shows a spinner. Persists until updated or dismissed.
|
|
70
|
+
|
|
71
|
+
<Canvas of={ToastStories.AppearanceShowcase} />
|
|
72
|
+
|
|
73
|
+
### Actions
|
|
74
|
+
|
|
75
|
+
Pass `action` with a label and `onAction`. Pressing it never dismisses the
|
|
76
|
+
toast, so it is well suited to a retry.
|
|
77
|
+
|
|
78
|
+
The action's placement is automatic. While the title and the action fit on
|
|
79
|
+
one row, the action sits inline beside the title. Otherwise the action drops
|
|
80
|
+
to its own row underneath. The title itself wraps, then truncates with an
|
|
81
|
+
ellipsis past a few lines.
|
|
82
|
+
|
|
83
|
+
<Canvas of={ToastStories.WithAction} />
|
|
84
|
+
|
|
85
|
+
### Durations
|
|
86
|
+
|
|
87
|
+
`Toaster`'s `durations` replaces the Lumen timing for the appearances you
|
|
88
|
+
list, in milliseconds. `0` keeps that appearance on screen until dismissed. A
|
|
89
|
+
`duration` on an individual toast overrides this configuration. The timer
|
|
90
|
+
starts when the toast becomes visible, and starts again when an update changes
|
|
91
|
+
appearance, loading, or duration.
|
|
92
|
+
|
|
93
|
+
Unlike web, there is no close button: toasts are dismissed by swiping left or
|
|
94
|
+
right, unless `dismissible` is `false`.
|
|
95
|
+
|
|
96
|
+
<Canvas of={ToastStories.WithDuration} />
|
|
97
|
+
|
|
98
|
+
### Programmatic dismissal
|
|
99
|
+
|
|
100
|
+
`toast.notify` and the appearance shortcuts return `{ id }`. Pass that id to
|
|
101
|
+
`toast.dismiss` when the toast is no longer relevant. `toast.dismissAll`
|
|
102
|
+
clears the queue.
|
|
103
|
+
|
|
104
|
+
<Canvas of={ToastStories.WithDismiss} />
|
|
105
|
+
|
|
106
|
+
### Position
|
|
107
|
+
|
|
108
|
+
`position` anchors the queue to the `top` or `bottom` of the screen — there
|
|
109
|
+
are no corner or center variants on React Native. Items enter from that same
|
|
110
|
+
edge and clear the safe area automatically. Use `insets` to clear extra
|
|
111
|
+
obstructions such as a custom tab bar.
|
|
112
|
+
|
|
113
|
+
### Queue
|
|
114
|
+
|
|
115
|
+
Up to `maxItems` toasts are visible at once (default 1). Extra items wait in a
|
|
116
|
+
FIFO backlog and appear as slots free up. Items waiting in the backlog are
|
|
117
|
+
stacked on the pile, so they slide out from behind the visible toasts instead
|
|
118
|
+
of entering from the edge.
|
|
119
|
+
|
|
120
|
+
### Accessibility
|
|
121
|
+
|
|
122
|
+
- Info, success and loading announce politely; warning and error announce
|
|
123
|
+
assertively. Android TalkBack reads the surface's `accessibilityLiveRegion`;
|
|
124
|
+
iOS VoiceOver has no live regions, so `Toaster` posts the title as an
|
|
125
|
+
announcement, interrupting current speech only for warning and error.
|
|
126
|
+
- Screen readers capture swipes, so each toast is a single element labelled by
|
|
127
|
+
its title, with dismissal and the action exposed as accessibility actions
|
|
128
|
+
(VoiceOver rotor, TalkBack actions menu). On iOS the two-finger escape scrub
|
|
129
|
+
also dismisses.
|
|
130
|
+
- Touching a toast pauses its timer, satisfying "pause on timed content".
|
|
131
|
+
Releasing it resumes from the remaining time.
|
|
132
|
+
|
|
133
|
+
## The `Toast` item
|
|
134
|
+
|
|
135
|
+
`Toaster` renders a `Toast` for each queued item. The variants above are that
|
|
136
|
+
surface. Render `Toast` yourself only when you need finer control, or when you
|
|
137
|
+
are plugging the item into a notification system you already own. You then
|
|
138
|
+
handle queueing, timing, and dismissal yourself.
|
|
139
|
+
|
|
140
|
+
</Tab>
|
|
141
|
+
|
|
142
|
+
<Tab label="Implementation">
|
|
143
|
+
<SetupNote />
|
|
144
|
+
|
|
145
|
+
### Setup
|
|
146
|
+
|
|
147
|
+
Mount `Toaster` once, near the app root — it takes no children and renders
|
|
148
|
+
the queue viewport as an absolutely-positioned overlay, so there is no
|
|
149
|
+
separate viewport to mount. Mounting more than one duplicates every toast on
|
|
150
|
+
screen and logs a console warning. Requires
|
|
151
|
+
`react-native-gesture-handler`'s `GestureHandlerRootView` and
|
|
152
|
+
`react-native-safe-area-context`'s `SafeAreaProvider` above it in the tree.
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
156
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
157
|
+
import { Toaster } from '@ledgerhq/lumen-ui-rnative';
|
|
158
|
+
|
|
159
|
+
function App() {
|
|
160
|
+
return (
|
|
161
|
+
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
162
|
+
<SafeAreaProvider>
|
|
163
|
+
<Toaster position='bottom' maxItems={1} />
|
|
164
|
+
<Screens />
|
|
165
|
+
</SafeAreaProvider>
|
|
166
|
+
</GestureHandlerRootView>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Triggering toasts
|
|
172
|
+
|
|
173
|
+
<Source of={ToastStories.Base} />
|
|
174
|
+
|
|
175
|
+
### With an action
|
|
176
|
+
|
|
177
|
+
<Source of={ToastStories.WithAction} />
|
|
178
|
+
|
|
179
|
+
### Durations
|
|
180
|
+
|
|
181
|
+
<Source of={ToastStories.WithDuration} />
|
|
182
|
+
|
|
183
|
+
### Programmatic dismissal
|
|
184
|
+
|
|
185
|
+
<Source of={ToastStories.WithDismiss} />
|
|
186
|
+
|
|
187
|
+
### Loading and updates
|
|
188
|
+
|
|
189
|
+
Start a loading toast, then update it in place to success or error. The toast
|
|
190
|
+
keeps the same id across the transition, and its timer restarts at the newly
|
|
191
|
+
resolved duration:
|
|
192
|
+
|
|
193
|
+
<Source of={ToastStories.WithUpdate} />
|
|
194
|
+
|
|
195
|
+
### Binding a promise
|
|
196
|
+
|
|
197
|
+
`promise` moves a single toast through loading, then success or error,
|
|
198
|
+
tracking the given promise automatically:
|
|
199
|
+
|
|
200
|
+
<Source of={ToastStories.WithPromise} />
|
|
201
|
+
|
|
202
|
+
</Tab>
|
|
203
|
+
</CustomTabs>
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { toast } from '@ledgerhq/lumen-utils-shared';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
6
|
+
import { Box } from "../../primitives/index.js";
|
|
7
|
+
import { Button } from "../Button/index.js";
|
|
8
|
+
import { Toast } from "./Toast.js";
|
|
9
|
+
import { Toaster } from "./Toaster.js";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const RANDOM_APPEARANCES = ['info', 'success', 'warning', 'error'];
|
|
12
|
+
const RANDOM_TITLES = ['Payment done', 'Report ready for review in 30 minutes', 'This is a very long toast message that wraps over up to five lines without an action', 'This is a very long toast message that wraps over up to five lines'];
|
|
13
|
+
const RANDOM_ACTION_LABELS = ['Open', 'Undo', 'Retry', 'Download the report', 'Retry the upload'];
|
|
14
|
+
const pickRandom = items => items[Math.floor(Math.random() * items.length)];
|
|
15
|
+
const showRandomToast = () => {
|
|
16
|
+
toast.notify({
|
|
17
|
+
appearance: pickRandom(RANDOM_APPEARANCES),
|
|
18
|
+
title: pickRandom(RANDOM_TITLES),
|
|
19
|
+
action: Math.random() > 0.5 ? {
|
|
20
|
+
label: pickRandom(RANDOM_ACTION_LABELS),
|
|
21
|
+
onAction: () => {}
|
|
22
|
+
} : undefined
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const meta = {
|
|
26
|
+
component: Toaster,
|
|
27
|
+
id: 'rnative-toast',
|
|
28
|
+
title: 'Core/Toast',
|
|
29
|
+
parameters: {
|
|
30
|
+
layout: 'centered',
|
|
31
|
+
backgrounds: {
|
|
32
|
+
default: 'light'
|
|
33
|
+
},
|
|
34
|
+
docs: {
|
|
35
|
+
source: {
|
|
36
|
+
language: 'tsx',
|
|
37
|
+
format: true,
|
|
38
|
+
type: 'dynamic'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
argTypes: {
|
|
43
|
+
durations: {
|
|
44
|
+
control: 'object'
|
|
45
|
+
},
|
|
46
|
+
insets: {
|
|
47
|
+
control: 'object'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export default meta;
|
|
52
|
+
export const Base = {
|
|
53
|
+
args: {
|
|
54
|
+
position: 'bottom',
|
|
55
|
+
maxItems: 1,
|
|
56
|
+
durations: {
|
|
57
|
+
info: 3000,
|
|
58
|
+
success: 3000,
|
|
59
|
+
warning: 3000,
|
|
60
|
+
error: 3000
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
render: args => /*#__PURE__*/_jsxs(SafeAreaProvider, {
|
|
64
|
+
children: [/*#__PURE__*/_jsx(Toaster, {
|
|
65
|
+
...args
|
|
66
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
|
67
|
+
lx: {
|
|
68
|
+
flexDirection: 'column',
|
|
69
|
+
alignItems: 'center',
|
|
70
|
+
gap: 's8'
|
|
71
|
+
},
|
|
72
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
73
|
+
appearance: "base",
|
|
74
|
+
size: "sm",
|
|
75
|
+
onPress: () => toast.info({
|
|
76
|
+
title: 'Your transaction was sent'
|
|
77
|
+
}),
|
|
78
|
+
children: "Show Info"
|
|
79
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
80
|
+
appearance: "base",
|
|
81
|
+
size: "sm",
|
|
82
|
+
onPress: () => toast.success({
|
|
83
|
+
title: 'Payment done'
|
|
84
|
+
}),
|
|
85
|
+
children: "Show Success"
|
|
86
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
87
|
+
appearance: "base",
|
|
88
|
+
size: "sm",
|
|
89
|
+
onPress: () => toast.warning({
|
|
90
|
+
title: 'Low balance'
|
|
91
|
+
}),
|
|
92
|
+
children: "Show Warning"
|
|
93
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
94
|
+
appearance: "base",
|
|
95
|
+
size: "sm",
|
|
96
|
+
onPress: () => toast.error({
|
|
97
|
+
title: 'Payment failed'
|
|
98
|
+
}),
|
|
99
|
+
children: "Show Error"
|
|
100
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
101
|
+
appearance: "base",
|
|
102
|
+
size: "sm",
|
|
103
|
+
onPress: () => toast.loading({
|
|
104
|
+
title: 'Processing payment'
|
|
105
|
+
}),
|
|
106
|
+
children: "Show Loading"
|
|
107
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
108
|
+
appearance: "base",
|
|
109
|
+
size: "sm",
|
|
110
|
+
onPress: showRandomToast,
|
|
111
|
+
children: "Show Random"
|
|
112
|
+
})]
|
|
113
|
+
})]
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
export const WithAction = {
|
|
117
|
+
render: () => /*#__PURE__*/_jsxs(SafeAreaProvider, {
|
|
118
|
+
children: [/*#__PURE__*/_jsx(Toaster, {}), /*#__PURE__*/_jsx(Button, {
|
|
119
|
+
appearance: "base",
|
|
120
|
+
onPress: () => toast.error({
|
|
121
|
+
title: 'Payment failed',
|
|
122
|
+
action: {
|
|
123
|
+
label: 'Retry',
|
|
124
|
+
onAction: () => {}
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
children: "Show actionable toast"
|
|
128
|
+
})]
|
|
129
|
+
})
|
|
130
|
+
};
|
|
131
|
+
export const WithDuration = {
|
|
132
|
+
render: () => /*#__PURE__*/_jsxs(SafeAreaProvider, {
|
|
133
|
+
children: [/*#__PURE__*/_jsx(Toaster, {}), /*#__PURE__*/_jsx(Button, {
|
|
134
|
+
appearance: "base",
|
|
135
|
+
onPress: () => toast.success({
|
|
136
|
+
title: 'Payment done'
|
|
137
|
+
}),
|
|
138
|
+
children: "Show auto-dismissing toast"
|
|
139
|
+
})]
|
|
140
|
+
})
|
|
141
|
+
};
|
|
142
|
+
const DismissDemo = () => {
|
|
143
|
+
const [id, setId] = useState(null);
|
|
144
|
+
return /*#__PURE__*/_jsx(Button, {
|
|
145
|
+
appearance: "base",
|
|
146
|
+
onPress: () => {
|
|
147
|
+
if (id === null) {
|
|
148
|
+
const next = toast.error({
|
|
149
|
+
title: 'Unable to save'
|
|
150
|
+
});
|
|
151
|
+
setId(next.id);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
toast.dismiss(id);
|
|
155
|
+
setId(null);
|
|
156
|
+
},
|
|
157
|
+
children: id === null ? 'Show toast' : 'Hide toast'
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
export const WithDismiss = {
|
|
161
|
+
render: () => /*#__PURE__*/_jsxs(SafeAreaProvider, {
|
|
162
|
+
children: [/*#__PURE__*/_jsx(Toaster, {}), /*#__PURE__*/_jsx(DismissDemo, {})]
|
|
163
|
+
})
|
|
164
|
+
};
|
|
165
|
+
const UpdateDemo = () => /*#__PURE__*/_jsx(Button, {
|
|
166
|
+
appearance: "base",
|
|
167
|
+
onPress: () => {
|
|
168
|
+
const {
|
|
169
|
+
id
|
|
170
|
+
} = toast.loading({
|
|
171
|
+
title: 'Uploading…'
|
|
172
|
+
});
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
toast.update(id, {
|
|
175
|
+
appearance: 'success',
|
|
176
|
+
loading: false,
|
|
177
|
+
title: 'Upload complete'
|
|
178
|
+
});
|
|
179
|
+
}, 2000);
|
|
180
|
+
},
|
|
181
|
+
children: "Upload file"
|
|
182
|
+
});
|
|
183
|
+
export const WithUpdate = {
|
|
184
|
+
render: () => /*#__PURE__*/_jsxs(SafeAreaProvider, {
|
|
185
|
+
children: [/*#__PURE__*/_jsx(Toaster, {}), /*#__PURE__*/_jsx(UpdateDemo, {})]
|
|
186
|
+
})
|
|
187
|
+
};
|
|
188
|
+
const simulateSaveProfile = () => new Promise(resolve => setTimeout(resolve, 2000));
|
|
189
|
+
const PromiseDemo = () => /*#__PURE__*/_jsx(Button, {
|
|
190
|
+
appearance: "base",
|
|
191
|
+
onPress: () => toast.promise(simulateSaveProfile(), {
|
|
192
|
+
loading: {
|
|
193
|
+
title: 'Saving…'
|
|
194
|
+
},
|
|
195
|
+
success: {
|
|
196
|
+
title: 'Profile saved'
|
|
197
|
+
},
|
|
198
|
+
error: {
|
|
199
|
+
title: 'Could not save'
|
|
200
|
+
}
|
|
201
|
+
}),
|
|
202
|
+
children: "Save profile"
|
|
203
|
+
});
|
|
204
|
+
export const WithPromise = {
|
|
205
|
+
render: () => /*#__PURE__*/_jsxs(SafeAreaProvider, {
|
|
206
|
+
children: [/*#__PURE__*/_jsx(Toaster, {}), /*#__PURE__*/_jsx(PromiseDemo, {})]
|
|
207
|
+
})
|
|
208
|
+
};
|
|
209
|
+
export const AppearanceShowcase = {
|
|
210
|
+
render: () => /*#__PURE__*/_jsxs(Box, {
|
|
211
|
+
lx: {
|
|
212
|
+
flexDirection: 'column',
|
|
213
|
+
gap: 's8',
|
|
214
|
+
width: 's400'
|
|
215
|
+
},
|
|
216
|
+
children: [/*#__PURE__*/_jsx(Toast, {
|
|
217
|
+
appearance: "info",
|
|
218
|
+
title: "Your transaction was sent"
|
|
219
|
+
}), /*#__PURE__*/_jsx(Toast, {
|
|
220
|
+
appearance: "success",
|
|
221
|
+
title: "Payment done"
|
|
222
|
+
}), /*#__PURE__*/_jsx(Toast, {
|
|
223
|
+
appearance: "warning",
|
|
224
|
+
title: "Low balance"
|
|
225
|
+
}), /*#__PURE__*/_jsx(Toast, {
|
|
226
|
+
appearance: "error",
|
|
227
|
+
title: "Payment failed",
|
|
228
|
+
action: {
|
|
229
|
+
label: 'Retry',
|
|
230
|
+
onAction: () => {}
|
|
231
|
+
}
|
|
232
|
+
}), /*#__PURE__*/_jsx(Toast, {
|
|
233
|
+
loading: true,
|
|
234
|
+
title: "Processing payment"
|
|
235
|
+
})]
|
|
236
|
+
})
|
|
237
|
+
};
|
|
238
|
+
//# sourceMappingURL=Toast.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["toast","useState","SafeAreaProvider","Box","Button","Toast","Toaster","jsx","_jsx","jsxs","_jsxs","RANDOM_APPEARANCES","RANDOM_TITLES","RANDOM_ACTION_LABELS","pickRandom","items","Math","floor","random","length","showRandomToast","notify","appearance","title","action","label","onAction","undefined","meta","component","id","parameters","layout","backgrounds","default","docs","source","language","format","type","argTypes","durations","control","insets","Base","args","position","maxItems","info","success","warning","error","render","children","lx","flexDirection","alignItems","gap","size","onPress","loading","WithAction","WithDuration","DismissDemo","setId","next","dismiss","WithDismiss","UpdateDemo","setTimeout","update","WithUpdate","simulateSaveProfile","Promise","resolve","PromiseDemo","promise","WithPromise","AppearanceShowcase","width"],"sourceRoot":"../../../../../../src","sources":["lib/Components/core/Toast/Toast.stories.tsx"],"mappings":";;AAAA,SAASA,KAAK,QAAQ,8BAA8B;AAEpD,SAASC,QAAQ,QAAQ,OAAO;AAChC,SAASC,gBAAgB,QAAQ,gCAAgC;AACjE,SAASC,GAAG,QAAQ,2BAAkB;AACtC,SAASC,MAAM,QAAQ,oBAAW;AAClC,SAASC,KAAK,QAAQ,YAAS;AAC/B,SAASC,OAAO,QAAQ,cAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAGpC,MAAMC,kBAAqC,GAAG,CAC5C,MAAM,EACN,SAAS,EACT,SAA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