@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.
- 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/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/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/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/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/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,576 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSafeContext,
|
|
3
|
+
isTextChildren,
|
|
4
|
+
} from '@ledgerhq/lumen-utils-shared';
|
|
5
|
+
import type { Key, ReactElement, ReactNode } from 'react';
|
|
6
|
+
import { Children, Fragment, isValidElement } from 'react';
|
|
7
|
+
import { StyleSheet } from 'react-native';
|
|
8
|
+
import { useStyleSheet } from '../../../../styles';
|
|
9
|
+
import { Box, Text } from '../../primitives';
|
|
10
|
+
import {
|
|
11
|
+
CheckmarkCircleFill,
|
|
12
|
+
ClockFill,
|
|
13
|
+
DeleteCircleFill,
|
|
14
|
+
} from '../../symbols';
|
|
15
|
+
import { Spinner } from '../Spinner';
|
|
16
|
+
import type {
|
|
17
|
+
TimelineItemBodyProps,
|
|
18
|
+
TimelineItemCaptionProps,
|
|
19
|
+
TimelineItemDescriptionProps,
|
|
20
|
+
TimelineItemHeaderProps,
|
|
21
|
+
TimelineItemLeadingProps,
|
|
22
|
+
TimelineItemLeadingRowProps,
|
|
23
|
+
TimelineItemProps,
|
|
24
|
+
TimelineItemStatus,
|
|
25
|
+
TimelineItemTitleProps,
|
|
26
|
+
TimelineItemTrailingProps,
|
|
27
|
+
TimelineProps,
|
|
28
|
+
} from './types';
|
|
29
|
+
|
|
30
|
+
type TimelineItemContextValue = {
|
|
31
|
+
status?: TimelineItemStatus;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type TimelinePosition = {
|
|
35
|
+
isFirst: boolean;
|
|
36
|
+
isLast: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type TimelineChild = {
|
|
40
|
+
key: Key;
|
|
41
|
+
node: ReactNode;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const flattenTimelineChildren = (
|
|
45
|
+
children: ReactNode,
|
|
46
|
+
keyPrefix = '',
|
|
47
|
+
): TimelineChild[] =>
|
|
48
|
+
Children.toArray(children).flatMap((child, index) => {
|
|
49
|
+
const key = `${keyPrefix}${isValidElement(child) ? (child.key ?? index) : index}`;
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
isValidElement<{ children?: ReactNode }>(child) &&
|
|
53
|
+
child.type === Fragment
|
|
54
|
+
) {
|
|
55
|
+
return flattenTimelineChildren(child.props.children, `${key}/`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return [{ key, node: child }];
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const [TimelineItemProvider, useTimelineItemContext] =
|
|
62
|
+
createSafeContext<TimelineItemContextValue>('TimelineItem');
|
|
63
|
+
|
|
64
|
+
const [TimelinePositionProvider, useTimelinePosition] =
|
|
65
|
+
createSafeContext<TimelinePosition>('Timeline', {
|
|
66
|
+
isFirst: true,
|
|
67
|
+
isLast: true,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const useTimelineStyles = () =>
|
|
71
|
+
useStyleSheet(
|
|
72
|
+
(t) => ({
|
|
73
|
+
root: {
|
|
74
|
+
width: t.sizes.full,
|
|
75
|
+
minWidth: 0,
|
|
76
|
+
flexDirection: 'column',
|
|
77
|
+
},
|
|
78
|
+
item: {
|
|
79
|
+
width: t.sizes.full,
|
|
80
|
+
minWidth: 0,
|
|
81
|
+
flexDirection: 'column',
|
|
82
|
+
position: 'relative',
|
|
83
|
+
},
|
|
84
|
+
rail: {
|
|
85
|
+
position: 'absolute',
|
|
86
|
+
top: 0,
|
|
87
|
+
bottom: 0,
|
|
88
|
+
start: 0,
|
|
89
|
+
width: t.sizes.s32,
|
|
90
|
+
flexDirection: 'column',
|
|
91
|
+
alignItems: 'center',
|
|
92
|
+
},
|
|
93
|
+
line: {
|
|
94
|
+
width: t.borderWidth.s2,
|
|
95
|
+
backgroundColor: t.colors.border.mutedSubtleHover,
|
|
96
|
+
},
|
|
97
|
+
lineIn: {
|
|
98
|
+
height: t.sizes.s16,
|
|
99
|
+
},
|
|
100
|
+
lineInHidden: {
|
|
101
|
+
opacity: 0,
|
|
102
|
+
},
|
|
103
|
+
indicatorSpacer: {
|
|
104
|
+
height: t.sizes.s32,
|
|
105
|
+
flexShrink: 0,
|
|
106
|
+
},
|
|
107
|
+
lineOut: {
|
|
108
|
+
flex: 1,
|
|
109
|
+
},
|
|
110
|
+
indicator: {
|
|
111
|
+
marginTop: t.spacings.s16,
|
|
112
|
+
width: t.sizes.s32,
|
|
113
|
+
height: t.sizes.s32,
|
|
114
|
+
flexShrink: 0,
|
|
115
|
+
alignSelf: 'flex-start',
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
justifyContent: 'center',
|
|
118
|
+
},
|
|
119
|
+
neutralDot: {
|
|
120
|
+
width: t.sizes.s12,
|
|
121
|
+
height: t.sizes.s12,
|
|
122
|
+
borderRadius: t.borderRadius.full,
|
|
123
|
+
backgroundColor: t.colors.bg.mutedPressed,
|
|
124
|
+
},
|
|
125
|
+
idleRing: {
|
|
126
|
+
width: t.sizes.s20,
|
|
127
|
+
height: t.sizes.s20,
|
|
128
|
+
borderRadius: t.borderRadius.full,
|
|
129
|
+
borderWidth: t.borderWidth.s2,
|
|
130
|
+
borderColor: t.colors.border.mutedSubtleHover,
|
|
131
|
+
},
|
|
132
|
+
header: {
|
|
133
|
+
flexDirection: 'row',
|
|
134
|
+
alignItems: 'center',
|
|
135
|
+
minHeight: t.sizes.s64,
|
|
136
|
+
minWidth: 0,
|
|
137
|
+
gap: t.spacings.s8,
|
|
138
|
+
},
|
|
139
|
+
leading: {
|
|
140
|
+
flex: 1,
|
|
141
|
+
minWidth: 0,
|
|
142
|
+
flexDirection: 'column',
|
|
143
|
+
gap: t.spacings.s2,
|
|
144
|
+
},
|
|
145
|
+
leadingRow: {
|
|
146
|
+
flexDirection: 'row',
|
|
147
|
+
alignItems: 'center',
|
|
148
|
+
minWidth: 0,
|
|
149
|
+
gap: t.spacings.s4,
|
|
150
|
+
},
|
|
151
|
+
caption: StyleSheet.flatten([
|
|
152
|
+
t.typographies.body4,
|
|
153
|
+
{
|
|
154
|
+
minWidth: 0,
|
|
155
|
+
flexShrink: 1,
|
|
156
|
+
color: t.colors.text.muted,
|
|
157
|
+
},
|
|
158
|
+
]),
|
|
159
|
+
description: StyleSheet.flatten([
|
|
160
|
+
t.typographies.body3,
|
|
161
|
+
{
|
|
162
|
+
minWidth: 0,
|
|
163
|
+
flexShrink: 1,
|
|
164
|
+
color: t.colors.text.muted,
|
|
165
|
+
},
|
|
166
|
+
]),
|
|
167
|
+
trailing: {
|
|
168
|
+
marginStart: 'auto',
|
|
169
|
+
flexShrink: 0,
|
|
170
|
+
flexDirection: 'column',
|
|
171
|
+
alignItems: 'flex-end',
|
|
172
|
+
},
|
|
173
|
+
body: {
|
|
174
|
+
marginStart: t.spacings.s40,
|
|
175
|
+
minWidth: 0,
|
|
176
|
+
paddingTop: t.spacings.s8,
|
|
177
|
+
paddingBottom: t.spacings.s12,
|
|
178
|
+
},
|
|
179
|
+
}),
|
|
180
|
+
[],
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const useTitleStyles = (muted: boolean) =>
|
|
184
|
+
useStyleSheet(
|
|
185
|
+
(t) => ({
|
|
186
|
+
title: StyleSheet.flatten([
|
|
187
|
+
t.typographies.body2SemiBold,
|
|
188
|
+
{
|
|
189
|
+
minWidth: 0,
|
|
190
|
+
flexShrink: 1,
|
|
191
|
+
color: muted ? t.colors.text.muted : t.colors.text.base,
|
|
192
|
+
},
|
|
193
|
+
]),
|
|
194
|
+
}),
|
|
195
|
+
[muted],
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const TimelineIndicator = ({ status }: { status?: TimelineItemStatus }) => {
|
|
199
|
+
const styles = useTimelineStyles();
|
|
200
|
+
const decorative = status !== 'loading';
|
|
201
|
+
const indicatorByStatus = {
|
|
202
|
+
success: (
|
|
203
|
+
<CheckmarkCircleFill
|
|
204
|
+
accessible={false}
|
|
205
|
+
color='success'
|
|
206
|
+
size={24}
|
|
207
|
+
testID='timeline-indicator-success'
|
|
208
|
+
/>
|
|
209
|
+
),
|
|
210
|
+
error: (
|
|
211
|
+
<DeleteCircleFill
|
|
212
|
+
accessible={false}
|
|
213
|
+
color='error'
|
|
214
|
+
size={24}
|
|
215
|
+
testID='timeline-indicator-error'
|
|
216
|
+
/>
|
|
217
|
+
),
|
|
218
|
+
pending: (
|
|
219
|
+
<ClockFill
|
|
220
|
+
accessible={false}
|
|
221
|
+
color='muted'
|
|
222
|
+
size={24}
|
|
223
|
+
testID='timeline-indicator-pending'
|
|
224
|
+
/>
|
|
225
|
+
),
|
|
226
|
+
loading: (
|
|
227
|
+
<Spinner color='muted' size={24} testID='timeline-indicator-loading' />
|
|
228
|
+
),
|
|
229
|
+
idle: (
|
|
230
|
+
<Box
|
|
231
|
+
accessible={false}
|
|
232
|
+
style={styles.idleRing}
|
|
233
|
+
testID='timeline-indicator-idle'
|
|
234
|
+
/>
|
|
235
|
+
),
|
|
236
|
+
} satisfies Record<TimelineItemStatus, ReactElement>;
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<Box
|
|
240
|
+
accessibilityElementsHidden={decorative}
|
|
241
|
+
importantForAccessibility={decorative ? 'no-hide-descendants' : 'auto'}
|
|
242
|
+
style={styles.indicator}
|
|
243
|
+
>
|
|
244
|
+
{status ? (
|
|
245
|
+
indicatorByStatus[status]
|
|
246
|
+
) : (
|
|
247
|
+
<Box
|
|
248
|
+
accessible={false}
|
|
249
|
+
style={styles.neutralDot}
|
|
250
|
+
testID='timeline-indicator-neutral'
|
|
251
|
+
/>
|
|
252
|
+
)}
|
|
253
|
+
</Box>
|
|
254
|
+
);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const TimelineRail = () => {
|
|
258
|
+
const styles = useTimelineStyles();
|
|
259
|
+
const { isFirst, isLast } = useTimelinePosition({
|
|
260
|
+
consumerName: 'TimelineItem',
|
|
261
|
+
contextRequired: false,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<Box
|
|
266
|
+
accessibilityElementsHidden
|
|
267
|
+
importantForAccessibility='no-hide-descendants'
|
|
268
|
+
pointerEvents='none'
|
|
269
|
+
style={styles.rail}
|
|
270
|
+
>
|
|
271
|
+
<Box
|
|
272
|
+
style={StyleSheet.flatten([
|
|
273
|
+
styles.line,
|
|
274
|
+
styles.lineIn,
|
|
275
|
+
isFirst && styles.lineInHidden,
|
|
276
|
+
])}
|
|
277
|
+
testID='timeline-line-in'
|
|
278
|
+
/>
|
|
279
|
+
<Box style={styles.indicatorSpacer} />
|
|
280
|
+
{!isLast && (
|
|
281
|
+
<Box
|
|
282
|
+
style={StyleSheet.flatten([styles.line, styles.lineOut])}
|
|
283
|
+
testID='timeline-line-out'
|
|
284
|
+
/>
|
|
285
|
+
)}
|
|
286
|
+
</Box>
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Vertical timeline. Lays out its items and holds no state of its own.
|
|
292
|
+
*
|
|
293
|
+
* @see {@link https://ldls-react-native.vercel.app/?path=/docs/rnative-timeline--docs Storybook}
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* <Timeline>
|
|
297
|
+
* <TimelineItem>
|
|
298
|
+
* <TimelineItemHeader>
|
|
299
|
+
* <TimelineItemLeading>
|
|
300
|
+
* <TimelineItemTitle>Payment confirmed</TimelineItemTitle>
|
|
301
|
+
* </TimelineItemLeading>
|
|
302
|
+
* </TimelineItemHeader>
|
|
303
|
+
* </TimelineItem>
|
|
304
|
+
* </Timeline>
|
|
305
|
+
*/
|
|
306
|
+
export const Timeline = ({
|
|
307
|
+
ref,
|
|
308
|
+
children,
|
|
309
|
+
lx,
|
|
310
|
+
style,
|
|
311
|
+
...props
|
|
312
|
+
}: TimelineProps) => {
|
|
313
|
+
const styles = useTimelineStyles();
|
|
314
|
+
const items = flattenTimelineChildren(children);
|
|
315
|
+
|
|
316
|
+
return (
|
|
317
|
+
<Box
|
|
318
|
+
ref={ref}
|
|
319
|
+
lx={lx}
|
|
320
|
+
style={StyleSheet.flatten([styles.root, style])}
|
|
321
|
+
{...props}
|
|
322
|
+
>
|
|
323
|
+
{items.map(({ key, node }, index) => (
|
|
324
|
+
<TimelinePositionProvider
|
|
325
|
+
key={key}
|
|
326
|
+
value={{
|
|
327
|
+
isFirst: index === 0,
|
|
328
|
+
isLast: index === items.length - 1,
|
|
329
|
+
}}
|
|
330
|
+
>
|
|
331
|
+
{node}
|
|
332
|
+
</TimelinePositionProvider>
|
|
333
|
+
))}
|
|
334
|
+
</Box>
|
|
335
|
+
);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* One row of a timeline. Draws the indicator from `status` and the connector
|
|
340
|
+
* to the neighbouring items.
|
|
341
|
+
*/
|
|
342
|
+
export const TimelineItem = ({
|
|
343
|
+
ref,
|
|
344
|
+
status,
|
|
345
|
+
children,
|
|
346
|
+
lx,
|
|
347
|
+
style,
|
|
348
|
+
...props
|
|
349
|
+
}: TimelineItemProps) => {
|
|
350
|
+
const styles = useTimelineStyles();
|
|
351
|
+
|
|
352
|
+
return (
|
|
353
|
+
<TimelineItemProvider value={{ status }}>
|
|
354
|
+
<Box
|
|
355
|
+
ref={ref}
|
|
356
|
+
lx={lx}
|
|
357
|
+
style={StyleSheet.flatten([styles.item, style])}
|
|
358
|
+
testID='timeline-item'
|
|
359
|
+
{...props}
|
|
360
|
+
>
|
|
361
|
+
<TimelineRail />
|
|
362
|
+
{children}
|
|
363
|
+
</Box>
|
|
364
|
+
</TimelineItemProvider>
|
|
365
|
+
);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Row beside the indicator. Holds the leading column and the trailing slot.
|
|
370
|
+
*/
|
|
371
|
+
export const TimelineItemHeader = ({
|
|
372
|
+
ref,
|
|
373
|
+
children,
|
|
374
|
+
lx,
|
|
375
|
+
style,
|
|
376
|
+
...props
|
|
377
|
+
}: TimelineItemHeaderProps) => {
|
|
378
|
+
const styles = useTimelineStyles();
|
|
379
|
+
const { status } = useTimelineItemContext({
|
|
380
|
+
consumerName: 'TimelineItemHeader',
|
|
381
|
+
contextRequired: true,
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
return (
|
|
385
|
+
<Box
|
|
386
|
+
ref={ref}
|
|
387
|
+
lx={lx}
|
|
388
|
+
style={StyleSheet.flatten([styles.header, style])}
|
|
389
|
+
{...props}
|
|
390
|
+
>
|
|
391
|
+
<TimelineIndicator status={status} />
|
|
392
|
+
{children}
|
|
393
|
+
</Box>
|
|
394
|
+
);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Caption, title, and description column.
|
|
399
|
+
*/
|
|
400
|
+
export const TimelineItemLeading = ({
|
|
401
|
+
ref,
|
|
402
|
+
children,
|
|
403
|
+
lx,
|
|
404
|
+
style,
|
|
405
|
+
...props
|
|
406
|
+
}: TimelineItemLeadingProps) => {
|
|
407
|
+
const styles = useTimelineStyles();
|
|
408
|
+
|
|
409
|
+
return (
|
|
410
|
+
<Box
|
|
411
|
+
ref={ref}
|
|
412
|
+
lx={lx}
|
|
413
|
+
style={StyleSheet.flatten([styles.leading, style])}
|
|
414
|
+
{...props}
|
|
415
|
+
>
|
|
416
|
+
{children}
|
|
417
|
+
</Box>
|
|
418
|
+
);
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Horizontal row for a title or description beside a tag.
|
|
423
|
+
*/
|
|
424
|
+
export const TimelineItemLeadingRow = ({
|
|
425
|
+
ref,
|
|
426
|
+
children,
|
|
427
|
+
lx,
|
|
428
|
+
style,
|
|
429
|
+
...props
|
|
430
|
+
}: TimelineItemLeadingRowProps) => {
|
|
431
|
+
const styles = useTimelineStyles();
|
|
432
|
+
|
|
433
|
+
return (
|
|
434
|
+
<Box
|
|
435
|
+
ref={ref}
|
|
436
|
+
lx={lx}
|
|
437
|
+
style={StyleSheet.flatten([styles.leadingRow, style])}
|
|
438
|
+
{...props}
|
|
439
|
+
>
|
|
440
|
+
{children}
|
|
441
|
+
</Box>
|
|
442
|
+
);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Overline above the title.
|
|
447
|
+
*/
|
|
448
|
+
export const TimelineItemCaption = ({
|
|
449
|
+
ref,
|
|
450
|
+
children,
|
|
451
|
+
lx,
|
|
452
|
+
style,
|
|
453
|
+
...props
|
|
454
|
+
}: TimelineItemCaptionProps) => {
|
|
455
|
+
const styles = useTimelineStyles();
|
|
456
|
+
|
|
457
|
+
return (
|
|
458
|
+
<Text
|
|
459
|
+
ref={ref}
|
|
460
|
+
allowFontScaling={false}
|
|
461
|
+
ellipsizeMode='tail'
|
|
462
|
+
lx={lx}
|
|
463
|
+
numberOfLines={1}
|
|
464
|
+
style={StyleSheet.flatten([styles.caption, style])}
|
|
465
|
+
{...props}
|
|
466
|
+
>
|
|
467
|
+
{children}
|
|
468
|
+
</Text>
|
|
469
|
+
);
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Title. An `idle` item uses the muted tone.
|
|
474
|
+
*/
|
|
475
|
+
export const TimelineItemTitle = ({
|
|
476
|
+
ref,
|
|
477
|
+
children,
|
|
478
|
+
lx,
|
|
479
|
+
style,
|
|
480
|
+
...props
|
|
481
|
+
}: TimelineItemTitleProps) => {
|
|
482
|
+
const { status } = useTimelineItemContext({
|
|
483
|
+
consumerName: 'TimelineItemTitle',
|
|
484
|
+
contextRequired: true,
|
|
485
|
+
});
|
|
486
|
+
const styles = useTitleStyles(status === 'idle');
|
|
487
|
+
|
|
488
|
+
return (
|
|
489
|
+
<Text
|
|
490
|
+
ref={ref}
|
|
491
|
+
allowFontScaling={false}
|
|
492
|
+
ellipsizeMode='tail'
|
|
493
|
+
lx={lx}
|
|
494
|
+
numberOfLines={1}
|
|
495
|
+
style={StyleSheet.flatten([styles.title, style])}
|
|
496
|
+
{...props}
|
|
497
|
+
>
|
|
498
|
+
{children}
|
|
499
|
+
</Text>
|
|
500
|
+
);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Description under the title.
|
|
505
|
+
*/
|
|
506
|
+
export const TimelineItemDescription = ({
|
|
507
|
+
ref,
|
|
508
|
+
children,
|
|
509
|
+
lx,
|
|
510
|
+
style,
|
|
511
|
+
...props
|
|
512
|
+
}: TimelineItemDescriptionProps) => {
|
|
513
|
+
const styles = useTimelineStyles();
|
|
514
|
+
|
|
515
|
+
return (
|
|
516
|
+
<Text
|
|
517
|
+
ref={ref}
|
|
518
|
+
allowFontScaling={false}
|
|
519
|
+
ellipsizeMode='tail'
|
|
520
|
+
lx={lx}
|
|
521
|
+
numberOfLines={1}
|
|
522
|
+
style={StyleSheet.flatten([styles.description, style])}
|
|
523
|
+
{...props}
|
|
524
|
+
>
|
|
525
|
+
{children}
|
|
526
|
+
</Text>
|
|
527
|
+
);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* End-aligned slot in the header.
|
|
532
|
+
*/
|
|
533
|
+
export const TimelineItemTrailing = ({
|
|
534
|
+
ref,
|
|
535
|
+
children,
|
|
536
|
+
lx,
|
|
537
|
+
style,
|
|
538
|
+
...props
|
|
539
|
+
}: TimelineItemTrailingProps) => {
|
|
540
|
+
const styles = useTimelineStyles();
|
|
541
|
+
|
|
542
|
+
return (
|
|
543
|
+
<Box
|
|
544
|
+
ref={ref}
|
|
545
|
+
lx={lx}
|
|
546
|
+
style={StyleSheet.flatten([styles.trailing, style])}
|
|
547
|
+
{...props}
|
|
548
|
+
>
|
|
549
|
+
{isTextChildren(children) ? <Text>{children}</Text> : children}
|
|
550
|
+
</Box>
|
|
551
|
+
);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Block under the header, indented past the indicator.
|
|
556
|
+
*/
|
|
557
|
+
export const TimelineItemBody = ({
|
|
558
|
+
ref,
|
|
559
|
+
children,
|
|
560
|
+
lx,
|
|
561
|
+
style,
|
|
562
|
+
...props
|
|
563
|
+
}: TimelineItemBodyProps) => {
|
|
564
|
+
const styles = useTimelineStyles();
|
|
565
|
+
|
|
566
|
+
return (
|
|
567
|
+
<Box
|
|
568
|
+
ref={ref}
|
|
569
|
+
lx={lx}
|
|
570
|
+
style={StyleSheet.flatten([styles.body, style])}
|
|
571
|
+
{...props}
|
|
572
|
+
>
|
|
573
|
+
{isTextChildren(children) ? <Text>{children}</Text> : children}
|
|
574
|
+
</Box>
|
|
575
|
+
);
|
|
576
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyledTextProps, StyledViewProps } from '../../../../styles';
|
|
3
|
+
|
|
4
|
+
export type TimelineItemStatus =
|
|
5
|
+
| 'idle'
|
|
6
|
+
| 'success'
|
|
7
|
+
| 'error'
|
|
8
|
+
| 'pending'
|
|
9
|
+
| 'loading';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Props for the Timeline root.
|
|
13
|
+
*/
|
|
14
|
+
export type TimelineProps = {
|
|
15
|
+
/**
|
|
16
|
+
* The timeline items.
|
|
17
|
+
* @required
|
|
18
|
+
*/
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Props for one timeline item.
|
|
24
|
+
*/
|
|
25
|
+
export type TimelineItemProps = {
|
|
26
|
+
/**
|
|
27
|
+
* Indicator and title tone. Omit it for a neutral item.
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
status?: TimelineItemStatus;
|
|
31
|
+
/**
|
|
32
|
+
* Header and content of the item.
|
|
33
|
+
* @required
|
|
34
|
+
*/
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Props for the row beside the indicator.
|
|
40
|
+
*/
|
|
41
|
+
export type TimelineItemHeaderProps = {
|
|
42
|
+
/**
|
|
43
|
+
* Leading and trailing parts.
|
|
44
|
+
* @required
|
|
45
|
+
*/
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Props for the text column opposite the trailing slot.
|
|
51
|
+
*/
|
|
52
|
+
export type TimelineItemLeadingProps = {
|
|
53
|
+
/**
|
|
54
|
+
* Caption, title, and description.
|
|
55
|
+
* @required
|
|
56
|
+
*/
|
|
57
|
+
children: ReactNode;
|
|
58
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Props for a horizontal row inside the leading column.
|
|
62
|
+
*/
|
|
63
|
+
export type TimelineItemLeadingRowProps = {
|
|
64
|
+
/**
|
|
65
|
+
* A title or description beside an optional tag.
|
|
66
|
+
* @required
|
|
67
|
+
*/
|
|
68
|
+
children: ReactNode;
|
|
69
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Props for the overline above the title.
|
|
73
|
+
*/
|
|
74
|
+
export type TimelineItemCaptionProps = {
|
|
75
|
+
/**
|
|
76
|
+
* Overline text. A date is the common case.
|
|
77
|
+
* @required
|
|
78
|
+
*/
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
} & Omit<StyledTextProps, 'children'>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Props for the item title.
|
|
84
|
+
*/
|
|
85
|
+
export type TimelineItemTitleProps = {
|
|
86
|
+
/**
|
|
87
|
+
* Title text.
|
|
88
|
+
* @required
|
|
89
|
+
*/
|
|
90
|
+
children: ReactNode;
|
|
91
|
+
} & Omit<StyledTextProps, 'children'>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Props for the description under the title.
|
|
95
|
+
*/
|
|
96
|
+
export type TimelineItemDescriptionProps = {
|
|
97
|
+
/**
|
|
98
|
+
* Description text.
|
|
99
|
+
* @required
|
|
100
|
+
*/
|
|
101
|
+
children: ReactNode;
|
|
102
|
+
} & Omit<StyledTextProps, 'children'>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Props for the end-aligned header slot.
|
|
106
|
+
*/
|
|
107
|
+
export type TimelineItemTrailingProps = {
|
|
108
|
+
/**
|
|
109
|
+
* Amount, tag, or text. A string or number is wrapped so it can render.
|
|
110
|
+
* @required
|
|
111
|
+
*/
|
|
112
|
+
children: ReactNode;
|
|
113
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Props for the block under the header.
|
|
117
|
+
*/
|
|
118
|
+
export type TimelineItemBodyProps = {
|
|
119
|
+
/**
|
|
120
|
+
* Content indented past the indicator. A string or number is wrapped so it can render.
|
|
121
|
+
* @required
|
|
122
|
+
*/
|
|
123
|
+
children: ReactNode;
|
|
124
|
+
} & Omit<StyledViewProps, 'children'>;
|