@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
@@ -1,12 +1,14 @@
1
- import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from "react"
1
+ import { useCallback, useEffect, useId, useRef, useState, type ReactNode, type RefObject } from "react"
2
2
  import { Animated, Platform, Pressable, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native"
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context"
4
+ import { FloatingPanel } from "../../internal/FloatingPanel"
4
5
  import { Glass } from "../../internal/Glass"
5
6
  import { glassOpacity, iosDim, Overlay } from "../../internal/Overlay"
6
7
  import { dangerText } from "../../theme/material"
7
8
  import { useTheme } from "../../theme/ThemeProvider"
8
9
  import { BottomSheetBase } from "../BottomSheet/BottomSheet"
9
10
  import { IconDefaultsProvider } from "../Icon/createIcon"
11
+ import { measure, type MenuAnchor, type Measurable } from "../Menu/Menu"
10
12
  import { Text } from "../Text/Text"
11
13
 
12
14
  export type ActionSheetAction = {
@@ -25,18 +27,26 @@ export type ActionSheetProps = {
25
27
  title?: ReactNode
26
28
  message?: ReactNode
27
29
  actions: ActionSheetAction[]
28
- /** The cancel action of iOS, apart from the others. Android closes the sheet with a tap outside or Back. @default "Cancel" */
30
+ /** The cancel action of iOS, the last of the panel. Android closes the sheet with a tap outside or Back. @default "Cancel" */
29
31
  cancelLabel?: string
32
+ /**
33
+ * The control the sheet opens from (a ref to a Button, a Pressable, a View). On iOS 26 the sheet then stands at it
34
+ * as a glass panel, over or under it, with no Cancel: a tap anywhere else closes it (an iPhone's action sheet with a
35
+ * `sourceItem`, WWDC25 "Build a UIKit app with the new design"). Android keeps its sheet from the bottom.
36
+ */
37
+ source?: RefObject<unknown>
30
38
  testID?: string
31
39
  }
32
40
 
33
41
  /**
34
- * A choice of actions from the bottom of the screen (React Native only: the web has a Menu). iOS 26 draws
35
- * UIAlertController's `.actionSheet` on an iPhone: a glass panel of 48pt capsule actions with the title and message
36
- * over them, and the cancel capsule apart under it; Android a menu sheet (its items: 48dp rows of Regular 16, the
37
- * icon in a 56dp slot in the ink, gray at night, the text 16 in with no icons, a gray title of 16 over them).
42
+ * A choice of actions (React Native only: the web has a Menu, a Popover or an alert Dialog). iOS 26 draws
43
+ * UIAlertController's `.actionSheet` on an iPhone: with a `source`, a glass panel at that control (as the web's
44
+ * Popover "Confirmation"), its 48pt capsule actions under the title and message, no Cancel, closed by a tap outside;
45
+ * with no source, the same panel in the middle of the screen, Cancel its last capsule (as the web's alert Dialog with a
46
+ * stacked footer). Android a menu sheet (its items: 48dp rows of Regular 16, the icon in a 56dp slot in the ink, gray
47
+ * at night, the text 16 in with no icons, a gray title of 16 over them).
38
48
  */
39
- export function ActionSheet({ open, onOpenChange, title, message, actions, cancelLabel = "Cancel", testID }: ActionSheetProps) {
49
+ export function ActionSheet({ open, onOpenChange, title, message, actions, cancelLabel = "Cancel", source, testID }: ActionSheetProps) {
40
50
  const theme = useTheme()
41
51
  const insets = useSafeAreaInsets()
42
52
  const { height: screen } = useWindowDimensions()
@@ -69,6 +79,27 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
69
79
  close()
70
80
  }
71
81
  const ids = { title: useId(), message: useId() }
82
+ // The source's place, measured as the sheet opens (and again when the window turns)
83
+ const [anchor, setAnchor] = useState<MenuAnchor | null>(null)
84
+ // A source that measures to nothing (no view yet, or one with no size): the sheet stands in the middle instead
85
+ const [unplaced, setUnplaced] = useState(false)
86
+ const { width: windowWidth } = useWindowDimensions()
87
+ const sourced = !theme.isAndroid && source != null && !unplaced
88
+ useEffect(() => {
89
+ if (!open || theme.isAndroid || source == null) return
90
+ let live = true
91
+ // A new opening measures again: the panel never shows at the source's last place first
92
+ setAnchor(null)
93
+ measure(source.current as Measurable | null, (box) => {
94
+ if (!live) return
95
+ const placed = box.width > 0 || box.height > 0
96
+ setAnchor(placed ? box : null)
97
+ setUnplaced(!placed)
98
+ })
99
+ return () => {
100
+ live = false
101
+ }
102
+ }, [open, theme.isAndroid, source, windowWidth, screen])
72
103
  if (theme.isAndroid) {
73
104
  const m = theme.material
74
105
  const icons = actions.some((action) => action.icon)
@@ -155,15 +186,66 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
155
186
  },
156
187
  ]}
157
188
  >
189
+ {/* iOS 27's action sheet: every action Semibold 17/22, a destructive one in the native red (the danger solid) */}
158
190
  <Text
159
- weight={preferred ? "semibold" : "medium"}
160
- color={item.disabled ? theme.color("--mobile-label-tertiary") : item.destructive ? theme.color("--color-text-danger") : theme.colors.text}
191
+ weight="semibold"
192
+ color={item.disabled ? theme.color("--mobile-label-tertiary") : item.destructive ? theme.color("--color-background-danger-solid") : theme.colors.text}
161
193
  style={styles.iosLabel}
162
194
  >
163
195
  {item.label}
164
196
  </Text>
165
197
  </Pressable>
166
198
  )
