@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
@@ -3,36 +3,20 @@ import {
3
3
  resolveBaseInputPlaceholder,
4
4
  useDisabledContext,
5
5
  } from '@ledgerhq/lumen-utils-shared';
6
- import {
7
- useCallback,
8
- useEffect,
9
- useImperativeHandle,
10
- useRef,
11
- useState,
12
- } from 'react';
13
- import { StyleSheet, Text, TextInput, View } from 'react-native';
14
- import Animated, {
15
- interpolate,
16
- useSharedValue,
17
- useAnimatedStyle,
18
- withTiming,
19
- cancelAnimation,
20
- } from 'react-native-reanimated';
6
+ import { useState } from 'react';
7
+ import { StyleSheet, TextInput, View } from 'react-native';
21
8
  import { useCommonTranslation } from '../../../../i18n';
22
- import type { LumenStyleSheetTheme } from '../../../../styles';
23
9
  import { useStyleSheet, useTheme } from '../../../../styles';
24
10
  import { RuntimeConstants } from '../../../utils';
25
- import { useTimingConfig } from '../../animations/useTimingConfig';
26
11
  import { InteractiveIcon } from '../../core/InteractiveIcon';
27
12
  import { Box, Pressable } from '../../primitives';
28
- import { CheckmarkCircleFill } from '../../symbols/icons/CheckmarkCircleFill';
29
13
  import { DeleteCircleFill } from '../../symbols/icons/DeleteCircleFill';
30
- import { InformationFill } from '../../symbols/icons/InformationFill';
31
- import {
32
- type BaseInputCounterProps,
33
- type BaseInputHelperTextProps,
34
- type BaseInputProps,
35
- } from './types';
14
+ import { BaseInputCounter } from './BaseInputCounter';
15
+ import { BaseInputHelperText } from './BaseInputHelperText';
16
+ import { BaseInputLabel } from './BaseInputLabel';
17
+ import { getMultilineLayout, getMultilineMinHeight } from './multilineLayout';
18
+ import { type BaseInputProps, type BaseInputStatus } from './types';
19
+ import { useBaseInputValue } from './useBaseInputValue/useBaseInputValue';
36
20
 
