@ledgerhq/lumen-ui-rnative 0.1.58 → 0.1.59

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 (189) hide show
  1. package/dist/module/lib/Components/animations/Pulse/Pulse.stories.js +9 -0
  2. package/dist/module/lib/Components/animations/Pulse/Pulse.stories.js.map +1 -1
  3. package/dist/module/lib/Components/animations/Spin/Spin.stories.js +3 -0
  4. package/dist/module/lib/Components/animations/Spin/Spin.stories.js.map +1 -1
  5. package/dist/module/lib/Components/core/AddressInput/AddressInput.figma.js +4 -0
  6. package/dist/module/lib/Components/core/AddressInput/AddressInput.figma.js.map +1 -1
  7. package/dist/module/lib/Components/core/AddressInput/AddressInput.js +18 -6
  8. package/dist/module/lib/Components/core/AddressInput/AddressInput.js.map +1 -1
  9. package/dist/module/lib/Components/core/AddressInput/AddressInput.mdx +26 -1
  10. package/dist/module/lib/Components/core/AddressInput/AddressInput.stories.js +30 -0
  11. package/dist/module/lib/Components/core/AddressInput/AddressInput.stories.js.map +1 -1
  12. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.stories.js +6 -0
  13. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.stories.js.map +1 -1
  14. package/dist/module/lib/Components/core/AmountInput/AmountInput.stories.js +64 -44
  15. package/dist/module/lib/Components/core/AmountInput/AmountInput.stories.js.map +1 -1
  16. package/dist/module/lib/Components/core/Banner/Banner.stories.js.map +1 -1
  17. package/dist/module/lib/Components/core/Button/Button.stories.js +21 -0
  18. package/dist/module/lib/Components/core/Button/Button.stories.js.map +1 -1
  19. package/dist/module/lib/Components/core/Card/Card.js +15 -10
  20. package/dist/module/lib/Components/core/Card/Card.js.map +1 -1
  21. package/dist/module/lib/Components/core/Card/Card.stories.js +19 -2
  22. package/dist/module/lib/Components/core/Card/Card.stories.js.map +1 -1
  23. package/dist/module/lib/Components/core/Card/Card.test.js +8 -3
  24. package/dist/module/lib/Components/core/Card/Card.test.js.map +1 -1
  25. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js +15 -0
  26. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js.map +1 -1
  27. package/dist/module/lib/Components/core/Checkbox/Checkbox.stories.js.map +1 -1
  28. package/dist/module/lib/Components/core/ContentBanner/ContentBanner.stories.js +13 -0
  29. package/dist/module/lib/Components/core/ContentBanner/ContentBanner.stories.js.map +1 -1
  30. package/dist/module/lib/Components/core/DescriptionItem/DescriptionItem.stories.js +11 -0
  31. package/dist/module/lib/Components/core/DescriptionItem/DescriptionItem.stories.js.map +1 -1
  32. package/dist/module/lib/Components/core/Divider/Divider.stories.js.map +1 -1
  33. package/dist/module/lib/Components/core/IconButton/IconButton.stories.js +10 -0
  34. package/dist/module/lib/Components/core/IconButton/IconButton.stories.js.map +1 -1
  35. package/dist/module/lib/Components/core/InteractiveIcon/InteractiveIcon.stories.js +12 -0
  36. package/dist/module/lib/Components/core/InteractiveIcon/InteractiveIcon.stories.js.map +1 -1
  37. package/dist/module/lib/Components/core/Link/Link.stories.js.map +1 -1
  38. package/dist/module/lib/Components/core/ListItem/ListItem.stories.js +21 -3
  39. package/dist/module/lib/Components/core/ListItem/ListItem.stories.js.map +1 -1
  40. package/dist/module/lib/Components/core/MediaBanner/MediaBanner.stories.js +18 -1
  41. package/dist/module/lib/Components/core/MediaBanner/MediaBanner.stories.js.map +1 -1
  42. package/dist/module/lib/Components/core/MediaButton/MediaButton.stories.js +9 -0
  43. package/dist/module/lib/Components/core/MediaButton/MediaButton.stories.js.map +1 -1
  44. package/dist/module/lib/Components/core/MediaCard/MediaCard.stories.js +13 -0
  45. package/dist/module/lib/Components/core/MediaCard/MediaCard.stories.js.map +1 -1
  46. package/dist/module/lib/Components/core/MediaTag/MediaTag.stories.js +13 -0
  47. package/dist/module/lib/Components/core/MediaTag/MediaTag.stories.js.map +1 -1
  48. package/dist/module/lib/Components/core/NavBar/NavBar.stories.js.map +1 -1
  49. package/dist/module/lib/Components/core/OptionList/OptionList.stories.js +52 -0
  50. package/dist/module/lib/Components/core/OptionList/OptionList.stories.js.map +1 -1
  51. package/dist/module/lib/Components/core/SearchInput/SearchInput.stories.js.map +1 -1
  52. package/dist/module/lib/Components/core/SectionHeader/SectionHeader.stories.js.map +1 -1
  53. package/dist/module/lib/Components/core/Skeleton/Skeleton.stories.js.map +1 -1
  54. package/dist/module/lib/Components/core/Spinner/Spinner.stories.js.map +1 -1
  55. package/dist/module/lib/Components/core/Spot/Spot.stories.js +20 -0
  56. package/dist/module/lib/Components/core/Spot/Spot.stories.js.map +1 -1
  57. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js +4 -0
  58. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js.map +1 -1
  59. package/dist/module/lib/Components/core/Subheader/Subheader.stories.js.map +1 -1
  60. package/dist/module/lib/Components/core/Switch/Switch.stories.js.map +1 -1
  61. package/dist/module/lib/Components/core/Tag/Tag.stories.js +12 -0
  62. package/dist/module/lib/Components/core/Tag/Tag.stories.js.map +1 -1
  63. package/dist/module/lib/Components/core/TextInput/TextInput.figma.js +4 -0
  64. package/dist/module/lib/Components/core/TextInput/TextInput.figma.js.map +1 -1
  65. package/dist/module/lib/Components/core/TextInput/TextInput.mdx +25 -0
  66. package/dist/module/lib/Components/core/TextInput/TextInput.stories.js +29 -0
  67. package/dist/module/lib/Components/core/TextInput/TextInput.stories.js.map +1 -1
  68. package/dist/module/lib/Components/core/TextInput/TextInput.test.js +125 -2
  69. package/dist/module/lib/Components/core/TextInput/TextInput.test.js.map +1 -1
  70. package/dist/module/lib/Components/core/Tile/Tile.stories.js +23 -1
  71. package/dist/module/lib/Components/core/Tile/Tile.stories.js.map +1 -1
  72. package/dist/module/lib/Components/core/TileButton/TileButton.stories.js +24 -0
  73. package/dist/module/lib/Components/core/TileButton/TileButton.stories.js.map +1 -1
  74. package/dist/module/lib/Components/core/Tooltip/Tooltip.stories.js +12 -0
  75. package/dist/module/lib/Components/core/Tooltip/Tooltip.stories.js.map +1 -1
  76. package/dist/module/lib/Components/core/Trend/Trend.stories.js +9 -0
  77. package/dist/module/lib/Components/core/Trend/Trend.stories.js.map +1 -1
  78. package/dist/module/lib/Components/internal/BaseInput/BaseInput.js +114 -201
  79. package/dist/module/lib/Components/internal/BaseInput/BaseInput.js.map +1 -1
  80. package/dist/module/lib/Components/internal/BaseInput/BaseInputCounter.js +32 -0
  81. package/dist/module/lib/Components/internal/BaseInput/BaseInputCounter.js.map +1 -0
  82. package/dist/module/lib/Components/internal/BaseInput/BaseInputHelperText.js +60 -0
  83. package/dist/module/lib/Components/internal/BaseInput/BaseInputHelperText.js.map +1 -0
  84. package/dist/module/lib/Components/internal/BaseInput/BaseInputLabel.js +126 -0
  85. package/dist/module/lib/Components/internal/BaseInput/BaseInputLabel.js.map +1 -0
  86. package/dist/module/lib/Components/internal/BaseInput/multilineLayout.js +34 -0
  87. package/dist/module/lib/Components/internal/BaseInput/multilineLayout.js.map +1 -0
  88. package/dist/module/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.js +46 -0
  89. package/dist/module/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.js.map +1 -0
  90. package/dist/module/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.test.js +111 -0
  91. package/dist/module/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.test.js.map +1 -0
  92. package/dist/module/lib/Components/primitives/Box/Box.stories.js.map +1 -1
  93. package/dist/module/lib/Components/primitives/Gradient/LinearGradient/LinearGradient.stories.js +14 -0
  94. package/dist/module/lib/Components/primitives/Gradient/LinearGradient/LinearGradient.stories.js.map +1 -1
  95. package/dist/module/lib/Components/primitives/Gradient/RadialGradient/RadialGradient.stories.js +8 -0
  96. package/dist/module/lib/Components/primitives/Gradient/RadialGradient/RadialGradient.stories.js.map +1 -1
  97. package/dist/module/lib/Components/primitives/Pressable/Pressable.stories.js.map +1 -1
  98. package/dist/module/lib/Components/primitives/Text/Text.stories.js.map +1 -1
  99. package/dist/module/lib/Components/symbols/Icon/Icon.stories.js.map +1 -1
  100. package/dist/typescript/src/lib/Components/core/AddressInput/AddressInput.d.ts +1 -1
  101. package/dist/typescript/src/lib/Components/core/AddressInput/AddressInput.d.ts.map +1 -1
  102. package/dist/typescript/src/lib/Components/core/Card/Card.d.ts.map +1 -1
  103. package/dist/typescript/src/lib/Components/core/SearchInput/types.d.ts +1 -1
  104. package/dist/typescript/src/lib/Components/core/SearchInput/types.d.ts.map +1 -1
  105. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInput.d.ts +1 -1
  106. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInput.d.ts.map +1 -1
  107. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInputCounter.d.ts +8 -0
  108. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInputCounter.d.ts.map +1 -0
  109. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInputHelperText.d.ts +8 -0
  110. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInputHelperText.d.ts.map +1 -0
  111. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInputLabel.d.ts +8 -0
  112. package/dist/typescript/src/lib/Components/internal/BaseInput/BaseInputLabel.d.ts.map +1 -0
  113. package/dist/typescript/src/lib/Components/internal/BaseInput/multilineLayout.d.ts +27 -0
  114. package/dist/typescript/src/lib/Components/internal/BaseInput/multilineLayout.d.ts.map +1 -0
  115. package/dist/typescript/src/lib/Components/internal/BaseInput/types.d.ts +48 -1
  116. package/dist/typescript/src/lib/Components/internal/BaseInput/types.d.ts.map +1 -1
  117. package/dist/typescript/src/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.d.ts +27 -0
  118. package/dist/typescript/src/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.d.ts.map +1 -0
  119. package/package.json +2 -2
  120. package/src/lib/Components/animations/Pulse/Pulse.stories.tsx +7 -2
  121. package/src/lib/Components/animations/Spin/Spin.stories.tsx +5 -2
  122. package/src/lib/Components/core/AddressInput/AddressInput.figma.tsx +4 -0
  123. package/src/lib/Components/core/AddressInput/AddressInput.mdx +26 -1
  124. package/src/lib/Components/core/AddressInput/AddressInput.stories.tsx +30 -2
  125. package/src/lib/Components/core/AddressInput/AddressInput.tsx +24 -8
  126. package/src/lib/Components/core/AmountDisplay/AmountDisplay.stories.tsx +8 -2
  127. package/src/lib/Components/core/AmountInput/AmountInput.stories.tsx +33 -13
  128. package/src/lib/Components/core/Avatar/Avatar.stories.tsx +1 -1
  129. package/src/lib/Components/core/AvatarButton/AvatarButton.stories.tsx +1 -1
  130. package/src/lib/Components/core/Banner/Banner.stories.tsx +2 -2
  131. package/src/lib/Components/core/Button/Button.stories.tsx +23 -2
  132. package/src/lib/Components/core/Card/Card.stories.tsx +19 -2
  133. package/src/lib/Components/core/Card/Card.test.tsx +10 -3
  134. package/src/lib/Components/core/Card/Card.tsx +20 -9
  135. package/src/lib/Components/core/CardButton/CardButton.stories.tsx +17 -2
  136. package/src/lib/Components/core/Checkbox/Checkbox.stories.tsx +3 -3
  137. package/src/lib/Components/core/ContentBanner/ContentBanner.stories.tsx +15 -2
  138. package/src/lib/Components/core/DescriptionItem/DescriptionItem.stories.tsx +13 -2
  139. package/src/lib/Components/core/Divider/Divider.stories.tsx +2 -2
  140. package/src/lib/Components/core/DotCount/DotCount.stories.tsx +1 -1
  141. package/src/lib/Components/core/DotIcon/DotIcon.stories.tsx +1 -1
  142. package/src/lib/Components/core/DotIndicator/DotIndicator.stories.tsx +1 -1
  143. package/src/lib/Components/core/DotSymbol/DotSymbol.stories.tsx +1 -1
  144. package/src/lib/Components/core/IconButton/IconButton.stories.tsx +12 -2
  145. package/src/lib/Components/core/InteractiveIcon/InteractiveIcon.stories.tsx +14 -2
  146. package/src/lib/Components/core/Link/Link.stories.tsx +2 -2
  147. package/src/lib/Components/core/ListItem/ListItem.stories.tsx +18 -0
  148. package/src/lib/Components/core/MediaBanner/MediaBanner.stories.tsx +19 -2
  149. package/src/lib/Components/core/MediaButton/MediaButton.stories.tsx +11 -2
  150. package/src/lib/Components/core/MediaCard/MediaCard.stories.tsx +13 -0
  151. package/src/lib/Components/core/MediaImage/MediaImage.stories.tsx +1 -1
  152. package/src/lib/Components/core/MediaTag/MediaTag.stories.tsx +15 -2
  153. package/src/lib/Components/core/NavBar/NavBar.stories.tsx +2 -2
  154. package/src/lib/Components/core/OptionList/OptionList.stories.tsx +52 -0
  155. package/src/lib/Components/core/PageIndicator/PageIndicator.stories.tsx +1 -1
  156. package/src/lib/Components/core/SearchInput/SearchInput.stories.tsx +2 -2
  157. package/src/lib/Components/core/SearchInput/types.ts +4 -1
  158. package/src/lib/Components/core/SectionHeader/SectionHeader.stories.tsx +2 -2
  159. package/src/lib/Components/core/SegmentedControl/SegmentedControl.stories.tsx +1 -1
  160. package/src/lib/Components/core/Skeleton/Skeleton.stories.tsx +2 -2
  161. package/src/lib/Components/core/Spinner/Spinner.stories.tsx +2 -2
  162. package/src/lib/Components/core/Spot/Spot.stories.tsx +22 -2
  163. package/src/lib/Components/core/Stepper/Stepper.stories.tsx +6 -2
  164. package/src/lib/Components/core/Subheader/Subheader.stories.tsx +2 -2
  165. package/src/lib/Components/core/Switch/Switch.stories.tsx +3 -3
  166. package/src/lib/Components/core/TabBar/TabBar.stories.tsx +1 -1
  167. package/src/lib/Components/core/Tag/Tag.stories.tsx +14 -2
  168. package/src/lib/Components/core/TextInput/TextInput.figma.tsx +4 -0
  169. package/src/lib/Components/core/TextInput/TextInput.mdx +25 -0
  170. package/src/lib/Components/core/TextInput/TextInput.stories.tsx +29 -2
  171. package/src/lib/Components/core/TextInput/TextInput.test.tsx +129 -2
  172. package/src/lib/Components/core/Tile/Tile.stories.tsx +24 -2
  173. package/src/lib/Components/core/TileButton/TileButton.stories.tsx +26 -2
  174. package/src/lib/Components/core/Tooltip/Tooltip.stories.tsx +14 -2
  175. package/src/lib/Components/core/Trend/Trend.stories.tsx +11 -2
  176. package/src/lib/Components/internal/BaseInput/BaseInput.tsx +123 -242
  177. package/src/lib/Components/internal/BaseInput/BaseInputCounter.tsx +35 -0
  178. package/src/lib/Components/internal/BaseInput/BaseInputHelperText.tsx +57 -0
  179. package/src/lib/Components/internal/BaseInput/BaseInputLabel.tsx +137 -0
  180. package/src/lib/Components/internal/BaseInput/multilineLayout.ts +49 -0
  181. package/src/lib/Components/internal/BaseInput/types.ts +49 -1
  182. package/src/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.test.ts +110 -0
  183. package/src/lib/Components/internal/BaseInput/useBaseInputValue/useBaseInputValue.ts +72 -0
  184. package/src/lib/Components/primitives/Box/Box.stories.tsx +2 -2
  185. package/src/lib/Components/primitives/Gradient/LinearGradient/LinearGradient.stories.tsx +6 -2
  186. package/src/lib/Components/primitives/Gradient/RadialGradient/RadialGradient.stories.tsx +5 -2
  187. package/src/lib/Components/primitives/Pressable/Pressable.stories.tsx +2 -2
  188. package/src/lib/Components/primitives/Text/Text.stories.tsx +2 -2
  189. package/src/lib/Components/symbols/Icon/Icon.stories.tsx +2 -2