199
+ const header =
200
+ title != null || message != null ? (
201
+ <View style={styles.iosHeader}>
202
+ {title != null ? (
203
+ <Text nativeID={ids.title} weight="semibold" accessibilityRole="header" style={styles.iosHeaderText}>
204
+ {title}
205
+ </Text>
206
+ ) : null}
207
+ {message != null ? (
208
+ <Text nativeID={ids.message} style={styles.iosHeaderText}>
209
+ {message}
210
+ </Text>
211
+ ) : null}
212
+ </View>
213
+ ) : null
214
+ if (sourced) {
215
+ // At its source: the phone popover's glass and corners (the web's Popover "Confirmation"), no Cancel
216
+ return (
217
+ <FloatingPanel
218
+ open={open && anchor != null}
219
+ onDismiss={close}
220
+ anchor={anchor}
221
+ side="top"
222
+ align="center"
223
+ sideOffset={8}
224
+ collisionPadding={{ top: Math.max(insets.top, 8), bottom: Math.max(insets.bottom, 8), left: 8, right: 8 }}
225
+ glass
226
+ role="dialog"
227
+ aria-label={typeof title === "string" ? title : undefined}
228
+ testID={testID}
229
+ style={{ width: Math.min(windowWidth - 16, theme.length("--action-sheet-source-width", 300)), maxHeight: screen - insets.top - insets.bottom - 16 }}
230
+ >
231
+ {() => (
232
+ <Glass
233
+ radius={theme.length("--popover-radius", 34)}
234
+ elevation="raised"
235
+ fillToken="--popover-mobile-background"
236
+ filterToken="--popover-mobile-backdrop-filter"
237
+ shadowToken="--menu-shadow"
238
+ style={styles.iosPanel}
239
+ >
240
+ <ScrollView style={styles.scroll} contentContainerStyle={styles.iosList} bounces={false}>
241
+ {header}
242
+ {actions.map((item, index) => action(item, index))}
243
+ </ScrollView>
244
+ </Glass>
245
+ )}
246
+ </FloatingPanel>
247
+ )
248
+ }
167
249
  // The web names the sheet by its title and describes it by its message; a phone keeps the modal view
168
250
  const a11y =
169
251
  Platform.OS === "web"
@@ -175,9 +257,9 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
175
257
  }
176
258
  : { accessibilityViewIsModal: true }
