@plexui/react-native 0.1.1 → 0.2.0

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 (149) hide show
  1. package/README.md +34 -0
  2. package/dist/es/components/ActionSheet/ActionSheet.js +53 -19
  3. package/dist/es/components/Alert/Alert.js +163 -0
  4. package/dist/es/components/Avatar/Avatar.js +20 -8
  5. package/dist/es/components/BottomActions/BottomActions.js +34 -0
  6. package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
  7. package/dist/es/components/Button/Button.js +108 -28
  8. package/dist/es/components/Card/Card.js +16 -8
  9. package/dist/es/components/Checkbox/Checkbox.js +67 -99
  10. package/dist/es/components/Chip/Chip.js +16 -7
  11. package/dist/es/components/Dialog/Dialog.js +38 -24
  12. package/dist/es/components/Field/Field.js +91 -0
  13. package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
  14. package/dist/es/components/Icon/createIcon.js +13 -2
  15. package/dist/es/components/Indicator/CircularProgress.js +80 -0
  16. package/dist/es/components/Indicator/LoadingDots.js +46 -0
  17. package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
  18. package/dist/es/components/Indicator/index.js +3 -0
  19. package/dist/es/components/Input/Input.js +69 -60
  20. package/dist/es/components/InputGroup/InputGroup.js +130 -0
  21. package/dist/es/components/List/List.js +175 -59
  22. package/dist/es/components/Menu/Menu.js +69 -40
  23. package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
  24. package/dist/es/components/OTPInput/OTPInput.js +9 -3
  25. package/dist/es/components/PageControl/PageControl.js +13 -7
  26. package/dist/es/components/Popover/Popover.js +128 -0
  27. package/dist/es/components/Progress/Progress.js +142 -0
  28. package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
  29. package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
  30. package/dist/es/components/Select/Select.js +97 -34
  31. package/dist/es/components/Separator/Separator.js +31 -0
  32. package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
  33. package/dist/es/components/Stepper/Stepper.js +219 -0
  34. package/dist/es/components/Switch/Switch.js +26 -12
  35. package/dist/es/components/TagInput/TagInput.js +121 -0
  36. package/dist/es/components/Text/Text.js +7 -4
  37. package/dist/es/components/TextLink/TextLink.js +42 -0
  38. package/dist/es/components/Textarea/Textarea.js +12 -0
  39. package/dist/es/components/Tip/Tip.js +193 -0
  40. package/dist/es/components/Toolbar/Toolbar.js +6 -2
  41. package/dist/es/components/Tooltip/Tooltip.js +272 -0
  42. package/dist/es/index.js +20 -2
  43. package/dist/es/internal/FloatingPanel.js +111 -0
  44. package/dist/es/internal/fieldStack.js +73 -0
  45. package/dist/es/internal/floating.js +97 -0
  46. package/dist/es/internal/ripple.js +119 -0
  47. package/dist/es/internal/row.js +2 -1
  48. package/dist/es/internal/transition.js +113 -0
  49. package/dist/es/theme/ThemeProvider.js +41 -9
  50. package/dist/es/theme/material.js +37 -7
  51. package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
  52. package/dist/types/components/Alert/Alert.d.ts +51 -0
  53. package/dist/types/components/Avatar/Avatar.d.ts +4 -2
  54. package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
  55. package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
  56. package/dist/types/components/Button/Button.d.ts +20 -5
  57. package/dist/types/components/Card/Card.d.ts +14 -1
  58. package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
  59. package/dist/types/components/Chip/Chip.d.ts +12 -1
  60. package/dist/types/components/Dialog/Dialog.d.ts +9 -5
  61. package/dist/types/components/Field/Field.d.ts +64 -0
  62. package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
  63. package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
  64. package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
  65. package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
  66. package/dist/types/components/Indicator/index.d.ts +3 -0
  67. package/dist/types/components/Input/Input.d.ts +13 -3
  68. package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
  69. package/dist/types/components/List/List.d.ts +57 -14
  70. package/dist/types/components/Menu/Menu.d.ts +4 -0
  71. package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
  72. package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
  73. package/dist/types/components/PageControl/PageControl.d.ts +11 -1
  74. package/dist/types/components/Popover/Popover.d.ts +86 -0
  75. package/dist/types/components/Progress/Progress.d.ts +56 -0
  76. package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
  77. package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
  78. package/dist/types/components/Select/Select.d.ts +36 -8
  79. package/dist/types/components/Separator/Separator.d.ts +19 -0
  80. package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
  81. package/dist/types/components/Stepper/Stepper.d.ts +61 -0
  82. package/dist/types/components/Switch/Switch.d.ts +5 -5
  83. package/dist/types/components/TagInput/TagInput.d.ts +44 -0
  84. package/dist/types/components/TextLink/TextLink.d.ts +30 -0
  85. package/dist/types/components/Textarea/Textarea.d.ts +19 -0
  86. package/dist/types/components/Tip/Tip.d.ts +71 -0
  87. package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
  88. package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
  89. package/dist/types/index.d.ts +20 -2
  90. package/dist/types/internal/FloatingPanel.d.ts +70 -0
  91. package/dist/types/internal/fieldStack.d.ts +48 -0
  92. package/dist/types/internal/floating.d.ts +71 -0
  93. package/dist/types/internal/ripple.d.ts +17 -0
  94. package/dist/types/internal/row.d.ts +15 -3
  95. package/dist/types/internal/transition.d.ts +37 -0
  96. package/dist/types/theme/ThemeProvider.d.ts +28 -4
  97. package/dist/types/theme/material.d.ts +20 -6
  98. package/dist/types/theme/types.d.ts +8 -0
  99. package/package.json +2 -2
  100. package/src/components/ActionSheet/ActionSheet.tsx +107 -38
  101. package/src/components/Alert/Alert.tsx +279 -0
  102. package/src/components/Avatar/Avatar.tsx +21 -9
  103. package/src/components/BottomActions/BottomActions.tsx +54 -0
  104. package/src/components/BottomSheet/BottomSheet.tsx +111 -25
  105. package/src/components/Button/Button.tsx +170 -35
  106. package/src/components/Card/Card.tsx +33 -9
  107. package/src/components/Checkbox/Checkbox.tsx +89 -124
  108. package/src/components/Chip/Chip.tsx +49 -6
  109. package/src/components/Dialog/Dialog.tsx +68 -37
  110. package/src/components/Field/Field.tsx +227 -0
  111. package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
  112. package/src/components/Icon/createIcon.tsx +16 -6
  113. package/src/components/Indicator/CircularProgress.tsx +141 -0
  114. package/src/components/Indicator/LoadingDots.tsx +79 -0
  115. package/src/components/Indicator/LoadingIndicator.tsx +166 -0
  116. package/src/components/Indicator/index.ts +3 -0
  117. package/src/components/Input/Input.tsx +126 -97
  118. package/src/components/InputGroup/InputGroup.tsx +261 -0
  119. package/src/components/List/List.tsx +345 -88
  120. package/src/components/Menu/Menu.tsx +83 -41
  121. package/src/components/NavigationButton/NavigationButton.tsx +35 -5
  122. package/src/components/OTPInput/OTPInput.tsx +21 -2
  123. package/src/components/PageControl/PageControl.tsx +36 -8
  124. package/src/components/Popover/Popover.tsx +261 -0
  125. package/src/components/Progress/Progress.tsx +255 -0
  126. package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
  127. package/src/components/RollingNumber/RollingNumber.tsx +189 -0
  128. package/src/components/Select/Select.tsx +175 -71
  129. package/src/components/Separator/Separator.tsx +51 -0
  130. package/src/components/ShimmerText/ShimmerText.tsx +144 -0
  131. package/src/components/Stepper/Stepper.tsx +386 -0
  132. package/src/components/Switch/Switch.tsx +26 -12
  133. package/src/components/TagInput/TagInput.tsx +227 -0
  134. package/src/components/Text/Text.tsx +8 -4
  135. package/src/components/TextLink/TextLink.tsx +77 -0
  136. package/src/components/Textarea/Textarea.tsx +23 -0
  137. package/src/components/Tip/Tip.tsx +410 -0
  138. package/src/components/Toolbar/Toolbar.tsx +27 -2
  139. package/src/components/Tooltip/Tooltip.tsx +478 -0
  140. package/src/index.ts +36 -2
  141. package/src/internal/FloatingPanel.tsx +199 -0
  142. package/src/internal/fieldStack.tsx +179 -0
  143. package/src/internal/floating.ts +131 -0
  144. package/src/internal/ripple.tsx +132 -0
  145. package/src/internal/row.ts +16 -3
  146. package/src/internal/transition.ts +124 -0
  147. package/src/theme/ThemeProvider.tsx +65 -15
  148. package/src/theme/material.ts +39 -7
  149. package/src/theme/types.ts +8 -0
