@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
@@ -2,6 +2,7 @@ import { useId, useState, type ReactNode } from "react"
2
2
  import { Animated, KeyboardAvoidingView, Platform, Pressable, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native"
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context"
4
4
  import { Glass } from "../../internal/Glass"
5
+ import { useRipple } from "../../internal/ripple"
5
6
  import { useKeyboardHeight } from "../../internal/keyboard"
6
7
  import { androidDialogMotion, canTransformGlass, glassOpacity, iosDim, Overlay, ANDROID_DIALOG, ANDROID_DIM } from "../../internal/Overlay"
7
8
  import { withAlpha, dangerText } from "../../theme/material"
@@ -42,7 +43,7 @@ export type DialogProps = {
42
43
  /**
43
44
  * A dialog that asks for a decision: on iOS the alert of iOS 26 (UIAlertController `.alert`: 320 wide, glass, radius
44
45
  * 34, capsule actions 48 tall, `--dialog-alert-*`, Dialog.module.css), on Android a flat alert (at most 356 wide,
45
- * radius 20, a Medium 20 title over 16 text, text buttons in the accent at the end, Android's dialog animation). The
46
+ * radius 21, a Medium 20 title over 16 text, text buttons in the accent at the end, Android's dialog animation). The
46
47
  * web Dialog's `mobileVariant="alert"` as one call; a sheet is `BottomSheet`.
47
48
  */
48
49
  export function Dialog({ open, onOpenChange, title, description, actions = [], children, mobileLayout, dismissible, testID }: DialogProps) {
@@ -183,8 +184,11 @@ export type ChoiceDialogProps = {
183
184
  onClose: () => void
184
185
  /** The setting's name, over the rows. */
185
186
  title?: ReactNode
186
- /** The one button, which closes the dialog. */
187
+ /** The button that closes the dialog with no change (the one button of a single choice). */
187
188
  cancelLabel: string
189
+ /** A multiple choice's button after Cancel, which applies the rows checked (`onOk`) and closes the dialog. */
190
+ okLabel?: string
191
+ onOk?: () => void
188
192
  /** The rows, across the dialog's whole width; they scroll under the title when the screen is short. */
189
193
  children: ReactNode
190
194
  /** Props for the element that holds the rows (its role and name). */
@@ -193,10 +197,11 @@ export type ChoiceDialogProps = {
193
197
  }
194
198
 
195
199
  /**
196
- * Android's single-choice alert (one option picked from a list): the dialog's panel, its title,
197
- * rows across its width and one Cancel button. Select's picker on Android; not part of the public API.
200
+ * Android's choice alert: the dialog's panel, its title and rows across its width; one Cancel button for a single
201
+ * choice (a row picks and closes), Cancel and OK at the end, 8 apart, for a multiple one (the rows check, OK applies).
202
+ * Select's picker on Android; not part of the public API.
198
203
  */
199
- export function ChoiceDialog({ open, onClose, title, cancelLabel, children, listProps, testID }: ChoiceDialogProps) {
204
+ export function ChoiceDialog({ open, onClose, title, cancelLabel, okLabel, onOk, children, listProps, testID }: ChoiceDialogProps) {
200
205
  const theme = useTheme()
201
206
  const ids = { title: useId(), description: useId() }
202
207
  const a11y =
@@ -213,7 +218,14 @@ export function ChoiceDialog({ open, onClose, title, cancelLabel, children, list
213
218
  <AndroidDialog
214
219
  theme={theme}
215
220
  title={title}
216
- actions={[{ label: cancelLabel, testID: testID ? `${testID}-cancel` : undefined }]}
221
+ actions={
222
+ okLabel != null
223
+ ? [
224
+ { label: cancelLabel, variant: "cancel", testID: testID ? `${testID}-cancel` : undefined },
225
+ { label: okLabel, preferred: true, onPress: onOk, testID: testID ? `${testID}-ok` : undefined },
226
+ ]
227
+ : [{ label: cancelLabel, testID: testID ? `${testID}-cancel` : undefined }]
228
+ }
217
229
  run={run}
218
230
  ids={ids}
219
231
  list={<View {...listProps}>{children}</View>}
@@ -366,27 +378,14 @@ function AndroidDialog({ theme, title, description, actions, run, ids, children,
366
378
  const order = stacked ? [...bar.keys()].reverse() : [...bar.keys()]
367
379
  const button = (index: number) => {
368
380
  const action = bar[index]
369
- // Android's dialog button: Medium 16 in the accent, red for a destructive one, half faded when
370
- // disabled; its press a pill of the label's color at 10%
371
- const color = action.variant === "destructive" ? dangerText(theme) : m.primary
372
381
  return (
373
- <Pressable
382
+ <AndroidDialogButton
374
383
  key={actions.indexOf(action)}
375
- accessibilityRole="button"
376
- accessibilityState={{ disabled: !!action.disabled }}
377
- disabled={action.disabled}
378
- onPress={() => run(action)}
379
- onLayout={(event) => {
380
- const next = event.nativeEvent.layout.width
381
- setWidths((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next })))
382
- }}
383
- testID={action.testID}
384
- style={({ pressed }) => [styles.androidButton, { opacity: action.disabled ? 0.5 : 1 }, pressed ? { backgroundColor: withAlpha(color, 0.1) } : null]}
385
- >
386
- <Text color={color} style={[styles.androidLabel, { ...theme.font("medium") }]}>
387
- {action.label}
388
- </Text>
389
- </Pressable>
384
+ theme={theme}
385
+ action={action}
386
+ run={run}
387
+ onWidth={(next) => setWidths((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next })))}
388
+ />
390
389
  )
391
390
  }
392
391
  return (
@@ -417,7 +416,7 @@ function AndroidDialog({ theme, title, description, actions, run, ids, children,
417
416
  </ScrollView>
418
417
  )}
419
418
  {bar.length ? (
420
- <View onLayout={(event) => setRoom(event.nativeEvent.layout.width - 16)} style={stacked ? styles.androidStack : [styles.androidActions, list != null ? styles.androidListActions : null]}>
419
+ <View onLayout={(event) => setRoom(event.nativeEvent.layout.width - 16)} style={stacked ? styles.androidStack : styles.androidActions}>
421
420
  {order.map((index) =>
422
421
  // The neutral actions at the start, a space, then the negative and the positive
423
422
  !stacked && index === neutral.length && neutral.length ? [<View key="space" style={styles.grow} />, button(index)] : button(index),
@@ -428,6 +427,36 @@ function AndroidDialog({ theme, title, description, actions, run, ids, children,
428
427
  )
429
428
  }
430
429
 
430
+ /**
431
+ * Android's dialog button: Medium 16 in the accent, red for a destructive one, half faded when disabled; its press the
432
+ * ripple of the label's color at 10% from the touch point, clipped to its 20dp pill (the platform's on a device).
433
+ */
434
+ function AndroidDialogButton({ theme, action, run, onWidth }: { theme: Theme; action: DialogAction; run: (action: DialogAction) => void; onWidth: (width: number) => void }) {
435
+ const color = action.variant === "destructive" ? dangerText(theme) : theme.material.primary
436
+ const press = withAlpha(color, 0.1)
437
+ const nativeRipple = Platform.OS === "android"
438
+ const ripple = useRipple(press, !nativeRipple, theme.reducedMotion)
439
+ return (
440
+ <Pressable
441
+ accessibilityRole="button"
442
+ accessibilityState={{ disabled: !!action.disabled }}
443
+ disabled={action.disabled}
444
+ onPress={() => run(action)}
445
+ onPressIn={nativeRipple ? undefined : ripple.start}
446
+ onPressOut={nativeRipple ? undefined : ripple.end}
447
+ android_ripple={nativeRipple ? { color: press, foreground: true } : undefined}
448
+ onLayout={(event) => onWidth(event.nativeEvent.layout.width)}
449
+ testID={action.testID}
450
+ style={[styles.androidButton, { opacity: action.disabled ? 0.5 : 1 }]}
451
+ >
452
+ {ripple.layer}
453
+ <Text color={color} style={[styles.androidLabel, { ...theme.font("medium") }]}>
454
+ {action.label}
455
+ </Text>
456
+ </Pressable>
457
+ )
458
+ }
459
+
431
460
  /** The space between dialog buttons, in a row and stacked. */
432
461
  const GAP = 8
433
462
 
@@ -441,21 +470,22 @@ const styles = StyleSheet.create({
441
470
  grow: { flex: 1, flexBasis: 0 },
442
471
  centered: { textAlign: "center" },
443
472
  iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: 16, borderCurve: "continuous" },
444
- // Android's alert: 20dp corners; the text 24 in, the title 19 from the top and 10 over the message, the
445
- // message 20 over the buttons
446
- android: { flexShrink: 1, borderRadius: 20, overflow: "hidden" },
447
- androidText: { paddingHorizontal: 24, paddingTop: 19, paddingBottom: 20, gap: 10 },
473
+ // Android's alert: 21dp corners (the catalog's); the text 24 in. Measured on the reference's alerts: the title's
474
+ // baseline 40 under the top, the message's first 33 under it in lines 18.75 apart (16sp Roboto's), its last 59
475
+ // over the buttons' (Roboto's font padding sets these 2 to 3 lower than the layout's 19, 10 and 20 would)
476
+ android: { flexShrink: 1, borderRadius: 21, overflow: "hidden" },
477
+ androidText: { paddingHorizontal: 24, paddingTop: 21, paddingBottom: 21, gap: 13 },
448
478
  androidTitle: { fontSize: 20, lineHeight: 24 },
449
- // Over a list the title keeps its 24 at the sides and 19 above, and stands 14 over the rows
450
- androidListTitle: { paddingHorizontal: 24, paddingTop: 19, paddingBottom: 14 },
479
+ // Over a list the title keeps its 24 at the sides, its line 21 under the panel's top (its capitals 25 under it and
480
+ // its baseline 40, as the reference's) and 11 over the rows, which start 56 under the top (the first radio at 71), as
481
+ // the web's
482
+ androidListTitle: { paddingHorizontal: 24, paddingTop: 21, paddingBottom: 11 },
451
483
  // A list with no title starts 8 under the panel's top
452
484
  androidListTop: { paddingTop: 8 },
453
- androidMessage: { fontSize: 16, lineHeight: 22 },
485
+ androidMessage: { fontSize: 16, lineHeight: 18.75 },
454
486
  androidContent: { marginTop: 6 },
455
- // The button row: 52 tall (6 over and under its 40dp buttons), 8 in from the sides
456
- androidActions: { flexDirection: "row", justifyContent: "flex-end", alignItems: "center", gap: GAP, paddingHorizontal: 8, paddingVertical: 6 },
457
- // Under a list of choices the row is 56: 8 over and under the buttons (measured on the platform's single-choice dialog)
458
- androidListActions: { paddingVertical: 8 },
487
+ // The button row: 56 tall (8 over and under its 40dp buttons, measured on the reference's alerts), 8 in from the sides
488
+ androidActions: { flexDirection: "row", justifyContent: "flex-end", alignItems: "center", gap: GAP, paddingHorizontal: 8, paddingVertical: 8 },
459
489
  // Stacked: 8 over and under the 40dp buttons (two make 96)
460
490
  androidStack: { alignItems: "flex-end", paddingHorizontal: 8, paddingVertical: 8 },
461
491
  // Android's dialog button: 40 tall, at least 64 wide, 12 at the sides; at least 40, so a larger font grows it
@@ -467,6 +497,7 @@ const styles = StyleSheet.create({
467
497
  paddingHorizontal: 12,
468
498
  paddingVertical: 8,
469
499
  borderRadius: 20,
500
+ overflow: "hidden",
470
501
  alignItems: "center",
471
502
  justifyContent: "center",
472
503
  },
@@ -0,0 +1,227 @@
1
+ import { cloneElement, isValidElement, useContext, useEffect, type ReactElement, type ReactNode } from "react"
2
+ import { StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
+ import ExclamationMarkCircle from "../../icons/plex/ExclamationMarkCircle"
4
+ import { textOf } from "../../internal/children"
5
+ import { FieldStack, FloatLabelContext } from "../../internal/fieldStack"
6
+ import { RowEndContext } from "../../internal/row"
7
+ import { dangerText } from "../../theme/material"
8
+ import { useTheme } from "../../theme/ThemeProvider"
9
+ import { Input } from "../Input/Input"
10
+ import { ListItem, ListStackedRow } from "../List/List"
11
+ import { Text } from "../Text/Text"
12
+ import { Textarea } from "../Textarea/Textarea"
13
+
14
+ /** What a Field hands its control: its name, the description's link and the invalid state. */
15
+ export type FieldControlProps = {
16
+ /** The label's text, the control's name (a child's own name wins). */
17
+ accessibilityLabel?: string
18
+ /** The description or the error: a hint on a phone. */
19
+ accessibilityHint?: string
20
+ /** The description or the error on the web (react-native-web). */
21
+ "aria-describedby"?: string
22
+ /** The field has an error. */
23
+ invalid: boolean
24
+ }
25
+
26
+ export type FieldProps = {
27
+ /** The label's text. It names the control. */
28
+ label: ReactNode
29
+ /** The label is not drawn; it still names the control. On a row the value or placeholder starts at the row's edge. */
30
+ hideLabel?: boolean
31
+ /** Words that explain the field, under it (on a row under its label). */
32
+ description?: ReactNode
33
+ /** An error under the control; it marks the control invalid. */
34
+ errorMessage?: ReactNode
35
+ /** Content at the end of the label's line, such as a link that acts on the field. */
36
+ labelAction?: ReactNode
37
+ /** An asterisk after the label (visual only). */
38
+ required?: boolean
39
+ /** @default "horizontal" on a row with a visible label, else "vertical" */
40
+ orientation?: "vertical" | "horizontal"
41
+ /** One line of a List, as the web's `Field row` in a FieldGroup. */
42
+ row?: boolean
43
+ /** On a row, the control takes the rest of the line after the label. */
44
+ fill?: boolean
45
+ /** On a row, a symbol before the label (a ListItem's `leading`). */
46
+ icon?: ReactNode
47
+ /** On a row, a control at the end of the row after the row's own control. */
48
+ action?: ReactNode
49
+ /** The field is unavailable as a whole: its label dims with the control (the web's `data-disabled` on a row). */
50
+ disabled?: boolean
51
+ /** The control, given the field's name, description and invalid state; or a function that places them itself. */
52
+ children: ReactElement | ((control: FieldControlProps) => ReactNode)
53
+ style?: StyleProp<ViewStyle>
54
+ testID?: string
55
+ }
56
+
57
+ type ChildProps = { accessibilityLabel?: string; "aria-label"?: string; invalid?: boolean; disabled?: boolean }
58
+
59
+ /** A control a Field floats its label in on Android: the outlined field of an Input or a Textarea. */
60
+ const floats = (child: ReactNode) => isValidElement(child) && (child.type === Input || child.type === Textarea)
61
+
62
+ /**
63
+ * A label, a description and an error around a control, linked to it: Plex UI's Field. On its own the label stands over
64
+ * the control (TextField's stack: iOS 15/20 Medium 8 above it, the help 4 under it; on Android an Input or a Textarea
65
+ * floats the label in its outlined field). With `row` it is a line of a List, as the web's `Field row` on a phone: the
66
+ * label at the start and the control at the end (a ListItem), or with `orientation="vertical"` or `hideLabel` the value
67
+ * a line of its own under the label (iOS: 15/20 in the secondary label, 13 above and below).
68
+ */
69
+ export function Field({
70
+ label,
71
+ hideLabel = false,
72
+ description,
73
+ errorMessage,
74
+ labelAction,
75
+ required = false,
76
+ orientation,
77
+ row = false,
78
+ fill = false,
79
+ icon,
80
+ action,
81
+ disabled,
82
+ children,
83
+ style,
84
+ testID,
85
+ }: FieldProps) {
86
+ const theme = useTheme()
87
+ const name = textOf(label) || undefined
88
+ const error = errorMessage != null && errorMessage !== false && errorMessage !== ""
89
+ const element = typeof children === "function" ? null : (children as ReactElement<ChildProps>)
90
+ const own = element?.props ?? {}
91
+ // The child's own name wins, as the web's
92
+ const control = (extra: Record<string, unknown>, bad: boolean): ReactNode => {
93
+ const props: FieldControlProps = { accessibilityLabel: own.accessibilityLabel ?? own["aria-label"] ?? name, invalid: bad || own.invalid === true, ...extra }
94
+ if (typeof children === "function") return children(props)
95
+ // A row is the frame of its field, whatever its variant, as the web's rows on a phone; beside the label the value
96
+ // ends at the row's end on Android too (the web's ghost row value), or starts the column of a List with `columns`
97
+ return cloneElement(children as ReactElement<Record<string, unknown>>, row && floats(element) ? { ...props, variant: "ghost", valueAtEnd: true } : props)
98
+ }
99
+ const asterisk = required ? <Text color={theme.isAndroid ? dangerText(theme) : theme.color("--color-text-danger")}> *</Text> : null
100
+ if (row) {
101
+ const vertical = hideLabel || (orientation ?? "horizontal") === "vertical"
102
+ if (vertical) {
103
+ return (
104
+ <ListStackedRow
105
+ label={hideLabel ? undefined : <>{label}{asterisk}</>}
106
+ description={description}
107
+ error={errorMessage}
108
+ disabled={disabled}
109
+ action={action ?? labelAction}
110
+ testID={testID}
111
+ >
112
+ {control({}, error)}
113
+ </ListStackedRow>
114
+ )
115
+ }
116
+ const end = control({}, error)
117
+ const ends = fill ? <FillEnd>{end}</FillEnd> : end
118
+ return (
119
+ <ListItem
120
+ label={<>{label}{asterisk}</>}
121
+ description={description}
122
+ error={errorMessage}
123
+ leading={icon}
124
+ disabled={disabled}
125
+ accessibilityLabel={name}
126
+ testID={testID}
127
+ trailing={action != null ? <View style={styles.ends}>{ends}{action}</View> : ends}
128
+ />
129
+ )
130
+ }
131
+ const dimmed = disabled ?? own.disabled === true
132
+ const floating = theme.isAndroid && !hideLabel && (orientation ?? "vertical") === "vertical" && floats(element)
133
+ const stack = (
134
+ <FieldStack
135
+ label={label}
136
+ hideLabel={hideLabel || orientation === "horizontal"}
137
+ required={required}
138
+ description={description}
139
+ errorMessage={errorMessage}
140
+ labelAction={orientation === "horizontal" ? undefined : labelAction}
141
+ disabled={dimmed}
142
+ floating={floating}
143
+ style={orientation === "horizontal" ? styles.grow : style}
144
+ testID={orientation === "horizontal" ? undefined : testID}
145
+ >
146
+ {({ described, invalid, shake }) =>
147
+ floating ? (
148
+ <FloatLabelContext.Provider value={{ label, required, shift: shake }}>{control(described, invalid)}</FloatLabelContext.Provider>
149
+ ) : (
150
+ control(described, invalid)
151
+ )
152
+ }
153
+ </FieldStack>
154
+ )
155
+ if (orientation !== "horizontal") return stack
156
+ // Beside the control: the label in its column, 40% of the field, as the web's horizontal Field
157
+ return (
158
+ <View testID={testID} style={[styles.horizontal, style]}>
159
+ <View style={[styles.column, { minHeight: theme.isAndroid ? 50 : theme.length("--control-size-lg", 44) }]}>
160
+ <Text weight="medium" color={dimmed ? "disabled" : theme.isAndroid ? theme.colors.textSecondary : "primary"} style={theme.isAndroid ? styles.androidLabel : styles.iosLabel}>
161
+ {label}
162
+ {asterisk}
163
+ </Text>
164
+ {labelAction}
165
+ </View>
166
+ {stack}
167
+ </View>
168
+ )
169
+ }
170
+
171
+ /** A row's end that takes the rest of the line after the label (`fill`). */
172
+ function FillEnd({ children }: { children: ReactNode }) {
173
+ const rowEnd = useContext(RowEndContext)
174
+ useEffect(() => {
175
+ if (rowEnd == null) return
176
+ rowEnd.fill(true)
177
+ return () => rowEnd.fill(false)
178
+ }, [rowEnd])
179
+ return <View style={styles.grow}>{children}</View>
180
+ }
181
+
182
+ export type FieldErrorProps = {
183
+ children: ReactNode
184
+ /** The exclamation mark before the message (iOS). Turn it off where the message stands alone. @default true */
185
+ icon?: boolean
186
+ nativeID?: string
187
+ style?: StyleProp<ViewStyle>
188
+ testID?: string
189
+ }
190
+
191
+ /**
192
+ * A form's error message, announced when it appears: Plex UI's FieldError. iOS: 15/20 in the danger color after a 16pt
193
+ * exclamation mark, 4 apart (`--mobile-field-error-*`); Android: the help's 14sp in the error color, with no mark.
194
+ */
195
+ export function FieldError({ children, icon = true, nativeID, style, testID }: FieldErrorProps) {
196
+ const theme = useTheme()
197
+ if (theme.isAndroid) {
198
+ return (
199
+ <Text nativeID={nativeID} testID={testID} color={dangerText(theme)} accessibilityLiveRegion="polite" style={[styles.androidError, style as never]}>
200
+ {children}
201
+ </Text>
202
+ )
203
+ }
204
+ const color = theme.color("--field-error-color", theme.color("--color-text-danger-outline", theme.color("--color-text-danger")))
205
+ const line = theme.length("--mobile-field-error-line-height", 20)
206
+ const size = theme.length("--mobile-field-error-icon-size", 16)
207
+ return (
208
+ <View nativeID={nativeID} testID={testID} accessibilityLiveRegion="polite" style={[styles.error, { gap: theme.length("--mobile-field-error-icon-gap", 4) }, style]}>
209
+ {icon ? <ExclamationMarkCircle size={size} color={color} style={{ marginTop: (line - size) / 2 }} /> : null}
210
+ <Text color={color} style={[styles.shrink, { fontSize: theme.length("--mobile-field-error-font-size", 15), lineHeight: line }]}>
211
+ {children}
212
+ </Text>
213
+ </View>
214
+ )
215
+ }
216
+
217
+ const styles = StyleSheet.create({
218
+ grow: { flex: 1, minWidth: 0 },
219
+ shrink: { flexShrink: 1 },
220
+ ends: { flexDirection: "row", alignItems: "center", gap: 8 },
221
+ horizontal: { alignSelf: "stretch", flexDirection: "row", alignItems: "flex-start", gap: 16 },
222
+ column: { width: "40%", justifyContent: "center", gap: 4 },
223
+ iosLabel: { fontSize: 15, lineHeight: 20 },
224
+ androidLabel: { fontSize: 14, lineHeight: 18 },
225
+ error: { flexDirection: "row", alignItems: "flex-start" },
226
+ androidError: { fontSize: 14, lineHeight: 18 },
227
+ })
@@ -0,0 +1,144 @@
1
+ import { useState, type ReactNode } from "react"
2
+ import type { StyleProp, ViewStyle } from "react-native"
3
+ import Eye from "../../icons/plex/Eye"
4
+ import EyeOff from "../../icons/plex/EyeOff"
5
+ import { FieldStack } from "../../internal/fieldStack"
6
+ import { useTheme } from "../../theme/ThemeProvider"
7
+ import { Field } from "../Field/Field"
8
+ import { Input, InputField, type InputProps } from "../Input/Input"
9
+ import { List, useInList } from "../List/List"
10
+ import { Textarea } from "../Textarea/Textarea"
11
+
12
+ export type FloatingLabelInputProps = Omit<InputProps, "variant" | "size" | "invalid" | "multiline" | "secureTextEntry" | "pill"> & {
13
+ /** The field's name: on Android it floats in the outlined field; on iOS it is the placeholder of its cell. */
14
+ label: string
15
+ /** An error under the field (iOS: inside the cell); it marks the field invalid. */
16
+ errorMessage?: string
17
+ /** @default false (true with an `errorMessage`) */
18
+ invalid?: boolean
19
+ /** Words under the field (iOS: the footer under its cell). */
20
+ description?: ReactNode
21
+ /**
22
+ * The kind of value: `password` hides it (with the eye that shows it, `revealable`); `email`, `tel`, `url` and
23
+ * `number` bring their keyboard. @default "text"
24
+ */
25
+ type?: "text" | "password" | "email" | "tel" | "url" | "number"
26
+ /** The eye at the end that shows or hides the value. @default true for `type="password"` with no `endAdornment` */
27
+ revealable?: boolean
28
+ /** Called with the new state each time the eye is pressed. */
29
+ onRevealedChange?: (revealed: boolean) => void
30
+ /** Several lines (a Textarea). @default false */
31
+ multiline?: boolean
32
+ /** The lines of a `multiline` field. @default 2 */
33
+ rows?: number
34
+ /**
35
+ * Where the label rests once it floats (Android): on the outline (`border`), or inside a filled box with the value
36
+ * under it (`inside`). @default "border"
37
+ */
38
+ labelPlacement?: "border" | "inside"
39
+ /** A capsule (the web's default). Android keeps the outlined field's 8dp corners unless it is set. */
40
+ pill?: boolean
41
+ style?: StyleProp<ViewStyle>
42
+ }
43
+
44
+ const KEYBOARD: Record<NonNullable<FloatingLabelInputProps["type"]>, Partial<InputProps>> = {
45
+ text: {},
46
+ password: { autoCapitalize: "none", autoCorrect: false },
47
+ email: { inputMode: "email", autoCapitalize: "none", autoCorrect: false },
48
+ tel: { inputMode: "tel" },
49
+ url: { inputMode: "url", autoCapitalize: "none", autoCorrect: false },
50
+ number: { inputMode: "decimal" },
51
+ }
52
+
53
+ /**
54
+ * A text field named by a label that floats into its frame: Plex UI's FloatingLabelInput. Android: the outlined field,
55
+ * its label 16sp at rest that springs to 12sp on the outline as the field takes focus or a value (or into a filled
56
+ * box with `labelPlacement="inside"`), the help 14sp under it and a shake on an error, as TextField. iOS has no
57
+ * floating label: the field is a cell named by its placeholder, as an iOS form (the web's phone view, a label-hidden
58
+ * `Field row`): a row of its List, or a List of its own with the description in its footer.
59
+ */
60
+ export function FloatingLabelInput({
61
+ label,
62
+ errorMessage,
63
+ invalid: invalidProp,
64
+ description,
65
+ type = "text",
66
+ revealable: revealableProp,
67
+ onRevealedChange,
68
+ multiline = false,
69
+ rows = 2,
70
+ labelPlacement = "border",
71
+ pill,
72
+ endAdornment,
73
+ disabled = false,
74
+ style,
75
+ testID,
76
+ accessibilityLabel,
77
+ ...rest
78
+ }: FloatingLabelInputProps) {
79
+ const theme = useTheme()
80
+ const inList = useInList()
81
+ const [revealed, setRevealed] = useState(false)
82
+ const error = errorMessage != null && errorMessage !== ""
83
+ const invalid = invalidProp ?? error
84
+ const revealable = revealableProp ?? (type === "password" && endAdornment == null)
85
+ const secure = (type === "password" || revealable) && !revealed && !multiline
86
+ const reveal = () => {
87
+ const next = !revealed
88
+ setRevealed(next)
89
+ onRevealedChange?.(next)
90
+ }
91
+ const eye = revealable && !multiline ? (
92
+ <Input.AdornmentButton accessibilityLabel={revealed ? "Hide" : "Show"} selected={revealed} disabled={disabled} onPress={reveal}>
93
+ {revealed ? <EyeOff /> : <Eye />}
94
+ </Input.AdornmentButton>
95
+ ) : null
96
+ const end =
97
+ endAdornment != null && eye != null ? (
98
+ <>
99
+ {endAdornment}
100
+ {eye}
101
+ </>
102
+ ) : (endAdornment ?? eye ?? undefined)
103
+ const field = {
104
+ ...KEYBOARD[type],
105
+ ...rest,
106
+ disabled,
107
+ invalid,
108
+ secureTextEntry: secure,
109
+ endAdornment: multiline ? undefined : end,
110
+ accessibilityLabel: accessibilityLabel ?? label,
111
+ }
112
+ if (theme.isAndroid) {
113
+ // The outlined field with its label floating on the line, or a filled box with the label inside
114
+ return (
115
+ <FieldStack label={label} description={description} errorMessage={errorMessage} invalid={invalid} disabled={disabled} floating style={style} testID={testID}>
116
+ {({ described, invalid: bad, shake }) => (
117
+ <InputField
118
+ {...field}
119
+ {...described}
120
+ variant={labelPlacement === "inside" ? "soft" : "outline"}
121
+ pill={labelPlacement === "border" && pill === true}
122
+ label={label}
123
+ invalid={bad}
124
+ shift={shake}
125
+ multiline={multiline}
126
+ rows={multiline ? rows : undefined}
127
+ />
128
+ )}
129
+ </FieldStack>
130
+ )
131
+ }
132
+ // iOS: a cell named by its placeholder, its error inside it
133
+ const cell = (
134
+ <Field row hideLabel label={label} description={inList ? description : undefined} errorMessage={errorMessage} disabled={disabled} testID={inList ? testID : undefined}>
135
+ {multiline ? <Textarea {...field} placeholder={rest.placeholder ?? label} rows={1} autoResize maxRows={Math.max(rows, 10)} /> : <Input {...field} placeholder={rest.placeholder ?? label} />}
136
+ </Field>
137
+ )
138
+ if (inList) return cell
139
+ return (
140
+ <List footer={description} testID={testID} style={style}>
141
+ {cell}
142
+ </List>
143
+ )
144
+ }
@@ -1,5 +1,5 @@
1
1
  import { createContext, createElement, memo, useContext, type ComponentType, type ReactNode } from "react"
2
- import { StyleSheet, type StyleProp, type ViewStyle } from "react-native"
2
+ import { Platform, StyleSheet, type StyleProp, type ViewStyle } from "react-native"
3
3
  import Svg, { Circle, Ellipse, G, Line, Path, Polygon, Polyline, Rect } from "react-native-svg"
4
4
  import { useTheme } from "../../theme/ThemeProvider"
5
5
 
@@ -64,6 +64,20 @@ function renderNodes(nodes: IconNode[], color: string, accent: string, keyPrefix
64
64
  })
65
65
  }
66
66
 
67
+ /** A named icon is an image for VoiceOver and TalkBack; an unnamed one is hidden from them. */
68
+ const nativeA11y = (label: string | undefined) => ({
69
+ accessible: !!label,
70
+ accessibilityLabel: label,
71
+ accessibilityRole: label ? ("image" as const) : undefined,
72
+ importantForAccessibility: label ? ("yes" as const) : ("no-hide-descendants" as const),
73
+ accessibilityElementsHidden: !label,
74
+ })
75
+
76
+ // On the web react-native-svg hands its props to the <svg> as they are, so the native names would reach the DOM (and
77
+ // React warns of them): there an icon takes the ARIA attributes instead
78
+ const webA11y = (label: string | undefined) =>
79
+ (label ? { role: "img", "aria-label": label } : { "aria-hidden": true, focusable: "false" }) as Record<string, unknown>
80
+
67
81
  /** Makes an icon component from its SVG data (scripts/build-icons.mjs writes one per icon of the shared sets). */
68
82
  export function createIcon(name: string, viewBox: string, nodes: IconNode[]): IconComponent {
69
83
  const Icon = memo(function Icon({ size, color, style, accessibilityLabel, testID }: IconProps) {
@@ -80,11 +94,7 @@ export function createIcon(name: string, viewBox: string, nodes: IconNode[]): Ic
80
94
  // does not reach a web icon then
81
95
  style={StyleSheet.flatten([styles.reset, { width: px, height: px }, style])}
82
96
  testID={testID}
83
- accessible={!!accessibilityLabel}
84
- accessibilityLabel={accessibilityLabel}
85
- accessibilityRole={accessibilityLabel ? "image" : undefined}
86
- importantForAccessibility={accessibilityLabel ? "yes" : "no-hide-descendants"}
87
- accessibilityElementsHidden={!accessibilityLabel}
97
+ {...(Platform.OS === "web" ? webA11y(accessibilityLabel) : nativeA11y(accessibilityLabel))}
88
98
  >
89
99
  {renderNodes(nodes, fill, theme.colors.accent, "", defaults.weight === "semibold" ? 1.25 : 1)}
90
100
  </Svg>