@@ -0,0 +1,137 @@
1
+ import { useEffect } from 'react';
2
+ import type { TextStyle } from 'react-native';
3
+ import { StyleSheet } from 'react-native';
4
+ import Animated, {
5
+ interpolate,
6
+ useSharedValue,
7
+ useAnimatedStyle,
8
+ withTiming,
9
+ cancelAnimation,
10
+ type AnimatedStyle,
11
+ } from 'react-native-reanimated';
12
+ import type { LumenStyleSheetTheme } from '../../../../styles';
13
+ import { useStyleSheet, useTheme } from '../../../../styles';
14
+ import { useTimingConfig } from '../../animations/useTimingConfig';
15
+ import type { BaseInputLabelProps } from './types';
16
+
17
+ const useAnimatedFloatingLabel = ({
18
+ isFloatingLabel,
19
+ theme,
20
+ }: {
21
+ isFloatingLabel: boolean;
22
+ theme: LumenStyleSheetTheme;
23
+ }): { animatedStyle: AnimatedStyle<TextStyle> } => {
24
+ const floatingAnimation = useSharedValue(isFloatingLabel ? 1 : 0);
25
+ const timingConfig = useTimingConfig({
26
+ duration: 150,
27
+ easing: 'linear',
28
+ });
29
+
30
+ useEffect(() => {
31
+ floatingAnimation.value = withTiming(isFloatingLabel ? 1 : 0, timingConfig);
32
+
33
+ return () => cancelAnimation(floatingAnimation);
34
+ }, [isFloatingLabel, timingConfig, floatingAnimation]);
35
+
36
+ const animatedStyle = useAnimatedStyle(
37
+ () => ({
38
+ top: interpolate(
39
+ floatingAnimation.value,
40
+ [0, 1],
41
+ [theme.spacings.s14, theme.spacings.s6],
42
+ ),
43
+ fontSize: interpolate(
44
+ floatingAnimation.value,
45
+ [0, 1],
46
+ [theme.typographies.body2.fontSize, theme.typographies.body4.fontSize],
47
+ ),
48
+ }),
49
+ [floatingAnimation, theme],
50
+ );
51
+
52
+ return { animatedStyle };
53
+ };
54
+
55
+ const useFloatingLabelStyles = ({
56
+ isFocused,
57
+ hasContent,
58
+ showClearButton,
59
+ status,
60
+ isEditable,
61
+ labelStaysFloatedWithPlaceholder,
62
+ }: {
63
+ isFocused: boolean;
64
+ hasContent: boolean;
65
+ showClearButton: boolean;
66
+ status: 'error' | 'success' | undefined;
67
+ isEditable: boolean;
68
+ labelStaysFloatedWithPlaceholder: boolean;
69
+ }): { label: TextStyle; animatedStyle: AnimatedStyle<TextStyle> } => {
70
+ const { theme } = useTheme();
71
+
72
+ const { label } = useStyleSheet(
73
+ (t) => ({
74
+ label: StyleSheet.flatten([
75
+ {
76
+ position: 'absolute',
77
+ left: t.spacings.s16,
78
+ width: t.sizes.full,
79
+ color: t.colors.text.muted,
80
+ },
81
+ hasContent &&
82
+ showClearButton && {
83
+ width: '92%',
84
+ },
85
+ status === 'error' && {
86
+ color: t.colors.text.error,
87
+ },
88
+ !isEditable && {
89
+ color: t.colors.text.disabled,
90
+ },
91
+ ]),
92
+ }),
93
+ [hasContent, showClearButton, status, isEditable],
94
+ );
95
+
96
+ const { animatedStyle } = useAnimatedFloatingLabel({
97
+ theme,
98
+ isFloatingLabel:
99
+ isFocused || hasContent || labelStaysFloatedWithPlaceholder,
100
+ });
101
+
102
+ return { label, animatedStyle };
103
+ };
104
+
105
+ /**
106
+ * Floating label rendered over the control inside `BaseInput`.
107
+ *
108
+ * @internal
109
+ */
110
+ export const BaseInputLabel = ({
111
+ isFocused,
112
+ hasContent,
113
+ showClearButton,
114
+ status,
115
+ isEditable,
116
+ labelStaysFloatedWithPlaceholder,
117
+ style,
118
+ children,
119
+ }: BaseInputLabelProps) => {
120
+ const styles = useFloatingLabelStyles({
121
+ isFocused,
122
+ hasContent,
123
+ showClearButton,
124
+ status,
125
+ isEditable,
126
+ labelStaysFloatedWithPlaceholder,
127
+ });
128
+
129
+ return (
130
+ <Animated.Text
131
+ style={[styles.label, styles.animatedStyle, style]}
132
+ numberOfLines={1}
133
+ >
134
+ {children}
135
+ </Animated.Text>
136
+ );
137
+ };
@@ -0,0 +1,49 @@
1
+ import type { LumenStyleSheetTheme } from '../../../../styles';
2
+
3
+ type MultilineLayout = {
4
+ lineHeight: number;
5
+ labelRowHeight: number;
6
+ paddingVertical: number;
7
+ };
8
+
9
+ type MultilineMinHeightArgs = {
10
+ hasLabel: boolean;
11
+ minLines: number;
12
+ maxLines: number | undefined;
13
+ };
14
+
15
+ /**
16
+ * Vertical layout values a multiline `BaseInput` is laid out from. A label floats
17
+ * over the field and shrinks its text to `body2`, which moves all three.
18
+ *
19
+ * @internal
20
+ */
21
+ export const getMultilineLayout = (
22
+ t: LumenStyleSheetTheme,
23
+ hasLabel: boolean,
24
+ ): MultilineLayout => ({
25
+ lineHeight: hasLabel
26
+ ? t.typographies.body2.lineHeight
27
+ : t.typographies.body1.lineHeight,
28
+ labelRowHeight: hasLabel ? t.spacings.s16 : 0,
29
+ paddingVertical: hasLabel ? t.spacings.s6 : t.spacings.s12,
30
+ });
31
+
32
+ /**
33
+ * Height floor of a multiline `BaseInput`: `minLines` of text — never more than
34
+ * `maxLines` — plus the label row and the vertical padding.
35
+ *
36
+ * @internal
37
+ */
38
+ export const getMultilineMinHeight = (
39
+ t: LumenStyleSheetTheme,
40
+ { hasLabel, minLines, maxLines }: MultilineMinHeightArgs,
41
+ ): number => {
42
+ const { lineHeight, labelRowHeight, paddingVertical } = getMultilineLayout(
43
+ t,
44
+ hasLabel,
45
+ );
46
+ const floorLines = maxLines ? Math.min(minLines, maxLines) : minLines;
47
+
48
+ return floorLines * lineHeight + labelRowHeight + 2 * paddingVertical;
49
+ };
@@ -70,6 +70,7 @@ export type BaseInputProps = {
70
70
  prefix?: React.ReactNode;
71
71
  /**
72
72
  * Optional function to extend the default clear behavior with custom logic.
73
+ * Called after the field is emptied. Clearing always calls `onChangeText('')`
73
74
  */
74
75
  onClear?: () => void;
75
76
  /**
@@ -77,9 +78,56 @@ export type BaseInputProps = {
77
78
  * @default false
78
79
  */
79
80
  hideClearButton?: boolean;
80
- } & Omit<TextInputProps, 'style'> &
81
+ /**
82
+ * Renders a multi-line field that auto-grows between `minLines` and `maxLines`.
83
+ * @default false
84
+ */
85
+ multiline?: boolean;
86
+ /**
87
+ * Minimum height of the field, in lines. Ignored unless `multiline` is set.
88
+ * @default 1
89
+ */
90
+ minLines?: number;
91
+ /**
92
+ * Growth ceiling, in lines; past it the field scrolls internally. Unbounded when
93
+ * omitted. Ignored unless `multiline` is set.
94
+ */
95
+ maxLines?: number;
96
+ } & Omit<TextInputProps, 'style' | 'multiline' | 'numberOfLines'> &
81
97
  BoxProps;