@@ -0,0 +1,166 @@
1
+ import { useEffect, useState } from "react"
2
+ import { Animated, Easing, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
+ import Svg, { Circle } from "react-native-svg"
4
+ import { nativeDriver } from "../../internal/transition"
5
+ import { useTheme } from "../../theme/ThemeProvider"
6
+ import type { Theme } from "../../theme/types"
7
+ import { textColor, type TextColor } from "../Text/Text"
8
+
9
+ export type LoadingIndicatorProps = {
10
+ /** Size of the indicator, in pixels. @default 20 */
11
+ size?: number
12
+ /**
13
+ * The spokes' width on iOS (by default the iOS 27 kit's proportion of the size: 2/14 up to 16, 4/30 to 27, 5/35
14
+ * from 28), the arc's stroke on Android (by default an eighth of the size).
15
+ */
16
+ strokeWidth?: number
17
+ /** The color, a text color or any color string; the web takes the text color (`currentcolor`). @default "primary" (iOS), the accent (Android) */
18
+ color?: TextColor | (string & {})
19
+ /** The time of one turn in ms, as the web's `--indicator-rotate-duration`; Android's cycle keeps its proportion. @default 800 */
20
+ duration?: number
21
+ /** The name read out, as a busy progress indicator; without one the spinner is decorative, as on the web. */
22
+ "aria-label"?: string
23
+ accessibilityLabel?: string
24
+ testID?: string
25
+ style?: StyleProp<ViewStyle>
26
+ }
27
+
28
+ /** The opacities of the eight spokes, from the top clockwise: the leading spoke, then the faintest, brightening. */
29
+ const SPOKES = [1, 0.15, 0.27, 0.39, 0.51, 0.63, 0.75, 0.87]
30
+
31
+ /** The kit's spoke for a size: Small (14) up to 16, Regular (30) to 27, Large (35) from 28, as width and height. */
32
+ function spoke(size: number) {
33
+ if (size <= 16) return { width: (2 / 14) * size, height: (4 / 14) * size }
34
+ if (size >= 28) return { width: (5 / 35) * size, height: (13 / 35) * size }
35
+ return { width: (4 / 30) * size, height: (10 / 30) * size }
36
+ }
37
+
38
+ /** CSS `steps(8, end)`: the spinner turns a spoke at a time. */
39
+ const eightSteps = (t: number) => Math.min(1, Math.floor(t * 8) / 8)
40
+
41
+ const defaultColor = (theme: Theme, color: LoadingIndicatorProps["color"]) =>
42
+ color ? textColor(theme, color) : theme.isAndroid ? theme.material.primary : textColor(theme, "primary")
43
+
44
+ /**
45
+ * A spinner for a loading state, as @plexui/ui's LoadingIndicator. iOS: the iOS 27 spinner (UIActivityIndicatorView)
46
+ * of eight rounded spokes, as the touch stylesheet draws it: 20pt, the spokes brightening to the leading one, a turn in
47
+ * 800ms in eight steps. Android: Material's circular progress, the arc of CircularProgressDrawable (a 5.4s cycle of four
48
+ * 250° surges) in the accent. With reduced motion it stands still.
49
+ */
50
+ export function LoadingIndicator({ size = 20, strokeWidth, color, duration = 800, "aria-label": ariaLabel, accessibilityLabel, testID, style }: LoadingIndicatorProps) {
51
+ const theme = useTheme()
52
+ const ink = defaultColor(theme, color)
53
+ const name = accessibilityLabel ?? ariaLabel
54
+ return (
55
+ <View
56
+ accessible={name != null}
57
+ accessibilityRole={name != null ? "progressbar" : undefined}
58
+ accessibilityLabel={name}
59
+ accessibilityState={name != null ? { busy: true } : undefined}
60
+ importantForAccessibility={name != null ? undefined : "no-hide-descendants"}
61
+ accessibilityElementsHidden={name == null}
62
+ testID={testID}
63
+ style={[{ width: size, height: size }, style]}
64
+ >
65
+ {theme.isAndroid ? (
66
+ <Arc size={size} stroke={strokeWidth ?? size / 8} color={ink} cycle={(SPIN.cycle * duration) / 800} still={theme.reducedMotion} />
67
+ ) : (
68
+ <Spokes size={size} strokeWidth={strokeWidth} color={ink} duration={duration} still={theme.reducedMotion} />
69
+ )}
70
+ </View>
71
+ )
72
+ }
73
+
74
+ function Spokes({ size, strokeWidth, color, duration, still }: { size: number; strokeWidth?: number; color: string; duration: number; still: boolean }) {
75
+ const [turn] = useState(() => new Animated.Value(0))
76
+ useEffect(() => {
77
+ turn.setValue(0)
78
+ if (still || duration <= 0) return
79
+ const loop = Animated.loop(Animated.timing(turn, { toValue: 1, duration, easing: eightSteps, useNativeDriver: nativeDriver, isInteraction: false }))
80
+ loop.start()
81
+ return () => loop.stop()
82
+ }, [turn, duration, still])
83
+ const { width: kitWidth, height } = spoke(size)
84
+ const width = strokeWidth ?? kitWidth
85
+ return (
86
+ <Animated.View style={[StyleSheet.absoluteFill, { transform: [{ rotate: turn.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "360deg"] }) }] }]}>
87
+ {SPOKES.map((opacity, index) => (
88
+ <View key={index} style={[StyleSheet.absoluteFill, { opacity, transform: [{ rotate: `${index * 45}deg` }] }]}>
89
+ <View style={{ position: "absolute", top: 0, left: (size - width) / 2, width, height, borderRadius: width / 2, backgroundColor: color }} />
90
+ </View>
91
+ ))}
92
+ </Animated.View>
93
+ )
94
+ }
95
+
96
+ /** Material's standard curve, on which the arc surges. */
97
+ const standard = Easing.bezier(0.4, 0, 0.2, 1)
98
+ /**
99
+ * Android's spinner over one 5400ms cycle (CircularProgressDrawable): the arc's head turns 1520° and makes four surges
100
+ * of 250°, 667ms each, 1350ms apart; its tail turns 20° behind the head's steady turn and makes the same surges 667ms
101
+ * later.
102
+ */
103
+ export const SPIN = { cycle: 5400, turn: 1520, lag: 20, surge: 250, surgeTime: 667, surgeEvery: 1350, surges: 4 }
104
+
105
+ /** The spinner at a share of its cycle: how far its tail has turned and how long its arc is, in degrees. */
106
+ export function spinnerAt(share: number) {
107
+ const t = share * SPIN.cycle
108
+ const surges = (delay: number) => {
109
+ let total = 0
110
+ for (let index = 0; index < SPIN.surges; index++) {
111
+ const from = delay + index * SPIN.surgeEvery
112
+ total += standard(Math.min(1, Math.max(0, (t - from) / SPIN.surgeTime))) * SPIN.surge
113
+ }
114
+ return total
115
+ }
116
+ const head = (t / SPIN.cycle) * SPIN.turn + surges(0)
117
+ // The tail stands still until the head is 20° on
118
+ const lagTime = (SPIN.lag * SPIN.cycle) / SPIN.turn
119
+ const tail = Math.max(0, (t - lagTime) / (SPIN.cycle - lagTime)) * (SPIN.turn - SPIN.lag) + surges(SPIN.surgeTime)
120
+ return { tail, arc: head - tail }
121
+ }
122
+
123
+ /** The still frame: the end of the first surge, a 270° arc. */
124
+ const STILL = SPIN.surgeTime / SPIN.cycle
125
+
126
+ /**
127
+ * The arc is redrawn from a clock on each frame: an animated SVG prop does not reach the element on the web. The
128
+ * stroke runs on a circle that fills the box, as Android lays its drawable out (8.75 of 20 with a 2.5 stroke).
129
+ */
130
+ function Arc({ size, stroke, color, cycle, still }: { size: number; stroke: number; color: string; cycle: number; still: boolean }) {
131
+ const [time, setShare] = useState(STILL)
132
+ const share = still || cycle <= 0 ? STILL : time
133
+ useEffect(() => {
134
+ if (still || cycle <= 0) return
135
+ const time = new Animated.Value(0)
136
+ const id = time.addListener(({ value }) => setShare(value))
137
+ const loop = Animated.loop(Animated.timing(time, { toValue: 1, duration: cycle, easing: Easing.linear, useNativeDriver: false, isInteraction: false }))
138
+ loop.start()
139
+ return () => {
140
+ loop.stop()
141
+ time.removeListener(id)
142
+ }
143
+ }, [cycle, still])
144
+ const { tail, arc } = spinnerAt(share)
145
+ const radius = Math.max(0, (size - stroke) / 2)
146
+ const length = 2 * Math.PI * radius
147
+ return (
148
+ // The circle's stroke starts at 3 o'clock and runs clockwise, as Android's arcs
149
+ <View style={[StyleSheet.absoluteFill, { transform: [{ rotate: `${tail}deg` }] }]}>
150
+ <Svg width={size} height={size}>
151
+ <Circle
152
+ cx={size / 2}
153
+ cy={size / 2}
154
+ r={radius}
155
+ fill="none"
156
+ stroke={color}
157
+ strokeWidth={stroke}
158
+ strokeLinecap="round"
159
+ // One dash as long as the arc, the rest of the circle a gap
160
+ strokeDasharray={[length, length]}
161
+ strokeDashoffset={length * (1 - arc / 360)}
162
+ />
163
+ </Svg>
164
+ </View>
165
+ )
166
+ }
@@ -0,0 +1,3 @@
1
+ export { CircularProgress, getSimulatedProgress, type CircularProgressProps } from "./CircularProgress"
2
+ export { LoadingDots, type LoadingDotsProps } from "./LoadingDots"
3
+ export { LoadingIndicator, type LoadingIndicatorProps } from "./LoadingIndicator"
@@ -17,19 +17,18 @@ import {
17
17
  type ViewStyle,
18
18
  } from "react-native"
