@ledgerhq/lumen-ui-rnative 0.1.64 → 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.
Files changed (136) hide show
  1. package/dist/module/lib/Components/core/CardButton/CardButton.js +2 -0
  2. package/dist/module/lib/Components/core/CardButton/CardButton.js.map +1 -1
  3. package/dist/module/lib/Components/core/CardButton/CardButton.mdx +4 -0
  4. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js +1 -0
  5. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js.map +1 -1
  6. package/dist/module/lib/Components/core/Link/Link.figma.js +2 -1
  7. package/dist/module/lib/Components/core/Link/Link.figma.js.map +1 -1
  8. package/dist/module/lib/Components/core/Link/Link.js +5 -3
  9. package/dist/module/lib/Components/core/Link/Link.js.map +1 -1
  10. package/dist/module/lib/Components/core/Link/Link.mdx +3 -2
  11. package/dist/module/lib/Components/core/Link/Link.stories.js +4 -1
  12. package/dist/module/lib/Components/core/Link/Link.stories.js.map +1 -1
  13. package/dist/module/lib/Components/core/Link/Link.test.js +2 -2
  14. package/dist/module/lib/Components/core/Link/Link.test.js.map +1 -1
  15. package/dist/module/lib/Components/core/Stepper/Stepper.js +76 -30
  16. package/dist/module/lib/Components/core/Stepper/Stepper.js.map +1 -1
  17. package/dist/module/lib/Components/core/Stepper/Stepper.mdx +37 -16
  18. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js +102 -2
  19. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js.map +1 -1
  20. package/dist/module/lib/Components/core/Stepper/Stepper.test.js +32 -1
  21. package/dist/module/lib/Components/core/Stepper/Stepper.test.js.map +1 -1
  22. package/dist/module/lib/Components/core/Timeline/Timeline.figma.js +83 -0
  23. package/dist/module/lib/Components/core/Timeline/Timeline.figma.js.map +1 -0
  24. package/dist/module/lib/Components/core/Timeline/Timeline.js +464 -0
  25. package/dist/module/lib/Components/core/Timeline/Timeline.js.map +1 -0
  26. package/dist/module/lib/Components/core/Timeline/Timeline.mdx +49 -0
  27. package/dist/module/lib/Components/core/Timeline/Timeline.stories.js +289 -0
  28. package/dist/module/lib/Components/core/Timeline/Timeline.stories.js.map +1 -0
  29. package/dist/module/lib/Components/core/Timeline/Timeline.test.js +234 -0
  30. package/dist/module/lib/Components/core/Timeline/Timeline.test.js.map +1 -0
  31. package/dist/module/lib/Components/core/Timeline/index.js +5 -0
  32. package/dist/module/lib/Components/core/Timeline/index.js.map +1 -0
  33. package/dist/module/lib/Components/core/Timeline/types.js +4 -0
  34. package/dist/module/lib/Components/core/Timeline/types.js.map +1 -0
  35. package/dist/module/lib/Components/core/Toast/Toast.figma.js +39 -0
  36. package/dist/module/lib/Components/core/Toast/Toast.figma.js.map +1 -0
  37. package/dist/module/lib/Components/core/Toast/Toast.js +138 -0
  38. package/dist/module/lib/Components/core/Toast/Toast.js.map +1 -0
  39. package/dist/module/lib/Components/core/Toast/Toast.mdx +203 -0
  40. package/dist/module/lib/Components/core/Toast/Toast.stories.js +238 -0
  41. package/dist/module/lib/Components/core/Toast/Toast.stories.js.map +1 -0
  42. package/dist/module/lib/Components/core/Toast/Toast.test.js +203 -0
  43. package/dist/module/lib/Components/core/Toast/Toast.test.js.map +1 -0
  44. package/dist/module/lib/Components/core/Toast/Toaster.js +147 -0
  45. package/dist/module/lib/Components/core/Toast/Toaster.js.map +1 -0
  46. package/dist/module/lib/Components/core/Toast/Toaster.test.js +732 -0
  47. package/dist/module/lib/Components/core/Toast/Toaster.test.js.map +1 -0
  48. package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js +70 -0
  49. package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js.map +1 -0
  50. package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js +33 -0
  51. package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js.map +1 -0
  52. package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js +224 -0
  53. package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js.map +1 -0
  54. package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js +82 -0
  55. package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js.map +1 -0
  56. package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js +21 -0
  57. package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js.map +1 -0
  58. package/dist/module/lib/Components/core/Toast/index.js +7 -0
  59. package/dist/module/lib/Components/core/Toast/index.js.map +1 -0
  60. package/dist/module/lib/Components/core/Toast/types.js +4 -0
  61. package/dist/module/lib/Components/core/Toast/types.js.map +1 -0
  62. package/dist/module/lib/Components/core/index.js +2 -0
  63. package/dist/module/lib/Components/core/index.js.map +1 -1
  64. package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts +2 -0
  65. package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts.map +1 -1
  66. package/dist/typescript/src/lib/Components/core/Link/Link.d.ts +1 -1
  67. package/dist/typescript/src/lib/Components/core/Link/Link.d.ts.map +1 -1
  68. package/dist/typescript/src/lib/Components/core/Link/types.d.ts +1 -1
  69. package/dist/typescript/src/lib/Components/core/Link/types.d.ts.map +1 -1
  70. package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts +4 -3
  71. package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts.map +1 -1
  72. package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts +12 -2
  73. package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts.map +1 -1
  74. package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts +56 -0
  75. package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts.map +1 -0
  76. package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts +3 -0
  77. package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts.map +1 -0
  78. package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts +109 -0
  79. package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts.map +1 -0
  80. package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts +24 -0
  81. package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts.map +1 -0
  82. package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts +35 -0
  83. package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts.map +1 -0
  84. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts +17 -0
  85. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts.map +1 -0
  86. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts +19 -0
  87. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts.map +1 -0
  88. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts +14 -0
  89. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts.map +1 -0
  90. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts +15 -0
  91. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts.map +1 -0
  92. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts +21 -0
  93. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts.map +1 -0
  94. package/dist/typescript/src/lib/Components/core/Toast/index.d.ts +5 -0
  95. package/dist/typescript/src/lib/Components/core/Toast/index.d.ts.map +1 -0
  96. package/dist/typescript/src/lib/Components/core/Toast/types.d.ts +75 -0
  97. package/dist/typescript/src/lib/Components/core/Toast/types.d.ts.map +1 -0
  98. package/dist/typescript/src/lib/Components/core/index.d.ts +2 -0
  99. package/dist/typescript/src/lib/Components/core/index.d.ts.map +1 -1
  100. package/package.json +3 -3
  101. package/src/lib/Components/core/CardButton/CardButton.mdx +4 -0
  102. package/src/lib/Components/core/CardButton/CardButton.stories.tsx +1 -0
  103. package/src/lib/Components/core/CardButton/CardButton.tsx +2 -0
  104. package/src/lib/Components/core/Link/Link.figma.tsx +1 -0
  105. package/src/lib/Components/core/Link/Link.mdx +3 -2
  106. package/src/lib/Components/core/Link/Link.stories.tsx +3 -2
  107. package/src/lib/Components/core/Link/Link.test.tsx +2 -0
  108. package/src/lib/Components/core/Link/Link.tsx +3 -1
  109. package/src/lib/Components/core/Link/types.ts +1 -1
  110. package/src/lib/Components/core/Stepper/Stepper.mdx +37 -16
  111. package/src/lib/Components/core/Stepper/Stepper.stories.tsx +50 -2
  112. package/src/lib/Components/core/Stepper/Stepper.test.tsx +29 -1
  113. package/src/lib/Components/core/Stepper/Stepper.tsx +73 -32
  114. package/src/lib/Components/core/Stepper/types.ts +12 -2
  115. package/src/lib/Components/core/Timeline/Timeline.figma.tsx +79 -0
  116. package/src/lib/Components/core/Timeline/Timeline.mdx +49 -0
  117. package/src/lib/Components/core/Timeline/Timeline.stories.tsx +250 -0
  118. package/src/lib/Components/core/Timeline/Timeline.test.tsx +275 -0
  119. package/src/lib/Components/core/Timeline/Timeline.tsx +576 -0
  120. package/src/lib/Components/core/Timeline/index.ts +2 -0
  121. package/src/lib/Components/core/Timeline/types.ts +124 -0
  122. package/src/lib/Components/core/Toast/Toast.figma.tsx +36 -0
  123. package/src/lib/Components/core/Toast/Toast.mdx +203 -0
  124. package/src/lib/Components/core/Toast/Toast.stories.tsx +260 -0
  125. package/src/lib/Components/core/Toast/Toast.test.tsx +181 -0
  126. package/src/lib/Components/core/Toast/Toast.tsx +163 -0
  127. package/src/lib/Components/core/Toast/Toaster.test.tsx +687 -0
  128. package/src/lib/Components/core/Toast/Toaster.tsx +157 -0
  129. package/src/lib/Components/core/Toast/hooks/useToastAccessibility.ts +82 -0
  130. package/src/lib/Components/core/Toast/hooks/useToastCollapse.ts +38 -0
  131. package/src/lib/Components/core/Toast/hooks/useToastGesture.ts +83 -0
  132. package/src/lib/Components/core/Toast/hooks/useToastMotion.ts +71 -0
  133. package/src/lib/Components/core/Toast/hooks/useToastViewportStyles.ts +45 -0
  134. package/src/lib/Components/core/Toast/index.ts +4 -0
  135. package/src/lib/Components/core/Toast/types.ts +94 -0
  136. package/src/lib/Components/core/index.ts +2 -0