82
98
 
99
+ export type BaseInputLabelProps = {
100
+ /**
101
+ * Whether the input currently has focus, which floats the label.
102
+ */
103
+ isFocused: boolean;
104
+ /**
105
+ * Whether the input holds a value, which keeps the label floated.
106
+ */
107
+ hasContent: boolean;
108
+ /**
109
+ * Whether the clear button is visible, which narrows the label to avoid it.
110
+ */
111
+ showClearButton: boolean;
112
+ /**
113
+ * Whether the input is editable, driving the disabled label colour.
114
+ */
115
+ isEditable: boolean;
116
+ /**
117
+ * Keeps the label floated even when empty and unfocused, used when a label
118
+ * and a placeholder are displayed together.
119
+ */
120
+ labelStaysFloatedWithPlaceholder: boolean;
121
+ /**
122
+ * Additional styles to apply to the label element.
123
+ */
124
+ style?: StyleProp<TextStyle>;
125
+ /**
126
+ * The label copy.
127
+ */
128
+ children: React.ReactNode;
129
+ } & Pick<BaseInputProps, 'status'>;
130
+
83
131
  export type BaseInputHelperTextProps = {
84
132
  /**
85
133
  * The helper copy shown below the input.
@@ -0,0 +1,110 @@
1
+ import { describe, expect, it, jest } from '@jest/globals';
2
+ import { act, renderHook } from '@testing-library/react-native';
3
+ import { useBaseInputValue } from './useBaseInputValue';
4
+
5
+ const createArgs = (
6
+ overrides: Partial<Parameters<typeof useBaseInputValue>[0]> = {},
7
+ ): Parameters<typeof useBaseInputValue>[0] => ({
8
+ value: undefined,
9
+ defaultValue: undefined,
10
+ onChangeText: undefined,
11
+ onClear: undefined,
12
+ ref: undefined,
13
+ ...overrides,
14
+ });
15
+
16
+ describe('useBaseInputValue', () => {
17
+ it('starts empty when neither value nor defaultValue is given', () => {
18
+ const { result } = renderHook(() => useBaseInputValue(createArgs()));
19
+
20
+ expect(result.current.value).toBe('');
21
+ expect(result.current.hasContent).toBe(false);
22
+ });
23
+
24
+ it('seeds the value from defaultValue when uncontrolled', () => {
25
+ const { result } = renderHook(() =>
26
+ useBaseInputValue(createArgs({ defaultValue: 'jane.doe' })),
27
+ );
28
+
29
+ expect(result.current.value).toBe('jane.doe');
30
+ expect(result.current.hasContent).toBe(true);
31
+ });
32
+
33
+ it('tracks typing and forwards the text when uncontrolled', () => {
34
+ const onChangeText = jest.fn();
35
+ const { result } = renderHook(() =>
36
+ useBaseInputValue(createArgs({ onChangeText })),
37
+ );
38
+
39
+ act(() => {
40
+ result.current.handleChangeText('ledger');
41
+ });
42
+
43
+ expect(result.current.value).toBe('ledger');
44
+ expect(onChangeText).toHaveBeenCalledTimes(1);
45
+ expect(onChangeText).toHaveBeenCalledWith('ledger');
46
+ });
47
+
48
+ it('derives the value from the prop when controlled and ignores internal tracking', () => {
49
+ const onChangeText = jest.fn();
50
+ const { result, rerender } = renderHook(
51
+ ({ value }: { value: string }) =>
52
+ useBaseInputValue(createArgs({ value, onChangeText })),
53
+ { initialProps: { value: 'first' } },
54
+ );
55
+
56
+ expect(result.current.value).toBe('first');
57
+
58
+ act(() => {
59
+ result.current.handleChangeText('typed but not applied');
60
+ });
61
+
62
+ expect(result.current.value).toBe('first');
63
+ expect(onChangeText).toHaveBeenCalledTimes(1);
64
+ expect(onChangeText).toHaveBeenCalledWith('typed but not applied');
65
+
66
+ rerender({ value: 'second' });
67
+
68
+ expect(result.current.value).toBe('second');
69
+ });
70
+
71
+ it('clears the mirror and calls onChangeText when uncontrolled', () => {
72
+ const onChangeText = jest.fn();
73
+ const onClear = jest.fn();
74
+ const { result } = renderHook(() =>
75
+ useBaseInputValue(
76
+ createArgs({ defaultValue: 'something', onChangeText, onClear }),
77
+ ),
78
+ );
79
+
80
+ act(() => {
81
+ result.current.handleClear();
82
+ });
83
+
84
+ expect(result.current.value).toBe('');
85
+ expect(result.current.hasContent).toBe(false);
86
+ expect(onChangeText).toHaveBeenCalledTimes(1);
87
+ expect(onChangeText).toHaveBeenCalledWith('');
88
+ expect(onClear).toHaveBeenCalledTimes(1);
89
+ });
90
+
91
+ it('calls onChangeText with an empty string on clear so controlled consumers react', () => {
92
+ const onChangeText = jest.fn();
93
+ const onClear = jest.fn();
94
+ const { result } = renderHook(() =>
95
+ useBaseInputValue(
96
+ createArgs({ value: 'controlled', onChangeText, onClear }),
97
+ ),
98
+ );
99
+
100
+ act(() => {
101
+ result.current.handleClear();
102
+ });
103
+
104
+ expect(onChangeText).toHaveBeenCalledTimes(1);
105
+ expect(onChangeText).toHaveBeenCalledWith('');
106
+ expect(onClear).toHaveBeenCalledTimes(1);
107
+ // The prop still drives the rendered value until the consumer updates it.
108
+ expect(result.current.value).toBe('controlled');
109
+ });
110
+ });
@@ -0,0 +1,72 @@
1
+ import { useMergedRef } from '@ledgerhq/lumen-utils-shared';
2
+ import type { RefCallback, RefObject } from 'react';
3
+ import { useRef, useState } from 'react';
4
+ import type { TextInput } from 'react-native';
5
+ import type { BaseInputProps } from '../types';
6
+
7
+ type UseBaseInputValueArgs = {
8
+ value: string | undefined;
9
+ defaultValue: string | undefined;
10
+ onChangeText: ((text: string) => void) | undefined;
11
+ onClear: (() => void) | undefined;
12
+ ref: BaseInputProps['ref'];
13
+ };
14
+
15
+ type UseBaseInputValueReturn = {
16
+ inputRef: RefObject<TextInput | null>;
17
+ composedRef: RefCallback<TextInput>;
18
+ value: string | undefined;
19
+ hasContent: boolean;
20
+ handleChangeText: (text: string) => void;
21
+ handleClear: () => void;
22
+ };
23
+
24
+ /**
25
+ * Tracks the input value for `BaseInput` and implements the clear button, in both
26
+ * controlled and uncontrolled mode.
27
+ *
28
+ * @internal
29
+ */
30
+ export const useBaseInputValue = ({
31
+ value: valueProp,
32
+ defaultValue,
33
+ onChangeText,
34
+ onClear,
35
+ ref,
36
+ }: UseBaseInputValueArgs): UseBaseInputValueReturn => {
37
+ const inputRef = useRef<TextInput>(null);
38
+ const composedRef = useMergedRef(ref, inputRef);
39
+
40
+ const [uncontrolledValue, setUncontrolledValue] = useState(
41
+ defaultValue ?? '',
42
+ );
43
+
44
+ const isControlled = valueProp !== undefined;
45
+ const value = isControlled ? valueProp : uncontrolledValue;
46
+
47
+ const hasContent = (value ?? '').length > 0;
48
+
49
+ const handleChangeText = (text: string): void => {
50
+ if (!isControlled) {
51
+ setUncontrolledValue(text);
52
+ }
53
+ onChangeText?.(text);
54
+ };
55
+
56
+ const handleClear = () => {
57
+ if (!isControlled) {
58
+ setUncontrolledValue('');
59
+ }
60
+ onChangeText?.('');
61
+ onClear?.();
62
+ };
63
+
64
+ return {
65
+ inputRef,
66
+ composedRef,
67
+ value,
68
+ hasContent,
69
+ handleChangeText,
70
+ handleClear,
71
+ };
72
+ };
@@ -1,7 +1,7 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
2
2
  import { Box } from './Box';
3
3
 
4
- const meta: Meta<typeof Box> = {
4
+ const meta = {
5
5
  component: Box,
6
6
  id: 'rnative-box',
7
7
  title: 'Primitives/Box',
@@ -14,7 +14,7 @@ const meta: Meta<typeof Box> = {
14
14
  },
15
15
  },
16
16
  },
17
- };
17
+ } satisfies Meta<typeof Box>;
18
18
 