19
19
  import XCircleFilled from "../../icons/plex/XCircleFilled"
20
- import { useDescription } from "../../internal/a11y"
21
20
  import { useAndroidGlass } from "../../internal/BarBackdrop"
21
+ import { FieldStack, FloatLabelContext } from "../../internal/fieldStack"
22
22
  import { Glass } from "../../internal/Glass"
23
23
  import { useRTL } from "../../internal/direction"
24
24
  import { springTo, stiffSpring } from "../../internal/motion"
25
25
  import { RowEndContext } from "../../internal/row"
26
- import { barShadow, barSurface, withAlpha, dangerText, stateLayer } from "../../theme/material"
26
+ import { androidGray, barShadow, barSurface, withAlpha, dangerText, stateLayer } from "../../theme/material"
27
27
  import { useTheme } from "../../theme/ThemeProvider"
28
28
  import type { Theme } from "../../theme/types"
29
29
  import { BarFieldContext, type ControlSize } from "../Button/Button"
30
30
  import { IconDefaultsProvider } from "../Icon/createIcon"
31
31
  import { MaterialCancel, MaterialClose } from "../Icon/material"
32
- import { Text } from "../Text/Text"
33
32
 
34
33
  export type InputVariant = "outline" | "soft" | "ghost"
35
34
 