@@ -0,0 +1,36 @@
1
+ import figma from '@figma/code-connect';
2
+ import { Toast } from './Toast';
3
+
4
+ figma.connect(
5
+ Toast,
6
+ 'https://www.figma.com/design/JxaLVMTWirCpU0rsbZ30k7?node-id=21016-59623',
7
+ {
8
+ imports: ["import { Toast } from '@ledgerhq/lumen-ui-rnative'"],
9
+ props: {
10
+ appearance: figma.enum('appearance', {
11
+ info: 'info',
12
+ success: 'success',
13
+ warning: 'warning',
14
+ error: 'error',
15
+ }),
16
+ loading: figma.enum('state', {
17
+ enabled: false,
18
+ loading: true,
19
+ }),
20
+ title: figma.string('text'),
21
+ action: figma.enum('action', {
22
+ none: undefined,
23
+ 'short-action': { label: 'Label', onAction: () => {} },
24
+ 'long-action': { label: 'Label', onAction: () => {} },
25
+ }),
26
+ },
27
+ example: (props) => (
28
+ <Toast
29
+ appearance={props.appearance}
30
+ loading={props.loading}
31
+ title={props.title}
32
+ action={props.action}
33
+ />
34
+ ),
35
+ },
36
+ );
@@ -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,260 @@
1
+ import { toast } from '@ledgerhq/lumen-utils-shared';
2
+ import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
3
+ import { useState } from 'react';
4
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
5
+ import { Box } from '../../primitives';
6
+ import { Button } from '../Button';
7
+ import { Toast } from './Toast';
8
+ import { Toaster } from './Toaster';
9
+ import type { ToastAppearance } from './types';
10
+
11
+ const RANDOM_APPEARANCES: ToastAppearance[] = [
12
+ 'info',
13
+ 'success',
14
+ 'warning',
15
+ 'error',
16
+ ];
17
+
18
+ const RANDOM_TITLES = [
19
+ 'Payment done',
20
+ 'Report ready for review in 30 minutes',
21
+ 'This is a very long toast message that wraps over up to five lines without an action',
22
+ 'This is a very long toast message that wraps over up to five lines',
23
+ ];
24
+
25
+ const RANDOM_ACTION_LABELS = [
26
+ 'Open',
27
+ 'Undo',
28
+ 'Retry',
29
+ 'Download the report',
30
+ 'Retry the upload',
31
+ ];
32
+
33
+ const pickRandom = <T,>(items: readonly T[]): T =>
34
+ items[Math.floor(Math.random() * items.length)];
35
+
36
+ const showRandomToast = (): void => {
37
+ toast.notify({
38
+ appearance: pickRandom(RANDOM_APPEARANCES),
39
+ title: pickRandom(RANDOM_TITLES),
40
+ action:
41
+ Math.random() > 0.5
42
+ ? { label: pickRandom(RANDOM_ACTION_LABELS), onAction: () => {} }
43
+ : undefined,
44
+ });
45
+ };
46
+
47
+ const meta = {
48
+ component: Toaster,
49
+ id: 'rnative-toast',
50
+ title: 'Core/Toast',
51
+ parameters: {
52
+ layout: 'centered',
53
+ backgrounds: { default: 'light' },
54
+ docs: {
55
+ source: {
56
+ language: 'tsx',
57
+ format: true,
58
+ type: 'dynamic',
59
+ },
60
+ },
61
+ },
62
+ argTypes: {
63
+ durations: { control: 'object' },
64
+ insets: { control: 'object' },
65
+ },
66
+ } satisfies Meta<typeof Toaster>;
67
+
68
+ export default meta;
69
+ type Story = StoryObj<typeof Toaster>;
70
+
71
+ export const Base: Story = {
72
+ args: {
73
+ position: 'bottom',
74
+ maxItems: 1,
75
+ durations: {
76
+ info: 3000,
77
+ success: 3000,
78
+ warning: 3000,
79
+ error: 3000,
80
+ },
81
+ },
82
+ render: (args) => (
83
+ <SafeAreaProvider>
84
+ <Toaster {...args} />
85
+ <Box lx={{ flexDirection: 'column', alignItems: 'center', gap: 's8' }}>
86
+ <Button
87
+ appearance='base'
88
+ size='sm'
89
+ onPress={() => toast.info({ title: 'Your transaction was sent' })}
90
+ >
91
+ Show Info
92
+ </Button>
93
+ <Button
94
+ appearance='base'
95
+ size='sm'
96
+ onPress={() => toast.success({ title: 'Payment done' })}
97
+ >
98
+ Show Success
99
+ </Button>
100
+ <Button
101
+ appearance='base'
102
+ size='sm'
103
+ onPress={() => toast.warning({ title: 'Low balance' })}
104
+ >
105
+ Show Warning
106
+ </Button>
107
+ <Button
108
+ appearance='base'
109
+ size='sm'
110
+ onPress={() => toast.error({ title: 'Payment failed' })}
111
+ >
112
+ Show Error
113
+ </Button>
114
+ <Button
115
+ appearance='base'
116
+ size='sm'
117
+ onPress={() => toast.loading({ title: 'Processing payment' })}
118
+ >
119
+ Show Loading
120
+ </Button>
121
+ <Button appearance='base' size='sm' onPress={showRandomToast}>
122
+ Show Random
123
+ </Button>
124
+ </Box>
125
+ </SafeAreaProvider>
126
+ ),
127
+ };
128
+
129
+ export const WithAction: Story = {
130
+ render: () => (
131
+ <SafeAreaProvider>
132
+ <Toaster />
133
+ <Button
134
+ appearance='base'
135
+ onPress={() =>
136
+ toast.error({
137
+ title: 'Payment failed',
138
+ action: { label: 'Retry', onAction: () => {} },
139
+ })
140
+ }
141
+ >
142
+ Show actionable toast
143
+ </Button>
144
+ </SafeAreaProvider>
145
+ ),
146
+ };
147
+
148
+ export const WithDuration: Story = {
149
+ render: () => (
150
+ <SafeAreaProvider>
151
+ <Toaster />
152
+ <Button
153
+ appearance='base'
154
+ onPress={() => toast.success({ title: 'Payment done' })}
155
+ >
156
+ Show auto-dismissing toast
157
+ </Button>
158
+ </SafeAreaProvider>
159
+ ),
160
+ };
161
+
162
+ const DismissDemo = () => {
163
+ const [id, setId] = useState<string | null>(null);
164
+
165
+ return (
166
+ <Button
167
+ appearance='base'
168
+ onPress={() => {
169
+ if (id === null) {
170
+ const next = toast.error({ title: 'Unable to save' });
171
+ setId(next.id);
172
+ return;
173
+ }
174
+ toast.dismiss(id);
175
+ setId(null);
176
+ }}
177
+ >
178
+ {id === null ? 'Show toast' : 'Hide toast'}
179
+ </Button>
180
+ );
181
+ };
182
+
183
+ export const WithDismiss: Story = {
184
+ render: () => (
185
+ <SafeAreaProvider>
186
+ <Toaster />
187
+ <DismissDemo />
188
+ </SafeAreaProvider>
189
+ ),
190
+ };
191
+
192
+ const UpdateDemo = () => (
193
+ <Button
194
+ appearance='base'
195
+ onPress={() => {
196
+ const { id } = toast.loading({ title: 'Uploading…' });
197
+ setTimeout(() => {
198
+ toast.update(id, {
199
+ appearance: 'success',
200
+ loading: false,
201
+ title: 'Upload complete',
202
+ });
203
+ }, 2000);
204
+ }}
205
+ >
206
+ Upload file
207
+ </Button>
208
+ );
209
+
210
+ export const WithUpdate: Story = {
211
+ render: () => (
212
+ <SafeAreaProvider>
213
+ <Toaster />
214
+ <UpdateDemo />
215
+ </SafeAreaProvider>
216
+ ),
217
+ };
218
+
219
+ const simulateSaveProfile = () =>
220
+ new Promise<void>((resolve) => setTimeout(resolve, 2000));
221
+
222
+ const PromiseDemo = () => (
223
+ <Button
224
+ appearance='base'
225
+ onPress={() =>
226
+ toast.promise(simulateSaveProfile(), {
227
+ loading: { title: 'Saving…' },
228
+ success: { title: 'Profile saved' },
229
+ error: { title: 'Could not save' },
230
+ })
231
+ }
232
+ >
233
+ Save profile
234
+ </Button>
235
+ );
236
+
237
+ export const WithPromise: Story = {
238
+ render: () => (
239
+ <SafeAreaProvider>
240
+ <Toaster />
241
+ <PromiseDemo />
242
+ </SafeAreaProvider>
243
+ ),
244
+ };
245
+
246
+ export const AppearanceShowcase: Story = {
247
+ render: () => (
248
+ <Box lx={{ flexDirection: 'column', gap: 's8', width: 's400' }}>
249
+ <Toast appearance='info' title='Your transaction was sent' />
250
+ <Toast appearance='success' title='Payment done' />
251
+ <Toast appearance='warning' title='Low balance' />
252
+ <Toast
253
+ appearance='error'
254
+ title='Payment failed'
255
+ action={{ label: 'Retry', onAction: () => {} }}
256
+ />
257
+ <Toast loading title='Processing payment' />
258
+ </Box>
259
+ ),
260
+ };
@@ -0,0 +1,181 @@
1
+ import { describe, it, expect, jest } from '@jest/globals';
2
+ import { ledgerLiveThemes } from '@ledgerhq/lumen-design-core';
3
+ import { fireEvent, render } from '@testing-library/react-native';
4
+ import { StyleSheet } from 'react-native';
5
+ import { ThemeProvider } from '../ThemeProvider/ThemeProvider';
6
+ import { Toast } from './Toast';
7
+
8
+ const TestWrapper = ({ children }: { children: React.ReactNode }) => (
9
+ <ThemeProvider themes={ledgerLiveThemes} colorScheme='dark' locale='en'>
10
+ {children}
11
+ </ThemeProvider>
12
+ );
13
+
14
+ describe('Toast', () => {
15
+ describe('Rendering', () => {
16
+ it('should render the title', () => {
17
+ const { getByText } = render(
18
+ <TestWrapper>
19
+ <Toast title='Payment done' />
20
+ </TestWrapper>,
21
+ );
22
+ getByText('Payment done');
23
+ });
24
+
25
+ it('should wrap the title over up to five lines', () => {
26
+ const { getByText } = render(
27
+ <TestWrapper>
28
+ <Toast title='A very long toast title' />
29
+ </TestWrapper>,
30
+ );
31
+ expect(getByText('A very long toast title').props.numberOfLines).toBe(5);
32
+ });
33
+
34
+ it('should not render a leading icon for the info appearance', () => {
35
+ const { queryByTestId } = render(
36
+ <TestWrapper>
37
+ <Toast title='Info' appearance='info' />
38
+ </TestWrapper>,
39
+ );
40
+ expect(queryByTestId('toast-icon')).toBeNull();
41
+ });
42
+
43
+ it('should render a status icon for non-info appearances', () => {
44
+ const { getByTestId } = render(
45
+ <TestWrapper>
46
+ <Toast title='Saved' appearance='success' />
47
+ </TestWrapper>,
48
+ );
49
+ getByTestId('toast-icon');
50
+ });
51
+
52
+ it('should render a spinner while loading', () => {
53
+ const { getByTestId } = render(
54
+ <TestWrapper>
55
+ <Toast title='Uploading' loading />
56
+ </TestWrapper>,
57
+ );
58
+ getByTestId('toast-spinner');
59
+ });
60
+ });
61
+
62
+ describe('Layout', () => {
63
+ it('should wrap the title and action together, so an action that does not fit drops to its own line under the title', () => {
64
+ const { getByTestId } = render(
65
+ <TestWrapper>
66
+ <Toast
67
+ title='Report ready'
68
+ action={{ label: 'Download the report', onAction: jest.fn() }}
69
+ />
70
+ </TestWrapper>,
71
+ );
72
+ expect(getByTestId('toast-text-action').props.style).toEqual(
73
+ expect.objectContaining({
74
+ flexDirection: 'row',
75
+ flexWrap: 'wrap',
76
+ alignItems: 'flex-start',
77
+ }),
78
+ );
79
+ expect(
80
+ getByTestId('toast-text-action').props.style.justifyContent,
81
+ ).toBeUndefined();
82
+ });
83
+
84
+ it('should not shift the action when there is no leading icon', () => {
85
+ const { getByTestId } = render(
86
+ <TestWrapper>
87
+ <Toast
88
+ appearance='info'
89
+ title='Report ready'
90
+ action={{ label: 'Open', onAction: jest.fn() }}
91
+ />
92
+ </TestWrapper>,
93
+ );
94
+ expect(
95
+ StyleSheet.flatten(getByTestId('toast-action').props.style).marginLeft,
96
+ ).toBeUndefined();
97
+ });
98
+
99
+ it('should shift the action to align its label with the title when there is a leading icon', () => {
100
+ const { getByTestId } = render(
101
+ <TestWrapper>
102
+ <Toast
103
+ appearance='success'
104
+ title='Report ready'
105
+ action={{ label: 'Open', onAction: jest.fn() }}
106
+ />
107
+ </TestWrapper>,
108
+ );
109
+ expect(
110
+ StyleSheet.flatten(getByTestId('toast-action').props.style).marginLeft,
111
+ ).toBe(-16);
112
+ });
113
+
114
+ it('should shift the action to align its label with the title when loading', () => {
115
+ const { getByTestId } = render(
116
+ <TestWrapper>
117
+ <Toast
118
+ loading
119
+ title='Uploading'
120
+ action={{ label: 'Cancel', onAction: jest.fn() }}
121
+ />
122
+ </TestWrapper>,
123
+ );
124
+ expect(
125
+ StyleSheet.flatten(getByTestId('toast-action').props.style).marginLeft,
126
+ ).toBe(-16);
127
+ });
128
+ });
129
+
130
+ describe('Accessibility', () => {
131
+ it('should announce info and success politely', () => {
132
+ const { getByTestId, rerender } = render(
133
+ <TestWrapper>
134
+ <Toast testID='toast' title='Info' appearance='info' />
135
+ </TestWrapper>,
136
+ );
137
+ expect(getByTestId('toast').props.accessibilityLiveRegion).toBe('polite');
138
+
139
+ rerender(
140
+ <TestWrapper>
141
+ <Toast testID='toast' title='Saved' appearance='success' />
142
+ </TestWrapper>,
143
+ );
144
+ expect(getByTestId('toast').props.accessibilityLiveRegion).toBe('polite');
145
+ });
146
+
147
+ it('should announce warning and error assertively', () => {
148
+ const { getByTestId, rerender } = render(
149
+ <TestWrapper>
150
+ <Toast testID='toast' title='Careful' appearance='warning' />
151
+ </TestWrapper>,
152
+ );
153
+ expect(getByTestId('toast').props.accessibilityLiveRegion).toBe(
154
+ 'assertive',
155
+ );
156
+
157
+ rerender(
158
+ <TestWrapper>
159
+ <Toast testID='toast' title='Failed' appearance='error' />
160
+ </TestWrapper>,
161
+ );
162
+ expect(getByTestId('toast').props.accessibilityLiveRegion).toBe(
163
+ 'assertive',
164
+ );
165
+ });
166
+ });
167
+
168
+ describe('Interactions', () => {
169
+ it('should render the action and fire onAction', () => {
170
+ const onAction = jest.fn();
171
+ const { getByText } = render(
172
+ <TestWrapper>
173
+ <Toast title='Upload failed' action={{ label: 'Retry', onAction }} />
174
+ </TestWrapper>,
175
+ );
176
+
177
+ fireEvent.press(getByText('Retry'));
178
+ expect(onAction).toHaveBeenCalledTimes(1);
179
+ });
180
+ });
181
+ });