177
259
  return (
178
- <Overlay open={open} onDismiss={close} scrim={iosDim(theme)} motion="sheet" testID={testID}>
260
+ <Overlay open={open} onDismiss={close} scrim={iosDim(theme)} testID={testID}>
179
261
  {(progress, opening, focus) => (
180
- <View pointerEvents="box-none" style={styles.bottom}>
262
+ <View pointerEvents="box-none" style={styles.center}>
181
263
  <Animated.View
182
264
  {...a11y}
183
265
  // On the web the sheet itself takes the first focus, not its first action with a ring
@@ -186,37 +268,21 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
186
268
  style={[
187
269
  focus.style,
188
270
  styles.iosStack,
189
- // An offset, not a transform: a transform would stop the glass's blur on the web
190
271
  {
191
- maxHeight: screen - insets.top - 8,
192
- paddingBottom: Math.max(insets.bottom, 8),
272
+ maxHeight: screen - insets.top - insets.bottom - 16,
193
273
  opacity: glassOpacity(progress, opening),
194
- // With reduced motion it fades in place
195
- top: theme.reducedMotion ? 0 : progress.interpolate({ inputRange: [0, 1], outputRange: [80, 0] }),
274
+ // An alert's entrance: it grows from 1.1 as it fades in; with reduced motion it fades in place. A
275
+ // transform would stop the glass's blur on the web, so the web only fades
276
+ transform: theme.reducedMotion || Platform.OS === "web" ? undefined : [{ scale: progress.interpolate({ inputRange: [0, 1], outputRange: [1.1, 1] }) }],
196
277
  },
197
278
  ]}
198
279
  >
199
280
  <Glass radius={theme.length("--dialog-alert-radius", 34)} elevation="raised" fillToken="--dialog-alert-background" style={[styles.iosPanel, styles.shrink]}>
200
- {/* Many actions scroll inside the panel; the cancel capsule stays in view */}
281
+ {/* Many actions scroll inside the panel; Cancel stays in view at its end */}
201
282
  <ScrollView style={styles.scroll} contentContainerStyle={styles.iosList} bounces={false}>
202
- {title != null || message != null ? (
203
- <View style={styles.iosHeader}>
204
- {title != null ? (
205
- <Text nativeID={ids.title} weight="semibold" color={theme.color("--dialog-alert-message-color")} accessibilityRole="header" style={styles.iosHeaderText}>
206
- {title}
207
- </Text>
208
- ) : null}
209
- {message != null ? (
210
- <Text nativeID={ids.message} color={theme.color("--dialog-alert-message-color")} style={styles.iosHeaderText}>
211
- {message}
212
- </Text>
213
- ) : null}
214
- </View>
215
- ) : null}
283
+ {header}
216
284
  {actions.map((item, index) => action(item, index))}
217
285
  </ScrollView>
218
- </Glass>
219
- <Glass radius={theme.length("--dialog-alert-radius", 34)} elevation="raised" fillToken="--dialog-alert-background" style={styles.iosPanel}>
220
286
  {action(
221
287
  {
222
288
  label: cancelLabel,
@@ -237,14 +303,17 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
237
303
  const ANDROID_PICK_EXIT = 180
238
304
 
239
305
  const styles = StyleSheet.create({
240
- bottom: { flex: 1, justifyContent: "flex-end" },
241
- iosStack: { paddingHorizontal: 8, gap: 8 },
242
- iosPanel: { padding: 16, gap: 8 },
306
+ center: { flex: 1, justifyContent: "center", alignItems: "center" },
307
+ // An alert's width at most (the kit's 300), 8 from the screen's edges on a narrow phone
308
+ iosStack: { width: "100%", maxWidth: 316, paddingHorizontal: 8 },
309
+ // iOS 27's action sheet (the iOS kit): 14 around, the actions 8 apart
310
+ iosPanel: { padding: 14, gap: 8 },
243
311
  iosList: { gap: 8 },
244
312
  shrink: { flexShrink: 1 },
245
313
  scroll: { flexGrow: 0 },
246
- iosHeader: { paddingHorizontal: 15, paddingTop: 4, paddingBottom: 6, gap: 2 },
247
- iosHeaderText: { fontSize: 13, lineHeight: 18, textAlign: "center" },
314
+ // The title Semibold and the message Regular, both Body 17/22 in the label color at the start, 8 in, 24 over the actions
315
+ iosHeader: { paddingHorizontal: 8, paddingTop: 8, paddingBottom: 16, gap: 10 },
316
+ iosHeaderText: { fontSize: 17, lineHeight: 22 },
248
317
  iosAction: {
249
318
  alignItems: "center",
250
319
  justifyContent: "center",
@@ -0,0 +1,279 @@
1
+ import { cloneElement, isValidElement, useState, type ReactElement, type ReactNode } from "react"
2
+ import { Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
+ import CheckCircle from "../../icons/plex/CheckCircle"
4
+ import InfoCircle from "../../icons/plex/InfoCircle"
5
+ import Warning from "../../icons/plex/Warning"
6
+ import X from "../../icons/plex/X"
7
+ import { flattenChildren, isRenderable } from "../../internal/children"
8
+ import { useTheme } from "../../theme/ThemeProvider"
9
+ import type { Theme } from "../../theme/types"
10
+ import { Button, buttonColors, type ButtonProps } from "../Button/Button"
11
+ import { IconDefaultsProvider } from "../Icon/createIcon"
12
+ import { Text, TextColorProvider } from "../Text/Text"
13
+
14
+ export type AlertColor = "primary" | "danger" | "success" | "info" | "discovery" | "caution" | "warning"
15
+ export type AlertVariant = "solid" | "soft" | "outline"
16
+ export type AlertMobileActions = "capsules" | "own"
17
+
18
+ export type AlertProps = {
19
+ /** @default "primary" */
20
+ color?: AlertColor
21
+ /** On a phone a soft or outline alert is gray, only its icon in the color; a solid one keeps its color. @default "outline" */
22
+ variant?: AlertVariant
23
+ /** The alert's title. */
24
+ title?: ReactNode
25
+ /** Its description. */
26
+ description?: ReactNode
27
+ /** Buttons for the alert's actions, under the message. */
28
+ actions?: ReactNode
29
+ /**
30
+ * `capsules`: each action a capsule as wide as half the alert at least, side by side (an iOS tip's buttons); `own`:
31
+ * the buttons as given, starting where the text starts, for an alert inside a block of buttons of its own.
32
+ * @default "capsules"
33
+ */
34
+ mobileActions?: AlertMobileActions
35
+ /** An icon in place of the one of the color; `false` shows none. */
36
+ indicator?: ReactNode | false
37
+ /** Shows a close button in the alert's corner, which calls this. */
38
+ onDismiss?: () => void
39
+ /** @default "Dismiss" */
40
+ dismissLabel?: string
41
+ /** A full-width strip across the top or bottom of a screen: square corners. @default false */
42
+ banner?: boolean
43
+ testID?: string
44
+ style?: StyleProp<ViewStyle>
45
+ /** The style of the actions' row. */
46
+ actionsStyle?: StyleProp<ViewStyle>
47
+ }
48
+
49
+ /** The icon of a color, as the web chooses it: a warning for warning, caution and danger, a check for success. */
50
+ function DefaultIndicator({ color }: { color: AlertColor }) {
51
+ if (color === "warning" || color === "caution" || color === "danger") return <Warning />
52
+ if (color === "success") return <CheckCircle />
53
+ return <InfoCircle />
54
+ }
55
+
56
+ /** The icon's color on a gray alert: the color's text, lighter in the dark where the text would read under 3:1. */
57
+ function tintOf(theme: Theme, color: AlertColor): string {
58
+ const dark = theme.scheme === "dark"
59
+ switch (color) {
60
+ case "primary":
61
+ return theme.color("--mobile-label-secondary", theme.colors.textSecondary)
62
+ case "warning":
63
+ return theme.color(dark ? "--orange-300" : "--color-text-warning")
64
+ case "danger":
65
+ return theme.color(dark ? "--red-300" : "--color-text-danger")
66
+ case "discovery":
67
+ return theme.color(dark ? "--purple-200" : "--color-text-discovery")
68
+ default:
69
+ return theme.color(`--color-text-${color}`)
70
+ }
71
+ }
72
+
73
+ /** The colors of an alert on a phone (Alert.module.css, `max-width: 767px`). */
74
+ export function alertColors(theme: Theme, color: AlertColor, variant: AlertVariant) {
75
+ if (variant === "solid") {
76
+ const text = theme.color(`--color-text-${color}-solid`)
77
+ return { background: theme.color(`--color-background-${color}-solid`), title: text, description: text, icon: text }
78
+ }
79
+ return {
80
+ background: theme.color("--alert-phone-background", theme.color("--color-background-secondary-soft-alpha")),
81
+ title: theme.colors.text,
82
+ // The secondary label at its native 60%, 70% in the dark
83
+ description: theme.color("--alert-phone-description-color", theme.color(theme.scheme === "dark" ? "--alpha-70" : "--alpha-60")),
84
+ icon: theme.color("--alert-phone-indicator-color", tintOf(theme, color)),
85
+ }
86
+ }
87
+
88
+ /**
89
+ * The phone's numbers of each platform. iOS: an inline tip of TipKit as Alert.module.css draws it at 767px and below
90
+ * (26 corners, 17/16 padding, a 22 symbol drawn at 26.4 6 in, the text at 56, 18 above the actions, 50pt capsules 8
91
+ * apart, a 26 close circle in a 44 target 5 from the corner). Android: the same card in the Plex Android look (16dp
92
+ * corners as its cards, 16 padding, a 24dp icon 16 from the text, Title M and Body M, 40dp buttons, the close glyph
93
+ * 24dp in a 48dp target).
94
+ */
95
+ function metricsOf(theme: Theme) {
96
+ if (theme.isAndroid) {
97
+ return { radius: 16, paddingTop: 16, paddingBottom: 16, paddingBottomActions: 16, paddingX: 16, glyph: 24, iconBox: 24, iconStart: 0, iconEnd: 0, gap: 16, rowGap: 16, close: { target: 48, circle: 0, icon: 24, offset: 4, room: 32 }, capsule: "lg" as const }
98
+ }
99
+ const glyph = 22
100
+ return {
101
+ radius: 26,
102
+ paddingTop: 17,
103
+ paddingBottom: 17,
104
+ paddingBottomActions: 16,
105
+ paddingX: 16,
106
+ glyph,
107
+ // A Plex icon draws its circle 20 of its 24: the icon is 26.4 so that its circle is TipKit's 22
108
+ iconBox: (glyph * 24) / 20,
109
+ iconStart: 6,
110
+ iconEnd: 4,
111
+ gap: 8,
112
+ rowGap: 18,
113
+ close: { target: 44, circle: 26, icon: 19, offset: 5, room: 34 },
114
+ capsule: "xl" as const,
115
+ }
116
+ }
117
+
118
+ /**
119
+ * An inline message (a notice, a warning), as @plexui/ui's Alert on a phone: the shape and text of an iOS tip
120
+ * (TipKit), the system's message inside a screen. A soft or outline alert is gray with the icon in its color, a solid
121
+ * one keeps its color; the actions stand under the message as capsules side by side; `onDismiss` puts a close button
122
+ * in the corner. Neither platform has an inline alert of its own: Android draws the same card in its own sizes. A
123
+ * danger alert is announced as an `alert`.
124
+ */
125
+ export function Alert({
126
+ color = "primary",
127
+ variant = "outline",
128
+ title,
129
+ description,
130
+ actions,
131
+ mobileActions = "capsules",
132
+ indicator,
133
+ onDismiss,
134
+ dismissLabel = "Dismiss",
135
+ banner = false,
136
+ testID,
137
+ style,
138
+ actionsStyle,
139
+ }: AlertProps) {
140
+ const theme = useTheme()
141
+ const android = theme.isAndroid
142
+ const m = metricsOf(theme)
143
+ const colors = alertColors(theme, color, variant)
144
+ const [actionsWidth, setActionsWidth] = useState(0)
145
+ const hasTitle = isRenderable(title)
146
+ const hasDescription = isRenderable(description)
147
+ const hasIndicator = indicator !== false
148
+ const items = flattenChildren(actions).filter(isRenderable)
149
+ const hasActions = items.length > 0
150
+ const own = mobileActions === "own"
151
+ const dismissible = onDismiss != null
152
+ // The first line of text stands on the middle of the icon: TipKit's 5 above and below a 22 symbol on iOS; on
153
+ // Android the icon sits on the title's 24 line, or 2 above a description's 20
154
+ const firstLine = hasTitle ? (android ? 24 : 22) : 20
155
+ const iconMargin = android ? { top: (firstLine - m.glyph) / 2, bottom: 0 } : hasTitle && hasDescription ? { top: 0, bottom: 10 } : { top: 5, bottom: 5 }
156
+ const messageAlign: ViewStyle = android
157
+ ? {}
158
+ : hasTitle && !hasDescription
159
+ ? { alignSelf: "center" }
160
+ : !hasTitle && hasIndicator
161
+ ? { marginTop: 5 + m.glyph / 2 - 10 }
162
+ : {}
163
+ // The first line stops short of the close button
164
+ const closeRoom = dismissible ? { paddingEnd: m.close.room } : null
165
+ // Capsules share the row, each at least half of it; `own` buttons keep their size and start under the text
166
+ const half = actionsWidth > 0 ? (actionsWidth - 8) / 2 : undefined
167
+ const actionItems = items.map((item, index) => {
168
+ if (own || !isValidElement(item) || item.type !== Button) return item
169
+ const button = item as ReactElement<ButtonProps>
170
+ return cloneElement(button, {
171
+ key: button.key ?? index,
172
+ size: m.capsule,
173
+ pill: true,
174
+ style: [button.props.style, styles.capsule, { minWidth: half }],
175
+ })
176
+ })
177
+ const textStart = hasIndicator ? m.iconStart + m.glyph + m.iconEnd + m.gap : android ? 0 : 6
178
+ return (
179
+ <View
180
+ testID={testID}
181
+ role={color === "danger" ? "alert" : undefined}
182
+ style={[
183
+ styles.alert,
184
+ {
185
+ columnGap: m.gap,
186
+ rowGap: m.rowGap,
187
+ paddingTop: m.paddingTop,
188
+ paddingBottom: hasActions ? m.paddingBottomActions : m.paddingBottom,
189
+ paddingHorizontal: m.paddingX,
190
+ borderRadius: banner ? 0 : m.radius,
191
+ backgroundColor: colors.background,
192
+ },
193
+ style,
194
+ ]}
195
+ >
196
+ {hasIndicator ? (
197
+ <View
198
+ style={[
199
+ styles.indicator,
200
+ { paddingStart: m.iconStart, paddingEnd: m.iconEnd, marginTop: iconMargin.top, marginBottom: iconMargin.bottom, minHeight: m.glyph, minWidth: m.glyph },
201
+ ]}
202
+ >
203
+ <IconDefaultsProvider size={m.iconBox} color={colors.icon}>
204
+ {/* The icon overhangs its place by its inset on each side, so the text stays at its column */}
205
+ <View style={{ width: m.glyph, height: m.glyph, alignItems: "center", justifyContent: "center" }}>
206
+ <View style={{ margin: (m.glyph - m.iconBox) / 2 }}>{indicator ?? <DefaultIndicator color={color} />}</View>
207
+ </View>
208
+ </IconDefaultsProvider>
209
+ </View>
210
+ ) : null}
211
+ <View style={[styles.message, { paddingStart: hasIndicator || android ? 0 : 6 }, messageAlign]}>
212
+ {hasTitle ? (
213
+ <Text variant="headline" color={colors.title} style={closeRoom}>
214
+ {title}
215
+ </Text>
216
+ ) : null}
217
+ {hasDescription ? (
218
+ <TextColorProvider value={colors.description}>
219
+ <Text
220
+ variant="subheadline"
221
+ color={colors.description}
222
+ style={[hasTitle ? (android ? styles.androidDescription : styles.description) : closeRoom]}
223
+ >
224
+ {description}
225
+ </Text>
226
+ </TextColorProvider>
227
+ ) : null}
228
+ </View>
229
+ {hasActions ? (
230
+ <View
231
+ onLayout={(event) => setActionsWidth(event.nativeEvent.layout.width)}
232
+ style={[styles.actions, { paddingStart: own ? textStart : 0 }, actionsStyle]}
233
+ >
234
+ {actionItems}
235
+ </View>
236
+ ) : null}
237
+ {dismissible ? <CloseButton onPress={onDismiss} label={dismissLabel} close={m.close} /> : null}
238
+ </View>
239
+ )
240
+ }
241
+
242
+ /**
243
+ * The close button of a phone alert: on iOS a 26 circle of a soft secondary button with a 19 cross, in a 44 target 5
244
+ * from the corner (Alert.module.css); on Android the cross alone, 24dp in a 48dp target, in the secondary ink.
245
+ */
246
+ function CloseButton({ onPress, label, close }: { onPress: () => void; label: string; close: ReturnType<typeof metricsOf>["close"] }) {
247
+ const theme = useTheme()
248
+ const colors = buttonColors(theme, "secondary", "soft", false, false)
249
+ return (
250
+ <Pressable
251
+ accessibilityRole="button"
252
+ accessibilityLabel={label}
253
+ onPress={onPress}
254
+ style={[styles.close, { width: close.target, height: close.target, top: close.offset, end: close.offset }]}
255
+ >
256
+ {({ pressed }) =>
257
+ close.circle > 0 ? (
258
+ <View style={{ width: close.circle, height: close.circle, borderRadius: close.circle / 2, alignItems: "center", justifyContent: "center", backgroundColor: pressed ? colors.pressed : colors.background }}>
259
+ <X size={close.icon} color={pressed && colors.pressedText ? colors.pressedText : colors.text} />
260
+ </View>
261
+ ) : (
262
+ <X size={close.icon} color={theme.colors.labelSecondary} style={pressed ? styles.pressed : undefined} />
263
+ )
264
+ }
265
+ </Pressable>
266
+ )
267
+ }
268
+
269
+ const styles = StyleSheet.create({
270
+ alert: { position: "relative", flexDirection: "row", flexWrap: "wrap", alignItems: "flex-start", alignSelf: "stretch", borderCurve: "continuous" },
271
+ indicator: { flexShrink: 0, alignItems: "center", justifyContent: "center" },
272
+ message: { flex: 1, minWidth: 0 },
273
+ description: { marginTop: 2, marginBottom: 4 },
274
+ androidDescription: { marginTop: 2 },
275
+ actions: { flexBasis: "100%", flexGrow: 1, flexDirection: "row", flexWrap: "wrap", gap: 8 },
276
+ capsule: { flexGrow: 1, flexShrink: 0, flexBasis: "auto", maxWidth: "100%" },
277
+ close: { position: "absolute", alignItems: "center", justifyContent: "center" },
278
+ pressed: { opacity: 0.6 },
279
+ })
@@ -1,5 +1,5 @@
1
1
  import { Children, isValidElement, useId, useState, type ComponentType, type ReactNode } from "react"
2
- import { Animated, Easing, Platform, Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
2
+ import { Animated, Easing, Platform, Pressable, StyleSheet, View, type ImageSourcePropType, type StyleProp, type ViewStyle } from "react-native"
3
3
  import Svg, { Circle, Defs, LinearGradient, Stop } from "react-native-svg"
4
4
  import { useTheme } from "../../theme/ThemeProvider"
5
5
  import type { Theme } from "../../theme/types"
@@ -16,6 +16,8 @@ export type AvatarProps = {
16
16
  name?: string
17
17
  /** A picture over the placeholder; when it fails to load, the placeholder stays. */
18
18
  imageUrl?: string
19
+ /** A picture as an Image source (a `require()`d asset, `{ uri }`), as `Card.Media` takes it; it wins over `imageUrl`. */
20
+ source?: ImageSourcePropType
19
21
  /**
20
22
  * @default "secondary". A `gradient` avatar in the secondary color takes one of the seven gradients from its name,
21
23
  * the same each time; the other colors take the nearest gradient
@@ -106,13 +108,15 @@ export function avatarColors(theme: Theme, color: AvatarColor, variant: "soft" |
106
108
  * `variant="gradient"` it is a gradient of one of seven colors from top to bottom with up to two white initials,
107
109
  * Medium at 18/50 of the circle.
108
110
  */
109
- export function Avatar({ name, imageUrl, color = "secondary", variant = "soft", size: sizeProp, Icon, overflowCount, onPress, accessibilityLabel, testID, style }: AvatarProps) {
111
+ export function Avatar({ name, imageUrl, source: sourceProp, color = "secondary", variant = "soft", size: sizeProp, Icon, overflowCount, onPress, accessibilityLabel, testID, style }: AvatarProps) {
110
112
  const theme = useTheme()
111
113
  const [failed, setFailed] = useState(false)
114
+ const source: ImageSourcePropType | undefined = sourceProp ?? (imageUrl ? { uri: imageUrl } : undefined)
112
115
  // A new picture gets its own try, even one that failed before
113
- const [shown, setShown] = useState(imageUrl)
114
- if (shown !== imageUrl) {
115
- setShown(imageUrl)
116
+ const pictureKey = sourceKey(source)
117
+ const [shown, setShown] = useState(pictureKey)
118
+ if (shown !== pictureKey) {
119
+ setShown(pictureKey)
116
120
  setFailed(false)
117
121
  }
118
122
  const size = sizeProp ?? theme.length("--avatar-size", 28)
@@ -141,7 +145,7 @@ export function Avatar({ name, imageUrl, color = "secondary", variant = "soft",
141
145
  {initialOf(name ?? "")}
142
146
  </Text>
143
147
  )
144
- const showImage = !!imageUrl && !failed
148
+ const showImage = source != null && !failed
145
149
  const body = (
146
150
  <>
147
151
  {fill ? (
@@ -160,7 +164,7 @@ export function Avatar({ name, imageUrl, color = "secondary", variant = "soft",
160
164
  {showImage ? (
161
165
  <View style={[StyleSheet.absoluteFill, { borderRadius: size / 2, overflow: "hidden" }]}>
162
166
  {/* A picture of its own for each address, so a new one fades in afresh */}
163
- <Picture key={imageUrl} uri={imageUrl} fade={theme.isAndroid ? (theme.reducedMotion ? 0 : 150) : undefined} onError={() => setFailed(true)} />
167
+ <Picture key={pictureKey} source={source} fade={theme.isAndroid ? (theme.reducedMotion ? 0 : 150) : undefined} onError={() => setFailed(true)} />
164
168
  {/* The hairline over the picture, inside its edge, so it does not change the size */}
165
169
  <View pointerEvents="none" style={[StyleSheet.absoluteFill, { borderRadius: size / 2, borderWidth: 1, borderColor: theme.color("--avatar-image-border-color") }]} />
166
170
  </View>
@@ -194,12 +198,20 @@ export function Avatar({ name, imageUrl, color = "secondary", variant = "soft",
194
198
  * The picture. Android fades it in over `fade` ms, linear, once it has loaded: a device's Image does it itself (its
195
199
  * own fade is 300ms), elsewhere the picture's opacity runs. Left out, the platform's own way stays.
196
200
  */
197
- function Picture({ uri, fade, onError }: { uri: string; fade?: number; onError: () => void }) {
201
+ /** What tells one picture from another: its address, or the asset a `require()` gives. */
202
+ function sourceKey(source: ImageSourcePropType | undefined): string | undefined {
203
+ if (source == null) return undefined
204
+ if (typeof source === "number") return `asset:${source}`
205
+ if (Array.isArray(source)) return source.map((item) => item.uri ?? "").join("|")
206
+ return (source as { uri?: string }).uri ?? JSON.stringify(source)
207
+ }
208
+
209
+ function Picture({ source, fade, onError }: { source: ImageSourcePropType; fade?: number; onError: () => void }) {
198
210
  const fades = fade != null && fade > 0 && Platform.OS !== "android"
199
211
  const [opacity] = useState(() => new Animated.Value(fades ? 0 : 1))
200
212
  return (
201
213
  <Animated.Image
202
- source={{ uri }}
214
+ source={source}
203
215
  onError={onError}
204
216
  fadeDuration={Platform.OS === "android" ? fade : undefined}
205
217
  onLoad={fades ? () => Animated.timing(opacity, { toValue: 1, duration: fade, easing: Easing.linear, useNativeDriver: false }).start() : undefined}
@@ -0,0 +1,54 @@
1
+ import { Children, cloneElement, isValidElement, type ReactElement, type ReactNode } from "react"
2
+ import { StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
+ import { useSafeAreaInsets } from "react-native-safe-area-context"
4
+ import { useTheme } from "../../theme/ThemeProvider"
5
+ import { Button, type ButtonProps } from "../Button/Button"
6
+
7
+ export type BottomActionsProps = {
8
+ /** The screen's main action, a Button, and an optional second Button under it (a ghost "Not now"). */
9
+ children: ReactNode
10
+ /** Puts the actions over the content (a scroll view under them); off, they take their room at the end of the screen. @default false */
11
+ floating?: boolean
12
+ testID?: string
13
+ style?: StyleProp<ViewStyle>
14
+ }
15
+
16
+ /**
17
+ * The main action at the bottom of a phone screen: an onboarding's "Continue", a form's "Create account". iOS 26: a
18
+ * capsule across the screen, 36pt from its sides, 52pt tall, its bottom just over the home indicator (2pt above the
19
+ * safe area, about 36pt from the screen's edge on a Face ID iPhone), as iOS 26's own setup screens set it; a second
20
+ * action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
21
+ * 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
22
+ */
23
+ export function BottomActions({ children, floating = false, testID, style }: BottomActionsProps) {
24
+ const theme = useTheme()
25
+ const insets = useSafeAreaInsets()
26
+ const android = theme.isAndroid
27
+ const side = android ? 16 : 36
28
+ // iOS: 2pt over the safe area (34 on a Face ID iPhone); a phone with a home button has none, so 16 there
29
+ const bottom = android ? Math.max(insets.bottom, 0) + 16 : insets.bottom > 0 ? insets.bottom + 2 : 16
30
+ const height = android ? 48 : 52
31
+ const actions = Children.toArray(children).map((child) =>
32
+ isValidElement(child) && child.type === Button
33
+ ? cloneElement(child as ReactElement<ButtonProps>, {
34
+ block: (child.props as ButtonProps).block ?? true,
35
+ size: (child.props as ButtonProps).size ?? "3xl",
36
+ style: [{ minHeight: height, borderRadius: height / 2 }, (child.props as ButtonProps).style],
37
+ })
38
+ : child,
39
+ )
40
+ return (
41
+ <View
42
+ testID={testID}
43
+ pointerEvents="box-none"
44
+ style={[styles.bar, { paddingHorizontal: side, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style]}
45
+ >
46
+ {actions}
47
+ </View>
48
+ )
49
+ }
50
+
51
+ const styles = StyleSheet.create({
52
+ bar: { alignSelf: "stretch", paddingTop: 8 },
53
+ floating: { position: "absolute", left: 0, right: 0, bottom: 0 },
54
+ })