@ledgerhq/lumen-ui-rnative 0.1.39 → 0.1.41
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/AmountDisplay/AmountDisplay.js +28 -11
- package/dist/module/lib/Components/AmountDisplay/AmountDisplay.js.map +1 -1
- package/dist/module/lib/Components/AmountDisplay/AmountDisplay.test.js +71 -0
- package/dist/module/lib/Components/AmountDisplay/AmountDisplay.test.js.map +1 -1
- package/dist/module/lib/Components/AmountInput/AmountInput.js +49 -154
- package/dist/module/lib/Components/AmountInput/AmountInput.js.map +1 -1
- package/dist/module/lib/Components/AmountInput/AmountInput.test.js +152 -0
- package/dist/module/lib/Components/AmountInput/AmountInput.test.js.map +1 -0
- package/dist/module/lib/Components/AmountInput/useAmountInputAnimations/useAmountInputAnimations.js +149 -0
- package/dist/module/lib/Components/AmountInput/useAmountInputAnimations/useAmountInputAnimations.js.map +1 -0
- package/dist/module/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.js +22 -0
- package/dist/module/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.js.map +1 -0
- package/dist/module/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.test.js +59 -0
- package/dist/module/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.test.js.map +1 -0
- package/dist/module/lib/Components/Avatar/Avatar.figma.js +5 -0
- package/dist/module/lib/Components/Avatar/Avatar.figma.js.map +1 -1
- package/dist/module/lib/Components/Avatar/Avatar.js +9 -2
- package/dist/module/lib/Components/Avatar/Avatar.js.map +1 -1
- package/dist/module/lib/Components/Avatar/Avatar.mdx +9 -0
- package/dist/module/lib/Components/Avatar/Avatar.stories.js +47 -0
- package/dist/module/lib/Components/Avatar/Avatar.stories.js.map +1 -1
- package/dist/module/lib/Components/Avatar/Avatar.test.js +23 -1
- package/dist/module/lib/Components/Avatar/Avatar.test.js.map +1 -1
- package/dist/module/lib/Components/BottomSheet/BottomSheetHeader.js +0 -3
- package/dist/module/lib/Components/BottomSheet/BottomSheetHeader.js.map +1 -1
- package/dist/module/lib/Components/Icon/Icon.test.js +1 -1
- package/dist/module/lib/Components/Switch/Switch.js +144 -8
- package/dist/module/lib/Components/Switch/Switch.js.map +1 -1
- package/dist/typescript/src/lib/Components/AmountDisplay/AmountDisplay.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/AmountInput/AmountInput.d.ts +1 -1
- package/dist/typescript/src/lib/Components/AmountInput/AmountInput.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/AmountInput/useAmountInputAnimations/useAmountInputAnimations.d.ts +16 -0
- package/dist/typescript/src/lib/Components/AmountInput/useAmountInputAnimations/useAmountInputAnimations.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.d.ts +18 -0
- package/dist/typescript/src/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/Avatar/Avatar.d.ts +1 -1
- package/dist/typescript/src/lib/Components/Avatar/Avatar.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/Avatar/types.d.ts +6 -0
- package/dist/typescript/src/lib/Components/Avatar/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheetHeader.d.ts +1 -1
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheetHeader.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/Switch/Switch.d.ts +1 -1
- package/dist/typescript/src/lib/Components/Switch/Switch.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/Switch/types.d.ts +2 -1
- package/dist/typescript/src/lib/Components/Switch/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/lib/Components/AmountDisplay/AmountDisplay.test.tsx +92 -0
- package/src/lib/Components/AmountDisplay/AmountDisplay.tsx +37 -15
- package/src/lib/Components/AmountInput/AmountInput.test.tsx +166 -0
- package/src/lib/Components/AmountInput/AmountInput.tsx +55 -110
- package/src/lib/Components/AmountInput/useAmountInputAnimations/useAmountInputAnimations.ts +100 -0
- package/src/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.test.ts +62 -0
- package/src/lib/Components/AmountInput/useAmountInputFormatting/useAmountInputFormatting.ts +48 -0
- package/src/lib/Components/Avatar/Avatar.figma.tsx +5 -0
- package/src/lib/Components/Avatar/Avatar.mdx +9 -0
- package/src/lib/Components/Avatar/Avatar.stories.tsx +41 -0
- package/src/lib/Components/Avatar/Avatar.test.tsx +31 -1
- package/src/lib/Components/Avatar/Avatar.tsx +17 -4
- package/src/lib/Components/Avatar/types.ts +6 -0
- package/src/lib/Components/BottomSheet/BottomSheetHeader.tsx +0 -4
- package/src/lib/Components/Icon/Icon.test.tsx +1 -1
- package/src/lib/Components/Switch/Switch.tsx +132 -11
- package/src/lib/Components/Switch/types.ts +3 -1
- package/dist/module/lib/Components/Switch/BaseSwitch.js +0 -221
- package/dist/module/lib/Components/Switch/BaseSwitch.js.map +0 -1
- package/dist/typescript/src/lib/Components/Switch/BaseSwitch.d.ts +0 -13
- package/dist/typescript/src/lib/Components/Switch/BaseSwitch.d.ts.map +0 -1
- package/src/lib/Components/Switch/BaseSwitch.tsx +0 -249
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { createSafeContext } from '@ledgerhq/lumen-utils-shared';
|
|
2
|
-
import { useCallback, useEffect } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
Pressable,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
type GestureResponderEvent,
|
|
7
|
-
} from 'react-native';
|
|
8
|
-
import Animated, {
|
|
9
|
-
cancelAnimation,
|
|
10
|
-
useAnimatedStyle,
|
|
11
|
-
useSharedValue,
|
|
12
|
-
withTiming,
|
|
13
|
-
} from 'react-native-reanimated';
|
|
14
|
-
import { useStyleSheet } from '../../../styles';
|
|
15
|
-
import { useTimingConfig } from '../../Animations/useTimingConfig';
|
|
16
|
-
|
|
17
|
-
import type { SlottablePressableProps, SlottableViewProps } from '../../types';
|
|
18
|
-
import { SlotPressable, SlotView } from '../Slot';
|
|
19
|
-
|
|
20
|
-
import type { SwitchProps } from './types';
|
|
21
|
-
|
|
22
|
-
const ROOT_COMPONENT_NAME = 'BaseSwitch';
|
|
23
|
-
const THUMB_COMPONENT_NAME = 'BaseSwitchThumb';
|
|
24
|
-
|
|
25
|
-
type BaseSwitchRootProps = SlottablePressableProps & {
|
|
26
|
-
checked: SwitchProps['checked'];
|
|
27
|
-
onCheckedChange: SwitchProps['onCheckedChange'];
|
|
28
|
-
disabled?: SwitchProps['disabled'];
|
|
29
|
-
size?: SwitchProps['size'];
|
|
30
|
-
onKeyDown?: (ev: React.KeyboardEvent) => void;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const [BaseSwitchProvider, useBaseSwitchContext] =
|
|
34
|
-
createSafeContext<BaseSwitchRootProps>(ROOT_COMPONENT_NAME);
|
|
35
|
-
|
|
36
|
-
const BaseSwitchRoot = ({
|
|
37
|
-
asChild,
|
|
38
|
-
checked,
|
|
39
|
-
size = 'md',
|
|
40
|
-
onCheckedChange,
|
|
41
|
-
disabled = false,
|
|
42
|
-
onPress: onPressProp,
|
|
43
|
-
'aria-valuetext': ariaValueText,
|
|
44
|
-
ref,
|
|
45
|
-
...props
|
|
46
|
-
}: BaseSwitchRootProps) => {
|
|
47
|
-
const styles = useStyles({
|
|
48
|
-
checked: !!checked,
|
|
49
|
-
disabled: !!disabled,
|
|
50
|
-
size,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const onPress = useCallback(
|
|
54
|
-
(ev: GestureResponderEvent) => {
|
|
55
|
-
if (disabled) return;
|
|
56
|
-
onCheckedChange?.(!checked);
|
|
57
|
-
onPressProp?.(ev);
|
|
58
|
-
},
|
|
59
|
-
[disabled, checked, onCheckedChange, onPressProp],
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const Component = asChild ? SlotPressable : Pressable;
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<BaseSwitchProvider
|
|
66
|
-
value={{
|
|
67
|
-
checked,
|
|
68
|
-
onCheckedChange,
|
|
69
|
-
disabled,
|
|
70
|
-
size,
|
|
71
|
-
}}
|
|
72
|
-
>
|
|
73
|
-
<Component
|
|
74
|
-
style={styles.root}
|
|
75
|
-
ref={ref}
|
|
76
|
-
aria-disabled={disabled}
|
|
77
|
-
role='switch'
|
|
78
|
-
aria-checked={checked}
|
|
79
|
-
onPress={onPress}
|
|
80
|
-
accessibilityState={{
|
|
81
|
-
checked,
|
|
82
|
-
disabled,
|
|
83
|
-
}}
|
|
84
|
-
accessibilityValue={ariaValueText ? { text: ariaValueText } : undefined}
|
|
85
|
-
disabled={disabled}
|
|
86
|
-
{...props}
|
|
87
|
-
/>
|
|
88
|
-
</BaseSwitchProvider>
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const THUMB_TRANSLATE: Record<Size, number> = {
|
|
93
|
-
sm: 8,
|
|
94
|
-
md: 16,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const useAnimatedThumb = ({
|
|
98
|
-
checked,
|
|
99
|
-
size,
|
|
100
|
-
}: {
|
|
101
|
-
checked: boolean | undefined;
|
|
102
|
-
size: Size;
|
|
103
|
-
}) => {
|
|
104
|
-
const timingConfig = useTimingConfig({ duration: 200, easing: 'easeInOut' });
|
|
105
|
-
const translateX = useSharedValue(checked ? THUMB_TRANSLATE[size] : 0);
|
|
106
|
-
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
translateX.value = withTiming(
|
|
109
|
-
checked ? THUMB_TRANSLATE[size] : 0,
|
|
110
|
-
timingConfig,
|
|
111
|
-
);
|
|
112
|
-
return () => cancelAnimation(translateX);
|
|
113
|
-
}, [checked, size, translateX, timingConfig]);
|
|
114
|
-
|
|
115
|
-
const animatedStyle = useAnimatedStyle(
|
|
116
|
-
() => ({
|
|
117
|
-
transform: [{ translateX: translateX.value }],
|
|
118
|
-
}),
|
|
119
|
-
[translateX],
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
return { animatedStyle };
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const BaseSwitchThumb = ({ asChild, ref, ...props }: SlottableViewProps) => {
|
|
126
|
-
const {
|
|
127
|
-
checked,
|
|
128
|
-
disabled,
|
|
129
|
-
size = 'md',
|
|
130
|
-
} = useBaseSwitchContext({
|
|
131
|
-
consumerName: THUMB_COMPONENT_NAME,
|
|
132
|
-
contextRequired: true,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const styles = useStyles({
|
|
136
|
-
checked: !!checked,
|
|
137
|
-
disabled: !!disabled,
|
|
138
|
-
size,
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const { animatedStyle } = useAnimatedThumb({ checked, size });
|
|
142
|
-
|
|
143
|
-
if (asChild) {
|
|
144
|
-
const Component = SlotView;
|
|
145
|
-
return (
|
|
146
|
-
<Component
|
|
147
|
-
ref={ref}
|
|
148
|
-
role='presentation'
|
|
149
|
-
style={styles.thumb}
|
|
150
|
-
{...props}
|
|
151
|
-
/>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return (
|
|
156
|
-
<Animated.View
|
|
157
|
-
ref={ref}
|
|
158
|
-
role='presentation'
|
|
159
|
-
style={[styles.thumbBase, animatedStyle]}
|
|
160
|
-
{...props}
|
|
161
|
-
/>
|
|
162
|
-
);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
type Size = NonNullable<SwitchProps['size']>;
|
|
166
|
-
|
|
167
|
-
const useStyles = ({
|
|
168
|
-
checked,
|
|
169
|
-
disabled,
|
|
170
|
-
size,
|
|
171
|
-
}: {
|
|
172
|
-
checked: boolean;
|
|
173
|
-
disabled: boolean;
|
|
174
|
-
size: Size;
|
|
175
|
-
}) => {
|
|
176
|
-
return useStyleSheet(
|
|
177
|
-
(t) => {
|
|
178
|
-
const sizes: Record<Size, { width: number; height: number }> = {
|
|
179
|
-
sm: { width: t.sizes.s24, height: t.sizes.s16 },
|
|
180
|
-
md: { width: t.sizes.s40, height: t.sizes.s24 },
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const thumbSizes: Record<Size, { size: number }> = {
|
|
184
|
-
sm: { size: t.sizes.s12 },
|
|
185
|
-
md: { size: t.sizes.s20 },
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const thumbTranslations: Record<Size, number> = {
|
|
189
|
-
sm: t.spacings.s8,
|
|
190
|
-
md: t.spacings.s16,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
root: StyleSheet.flatten([
|
|
195
|
-
{
|
|
196
|
-
flexDirection: 'row',
|
|
197
|
-
justifyContent: 'flex-start',
|
|
198
|
-
alignItems: 'center',
|
|
199
|
-
borderRadius: t.borderRadius.full,
|
|
200
|
-
padding: t.spacings.s2,
|
|
201
|
-
overflow: 'hidden',
|
|
202
|
-
...sizes[size],
|
|
203
|
-
minWidth: sizes[size].width,
|
|
204
|
-
maxWidth: sizes[size].width,
|
|
205
|
-
minHeight: sizes[size].height,
|
|
206
|
-
maxHeight: sizes[size].height,
|
|
207
|
-
},
|
|
208
|
-
!checked &&
|
|
209
|
-
!disabled && {
|
|
210
|
-
backgroundColor: t.colors.bg.mutedStrong,
|
|
211
|
-
},
|
|
212
|
-
checked &&
|
|
213
|
-
!disabled && {
|
|
214
|
-
backgroundColor: t.colors.bg.active,
|
|
215
|
-
},
|
|
216
|
-
disabled && {
|
|
217
|
-
backgroundColor: t.colors.bg.disabled,
|
|
218
|
-
},
|
|
219
|
-
]),
|
|
220
|
-
thumbBase: StyleSheet.flatten([
|
|
221
|
-
{
|
|
222
|
-
borderRadius: t.borderRadius.full,
|
|
223
|
-
backgroundColor: 'white',
|
|
224
|
-
width: thumbSizes[size].size,
|
|
225
|
-
height: thumbSizes[size].size,
|
|
226
|
-
},
|
|
227
|
-
disabled && {
|
|
228
|
-
backgroundColor: t.colors.bg.base,
|
|
229
|
-
},
|
|
230
|
-
]),
|
|
231
|
-
thumb: StyleSheet.flatten([
|
|
232
|
-
{
|
|
233
|
-
borderRadius: t.borderRadius.full,
|
|
234
|
-
backgroundColor: 'white',
|
|
235
|
-
width: thumbSizes[size].size,
|
|
236
|
-
height: thumbSizes[size].size,
|
|
237
|
-
transform: [{ translateX: checked ? thumbTranslations[size] : 0 }],
|
|
238
|
-
},
|
|
239
|
-
disabled && {
|
|
240
|
-
backgroundColor: t.colors.bg.base,
|
|
241
|
-
},
|
|
242
|
-
]),
|
|
243
|
-
};
|
|
244
|
-
},
|
|
245
|
-
[checked, disabled, size],
|
|
246
|
-
);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
export { BaseSwitchRoot, BaseSwitchThumb };
|