@plexui/react-native 0.1.1 → 0.2.1

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 +67 -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 +39 -19
  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 +23 -4
  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 +123 -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 +83 -20
  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
@@ -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
  })
@@ -0,0 +1,261 @@
1
+ import { createContext, isValidElement, useContext, type ReactElement, type ReactNode } from "react"
2
+ import { Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
+ import { flattenChildren } from "../../internal/children"
4
+ import { RowEndContext } from "../../internal/row"
5
+ import { useTheme } from "../../theme/ThemeProvider"
6
+ import { Button, buttonColors, type ButtonProps, type ControlSize } from "../Button/Button"
7
+ import { IconDefaultsProvider } from "../Icon/createIcon"
8
+ import { InputAdornmentButton, InputField, type InputProps } from "../Input/Input"
9
+ import { Text, type TextProps } from "../Text/Text"
10
+
11
+ type GroupState = { size: ControlSize; pill: boolean; disabled: boolean; invalid: boolean; row: boolean }
12
+
13
+ const GroupContext = createContext<GroupState | null>(null)
14
+
15
+ /** The size of a button in a group, a step under the field's (InputGroup.tsx). */
16
+ const BUTTON_SIZE: Record<ControlSize, ControlSize> = { "3xs": "3xs", "2xs": "3xs", xs: "3xs", sm: "3xs", md: "2xs", lg: "sm", xl: "md", "2xl": "lg", "3xl": "xl" }
17
+
18
+ export type InputGroupProps = {
19
+ /** @default "outline" */
20
+ variant?: "outline" | "soft"
21
+ /** @default "md" */
22
+ size?: ControlSize
23
+ /** A capsule. @default false */
24
+ pill?: boolean
25
+ /** @default false */
26
+ disabled?: boolean
27
+ /** @default false */
28
+ invalid?: boolean
29
+ /** One `InputGroup.Input` or `InputGroup.Textarea`, and `InputGroup.Addon`s around it. */
30
+ children: ReactNode
31
+ style?: StyleProp<ViewStyle>
32
+ testID?: string
33
+ }
34
+
35
+ export type InputGroupInputProps = Omit<InputProps, "variant" | "size" | "pill" | "startAdornment" | "endAdornment" | "multiline">
36
+ export type InputGroupTextareaProps = InputGroupInputProps & {
37
+ /** @default 3 */
38
+ rows?: number
39
+ autoResize?: boolean
40
+ maxRows?: number
41
+ }
42
+
43
+ export type InputGroupAddonAlign = "inline-start" | "inline-end" | "block-start" | "block-end"
44
+ export type InputGroupAddonProps = {
45
+ /**
46
+ * Where the addon sits: before or after the control on its line, or as a row above or below it (a Textarea's heading
47
+ * or counter). @default "inline-start"
48
+ */
49
+ align?: InputGroupAddonAlign
50
+ children: ReactNode
51
+ style?: StyleProp<ViewStyle>
52
+ }
53
+
54
+ export type InputGroupButtonProps = Omit<ButtonProps, "size"> & {
55
+ /** @default "secondary" */
56
+ color?: ButtonProps["color"]
57
+ }
58
+
59
+ export type InputGroupTextProps = TextProps
60
+
61
+ /** The control of a group: its props, read by the group (it is drawn by the group's field). */
62
+ function InputGroupInput(_props: InputGroupInputProps): ReactElement | null {
63
+ return null
64
+ }
65
+
66
+ function InputGroupTextarea(_props: InputGroupTextareaProps): ReactElement | null {
67
+ return null
68
+ }
69
+
70
+ /** Content beside, above or below the control: icons, text, buttons. */
71
+ function InputGroupAddon({ children, style }: InputGroupAddonProps) {
72
+ return <View style={[styles.addon, style]}>{children}</View>
73
+ }
74
+
75
+ /**
76
+ * A ghost Button sized from the group, a step under the field. An icon alone (`uniform`) is the field's adornment
77
+ * button: its 44pt (48dp) target around a 20pt (24dp) glyph in the field's icon gray.
78
+ */
79
+ function InputGroupButton({ color = "secondary", variant = "ghost", uniform = false, disabled, children, accessibilityLabel, onPress, style, ...rest }: InputGroupButtonProps) {
80
+ const group = useContext(GroupContext)
81
+ const theme = useTheme()
82
+ if (uniform && variant === "ghost" && group?.row && !theme.isAndroid) {
83
+ // In a row on iOS, as the web's on a phone: a 36pt square (the 44pt row control less 4 above and below) that ends
84
+ // at the row's inset, an 18pt symbol in the ghost button's color
85
+ const size = theme.length("--control-size-lg", 44) - 8
86
+ const off = disabled ?? group.disabled
87
+ return (
88
+ <Pressable
89
+ accessibilityRole="button"
90
+ accessibilityLabel={accessibilityLabel}
91
+ accessibilityState={{ disabled: off }}
92
+ disabled={off}
93
+ onPress={onPress ?? undefined}
94
+ style={({ pressed }) => [
95
+ styles.rowButton,
96
+ // It overhangs the row's line, as the web's, so the row keeps its 52
97
+ { width: size, height: size, marginVertical: (theme.length("--field-row-label-line-height", 22) - size) / 2, opacity: off || pressed ? 0.5 : 1 },
98
+ style,
99
+ ]}
100
+ >
101
+ <IconDefaultsProvider size={theme.length("--control-icon-size-md", 18)} color={buttonColors(theme, color, "ghost", false, false).text}>
102
+ {children}
103
+ </IconDefaultsProvider>
104
+ </Pressable>
105
+ )
106
+ }
107
+ if (uniform && variant === "ghost") {
108
+ return (
109
+ <InputAdornmentButton accessibilityLabel={accessibilityLabel ?? ""} disabled={disabled ?? group?.disabled} onPress={onPress ?? undefined} style={style}>
110
+ {children}
111
+ </InputAdornmentButton>
112
+ )
113
+ }
114
+ return (
115
+ <Button
116
+ {...rest}
117
+ color={color}
118
+ variant={variant}
119
+ uniform={uniform}
120
+ size={BUTTON_SIZE[group?.size ?? "md"]}
121
+ disabled={disabled ?? group?.disabled}
122
+ accessibilityLabel={accessibilityLabel}
123
+ onPress={onPress}
124
+ style={style}
125
+ >
126
+ {children}
127
+ </Button>
128
+ )
129
+ }
130
+
131
+ /** Plain text in an addon (a prefix, a unit, a counter): the field's type in the secondary label. */
132
+ function InputGroupText({ style, children, ...rest }: InputGroupTextProps) {
133
+ const theme = useTheme()
134
+ const group = useContext(GroupContext)
135
+ const type = theme.isAndroid
136
+ ? group?.row
137
+ ? styles.androidRowText
138
+ : styles.androidText
139
+ : { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) }
140
+ return (
141
+ <Text {...rest} color={theme.colors.labelSecondary} numberOfLines={1} style={[type, { opacity: group?.disabled ? 0.5 : 1 }, style]}>
142
+ {children}
143
+ </Text>
144
+ )
145
+ }
146
+
147
+ type AddonElement = ReactElement<InputGroupAddonProps>
148
+
149
+ /**
150
+ * A field with addons around its control: Plex UI's InputGroup. The addons on its line are the field's adornments
151
+ * (an icon, a prefix, a unit, a button), in the frame of an Input of the same `variant`, `size` and `pill`; block
152
+ * addons stand as rows above and below the control inside one frame. In a List row (a `Field row`) the row is the
153
+ * frame, as the web's on a phone: a prefix sits right before the value in the secondary label, a unit right after it
154
+ * ("72 kg"), a button at the row's end.
155
+ */
156
+ export function InputGroup({ variant = "outline", size = "md", pill = false, disabled = false, invalid = false, children, style, testID }: InputGroupProps) {
157
+ const theme = useTheme()
158
+ const rowEnd = useContext(RowEndContext)
159
+ const row = rowEnd != null
160
+ const parts = flattenChildren(children).filter(isValidElement)
161
+ const control = parts.find((part) => part.type === InputGroupInput || part.type === InputGroupTextarea) as
162
+ | ReactElement<InputGroupTextareaProps>
163
+ | undefined
164
+ const addons = parts.filter((part) => part.type === InputGroupAddon) as AddonElement[]
165
+ const at = (align: InputGroupAddonAlign) => addons.filter((addon) => (addon.props.align ?? "inline-start") === align)
166
+ const inline = (align: "inline-start" | "inline-end") => {
167
+ const found = at(align)
168
+ return found.length === 0 ? undefined : <View style={styles.addons}>{found}</View>
169
+ }
170
+ const multiline = control?.type === InputGroupTextarea
171
+ const own = control?.props ?? {}
172
+ const state: GroupState = { size, pill, disabled, invalid, row }
173
+ const field = (props: Partial<InputProps> & { rows?: number; autoResize?: boolean; maxRows?: number; valueAtEnd?: boolean }) => (
174
+ <InputField
175
+ {...own}
176
+ disabled={own.disabled ?? disabled}
177
+ invalid={own.invalid ?? invalid}
178
+ size={size}
179
+ pill={pill}
180
+ multiline={multiline}
181
+ rows={multiline ? (own.rows ?? 3) : undefined}
182
+ {...props}
183
+ />
184
+ )
185
+ if (row) {
186
+ // The row is the frame: the prefix right before the value, the unit 8 after it (as the web's "5 km"), a button at
187
+ // the end
188
+ const start = inline("inline-start")
189
+ const end = inline("inline-end")
190
+ // A text prefix is part of the value ("$0.00", as iOS writes it); an icon keeps a gap before the value
191
+ const textPrefix = at("inline-start").every((addon) =>
192
+ flattenChildren(addon.props.children).every((child) => typeof child === "string" || (isValidElement(child) && child.type === InputGroupText)),
193
+ )
194
+ return (
195
+ <GroupContext.Provider value={state}>
196
+ <View testID={testID} style={[styles.inRow, style]}>
197
+ {start != null ? <View style={{ marginEnd: textPrefix ? 0 : theme.isAndroid ? 4 : 8 }}>{start}</View> : null}
198
+ {/* On Android a value before its unit stands at the row's end, as a value row's ("72 kg") */}
199
+ <View style={styles.grow}>{field({ variant: "ghost", style: theme.isAndroid ? styles.flush : undefined, valueAtEnd: theme.isAndroid && rowEnd.align !== "start" })}</View>
200
+ {end != null ? <View style={{ marginStart: theme.isAndroid ? 4 : 8 }}>{end}</View> : null}
201
+ </View>
202
+ </GroupContext.Provider>
203
+ )
204
+ }
205
+ const above = at("block-start")
206
+ const below = at("block-end")
207
+ if (above.length === 0 && below.length === 0) {
208
+ return (
209
+ <GroupContext.Provider value={state}>
210
+ {field({ variant, startAdornment: inline("inline-start"), endAdornment: inline("inline-end"), style, testID })}
211
+ </GroupContext.Provider>
212
+ )
213
+ }
214
+ // Block addons: rows above and below the control in one frame, the control bare between them
215
+ const radius = theme.isAndroid ? 8 : theme.length("--control-radius-lg", 10)
216
+ return (
217
+ <GroupContext.Provider value={state}>
218
+ <View
219
+ testID={testID}
220
+ style={[
221
+ styles.block,
222
+ {
223
+ borderRadius: pill ? 9999 : radius,
224
+ borderWidth: variant === "outline" ? StyleSheet.hairlineWidth * 2 : 0,
225
+ borderColor: invalid ? theme.color("--color-border-danger-outline", theme.colors.border) : theme.colors.border,
226
+ backgroundColor: variant === "soft" ? theme.color("--input-soft-background-color", theme.colors.surfaceSecondary) : undefined,
227
+ opacity: disabled ? 0.5 : 1,
228
+ },
229
+ style,
230
+ ]}
231
+ >
232
+ {above.length > 0 ? <View style={[styles.blockRow, styles.blockTop]}>{above}</View> : null}
233
+ {field({ variant: "ghost", startAdornment: inline("inline-start"), endAdornment: inline("inline-end") })}
234
+ {below.length > 0 ? <View style={[styles.blockRow, styles.blockBottom]}>{below}</View> : null}
235
+ </View>
236
+ </GroupContext.Provider>
237
+ )
238
+ }
239
+
240
+ InputGroup.Input = InputGroupInput
241
+ InputGroup.Textarea = InputGroupTextarea
242
+ InputGroup.Addon = InputGroupAddon
243
+ InputGroup.Button = InputGroupButton
244
+ InputGroup.Text = InputGroupText
245
+
246
+ export { InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea }
247
+
248
+ const styles = StyleSheet.create({
249
+ addon: { flexDirection: "row", alignItems: "center", gap: 8 },
250
+ addons: { flexDirection: "row", alignItems: "center", gap: 8 },
251
+ inRow: { flex: 1, minWidth: 0, flexDirection: "row", alignItems: "center" },
252
+ grow: { flex: 1, minWidth: 0 },
253
+ rowButton: { alignItems: "center", justifyContent: "center" },
254
+ flush: { paddingStart: 0, paddingEnd: 0 },
255
+ androidText: { fontSize: 16, lineHeight: 20 },
256
+ androidRowText: { fontSize: 16, lineHeight: 20 },
257
+ block: { alignSelf: "stretch", overflow: "hidden" },
258
+ blockRow: { paddingHorizontal: 12, flexDirection: "row", alignItems: "center", gap: 8 },
259
+ blockTop: { paddingTop: 10 },
260
+ blockBottom: { paddingBottom: 10 },
261
+ })