@plexui/react-native 0.1.0 → 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,4 +1,5 @@
1
1
  import { createContext } from "react"
2
+ import type { GestureResponderEvent } from "react-native"
2
3
 
3
4
  /** The end of a List row, as its control sees it. */
4
5
  export type RowEnd = {
@@ -12,6 +13,17 @@ export type RowEnd = {
12
13
  * an Android value row opens its choice from anywhere on the row). Rows that do not offer it leave it out.
13
14
  */
14
15
  press?: (open: (() => void) | null) => void
16
+ /**
17
+ * Where a field's text stands: at the row's `end` (a row's value), or at the `start` of its own column (a List with
18
+ * `columns`, the web's `[data-field-columns]`). @default "end"
19
+ */
20
+ align?: "start" | "end"
21
+ /**
22
+ * The field is a line of its own under the row's label, or alone in the row (the web's `Field row` with
23
+ * `orientation="vertical"` or `hideLabel`): no frame on either platform, the text from the row's text start, as
24
+ * tall as its lines.
25
+ */
26
+ stacked?: boolean
15
27
  }
16
28
 
17
29
  /**
@@ -27,7 +39,7 @@ export const RowEndContext = createContext<RowEnd | null>(null)
27
39
  * checkbox's toggle) and tells the row while a finger is on it, so the row shows its press. iOS lights a held choice
28
40
  * row (a check or a radio), not a switch row; Android's list selector shows for a touch anywhere on the row.
29
41
  */
30
- export const RowHoldContext = createContext<((held: boolean) => void) | null>(null)
42
+ export const RowHoldContext = createContext<((held: boolean, event?: GestureResponderEvent) => void) | null>(null)
31
43
 
32
44
  /**
33
45
  * Inside the start of a List row: a RadioGroup option given as the row's `leading` (a list of choices with the mark
@@ -49,6 +61,7 @@ export type RowFrame = {
49
61
  export const RowFrameContext = createContext<RowFrame | null>(null)
50
62
 
51
63
  /** A control's press handlers that hold its row while a finger is on it (none outside a pressable row). */
