@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,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>
@@ -0,0 +1,141 @@
1
+ import { useEffect, useState } from "react"
2
+ import { View, type StyleProp, type ViewStyle } from "react-native"
3
+ import Svg, { Circle } from "react-native-svg"
4
+ import { curves } from "../../internal/motion"
5
+ import { cssEase, useTweenedNumber } from "../../internal/transition"
6
+ import { useTheme } from "../../theme/ThemeProvider"
7
+ import type { Theme } from "../../theme/types"
8
+
9
+ export type CircularProgressProps = {
10
+ /** Maximum duration to use for simulated upload progress in ms. @default 15000 */
11
+ maxDuration?: number
12
+ /** Sets the progress to full and resolves the simulated timer. @default false */
13
+ done?: boolean
14
+ /** A fixed progress, 0 to 100, instead of the simulated one. */
15
+ progress?: number
16
+ /** Size of the indicator, in pixels. @default 28 */
17
+ size?: number
18
+ /** Stroke width of the ring, in pixels of its 20px drawing, between 1 and 4. @default 2 */
19
+ strokeWidth?: number
20
+ /** Color of the active progress track (stroke): a color or a token, such as `"var(--gray-1000)"`. */
21
+ trackActiveColor?: string
22
+ /** Color of the base track (background stroke): a color or a token, such as `"var(--alpha-15)"`. */
23
+ trackColor?: string
24
+ /** The name read out, as a progress bar. */
25
+ "aria-label"?: string
26
+ accessibilityLabel?: string
27
+ testID?: string
28
+ style?: StyleProp<ViewStyle>
29
+ }
30
+
31
+ /**
32
+ * Deterministically returns a progress value between 0 and 100 that decays as it approaches 100, based on a maximum
33
+ * duration and the elapsed time, as @plexui/ui's simulated progress.
34
+ */
35
+ export function getSimulatedProgress(maxTime: number, elapsedTime: number) {
36
+ const P_max = 99.9 // Maximum percentage to approach (less than 100%)
37
+ const P1 = 35 // Percentage at which the rate slows down
38
+ const initialRate = (3 * 100) / maxTime // Initial rate (% per ms)
39
+ const t1 = P1 / initialRate // Time when progress reaches P1
40
+ let percentage
41
+ if (elapsedTime <= t1) {
42
+ // Phase 1: a linear increase at the start, to show consistency in progress
43
+ percentage = initialRate * elapsedTime
44
+ } else {
45
+ // Phase 2: the progress slows down, approaching P_max
46
+ const k = 4
47
+ const remainingTime = maxTime - t1
48
+ const timeSinceT1 = elapsedTime - t1
49
+ percentage = P1 + (P_max - P1) * (1 - Math.exp(-k * (timeSinceT1 / remainingTime)))
50
+ }
51
+ return Math.min(percentage, P_max)
52
+ }
53
+
54
+ /** A progress that rises every 100ms from the mount, slowing as it nears 100, and is 100 once `completed`. */
55
+ function useSimulatedProgress(maxDuration: number, completed: boolean) {
56
+ const [startAt] = useState(() => Date.now())
57
+ const [progress, setProgress] = useState(() => getSimulatedProgress(maxDuration, Date.now() - startAt))
58
+ useEffect(() => {
59
+ if (completed) return
60
+ const id = setInterval(() => {
61
+ const elapsed = Date.now() - startAt
62
+ setProgress(elapsed >= maxDuration ? 100 : getSimulatedProgress(maxDuration, elapsed))
63
+ }, 100)
64
+ return () => clearInterval(id)
65
+ }, [completed, maxDuration, startAt])
66
+ return completed ? 100 : progress
67
+ }
68
+
69
+ /** A color prop: a token (`var(--…)`) resolved for the scheme, or a color as it is. */
70
+ const resolve = (theme: Theme, value: string | undefined, fallback: string) => {
71
+ if (!value) return fallback
72
+ if (!value.includes("var(") && !value.includes("light-dark(")) return value
73
+ const resolved = theme.value(value)
74
+ return typeof resolved === "string" ? resolved : fallback
75
+ }
76
+
77
+ /** The drawing: a ring of radius 8 in a 20px box, its progress a dash of 50 that starts at 12 o'clock. */
78
+ const DASH = 50
79
+
80
+ /**
81
+ * A progress ring, as @plexui/ui's CircularProgress: a light green track and a green arc for its share, 28px by
82
+ * default. Without `progress` it simulates one over `maxDuration`, and `done` fills it. Neither platform has a ring
83
+ * of its own for this, so both draw the Plex ring; a new value moves the arc in 300ms (ease) on iOS, as the web's
84
+ * transition, and in Android's determinate radial progress time (200ms, decelerating); at once with reduced motion.
85
+ */
86
+ export function CircularProgress({
87
+ maxDuration = 15000,
88
+ done = false,
89
+ progress: progressProp,
90
+ size = 28,
91
+ strokeWidth,
92
+ trackActiveColor,
93
+ trackColor,
94
+ "aria-label": ariaLabel,
95
+ accessibilityLabel,
96
+ testID,
97
+ style,
98
+ }: CircularProgressProps) {
99
+ const theme = useTheme()
100
+ const simulated = useSimulatedProgress(maxDuration, progressProp !== undefined || done)
101
+ const progress = Math.max(0, Math.min(100, progressProp ?? simulated))
102
+ const shown = useTweenedNumber(progress, {
103
+ duration: theme.isAndroid ? 200 : 300,
104
+ easing: theme.isAndroid ? curves.decelerate : cssEase,
105
+ reducedMotion: theme.reducedMotion,
106
+ })
107
+ const stroke = strokeWidth ? Math.min(4, strokeWidth) : 2
108
+ // The web's `light-dark(#deede9, var(--green-a50))`: a light green, the green at 15% at night
109
+ const track = resolve(theme, trackColor, theme.scheme === "dark" ? theme.color("--green-a50") : "#DEEDE9")
110
+ const active = resolve(theme, trackActiveColor, theme.color("--green-500"))
111
+ const name = accessibilityLabel ?? ariaLabel
112
+ return (
113
+ <View
114
+ accessible={name != null}
115
+ accessibilityRole={name != null ? "progressbar" : undefined}
116
+ accessibilityLabel={name}
117
+ accessibilityValue={name != null ? { min: 0, max: 100, now: Math.round(progress) } : undefined}
118
+ importantForAccessibility={name != null ? undefined : "no-hide-descendants"}
119
+ accessibilityElementsHidden={name == null}
120
+ testID={testID}
121
+ style={[{ width: size, height: size }, style]}
122
+ >
123
+ <Svg width={size} height={size} viewBox="0 0 20 20">
124
+ <Circle cx={10} cy={10} r={8} fill="none" stroke={track} strokeWidth={stroke} />
125
+ <Circle
126
+ cx={10}
127
+ cy={10}
128
+ r={8}
129
+ fill="none"
130
+ stroke={active}
131
+ strokeWidth={stroke}
132
+ strokeLinecap="round"
133
+ strokeDasharray={[DASH, DASH]}
134
+ strokeDashoffset={DASH - DASH * (shown / 100)}
135
+ // The dash starts at 12 o'clock, as the web's ring turned back a quarter
136
+ transform="rotate(-90 10 10)"
137
+ />
138
+ </Svg>
139
+ </View>
140
+ )
141
+ }
@@ -0,0 +1,79 @@
1
+ import { Animated, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
2
+ import { curves } from "../../internal/motion"
3
+ import { cssEase, useLoopClock } from "../../internal/transition"
4
+ import { useTheme } from "../../theme/ThemeProvider"
5
+ import { textColor, type TextColor } from "../Text/Text"
6
+
7
+ export type LoadingDotsProps = {
8
+ /** The color of the dots, a text color or any color string; the web takes the text color. @default "primary" */
9
+ color?: TextColor | (string & {})
10
+ /** The name read out, as a busy progress indicator; without one the dots are decorative, as on the web. */
11
+ "aria-label"?: string
12
+ accessibilityLabel?: string
13
+ testID?: string
14
+ style?: StyleProp<ViewStyle>
15
+ }
16
+
17
+ const DOT = 8
18
+ const GAP = 4
19
+
20
+ /** iOS, as the web's dots: each pulses .15 → .4 → .15 in 1s (ease), 0.2s after the one before it. */
21
+ const IOS = { period: 1000, delays: [0, 200, 400] }
22
+ /** Android, the Plex Android look's typing dots: each grows over 320ms and shrinks over 320ms (decelerating) every 800ms, 150ms after the one before it; 1.33 to 2.33 of radius. */
23
+ const ANDROID = { period: 800, delays: [0, 150, 300], rest: 1.33 / 2.33 }
24
+
25
+ /**
26
+ * Three pulsing dots for typing or a short wait, as @plexui/ui's LoadingDots: 8px dots 4px apart, as tall as a line
27
+ * of text (24). iOS pulses their opacity as the web does; Android grows and shrinks them on the Plex Android look's
28
+ * typing timing, in the same tones. With reduced motion they stand still.
29
+ */
30
+ export function LoadingDots({ color, "aria-label": ariaLabel, accessibilityLabel, testID, style }: LoadingDotsProps) {
31
+ const theme = useTheme()
32
+ const ink = textColor(theme, color ?? "primary")
33
+ const name = accessibilityLabel ?? ariaLabel
34
+ const timing = theme.isAndroid ? ANDROID : IOS
35
+ return (
36
+ <View
37
+ accessible={name != null}
38
+ accessibilityRole={name != null ? "progressbar" : undefined}
39
+ accessibilityLabel={name}
40
+ accessibilityState={name != null ? { busy: true } : undefined}
41
+ importantForAccessibility={name != null ? undefined : "no-hide-descendants"}
42
+ accessibilityElementsHidden={name == null}
43
+ testID={testID}
44
+ style={[styles.root, { height: theme.length("--font-text-md-line-height", 24) }, style]}
45
+ >
46
+ {timing.delays.map((delay, index) => (
47
+ <Dot key={index} delay={delay} color={ink} android={theme.isAndroid} still={theme.reducedMotion} />
48
+ ))}
49
+ </View>
50
+ )
51
+ }
52
+
53
+ function Dot({ delay, color, android, still }: { delay: number; color: string; android: boolean; still: boolean }) {
54
+ const { period } = android ? ANDROID : IOS
55
+ const clock = useLoopClock(period, !still, true, delay)
56
+ if (android) {
57
+ // Grows for 320ms, shrinks for 320ms, rests until 800ms; its tone follows its size
58
+ const grow = clock.interpolate({ inputRange: [0, 320, 640, period], outputRange: [0, 1, 0, 0], easing: curves.decelerate })
59
+ return (
60
+ <Animated.View
61
+ style={[
62
+ styles.dot,
63
+ {
64
+ backgroundColor: color,
65
+ opacity: grow.interpolate({ inputRange: [0, 1], outputRange: [0.15, 0.4] }),
66
+ transform: [{ scale: grow.interpolate({ inputRange: [0, 1], outputRange: [ANDROID.rest, 1] }) }],
67
+ },
68
+ ]}
69
+ />
70
+ )
71
+ }
72
+ const opacity = clock.interpolate({ inputRange: [0, 0.2 * period, period], outputRange: [0.15, 0.4, 0.15], easing: cssEase })
73
+ return <Animated.View style={[styles.dot, { backgroundColor: color, opacity }]} />
74
+ }
75
+
76
+ const styles = StyleSheet.create({
77
+ root: { flexDirection: "row", alignItems: "center", justifyContent: "flex-start", gap: GAP },
78
+ dot: { width: DOT, height: DOT, borderRadius: DOT / 2 },
79
+ })