@@ -83,8 +82,8 @@ const IOS_FIELD: Record<ControlSize, { height: ControlSize; radius: "sm" | "md"
83
82
  const IOS_RADIUS = { sm: 6, md: 8, lg: 10, xl: 12 }
84
83
  const IOS_GAP = { md: 8, lg: 10 }
85
84
 
86
- /** Android's outlined line with focus. */
87
- const FOCUS_LINE = 1.667
85
+ /** Android's outlined line with focus: 1.5dp (the reference's focused field). */
86
+ const FOCUS_LINE = 1.5
88
87
 
89
88
  /** Android's idle outlined line: 0.5dp, at least 2 device pixels (1 on a 1x screen). */
90
89
  function hairline() {
@@ -189,25 +188,25 @@ export function fieldLook(
189
188
  gutter: 18,
190
189
  }
191
190
  }
192
- // Android's fields: `outline` is the outlined field (radius 8, a hairline that thickens to 1.667dp in the accent
193
- // on focus, the label floating on the top line), `soft` a field filled with the text color at 5% (the chips' and
194
- // sheets' search fields), `ghost` the bare field of a card. The text is 17 with a 38% hint; a field is 50dp (a
195
- // row's height), 56 with a label; disabled dims it to 50%. Focused, the line and the label take the accent, its
196
- // lighter text in dark mode (#6EB2EF)
191
+ // Android's fields: `outline` is the outlined field (radius 8, a hairline in a light gray that thickens to 1.5dp in
192
+ // the accent on focus, the label floating on the top line, the text 16), `soft` a field filled with the text color
193
+ // at 5% (the chips' and sheets' search fields), `ghost` the bare field of a card (the text 17, 22 in). The hint is
194
+ // a light gray (#A8A8A8, #7D7D7D at night); a field is 50dp (a row's height), 56 with a label; disabled dims it to
195
+ // 50%. Focused, the line and the label take the accent, its lighter text in dark mode (#6EB2EF)
197
196
  const outlined = variant === "outline"
198
197
  const ghost = variant === "ghost"
199
198
  const accent = state.invalid ? dangerText(theme) : state.focused ? focusAccent(theme) : null
200
199
  const height = label ? 56 : 50
201
200
  const radius = pill ? height / 2 : 8
202
- // The idle line: a hairline in the text at 16%, 24% in dark mode
203
- const idle = withAlpha(m.onSurface, theme.scheme === "dark" ? 0.24 : 0.16)
201
+ // The idle line: a hairline in a light gray (#DBDBDB), the text at 24% in dark mode
202
+ const idle = androidGray(theme, "fieldLine")
204
203
  const frame: FieldFrame | null = outlined
205
204
  ? { outlined: true, color: accent ?? idle, width: state.focused && !state.disabled ? FOCUS_LINE : hairline(), radius }
206
205
  : state.invalid
207
206
  ? // A field with no line of its own shows an error as Android's underline does: 2dp in the error color
208
207
  ghost
209
208
  ? { outlined: false, color: dangerText(theme), width: 2, radius: 0 }
210
- : { outlined: true, color: dangerText(theme), width: 1.667, radius }
209
+ : { outlined: true, color: dangerText(theme), width: FOCUS_LINE, radius }
211
210
  : null
212
211
  const box: ViewStyle = {
213
212
  minHeight: height,
@@ -215,13 +214,13 @@ export function fieldLook(
215
214
  backgroundColor: variant === "soft" ? withAlpha(m.onSurface, 0.05) : "transparent",
216
215
  opacity: state.disabled ? 0.5 : 1,
217
216
  }
218
- const hint = withAlpha(m.onSurface, 0.38)
217
+ const hint = androidGray(theme, "hint")
219
218
  return {
220
219
  box,
221
220
  glass: false,
222
221
  frame,
223
222
  gap: 12,
224
- text: { fontSize: 17, lineHeight: 20, color: m.onSurface },
223
+ text: { fontSize: outlined ? 16 : 17, lineHeight: 20, color: m.onSurface },
225
224
  placeholder: hint,
226
225
  icon: m.onSurfaceVariant,
227
226
  trailingIcon: state.invalid ? dangerText(theme) : m.onSurfaceVariant,
@@ -233,8 +232,8 @@ export function fieldLook(
233
232
  clearTarget: 48,
234
233
  adornmentOffset: 0,
235
234
  height,
236
- // A card's bare field stands 21dp in, as a card's edit row; the others 14
237
- gutter: ghost ? 21 : 14,
235
+ // A card's bare field stands 22dp in, as a card's input row; the others 14
236
+ gutter: ghost ? 22 : 14,
238
237
  }
239
238
  }
240
239
  if (bar) {
@@ -298,7 +297,8 @@ export function fieldLook(
298
297
  } as ViewStyle,
299
298
  gap: theme.length(`--input-gap-${row.gap}`, IOS_GAP[row.gap]),
300
299
  text: { fontSize: 17, lineHeight: 22, color: theme.color("--input-text-color", theme.colors.text) },
301
- placeholder: theme.color("--input-placeholder-text-color", theme.colors.textTertiary),
300
+ // iOS's placeholder is the tertiary label (UIColor.placeholderText, the ink at 25%), as in a form row
301
+ placeholder: theme.colors.labelTertiary,
302
302
  icon: theme.color("--mobile-label-secondary"),
303
303
  frame: null as FieldFrame | null,
304
304
  trailingIcon: theme.color("--mobile-label-secondary"),
@@ -524,8 +524,22 @@ export function InputAdornmentButton({ children, accessibilityLabel, selected, d
524
524
 
525
525
  Input.AdornmentButton = InputAdornmentButton
526
526
 
527
- /** `shift` moves the field sideways (TextField's shake on an error). */
528
- type FieldExtras = { label?: ReactNode; required?: boolean; shift?: Animated.Value }
527
+ /**
528
+ * `shift` moves the field sideways (TextField's shake on an error). With `multiline` (a Textarea) `rows` sets the
529
+ * least height in lines, and `autoResize` grows the field with its text up to `maxRows` (else it stays at `rows` and
530
+ * scrolls).
531
+ */
532
+ export type FieldExtras = {
533
+ label?: ReactNode
534
+ required?: boolean
535
+ shift?: Animated.Value
536
+ rows?: number
537
+ maxRows?: number
538
+ autoResize?: boolean
539
+ /** Android, at a row's end: the value stands at the end, as a value row's and the web's ghost row value (a Field row's
540
+ * Input, an InputGroup's value before its unit); in a List with `columns` it still starts its column. */
541
+ valueAtEnd?: boolean
542
+ }
529
543
 
530
544
  /** The field itself; TextField passes it a floating label on Android. */
531
545
  export function InputField({
@@ -539,9 +553,13 @@ export function InputField({
539
553
  pill = false,
540
554
  style,
541
555
  testID,
542
- label,
543
- required,
544
- shift,
556
+ label: ownLabel,
557
+ required: ownRequired,
558
+ shift: ownShift,
559
+ rows,
560
+ maxRows,
561
+ autoResize = false,
562
+ valueAtEnd = false,
545
563
  value,
546
564
  defaultValue,
547
565
  onChangeText,
@@ -554,6 +572,11 @@ export function InputField({
554
572
  ...rest
555
573
  }: InputProps & FieldExtras) {
556
574
  const theme = useTheme()
575
+ // A Field's label, floated in the field on Android (FloatLabelContext); the field's own wins
576
+ const floatLabel = useContext(FloatLabelContext)
577
+ const label = ownLabel ?? floatLabel?.label
578
+ const required = ownRequired ?? floatLabel?.required
579
+ const shift = ownShift ?? floatLabel?.shift
557
580
  const [focused, setFocused] = useState(false)
558
581
  const [own, setOwn] = useState(defaultValue ?? "")
559
582
  const text = value ?? own
@@ -570,6 +593,12 @@ export function InputField({
570
593
  const rowEnd = useContext(RowEndContext)
571
594
  const fillsRow = rowEnd != null && !barField
572
595
  const inRow = fillsRow && !theme.isAndroid
596
+ // A line of its own under a row's label, or alone in the row (the web's vertical or label-hidden `Field row`): the
597
+ // bare value on both platforms, from the row's text start; in a List with `columns` the value starts its column
598
+ const stacked = fillsRow && rowEnd?.stacked === true
599
+ const bare = inRow || stacked
600
+ const startAligned = stacked || rowEnd?.align === "start"
601
+ const multiline = rest.multiline === true
573
602
  // The row's value stands at its end: the right, or the left in a right-to-left row (a phone turns "right" over
574
603
  // itself, the web does not)
575
604
  const { ref: textBox, rtl } = useRTL<ComponentRef<typeof View>>()
@@ -600,13 +629,15 @@ export function InputField({
600
629
  )
601
630
  const look = barSearch
602
631
  ? { ...fieldLookOf, box: { ...fieldLookOf.box, ...androidGlass } as ViewStyle }
603
- : inRow
632
+ : bare
604
633
  ? {
605
634
  ...fieldLookOf,
606
- box: { minHeight: theme.length("--field-row-label-line-height", 22), opacity: disabled ? 0.5 : 1 } as ViewStyle,
607
- placeholder: theme.colors.labelTertiary,
635
+ box: { minHeight: theme.isAndroid ? fieldLookOf.text.lineHeight : theme.length("--field-row-label-line-height", 22), opacity: disabled ? 0.5 : 1 } as ViewStyle,
636
+ frame: null,
637
+ placeholder: theme.isAndroid ? fieldLookOf.placeholder : theme.colors.labelTertiary,
608
638
  text: { ...fieldLookOf.text, color: theme.colors.text },
609
639
  adornmentOffset: 0,
640
+ gutter: 0,
610
641
  }
611
642
  : fieldLookOf
612
643
  const floating = theme.isAndroid && label != null && !barField
@@ -637,12 +668,31 @@ export function InputField({
637
668
  // A 24dp icon stands 12 in, the text 12 past it (48 in); otherwise the text is 14 in (the outlined field), 21 in a
638
669
  // card's bare field, or 20 in a bar's search field. Android's search field keeps its text 48 from the end
639
670
  // (at a row's end the row sets the edge: a bare field keeps 14)
640
- const edge = barField && !search ? 20 : fillsRow && variant === "ghost" ? 14 : look.gutter
671
+ // A ghost value that starts a row's column, or (Android) stands at the row's end, has the row's insets for its own
672
+ const flush = fillsRow && variant === "ghost" && (rowEnd?.align === "start" || (theme.isAndroid && valueAtEnd))
673
+ const edge = barField && !search ? 20 : stacked || flush ? 0 : fillsRow && variant === "ghost" ? 14 : look.gutter
641
674
  const endEdge = search ? 48 : edge
642
675
  const sides: ViewStyle | null = theme.isAndroid
643
- ? { paddingStart: startAdornment ? 12 : edge, paddingEnd: endAdornment || showClear || androidClear ? 12 : endEdge }
676
+ ? stacked
677
+ ? { paddingStart: 0, paddingEnd: 0 }
678
+ : { paddingStart: startAdornment ? 12 : edge, paddingEnd: endAdornment || showClear || androidClear ? 12 : endEdge }
644
679
  : null
645
680
  const textStart = theme.isAndroid ? (startAdornment ? 48 : edge) : 0
681
+ // Above and below the text: a label floated inside a filled field (8 to 24) sets the text under it; Android centres
682
+ // a line in the field's height; iOS keeps 10 in its border (11 from the edge); a bare value none
683
+ const padding = bare
684
+ ? { top: 0, bottom: 0 }
685
+ : floating && !outlined
686
+ ? { top: 26, bottom: 10 }
687
+ : theme.isAndroid
688
+ ? { top: (look.height - look.text.lineHeight) / 2, bottom: (look.height - look.text.lineHeight) / 2 }
689
+ : { top: 10, bottom: 10 }
690
+ // A Textarea's lines: `rows` at least; with `autoResize` as many as its text takes (a hidden copy of the text, as
691
+ // wide as the field's, measures them), up to `maxRows` (the larger of `rows` and 10, as the web's)
692
+ const minLines = Math.max(1, Math.round(rows ?? 1))
693
+ const maxLines = Math.max(minLines, Math.round(maxRows ?? Math.max(minLines, 10)))
694
+ const [measured, setMeasured] = useState(0)
695
+ const lines = multiline && autoResize && measured > 0 ? Math.min(maxLines, Math.max(minLines, Math.round(measured / look.text.lineHeight))) : minLines
646
696
  // An outlined label floats to the text's start over the line (past a pill's round end), the cut 5 around it
647
697
  const floatedStart = pill ? look.height / 2 : 14
648
698
  const [labelWidth, setLabelWidth] = useState(0)
@@ -675,7 +725,7 @@ export function InputField({
675
725
  raised={!!barField?.raised}
676
726
  radius={look.height / 2}
677
727
  shift={shift}
678
- style={[styles.box, look.box, { gap: look.gap }, sides, style]}
728
+ style={[styles.box, look.box, { gap: look.gap }, multiline ? styles.boxTop : null, sides, style]}
679
729
  testID={testID}
680
730
  >
681
731
  {theme.isAndroid ? <FieldOutline frame={look.frame} cut={cut} motion={lineMotion} /> : null}
@@ -726,6 +776,18 @@ export function InputField({
726
776
  </Animated.View>
727
777
  </>
728
778
  ) : null}
779
+ {multiline && autoResize ? (
780
+ <NativeText
781
+ aria-hidden
782
+ accessibilityElementsHidden
783
+ importantForAccessibility="no-hide-descendants"
784
+ onLayout={(event) => setMeasured(event.nativeEvent.layout.height)}
785
+ style={[styles.mirror, look.text, theme.font("regular")]}
786
+ >
787
+ {/* A last empty line keeps its height: Text drops a trailing line break */}
788
+ {`${text || rest.placeholder || " "}\u200b`}
789
+ </NativeText>
790
+ ) : null}
729
791
  <TextInput
730
792
  {...rest}
731
793
  ref={setInput}
@@ -761,8 +823,12 @@ export function InputField({
761
823
  look.text,
762
824
  theme.font("regular"),
763
825
  // A label floated inside the field (8 to 24) sets the text under it
764
- floating && !outlined ? { paddingTop: 26, paddingBottom: 10 } : { paddingVertical: theme.isAndroid ? (look.height - look.text.lineHeight) / 2 : inRow ? 0 : 10 },
765
- inRow ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
826
+ { paddingTop: padding.top, paddingBottom: padding.bottom },
827
+ (inRow && !startAligned) || (fillsRow && valueAtEnd && !startAligned) ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
828
+ // A value in a row that the person cannot edit is the secondary label, as the web's phone rows (iOS's
829
+ // values of a row that only informs)
830
+ fillsRow && readOnly && !disabled ? { color: theme.colors.labelSecondary } : null,
831
+ multiline ? { height: lines * look.text.lineHeight + padding.top + padding.bottom, textAlignVertical: "top" } : null,
766
832
  ]}
767
833
  />
768
834
  </View>
@@ -834,72 +900,32 @@ export type TextFieldProps = InputProps & {
834
900
  */
835
901
  export function TextField({ label, description, errorMessage, required, invalid, ...input }: TextFieldProps) {
836
902
  const theme = useTheme()
837
- const error = errorMessage != null && errorMessage !== false && errorMessage !== ""
838
- const bad = invalid || error
839
- const help = error ? errorMessage : description
840
- // The help or the error describes the field: read after its label (a hint on a phone, `aria-describedby` on the
841
- // web). A caller's own hint wins; its described-by ids are kept with this one.
842
- const described = useDescription(help)
843
- const describedBy = [(input as DescribedBy)["aria-describedby"], (described.props as DescribedBy)["aria-describedby"]].filter(Boolean).join(" ") || undefined
844
- const describedProps = {
845
- ...described.props,
846
- ...(describedBy ? { "aria-describedby": describedBy } : null),
847
- ...(input.accessibilityHint != null ? { accessibilityHint: input.accessibilityHint } : null),
848
- }
849
- // Android shakes the field when an error message appears: flung left at 350dp/s on a spring of stiffness 600 at half
850
- // its critical damping, it swings back and settles where it stood
851
- const [shake] = useState(() => new Animated.Value(0))
852
- const hadError = useRef(error)
853
- useEffect(() => {
854
- const appeared = error && !hadError.current
855
- hadError.current = error
856
- if (!appeared || !theme.isAndroid || theme.reducedMotion) return
857
- shake.setValue(0)
858
- Animated.spring(shake, { toValue: 0, velocity: -350, ...stiffSpring(600, 0.5), useNativeDriver: false }).start()
859
- }, [error, shake, theme.isAndroid, theme.reducedMotion])
860
- if (theme.isAndroid) {
861
- return (
862
- <View style={styles.field}>
863
- <InputField {...input} {...describedProps} label={label} required={required} invalid={bad} shift={shake} />
864
- {help != null ? (
865
- // Android's help under a field: 14 in the gray of secondary text, or in the error color, at the text's 14
866
- // (dimmed with a disabled field)
867
- <Text
868
- nativeID={described.id}
869
- color={bad ? dangerText(theme) : theme.colors.textSecondary}
870
- accessibilityLiveRegion={error ? "polite" : undefined}
871
- style={{ fontSize: 14, lineHeight: 18, paddingHorizontal: 14, paddingTop: 6, opacity: input.disabled ? 0.5 : 1 }}
872
- >
873
- {help}
874
- </Text>
875
- ) : null}
876
- </View>
877
- )
878
- }
879
903
  return (
880
- <View style={[styles.field, { gap: 8 }]}>
881
- <Text weight="medium" style={{ fontSize: 15, lineHeight: 20 }} color={input.disabled ? "disabled" : "primary"}>
882
- {label}
883
- {required ? <Text color={theme.color("--color-text-danger")}> *</Text> : null}
884
- </Text>
885
- <InputField
886
- {...input}
887
- {...describedProps}
888
- accessibilityLabel={input.accessibilityLabel ?? (typeof label === "string" ? label : undefined)}
889
- required={required}
890
- invalid={bad}
891
- />
892
- {help != null ? (
893
- <Text
894
- nativeID={described.id}
895
- color={bad ? theme.color("--color-text-danger") : "secondary"}
896
- accessibilityLiveRegion={error ? "polite" : undefined}
897
- style={{ fontSize: theme.length("--mobile-field-error-font-size", 15), lineHeight: theme.length("--mobile-field-error-line-height", 20), marginTop: theme.length("--mobile-field-error-offset", 4) - 8 }}
898
- >
899
- {help}
900
- </Text>
901
- ) : null}
902
- </View>
904
+ <FieldStack
905
+ label={label}
906
+ required={required}
907
+ description={description}
908
+ errorMessage={errorMessage}
909
+ invalid={invalid}
910
+ disabled={input.disabled}
911
+ floating={theme.isAndroid}
912
+ describedBy={(input as DescribedBy)["aria-describedby"]}
913
+ hint={input.accessibilityHint}
914
+ >
915
+ {({ described, invalid: bad, shake }) =>
916
+ theme.isAndroid ? (
917
+ <InputField {...input} {...described} label={label} required={required} invalid={bad} shift={shake} />
918
+ ) : (
919
+ <InputField
920
+ {...input}
921
+ {...described}
922
+ accessibilityLabel={input.accessibilityLabel ?? (typeof label === "string" ? label : undefined)}
923
+ required={required}
924
+ invalid={bad}
925
+ />
926
+ )
927
+ }
928
+ </FieldStack>
903
929
  )
904
930
  }
905
931
 
@@ -913,15 +939,18 @@ const styles = StyleSheet.create({
913
939
  // Centered in the 48dp target
914
940
  adornmentPressed: { position: "absolute", top: 4, start: 4, width: 40, height: 40, borderRadius: 20 },
915
941
  box: { flexDirection: "row", alignItems: "center", alignSelf: "stretch" },
942
+ // A field of several lines keeps its adornments on its first line
943
+ boxTop: { alignItems: "flex-start" },
916
944
  grow: { flex: 1, minWidth: 0, justifyContent: "center" },
917
945
  // On the web a zero width leaves Chrome's `auto` focus ring drawn round the text: the field shows its focus itself
918
946
  input: { margin: 0, padding: 0, outlineWidth: 0, outlineStyle: "none" as "solid", minWidth: 0 },
919
947
  floating: { position: "absolute", start: 0, maxWidth: "100%", flexDirection: "row" },
920
948
  measure: { position: "absolute", start: 0, top: 0, opacity: 0 },
949
+ // As wide as the text, out of the flow and unseen
950
+ mirror: { position: "absolute", start: 0, end: 0, top: 0, opacity: 0 },
921
951
  underline: { position: "absolute", left: 0, right: 0, bottom: 0 },
922
952
  window: { position: "absolute", overflow: "hidden" },
923
953
  copy: { position: "absolute" },
924
954
  clear: { alignItems: "center", justifyContent: "center" },
925
955
  clearStretch: { alignSelf: "stretch" },
926
- field: { alignSelf: "stretch" },
927
956
  })