52
- export function rowHold(hold: ((held: boolean) => void) | null) {
53
- return hold ? { onPressIn: () => hold(true), onPressOut: () => hold(false) } : null
64
+ export function rowHold(hold: ((held: boolean, event?: GestureResponderEvent) => void) | null) {
65
+ // The touch goes with the hold: Android's row ripples from it
66
+ return hold ? { onPressIn: (event: GestureResponderEvent) => hold(true, event), onPressOut: () => hold(false) } : null
54
67
  }
@@ -0,0 +1,124 @@
1
+ import { useEffect, useLayoutEffect, useState } from "react"
2
+ import { Animated, Easing, Platform, type EasingFunction } from "react-native"
3
+
4
+ /** Transforms and opacity run on the native driver on a phone; react-native-web has none. */
5
+ export const nativeDriver = Platform.OS !== "web"
6
+
7
+ /** CSS's `ease`, the default curve of a CSS transition and of each keyframe of a CSS animation. */
8
+ export const cssEase = Easing.bezier(0.25, 0.1, 0.25, 1)
9
+
10
+ const beziers = new Map<string, EasingFunction>()
11
+
12
+ /** A `cubic-bezier()` value (a motion token) as an easing; CSS's named curves too. Anything else is `fallback`. */
13
+ export function cssEasing(value: unknown, fallback: EasingFunction = cssEase): EasingFunction {
14
+ if (typeof value !== "string") return fallback
15
+ const named: Record<string, [number, number, number, number]> = {
16
+ ease: [0.25, 0.1, 0.25, 1],
17
+ "ease-in": [0.42, 0, 1, 1],
18
+ "ease-out": [0, 0, 0.58, 1],
19
+ "ease-in-out": [0.42, 0, 0.58, 1],
20
+ linear: [0, 0, 1, 1],
21
+ }
22
+ const match = /cubic-bezier\(\s*([-\d.]+)\s*,\s*([-\d.]+)\s*,\s*([-\d.]+)\s*,\s*([-\d.]+)\s*\)/.exec(value)
23
+ const points = match ? (match.slice(1).map(Number) as [number, number, number, number]) : named[value.trim()]
24
+ if (!points) return fallback
25
+ const key = points.join(",")
26
+ let easing = beziers.get(key)
27
+ if (!easing) {
28
+ easing = Easing.bezier(...points)
29
+ beziers.set(key, easing)
30
+ }
31
+ return easing
32
+ }
33
+
34
+ type TransitionOptions = {
35
+ duration: number
36
+ easing: EasingFunction
37
+ /** Runs on the native driver: only for transforms and opacity. */
38
+ native?: boolean
39
+ /** With reduced motion the value is there at once. */
40
+ reducedMotion?: boolean
41
+ }
42
+
43
+ /**
44
+ * A number that moves to `target` as a CSS transition does: from where it stands, over `duration` on `easing`; at
45
+ * once with reduced motion or a zero duration.
46
+ */
47
+ export function useTransitionValue(target: number, { duration, easing, native = false, reducedMotion = false }: TransitionOptions) {
48
+ const [value] = useState(() => new Animated.Value(target))
49
+ useEffect(() => {
50
+ if (reducedMotion || duration <= 0) {
51
+ value.stopAnimation()
52
+ value.setValue(target)
53
+ return
54
+ }
55
+ const animation = Animated.timing(value, { toValue: target, duration, easing, useNativeDriver: native && nativeDriver, isInteraction: false })
56
+ animation.start()
57
+ return () => animation.stop()
58
+ }, [value, target, duration, easing, native, reducedMotion])
59
+ return value
60
+ }
61
+
62
+ /**
63
+ * A color that changes as a CSS `transition: background-color` does: from the color it showed to the new one over
64
+ * `duration`; at once with reduced motion or a zero duration (a pressed fill that lands at once).
65
+ */
66
+ export function useColorTransition(color: string, { duration, easing, reducedMotion = false }: Omit<TransitionOptions, "native">) {
67
+ const [progress] = useState(() => new Animated.Value(1))
68
+ const [pair, setPair] = useState({ from: color, to: color })
69
+ if (pair.to !== color) setPair({ from: pair.to, to: color })
70
+ const instant = reducedMotion || duration <= 0
71
+ // The new pair starts from its first color before it is drawn
72
+ useLayoutEffect(() => {
73
+ progress.stopAnimation()
74
+ progress.setValue(pair.from === pair.to || instant ? 1 : 0)
75
+ }, [pair, instant, progress])
76
+ useEffect(() => {
77
+ if (pair.from === pair.to || instant) return
78
+ const animation = Animated.timing(progress, { toValue: 1, duration, easing, useNativeDriver: false, isInteraction: false })
79
+ animation.start()
80
+ return () => animation.stop()
81
+ }, [pair, instant, duration, easing, progress])
82
+ if (pair.from === pair.to || instant) return color
83
+ return progress.interpolate({ inputRange: [0, 1], outputRange: [pair.from, pair.to] })
84
+ }
85
+
86
+ /**
87
+ * A clock for a looping animation: 0 to `period` ms, linear, over and over while `running`, after `delay` ms (a CSS
88
+ * animation's delay: only before the first turn). Parts of the animation read it through `interpolate`, as a CSS
89
+ * animation's keyframes read its time.
90
+ */
91
+ export function useLoopClock(period: number, running: boolean, native: boolean, delay = 0) {
92
+ const [clock] = useState(() => new Animated.Value(0))
93
+ useEffect(() => {
94
+ clock.stopAnimation()
95
+ clock.setValue(0)
96
+ if (!running) return
97
+ const loop = Animated.loop(Animated.timing(clock, { toValue: period, duration: period, easing: Easing.linear, useNativeDriver: native && nativeDriver, isInteraction: false }))
98
+ if (delay <= 0) {
99
+ loop.start()
100
+ return () => loop.stop()
101
+ }
102
+ const timer = setTimeout(() => loop.start(), delay)
103
+ return () => {
104
+ clearTimeout(timer)
105
+ loop.stop()
106
+ }
107
+ }, [clock, period, running, native, delay])
108
+ return clock
109
+ }
110
+
111
+ /**
112
+ * A number that moves to `target` as a CSS transition does, handed back as a plain number on each frame: for a value
113
+ * an animated prop cannot carry (an SVG stroke, which does not reach the element on the web).
114
+ */
115
+ export function useTweenedNumber(target: number, { duration, easing, reducedMotion = false }: Omit<TransitionOptions, "native">) {
116
+ const value = useTransitionValue(target, { duration, easing, reducedMotion })
117
+ const [shown, setShown] = useState(target)
118
+ useEffect(() => {
119
+ const id = value.addListener(({ value: next }) => setShown(next))
120
+ return () => value.removeListener(id)
121
+ }, [value])
122
+ // A value set at once (reduced motion) reaches no listener before the next frame
123
+ return reducedMotion || duration <= 0 ? target : shown
124
+ }
@@ -19,7 +19,7 @@ export type ThemeProviderProps = {
19
19
  * `"primary"` is the Plex primary, the ink, as on the web. `"accent"` is each platform's own: on iOS a switch turns
20
20
  * the system green and a checkbox or a checkmark the accent, the iOS tint; on Android all of them take the accent.
21
21
  * Pass `Platform.select` for a different one per platform. A nested ThemeProvider takes its parent's.
22
- * @default "primary"
22
+ * @default "primary" on iOS, "accent" on Android (as the web's Android look)
23
23
  */
24
24
  selectionColor?: SelectionColor
25
25
  /**
@@ -27,8 +27,17 @@ export type ThemeProviderProps = {
27
27
  * parent's brand and lays its own over it.
28
28
  */
29
29
  brand?: BrandTheme
30
- /** Faces of the kit (a nested ThemeProvider takes its parent's). Without them the platform's own face is used; see `interFonts`. */
31
- fonts?: FontFamilies
30
+ /**
31
+ * Faces of the kit (a nested ThemeProvider takes its parent's). Without them the platform's own face is used; see
32
+ * `interFonts` and `robotoFonts`. Faces per drawn platform, `{ ios, android }`, take the one of `platform`: the
33
+ * Material 3 look in a browser on a Mac would otherwise draw in SF, the browser's system face, not Roboto.
34
+ */
35
+ fonts?: FontFamilies | PlatformFonts
36
+ /**
37
+ * The width the phone layer is laid out for, in place of the window's: a phone drawn in a frame inside a wider window
38
+ * (a gallery, a review page) sets the frame's width, 402 for an iPhone 17 Pro.
39
+ */
40
+ viewportWidth?: number
32
41
  children?: ReactNode
33
42
  }
34
43
 
@@ -44,22 +53,47 @@ export const interFonts: FontFamilies = {
44
53
  sans: { regular: "Inter_400Regular", medium: "Inter_500Medium", semibold: "Inter_600SemiBold", bold: "Inter_700Bold" },
45
54
  }
46
55
 
56
+ /**
57
+ * The family names `@expo-google-fonts/roboto` registers, for `fonts`: the face of Material 3. An Android device has
58
+ * Roboto as its system face already; the web needs it loaded, for the Android look in a browser.
59
+ *
60
+ * ```tsx
61
+ * const [loaded] = useFonts({ Roboto_400Regular, Roboto_500Medium, Roboto_600SemiBold, Roboto_700Bold })
62
+ * <ThemeProvider platform={platform} fonts={{ android: robotoFonts }}>
63
+ * ```
64
+ */
65
+ export const robotoFonts: FontFamilies = {
66
+ sans: { regular: "Roboto_400Regular", medium: "Roboto_500Medium", semibold: "Roboto_600SemiBold", bold: "Roboto_700Bold" },
67
+ }
68
+
69
+ /** Faces for each drawn platform: iOS (the system face when left out) and Android. */
70
+ export type PlatformFonts = { ios?: FontFamilies; android?: FontFamilies }
71
+
72
+ const isPlatformFonts = (fonts: FontFamilies | PlatformFonts): fonts is PlatformFonts => "ios" in fonts || "android" in fonts
73
+
47
74
  const ThemeContext = createContext<Theme | null>(null)
48
75
 
49
76
  /** What a ThemeProvider was given, for a ThemeProvider nested in it to start from. */
50
77
  type ThemeSettings = {
51
78
  scheme: ColorScheme | "system"
52
79
  platform: PlatformStyle
53
- selectionColor: SelectionColor
54
- overrides: Record<string, string> | undefined; fonts: FontFamilies | undefined }
80
+ selectionColor: SelectionColor | undefined
81
+ overrides: Record<string, string> | undefined
82
+ fonts: FontFamilies | undefined
83
+ viewportWidth: number | undefined
84
+ }
55
85
  const ThemeSettingsContext = createContext<ThemeSettings | null>(null)
56
86
 
57
- // On the web (react-native-web) the type is Inter's variable font, which the Plex UI tokens set at SF's own Medium and
58
- // Semibold strokes, 510 and 590 (touch.css); a device's system font takes the named weights
87
+ // On the web (react-native-web) a family the app sets (Inter's variable font in the docs) takes the Plex UI tokens' SF
88
+ // strokes, Medium 510 and Semibold 590 (touch.css); a device's system font takes the named weights
59
89
  const WEIGHTS: Record<FontWeightName, TextStyle["fontWeight"]> =
60
90
  Platform.OS === "web"
61
91
  ? { regular: "400", medium: "510" as TextStyle["fontWeight"], semibold: "590" as TextStyle["fontWeight"], bold: "700" }
62
92
  : { regular: "400", medium: "500", semibold: "600", bold: "700" }
93
+ // The web's system font (react-native-web's own stack, no family set): Chromium draws 501–549 of it as a synthesized bold,
94
+ // heavier than 590, so Medium is 500 there; 590 is SF's own Semibold, as an iPhone draws it
95
+ const SYSTEM_WEIGHTS: Record<FontWeightName, TextStyle["fontWeight"]> =
96
+ Platform.OS === "web" ? { ...WEIGHTS, medium: "500" } : WEIGHTS
63
97
 
64
98
  /** The platform a ThemeProvider draws by default. */
65
99
  export function defaultPlatform(): PlatformStyle {
@@ -118,7 +152,7 @@ function fontFor(fonts: FontFamilies | undefined, weight: FontWeightName) {
118
152
  const family = sans?.[weight] ?? (weight === "semibold" ? sans?.bold : undefined) ?? sans?.regular
119
153
  // A family per weight carries its weight: a weight on top would be synthesized on Android
120
154
  if (family && sans?.[weight]) return { fontFamily: family }
121
- return family ? { fontFamily: family, fontWeight: WEIGHTS[weight] } : { fontWeight: WEIGHTS[weight] }
155
+ return family ? { fontFamily: family, fontWeight: WEIGHTS[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] }
122
156
  }
123
157
 
124
158
  /** Builds a theme for a scheme and a platform (ThemeProvider does it for its children). */
@@ -181,7 +215,11 @@ export function createTheme(options: {
181
215
  textInverse: color("--color-text-inverse"),
182
216
  textAccent: color("--color-text-accent"),
183
217
  textDanger: color("--color-text-danger"),
218
+ textSuccess: color("--color-text-success"),
184
219
  accent: color("--color-accent"),
220
+ success: color("--color-background-success-solid"),
221
+ onSuccess: color("--color-text-success-solid"),
222
+ danger: color("--color-background-danger-solid"),
185
223
  background: color("--mobile-surface-plain-primary", color("--color-surface")),
186
224
  groupedBackground: color("--mobile-surface-grouped-primary", color("--color-surface-secondary")),
187
225
  groupedSurface: color("--mobile-surface-grouped-secondary", color("--color-surface")),
@@ -203,13 +241,14 @@ export function createTheme(options: {
203
241
  * Gives its children the Plex UI theme: tokens resolved from @plexui/styles for the scheme, the brand and a phone,
204
242
  * and the platform the components draw. Nest one to theme a part of a screen (a dark sheet on a light page).
205
243
  */
206
- export function ThemeProvider({ scheme, platform, selectionColor, brand, fonts, children }: ThemeProviderProps) {
244
+ export function ThemeProvider({ scheme, platform, selectionColor, brand, fonts: fontsProp, viewportWidth, children }: ThemeProviderProps) {
207
245
  // A nested provider starts from its parent: a dark sheet on a light page keeps the page's platform, brand and faces
208
246
  const parent = useContext(ThemeSettingsContext)
209
247
  const system = useColorScheme()
210
248
  const wantedScheme = scheme ?? parent?.scheme ?? "system"
211
249
  const resolvedScheme: ColorScheme = wantedScheme === "system" ? (system === "dark" ? "dark" : "light") : wantedScheme
212
- const { width } = useWindowDimensions()
250
+ const window = useWindowDimensions()
251
+ const width = viewportWidth ?? parent?.viewportWidth ?? window.width
213
252
  const reducedMotion = useReducedMotion()
214
253
  // The phone layers of the CSS apply up to 767px: a tablet keeps the touch sizes. Only the bands of the CSS matter.
215
254
  const band = width >= 414 ? 414 : 393
@@ -225,10 +264,14 @@ export function ThemeProvider({ scheme, platform, selectionColor, brand, fonts,
225
264
  useEffect(() => {
226
265
  warnUnresolvedColors(JSON.parse(brandKey) === null ? undefined : { colors: JSON.parse(brandKey) }, resolver)
227
266
  }, [brandKey, resolver])
228
- const faces = brand?.fonts ?? fonts ?? parent?.fonts
229
- const facesKey = JSON.stringify(faces ?? null)
230
267
  const resolvedPlatform = platform ?? parent?.platform ?? defaultPlatform()
231
- const selection = selectionColor ?? parent?.selectionColor ?? "primary"
268
+ const fonts = fontsProp && isPlatformFonts(fontsProp) ? (fontsProp[resolvedPlatform] ?? null) : fontsProp
269
+ // `null`: faces per platform that leave this platform out draw the system face, not the parent's
270
+ const faces = brand?.fonts ?? (fonts === null ? undefined : (fonts ?? parent?.fonts))
271
+ const facesKey = JSON.stringify(faces ?? null)
272
+ // The color a provider was given (or its parent's); unset, iOS takes the ink and Android its accent
273
+ const chosenSelection = selectionColor ?? parent?.selectionColor
274
+ const selection: SelectionColor = chosenSelection ?? (resolvedPlatform === "android" ? "accent" : "primary")
232
275
  const theme = useMemo(
233
276
  () =>
234
277
  createTheme({
@@ -242,8 +285,15 @@ export function ThemeProvider({ scheme, platform, selectionColor, brand, fonts,
242
285
  [resolver, resolvedScheme, resolvedPlatform, facesKey, reducedMotion, selection],
243
286
  )
244
287
  const settings = useMemo<ThemeSettings>(
245
- () => ({ scheme: wantedScheme, platform: resolvedPlatform, selectionColor: selection, overrides: JSON.parse(overridesKey) ?? undefined, fonts: JSON.parse(facesKey) ?? undefined }),
246
- [wantedScheme, resolvedPlatform, selection, overridesKey, facesKey],
288
+ () => ({
289
+ scheme: wantedScheme,
290
+ platform: resolvedPlatform,
291
+ selectionColor: chosenSelection,
292
+ overrides: JSON.parse(overridesKey) ?? undefined,
293
+ fonts: JSON.parse(facesKey) ?? undefined,
294
+ viewportWidth: viewportWidth ?? parent?.viewportWidth,
295
+ }),
296
+ [wantedScheme, resolvedPlatform, chosenSelection, overridesKey, facesKey, viewportWidth, parent?.viewportWidth],
247
297
  )
248
298
  return (
249
299
  <ThemeSettingsContext.Provider value={settings}>
@@ -154,10 +154,17 @@ export function materialColors(resolve: (css: string) => string, scheme?: "light
154
154
  export const stateLayer = { hover: 0.08, focus: 0.1, pressed: 0.1, dragged: 0.16 } as const
155
155
 
156
156
  /**
157
- * The press of a row in a section on Android: the settings list selector, a near-black at 11% (#1D000010) over a
158
- * light card, and the dark theme's list selector, white at 5%, over a dark one.
157
+ * The press of a row in a section on Android: black at 4.7% over a light card, as the reference's phone build draws a
158
+ * held card row (its public source's settings selector, #1D000010 at 11%, reads too dark beside it), and the dark
159
+ * theme's list selector, white at 5%, over a dark one.
159
160
  */
160
- export const controlHighlight = (scheme: "light" | "dark") => (scheme === "dark" ? "rgba(255, 255, 255, 0.05)" : "rgba(0, 0, 16, 0.114)")
161
+ export const controlHighlight = (scheme: "light" | "dark") => (scheme === "dark" ? "rgba(255, 255, 255, 0.05)" : "rgba(0, 0, 0, 0.047)")
162
+
163
+ /**
164
+ * Android's list selector outside a section, the ripple of a popup's item and of a dialog's row: black at 0x0F of
165
+ * 255 over a light surface, white at 0x0D at night.
166
+ */
167
+ export const androidSelector = (scheme: "light" | "dark") => (scheme === "dark" ? "rgba(255, 255, 255, 0.051)" : "rgba(0, 0, 0, 0.059)")
161
168
 
162
169
  /**
163
170
  * Text in the accent on Android, as the blue text over a card (a section header, a row's value). Light: #298ACF,
@@ -178,12 +185,37 @@ export function dangerText(theme: Theme): string {
178
185
  }
179
186
 
180
187
  /**
181
- * The divider between the rows of a card on Android: a light gray over a light card (#D9D9D9; the Plex `--gray-150`)
182
- * and darker than the card at night (#000000 under a #181819 card; the darkest Plex gray, `--gray-0`, the grouped
183
- * canvas).
188
+ * The divider between the rows of a card on Android: a light gray over a light card (#D9D9D9) and darker than the
189
+ * card at night (#000000 under a #181819 card; the darkest Plex gray, `--gray-0`, the grouped canvas), as the web's
190
+ * `--android-divider`.
184
191
  */
185
192
  export function divider(theme: Theme): string {
186
- return theme.color(theme.scheme === "dark" ? "--gray-0" : "--gray-150", theme.colors.separator)
193
+ return theme.scheme === "dark" ? theme.color("--gray-0", theme.colors.separator) : "#D9D9D9"
194
+ }
195
+
196
+ /**
197
+ * The fixed grays of the Plex Android look, each with its night pair, as the web's android.css sets them: an off
198
+ * switch's track (`--android-switch-off`: #A7ADB2, `--gray-500` at night), an empty checkbox's ring
199
+ * (`--android-checkbox-ring`: #B0B9C2, `--gray-500`), a field's idle line (`--android-field-line`: #DBDBDB, the text
200
+ * at 24%), a field's hint (`--android-hint`: #A8A8A8, #7D7D7D), the gap between a row menu's groups
201
+ * (`--android-popup-gap`: #F5F5F5, #262626) and a header menu's (`--android-menu-band`: the text at 6%).
202
+ */
203
+ export function androidGray(theme: Theme, role: "switchOff" | "checkboxRing" | "fieldLine" | "hint" | "popupGap" | "menuBand"): string {
204
+ const dark = theme.scheme === "dark"
205
+ switch (role) {
206
+ case "switchOff":
207
+ return dark ? theme.color("--gray-500") : "#A7ADB2"
208
+ case "checkboxRing":
209
+ return dark ? theme.color("--gray-500") : "#B0B9C2"
210
+ case "fieldLine":
211
+ return dark ? withAlpha(theme.colors.text, 0.24) : "#DBDBDB"
212
+ case "hint":
213
+ return dark ? "#7D7D7D" : "#A8A8A8"
214
+ case "popupGap":
215
+ return dark ? "#262626" : "#F5F5F5"
216
+ case "menuBand":
217
+ return withAlpha(theme.colors.text, 0.06)
218
+ }
187
219
  }
188
220
 
189
221
  /**
@@ -82,7 +82,15 @@ export type ThemeColors = {
82
82
  textInverse: string
83
83
  textAccent: string
84
84
  textDanger: string
85
+ /** The positive color as text: a "Verified" or "Saved" line (`--color-text-success`). */
86
+ textSuccess: string
85
87
  accent: string
88
+ /** The positive color as a fill or a glyph: a verified checkmark, a done state (`--color-background-success-solid`; iOS's systemGreen place). */
89
+ success: string
90
+ /** The color of text and glyphs on `success`. */
91
+ onSuccess: string
92
+ /** The destructive color as a fill (`--color-background-danger-solid`). */
93
+ danger: string
86
94
  /** The canvas of a plain screen. */
87
95
  background: string
88
96
  /** The canvas of a grouped screen (iOS grouped lists). */