19
19
  export default meta;
20
20
  type Story = StoryObj<typeof Box>;
@@ -4,7 +4,7 @@ import { Box } from '../../Box';
4
4
  import { Text } from '../../Text';
5
5
  import { LinearGradient } from './LinearGradient';
6
6
 
7
- const meta: Meta<typeof LinearGradient> = {
7
+ const meta = {
8
8
  component: LinearGradient,
9
9
  id: 'rnative-lineargradient',
10
10
  title: 'Primitives/LinearGradient',
@@ -19,7 +19,7 @@ const meta: Meta<typeof LinearGradient> = {
19
19
  },
20
20
  },
21
21
  },
22
- };
22
+ } satisfies Meta<typeof LinearGradient>;
23
23
 
24
24
  export default meta;
25
25
  type Story = StoryObj<typeof LinearGradient>;
@@ -37,6 +37,9 @@ export const Base: Story = {
37
37
  };
38
38
 
39
39
  export const DirectionShowcase: Story = {
40
+ args: {
41
+ stops: [{ color: 'accent' }, { color: 'active', opacity: 0 }],
42
+ },
40
43
  render: () => {
41
44
  const orientations = [
42
45
  'to-bottom',
@@ -130,6 +133,7 @@ export const WithMultipleStops: Story = {
130
133
 
131
134
  export const CryptoGradients: Story = {
132
135
  args: {
136
+ stops: [{ color: 'accent' }, { color: 'active', opacity: 0 }],
133
137
  direction: 'to-bottomright',
134
138
  lx: {
135
139
  borderRadius: 'md',
@@ -3,7 +3,7 @@ import { Box } from '../../Box';
3
3
  import { Text } from '../../Text';
4
4
  import { RadialGradient } from './RadialGradient';
5
5
 
6
- const meta: Meta<typeof RadialGradient> = {
6
+ const meta = {
7
7
  component: RadialGradient,
8
8
  id: 'rnative-radialgradient',
9
9
  title: 'Primitives/RadialGradient',
@@ -18,7 +18,7 @@ const meta: Meta<typeof RadialGradient> = {
18
18
  },
19
19
  },
20
20
  },
21
- };
21
+ } satisfies Meta<typeof RadialGradient>;
22
22
 
23
23
  export default meta;
24
24
  type Story = StoryObj<typeof RadialGradient>;
@@ -35,6 +35,9 @@ export const Base: Story = {
35
35
  };
36
36
 
37
37
  export const CenterPositionShowcase: Story = {
38
+ args: {
39
+ stops: [{ color: 'accent' }, { color: 'active', opacity: 0 }],
40
+ },
38
41
  render: () => {
39
42
  const positions = [
40
43
  {
@@ -1,7 +1,7 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
2
2
  import { Pressable } from './Pressable';
3
3
 
4
- const meta: Meta<typeof Pressable> = {
4
+ const meta = {
5
5
  component: Pressable,
6
6
  id: 'rnative-pressable',
7
7
  title: 'Primitives/Pressable',
@@ -14,7 +14,7 @@ const meta: Meta<typeof Pressable> = {
14
14
  },
15
15
  },
16
16
  },
17
- };
17
+ } satisfies Meta<typeof Pressable>;
18
18
 
19
19
  export default meta;
20
20
  type Story = StoryObj<typeof Pressable>;
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
2
2
  import { Text } from './Text';
3
3
  import type { TextProps } from './types';
4
4
 
5
- const meta: Meta<TextProps> = {
5
+ const meta = {
6
6
  component: Text,
7
7
  id: 'rnative-text',
8
8
  title: 'Primitives/Text',
@@ -15,7 +15,7 @@ const meta: Meta<TextProps> = {
15
15
  },
16
16
  },
17
17
  },
18
- };
18
+ } satisfies Meta<TextProps>;
19
19
 
20
20
  export default meta;
21
21
  type Story = StoryObj<TextProps>;
@@ -6,10 +6,10 @@ import { Box, Text, Pressable } from '../../primitives';
6
6
  import * as Icons from '../../symbols';
7
7
  import type { IconSize } from './types';
8
8
 
9
- const meta: Meta = {
9
+ const meta = {
10
10
  id: 'rnative-icon',
11
11
  title: 'Symbols/Interface Icons',
12
- };
12
+ } satisfies Meta;
13
13
 
14
14
  export default meta;
15
15