37
21
  export const BaseInput = ({
38
22
  lx,
@@ -53,6 +37,10 @@ export const BaseInput = ({
53
37
  suffix,
54
38
  ref,
55
39
  placeholder: placeholderProp,
40
+ onClear,
41
+ multiline = false,
42
+ minLines = 1,
43
+ maxLines,
56
44
  ...props
57
45
  }: BaseInputProps) => {
58
46
  const disabled = useDisabledContext({
@@ -61,18 +49,23 @@ export const BaseInput = ({
61
49
  });
62
50
  const { t } = useCommonTranslation();
63
51
  const { theme } = useTheme();
64
- const inputRef = useRef<TextInput>(null);
65
- useImperativeHandle(ref, () => inputRef.current as TextInput);
66
-
67
- const [uncontrolledValue, setUncontrolledValue] = useState(
68
- props.defaultValue || '',
69
- );
70
- const [isFocused, setIsFocused] = useState(false);
71
52
 
72
- const isControlled = props.value !== undefined;
73
- const value = isControlled ? props.value : uncontrolledValue;
53
+ const {
54
+ inputRef,
55
+ composedRef,
56
+ value,
57
+ hasContent,
58
+ handleChangeText,
59
+ handleClear,
60
+ } = useBaseInputValue({
61
+ value: props.value,
62
+ defaultValue: props.defaultValue,
63
+ onChangeText: onChangeTextProp,
64
+ onClear,
65
+ ref,
66
+ });
74
67
 
75
- const hasContent = (value ?? '').length > 0;
68
+ const [isFocused, setIsFocused] = useState(false);
76
69
 
77
70
  const { inputPlaceholder, labelStaysFloatedWithPlaceholder } =
78
71
  resolveBaseInputPlaceholder({
@@ -87,42 +80,19 @@ export const BaseInput = ({
87
80
  const showCount = Boolean(maxCount && maxCount > 0);
88
81
  const showHelper = !!helperText;
89
82
 
90
- const handleChangeText = useCallback(
91
- (text: string) => {
92
- if (!isControlled) {
93
- setUncontrolledValue(text);
94
- }
95
- onChangeTextProp?.(text);
96
- },
97
- [isControlled, onChangeTextProp],
98
- );
99
-
100
- const handleClear = () => {
101
- if (isControlled) {
102
- onChangeTextProp?.('');
103
- } else {
104
- setUncontrolledValue('');
105
- }
106
- props.onClear?.();
107
- };
108
-
109
83
  // Both properties can be used to determine if the input is editable.
110
84
  const isEditable = editable !== false && !readOnly && !disabled;
111
85
 
86
+ const hasLabel = !!label;
87
+
112
88
  const styles = useStyles({
113
89
  status,
114
90
  isFocused,
115
91
  isEditable: !disabled,
116
- hasLabel: !!label,
117
- });
118
-
119
- const floatingLabelStyles = useFloatingLabelStyles({
120
- hasContent,
121
- isFocused,
122
- showClearButton,
123
- status,
124
- isEditable: !disabled,
125
- labelStaysFloatedWithPlaceholder,
92
+ hasLabel,
93
+ multiline,
94
+ minLines,
95
+ maxLines,
126
96
  });
127
97
 
128
98
  return (
@@ -136,7 +106,7 @@ export const BaseInput = ({
136
106
  {prefix}
137
107
 
138
108
  <TextInput
139
- ref={inputRef}
109
+ ref={composedRef}
140
110
  value={value}
141
111
  placeholder={inputPlaceholder}
142
112
  style={StyleSheet.flatten([styles.input, inputStyle])}
@@ -148,20 +118,27 @@ export const BaseInput = ({
148
118
  autoCorrect={false}
149
119
  selectionColor={theme.colors.text.active}
150
120
  placeholderTextColor={theme.colors.text.muted}
121
+ multiline={multiline}
122
+ // iOS hands the drag to the parent by default and the container Pressable
123
+ // claims it, which stops a clamped field from scrolling.
124
+ rejectResponderTermination={!multiline}
151
125
  {...props}
152
126
  />
153
127
 
154
128
  {label && (
155
- <Animated.Text
156
- style={[
157
- floatingLabelStyles.label,
158
- floatingLabelStyles.animatedStyle,
159
- labelStyle,
160
- ]}
161
- numberOfLines={1}
129
+ <BaseInputLabel
130
+ isFocused={isFocused}
131
+ hasContent={hasContent}
132
+ showClearButton={showClearButton}
133
+ status={status}
134
+ isEditable={!disabled}
135
+ labelStaysFloatedWithPlaceholder={
136
+ labelStaysFloatedWithPlaceholder
137
+ }
138
+ style={labelStyle}
162
139
  >
163
140
  {label}
164
- </Animated.Text>
141
+ </BaseInputLabel>
165
142
  )}
166
143
 
167
144
  {(suffix || (!hideClearButton && !disabled)) && (
@@ -200,53 +177,36 @@ export const BaseInput = ({
200
177
  );
201
178
  };
202
179
 
203
- const BaseInputHelperText = ({
204
- helperText,
205
- status,
206
- }: BaseInputHelperTextProps) => {
207
- const styles = useHelperTextStyles({ status });
208
-
209
- return (
210
- <View style={styles.helperContainer}>
211
- {!status && <InformationFill size={16} color='muted' />}
212
- {status === 'error' && <DeleteCircleFill size={16} color='error' />}
213
- {status === 'success' && (
214
- <CheckmarkCircleFill size={16} color='success' />
215
- )}
216
- <Text style={styles.helperText}>{helperText}</Text>
217
- </View>
218
- );
219
- };
220
-
221
- const BaseInputCounter = ({ count, maxCount }: BaseInputCounterProps) => {
222
- const styles = useCounterStyles();
223
-
224
- return (
225
- <Text style={styles.counterText} accessibilityLiveRegion='polite'>
226
- {`${count}/${maxCount}`}
227
- </Text>
228
- );
180
+ type StyleParams = {
181
+ status: BaseInputStatus | undefined;
182
+ isFocused: boolean;
183
+ isEditable: boolean;
184
+ hasLabel: boolean;
185
+ multiline: boolean;
186
+ minLines: number;
187
+ maxLines: number | undefined;
229
188
  };
230
189
 
231
- const useStyles = ({
190
+ const useRowStyles = ({
232
191
  status,
233
192
  isFocused,
234
193
  isEditable,
235
194
  hasLabel,
236
- }: {
237
- status: 'error' | 'success' | undefined;
238
- isFocused: boolean;
239
- isEditable: boolean;
240
- hasLabel: boolean;
241
- }) => {
195
+ multiline,
196
+ minLines,
197
+ maxLines,
198
+ }: StyleParams) => {
242
199
  return useStyleSheet(
243
200
  (t) => {
244
- const hasStatusBorder = status === 'error' || status === 'success';
245
201
  const statusBorderColors = {
246
202
  error: t.colors.border.error,
247
203
  success: t.colors.border.success,
248
204
  } as const;
249
205
  const statusBorderColor = status ? statusBorderColors[status] : undefined;
206
+ const borderWidth =
207
+ statusBorderColor && !isFocused ? t.borderWidth.s1 : t.borderWidth.s2;
208
+
209
+ const { paddingVertical } = getMultilineLayout(t, hasLabel);
250
210
 
251
211
  return {
252
212
  container: StyleSheet.flatten([
@@ -260,22 +220,52 @@ const useStyles = ({
260
220
  paddingHorizontal: t.spacings.s16,
261
221
  borderRadius: t.borderRadius.sm,
262
222
  backgroundColor: t.colors.bg.muted,
263
- borderWidth: t.borderWidth.s2,
223
+ borderWidth,
264
224
  borderColor: 'transparent',
265
225
  overflow: 'hidden',
266
226
  },
267
- hasStatusBorder &&
268
- statusBorderColor && {
269
- borderWidth: isFocused ? t.borderWidth.s2 : t.borderWidth.s1,
270
- borderColor: statusBorderColor,
271
- },
227
+ statusBorderColor && { borderColor: statusBorderColor },
272
228
  !isEditable && {
273
229
  backgroundColor: t.colors.bg.disabled,
274
230
  },
275
231
  isFocused &&
276
- !hasStatusBorder &&
232
+ !statusBorderColor &&
277
233
  isEditable && { borderColor: t.colors.border.active },
234
+ multiline && {
235
+ alignItems: 'flex-start',
236
+ paddingVertical,
237
+ minHeight: getMultilineMinHeight(t, {
238
+ hasLabel,
239
+ minLines,
240
+ maxLines,
241
+ }),
242
+ },
278
243
  ]),
244
+ suffixContainer: StyleSheet.flatten([
245
+ {
246
+ minWidth: t.sizes.s20,
247
+ alignItems: 'center',
248
+ justifyContent: 'center',
249
+ },
250
+ multiline && { marginTop: t.spacings.s2 },
251
+ ]),
252
+ };
253
+ },
254
+ [status, isFocused, isEditable, hasLabel, multiline, minLines, maxLines],
255
+ );
256
+ };
257
+
258
+ const useInputStyles = ({
259
+ isEditable,
260
+ hasLabel,
261
+ multiline,
262
+ maxLines,
263
+ }: Omit<StyleParams, 'status' | 'isFocused' | 'minLines'>) => {
264
+ return useStyleSheet(
265
+ (t) => {
266
+ const { lineHeight, labelRowHeight } = getMultilineLayout(t, hasLabel);
267
+
268
+ return {
279
269
  input: StyleSheet.flatten([
280
270
  {
281
271
  position: 'relative',
@@ -300,149 +290,40 @@ const useStyles = ({
300
290
  backgroundColor: t.colors.bg.disabled,
301
291
  color: t.colors.text.disabled,
302
292
  },
293
+ multiline && {
294
+ paddingTop: 0,
295
+ paddingBottom: 0,
296
+ marginTop: labelRowHeight,
297
+ minHeight: lineHeight,
298
+ maxHeight: maxLines ? maxLines * lineHeight : undefined,
299
+ },
300
+ multiline && RuntimeConstants.isAndroid && { lineHeight },
303
301
  ]),
304
- footerContainer: {
305
- marginTop: t.spacings.s8,
306
- flexDirection: 'row',
307
- alignItems: 'flex-start',
308
- justifyContent: 'space-between',
309
- gap: t.spacings.s8,
310
- },
311
- suffixContainer: {
312
- minWidth: t.sizes.s20,
313
- alignItems: 'center',
314
- justifyContent: 'center',
315
- },
316
302
  };
317
303
  },
318
- [status, isFocused, isEditable, hasLabel],
304
+ [isEditable, hasLabel, multiline, maxLines],
319
305
  );
320
306
  };
321
307
 
322
- const useHelperTextStyles = ({
323
- status,
324
- }: {
325
- status: BaseInputProps['status'];
326
- }) => {
308
+ const useFooterStyles = () => {
327
309
  return useStyleSheet(
328
310
  (t) => ({
329
- helperContainer: {
330
- flex: 1,
311
+ footerContainer: {
312
+ marginTop: t.spacings.s8,
331
313
  flexDirection: 'row',
332
- alignItems: 'center',
333
- gap: t.spacings.s2,
334
- },
335
- helperText: {
336
- ...t.typographies.body3,
337
- flex: 1,
338
- color: {
339
- error: t.colors.text.error,
340
- success: t.colors.text.success,
341
- default: t.colors.text.muted,
342
- }[status ?? 'default'],
343
- },
344
- }),
345
- [status],
346
- );
347
- };
348
-
349
- const useCounterStyles = () => {
350
- return useStyleSheet(
351
- (t) => ({
352
- counterText: {
353
- ...t.typographies.body3,
354
- flexShrink: 0,
355
- color: t.colors.text.muted,
314
+ alignItems: 'flex-start',
315
+ justifyContent: 'space-between',
316
+ gap: t.spacings.s8,
356
317
  },
357
318
  }),
358
319
  [],
359
320
  );
360
321
  };
361
322
 
362
- const useAnimatedFloatingLabel = ({
363
- isFloatingLabel,
364
- theme,
365
- }: {
366
- isFloatingLabel: boolean;
367
- theme: LumenStyleSheetTheme;
368
- }) => {
369
- const floatingAnimation = useSharedValue(isFloatingLabel ? 1 : 0);
370
- const timingConfig = useTimingConfig({
371
- duration: 150,
372
- easing: 'linear',
373
- });
374
-
375
- useEffect(() => {
376
- floatingAnimation.value = withTiming(isFloatingLabel ? 1 : 0, timingConfig);
377
-
378
- return () => cancelAnimation(floatingAnimation);
379
- }, [isFloatingLabel, timingConfig, floatingAnimation]);
380
-
381
- const animatedStyle = useAnimatedStyle(
382
- () => ({
383
- top: interpolate(
384
- floatingAnimation.value,
385
- [0, 1],
386
- [theme.spacings.s14, theme.spacings.s6],
387
- ),
388
- fontSize: interpolate(
389
- floatingAnimation.value,
390
- [0, 1],
391
- [theme.typographies.body2.fontSize, theme.typographies.body4.fontSize],
392
- ),
393
- }),
394
- [floatingAnimation, theme],
395
- );
396
-
397
- return { animatedStyle };
398
- };
399
-
400
- const useFloatingLabelStyles = ({
401
- isFocused,
402
- hasContent,
403
- showClearButton,
404
- status,
405
- isEditable,
406
- labelStaysFloatedWithPlaceholder,
407
- }: {
408
- isFocused: boolean;
409
- hasContent: boolean;
410
- showClearButton: boolean;
411
- status: 'error' | 'success' | undefined;
412
- isEditable: boolean;
413
- labelStaysFloatedWithPlaceholder: boolean;
414
- }) => {
415
- const { theme } = useTheme();
416
-
417
- const { label } = useStyleSheet(
418
- (t) => ({
419
- label: StyleSheet.flatten([
420
- {
421
- position: 'absolute',
422
- left: t.spacings.s16,
423
- width: t.sizes.full,
424
- color: t.colors.text.muted,
425
- },
426
- hasContent &&
427
- showClearButton && {
428
- width: '92%',
429
- },
430
- status === 'error' && {
431
- color: t.colors.text.error,
432
- },
433
- !isEditable && {
434
- color: t.colors.text.disabled,
435
- },
436
- ]),
437
- }),
438
- [hasContent, showClearButton, status, isEditable],
439
- );
440
-
441
- const { animatedStyle } = useAnimatedFloatingLabel({
442
- theme,
443
- isFloatingLabel:
444
- isFocused || hasContent || labelStaysFloatedWithPlaceholder,
445
- });
323
+ const useStyles = (params: StyleParams) => {
324
+ const { container, suffixContainer } = useRowStyles(params);
325
+ const { input } = useInputStyles(params);
326
+ const { footerContainer } = useFooterStyles();
446
327
 
447
- return { label, animatedStyle };
328
+ return { container, input, suffixContainer, footerContainer };
448
329
  };
@@ -0,0 +1,35 @@
1
+ import type { TextStyle } from 'react-native';
2
+ import { Text } from 'react-native';
3
+ import { useStyleSheet } from '../../../../styles';
4
+ import type { BaseInputCounterProps } from './types';
5
+
6
+ const useCounterStyles = (): { counterText: TextStyle } => {
7
+ return useStyleSheet(
8
+ (t) => ({
9
+ counterText: {
10
+ ...t.typographies.body3,
11
+ flexShrink: 0,
12
+ color: t.colors.text.muted,
13
+ },
14
+ }),
15
+ [],
16
+ );
17
+ };
18
+
19
+ /**
20
+ * Character counter rendered below the control inside `BaseInput`.
21
+ *
22
+ * @internal
23
+ */
24
+ export const BaseInputCounter = ({
25
+ count,
26
+ maxCount,
27
+ }: BaseInputCounterProps) => {
28
+ const styles = useCounterStyles();
29
+
30
+ return (
31
+ <Text style={styles.counterText} accessibilityLiveRegion='polite'>
32
+ {`${count}/${maxCount}`}
33
+ </Text>
34
+ );
35
+ };
@@ -0,0 +1,57 @@
1
+ import type { TextStyle, ViewStyle } from 'react-native';
2
+ import { Text, View } from 'react-native';
3
+ import { useStyleSheet } from '../../../../styles';
4
+ import { CheckmarkCircleFill } from '../../symbols/icons/CheckmarkCircleFill';
5
+ import { DeleteCircleFill } from '../../symbols/icons/DeleteCircleFill';
6
+ import { InformationFill } from '../../symbols/icons/InformationFill';
7
+ import type { BaseInputHelperTextProps, BaseInputProps } from './types';
8
+
9
+ const useHelperTextStyles = ({
10
+ status,
11
+ }: {
12
+ status: BaseInputProps['status'];
13
+ }): { helperContainer: ViewStyle; helperText: TextStyle } => {
14
+ return useStyleSheet(
15
+ (t) => ({
16
+ helperContainer: {
17
+ flex: 1,
18
+ flexDirection: 'row',
19
+ alignItems: 'flex-start',
20
+ gap: t.spacings.s2,
21
+ },
22
+ helperText: {
23
+ ...t.typographies.body3,
24
+ flex: 1,
25
+ color: {
26
+ error: t.colors.text.error,
27
+ success: t.colors.text.success,
28
+ default: t.colors.text.muted,
29
+ }[status ?? 'default'],
30
+ },
31
+ }),
32
+ [status],
33
+ );
34
+ };
35
+
36
+ /**
37
+ * Hint, error or success copy rendered below the control inside `BaseInput`.
38
+ *
39
+ * @internal
40
+ */
41
+ export const BaseInputHelperText = ({
42
+ helperText,
43
+ status,
44
+ }: BaseInputHelperTextProps) => {
45
+ const styles = useHelperTextStyles({ status });
46
+
47
+ return (
48
+ <View style={styles.helperContainer}>
49
+ {!status && <InformationFill size={16} color='muted' />}
50
+ {status === 'error' && <DeleteCircleFill size={16} color='error' />}
51
+ {status === 'success' && (
52
+ <CheckmarkCircleFill size={16} color='success' />
53
+ )}
54
+ <Text style={styles.helperText}>{helperText}</Text>
55
+ </View>
56
+ );
57
+ };