@plexui/react-native 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +34 -0
  2. package/dist/es/components/ActionSheet/ActionSheet.js +67 -19
  3. package/dist/es/components/Alert/Alert.js +163 -0
  4. package/dist/es/components/Avatar/Avatar.js +20 -8
  5. package/dist/es/components/BottomActions/BottomActions.js +34 -0
  6. package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
  7. package/dist/es/components/Button/Button.js +108 -28
  8. package/dist/es/components/Card/Card.js +16 -8
  9. package/dist/es/components/Checkbox/Checkbox.js +67 -99
  10. package/dist/es/components/Chip/Chip.js +39 -19
  11. package/dist/es/components/Dialog/Dialog.js +38 -24
  12. package/dist/es/components/Field/Field.js +91 -0
  13. package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
  14. package/dist/es/components/Icon/createIcon.js +13 -2
  15. package/dist/es/components/Indicator/CircularProgress.js +80 -0
  16. package/dist/es/components/Indicator/LoadingDots.js +46 -0
  17. package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
  18. package/dist/es/components/Indicator/index.js +3 -0
  19. package/dist/es/components/Input/Input.js +69 -60
  20. package/dist/es/components/InputGroup/InputGroup.js +130 -0
  21. package/dist/es/components/List/List.js +175 -59
  22. package/dist/es/components/Menu/Menu.js +69 -40
  23. package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
  24. package/dist/es/components/OTPInput/OTPInput.js +9 -3
  25. package/dist/es/components/PageControl/PageControl.js +13 -7
  26. package/dist/es/components/Popover/Popover.js +128 -0
  27. package/dist/es/components/Progress/Progress.js +142 -0
  28. package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
  29. package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
  30. package/dist/es/components/Select/Select.js +97 -34
  31. package/dist/es/components/Separator/Separator.js +31 -0
  32. package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
  33. package/dist/es/components/Stepper/Stepper.js +219 -0
  34. package/dist/es/components/Switch/Switch.js +26 -12
  35. package/dist/es/components/TagInput/TagInput.js +121 -0
  36. package/dist/es/components/Text/Text.js +7 -4
  37. package/dist/es/components/TextLink/TextLink.js +42 -0
  38. package/dist/es/components/Textarea/Textarea.js +12 -0
  39. package/dist/es/components/Tip/Tip.js +193 -0
  40. package/dist/es/components/Toolbar/Toolbar.js +6 -2
  41. package/dist/es/components/Tooltip/Tooltip.js +272 -0
  42. package/dist/es/index.js +20 -2
  43. package/dist/es/internal/FloatingPanel.js +111 -0
  44. package/dist/es/internal/fieldStack.js +73 -0
  45. package/dist/es/internal/floating.js +97 -0
  46. package/dist/es/internal/ripple.js +119 -0
  47. package/dist/es/internal/row.js +2 -1
  48. package/dist/es/internal/transition.js +113 -0
  49. package/dist/es/theme/ThemeProvider.js +41 -9
  50. package/dist/es/theme/material.js +37 -7
  51. package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
  52. package/dist/types/components/Alert/Alert.d.ts +51 -0
  53. package/dist/types/components/Avatar/Avatar.d.ts +4 -2
  54. package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
  55. package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
  56. package/dist/types/components/Button/Button.d.ts +20 -5
  57. package/dist/types/components/Card/Card.d.ts +14 -1
  58. package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
  59. package/dist/types/components/Chip/Chip.d.ts +23 -4
  60. package/dist/types/components/Dialog/Dialog.d.ts +9 -5
  61. package/dist/types/components/Field/Field.d.ts +64 -0
  62. package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
  63. package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
  64. package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
  65. package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
  66. package/dist/types/components/Indicator/index.d.ts +3 -0
  67. package/dist/types/components/Input/Input.d.ts +13 -3
  68. package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
  69. package/dist/types/components/List/List.d.ts +57 -14
  70. package/dist/types/components/Menu/Menu.d.ts +4 -0
  71. package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
  72. package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
  73. package/dist/types/components/PageControl/PageControl.d.ts +11 -1
  74. package/dist/types/components/Popover/Popover.d.ts +86 -0
  75. package/dist/types/components/Progress/Progress.d.ts +56 -0
  76. package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
  77. package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
  78. package/dist/types/components/Select/Select.d.ts +36 -8
  79. package/dist/types/components/Separator/Separator.d.ts +19 -0
  80. package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
  81. package/dist/types/components/Stepper/Stepper.d.ts +61 -0
  82. package/dist/types/components/Switch/Switch.d.ts +5 -5
  83. package/dist/types/components/TagInput/TagInput.d.ts +44 -0
  84. package/dist/types/components/TextLink/TextLink.d.ts +30 -0
  85. package/dist/types/components/Textarea/Textarea.d.ts +19 -0
  86. package/dist/types/components/Tip/Tip.d.ts +71 -0
  87. package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
  88. package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
  89. package/dist/types/index.d.ts +20 -2
  90. package/dist/types/internal/FloatingPanel.d.ts +70 -0
  91. package/dist/types/internal/fieldStack.d.ts +48 -0
  92. package/dist/types/internal/floating.d.ts +71 -0
  93. package/dist/types/internal/ripple.d.ts +17 -0
  94. package/dist/types/internal/row.d.ts +15 -3
  95. package/dist/types/internal/transition.d.ts +37 -0
  96. package/dist/types/theme/ThemeProvider.d.ts +28 -4
  97. package/dist/types/theme/material.d.ts +20 -6
  98. package/dist/types/theme/types.d.ts +8 -0
  99. package/package.json +2 -2
  100. package/src/components/ActionSheet/ActionSheet.tsx +123 -38
  101. package/src/components/Alert/Alert.tsx +279 -0
  102. package/src/components/Avatar/Avatar.tsx +21 -9
  103. package/src/components/BottomActions/BottomActions.tsx +54 -0
  104. package/src/components/BottomSheet/BottomSheet.tsx +111 -25
  105. package/src/components/Button/Button.tsx +170 -35
  106. package/src/components/Card/Card.tsx +33 -9
  107. package/src/components/Checkbox/Checkbox.tsx +89 -124
  108. package/src/components/Chip/Chip.tsx +83 -20
  109. package/src/components/Dialog/Dialog.tsx +68 -37
  110. package/src/components/Field/Field.tsx +227 -0
  111. package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
  112. package/src/components/Icon/createIcon.tsx +16 -6
  113. package/src/components/Indicator/CircularProgress.tsx +141 -0
  114. package/src/components/Indicator/LoadingDots.tsx +79 -0
  115. package/src/components/Indicator/LoadingIndicator.tsx +166 -0
  116. package/src/components/Indicator/index.ts +3 -0
  117. package/src/components/Input/Input.tsx +126 -97
  118. package/src/components/InputGroup/InputGroup.tsx +261 -0
  119. package/src/components/List/List.tsx +345 -88
  120. package/src/components/Menu/Menu.tsx +83 -41
  121. package/src/components/NavigationButton/NavigationButton.tsx +35 -5
  122. package/src/components/OTPInput/OTPInput.tsx +21 -2
  123. package/src/components/PageControl/PageControl.tsx +36 -8
  124. package/src/components/Popover/Popover.tsx +261 -0
  125. package/src/components/Progress/Progress.tsx +255 -0
  126. package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
  127. package/src/components/RollingNumber/RollingNumber.tsx +189 -0
  128. package/src/components/Select/Select.tsx +175 -71
  129. package/src/components/Separator/Separator.tsx +51 -0
  130. package/src/components/ShimmerText/ShimmerText.tsx +144 -0
  131. package/src/components/Stepper/Stepper.tsx +386 -0
  132. package/src/components/Switch/Switch.tsx +26 -12
  133. package/src/components/TagInput/TagInput.tsx +227 -0
  134. package/src/components/Text/Text.tsx +8 -4
  135. package/src/components/TextLink/TextLink.tsx +77 -0
  136. package/src/components/Textarea/Textarea.tsx +23 -0
  137. package/src/components/Tip/Tip.tsx +410 -0
  138. package/src/components/Toolbar/Toolbar.tsx +27 -2
  139. package/src/components/Tooltip/Tooltip.tsx +478 -0
  140. package/src/index.ts +36 -2
  141. package/src/internal/FloatingPanel.tsx +199 -0
  142. package/src/internal/fieldStack.tsx +179 -0
  143. package/src/internal/floating.ts +131 -0
  144. package/src/internal/ripple.tsx +132 -0
  145. package/src/internal/row.ts +16 -3
  146. package/src/internal/transition.ts +124 -0
  147. package/src/theme/ThemeProvider.tsx +65 -15
  148. package/src/theme/material.ts +39 -7
  149. package/src/theme/types.ts +8 -0
@@ -0,0 +1,386 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
2
+ import { Animated, Platform, Pressable, StyleSheet, View, type AccessibilityActionEvent, type StyleProp, type ViewStyle } from "react-native"
3
+ import Minus from "../../icons/plex/Minus"
4
+ import Plus from "../../icons/plex/Plus"
5
+ import RemoveTrash from "../../icons/plex/RemoveTrash"
6
+ import { cssEase, useColorTransition } from "../../internal/transition"
7
+ import { mix, withAlpha } from "../../theme/material"
8
+ import { useTheme } from "../../theme/ThemeProvider"
9
+ import type { Theme } from "../../theme/types"
10
+ import { Text } from "../Text/Text"
11
+
12
+ export type StepperProps = {
13
+ /** The controlled value. Use with `onChange`. */
14
+ value?: number
15
+ /** The value when it is initially rendered. Use when you do not need to control the value. @default min */
16
+ defaultValue?: number
17
+ /** Called with the next value after a step. */
18
+ onChange?: (value: number) => void
19
+ /** The lowest value. @default 0 */
20
+ min?: number
21
+ /** The highest value. @default 100 */
22
+ max?: number
23
+ /** The amount each step adds or removes. @default 1 */
24
+ step?: number
25
+ /** A step past `max` continues from `min`, and one below `min` from `max`. @default false */
26
+ wrap?: boolean
27
+ /** Holding a segment keeps stepping, as a native stepper does. @default true */
28
+ autoRepeat?: boolean
29
+ /** When `true`, prevents the user from interacting with the stepper. */
30
+ disabled?: boolean
31
+ /** Fully rounded ends. @default true */
32
+ pill?: boolean
33
+ /**
34
+ * Shows the value between the minus and the plus on one fill, as a cart's quantity: round segments and no
35
+ * separator. Without it the stepper shows no value, as the native one. @default false
36
+ */
37
+ showValue?: boolean
38
+ /** Accessible name of the decrement segment. @default "Decrease" */
39
+ decrementLabel?: string
40
+ /** Accessible name of the increment segment. @default "Increase" */
41
+ incrementLabel?: string
42
+ /**
43
+ * Called when the decrement segment is pressed at `min`. With it, the segment shows a trash can there and removes
44
+ * the item, as a cart's stepper does at a quantity of one (without `wrap`).
45
+ */
46
+ onRemove?: () => void
47
+ /** Accessible name of the decrement segment when it removes. @default "Remove" */
48
+ removeLabel?: string
49
+ /** Accessible name of the value the stepper changes, when no visible label names it. */
50
+ "aria-label"?: string
51
+ /** The `nativeID` of the visible label of the value the stepper changes (Android and the web). */
52
+ "aria-labelledby"?: string
53
+ accessibilityLabel?: string
54
+ testID?: string
55
+ style?: StyleProp<ViewStyle>
56
+ }
57
+
58
+ /** Delay before a held segment starts repeating, and the time between repeats, in ms. */
59
+ const REPEAT_DELAY = 400
60
+ const REPEAT_INTERVAL = 100
61
+
62
+ const decimals = (n: number) => {
63
+ const [, fraction = ""] = String(n).split(".")
64
+ return fraction.length
65
+ }
66
+
67
+ /** The value one step away, clamped to the range or wrapped, without floating point drift. */
68
+ export const stepValue = (current: number, direction: 1 | -1, { min, max, step, wrap }: { min: number; max: number; step: number; wrap: boolean }) => {
69
+ const precision = Math.max(decimals(step), decimals(min), decimals(current))
70
+ const next = Number((current + direction * step).toFixed(precision))
71
+ if (next > max) return wrap ? min : max
72
+ if (next < min) return wrap ? max : min
73
+ return next
74
+ }
75
+
76
+ type Segment = "decrement" | "increment"
77
+
78
+ /** The first number of a `scale` token ("1.1667 1"): how much wider the minus is drawn than the plus. */
79
+ const scaleX = (value: unknown) => {
80
+ const first = typeof value === "number" ? value : parseFloat(String(value ?? ""))
81
+ return Number.isFinite(first) && first > 0 ? first : 1
82
+ }
83
+
84
+ /**
85
+ * The look of the stepper. iOS: the phone layer's tokens, the native 93 x 32 capsule of two 46.5pt segments, each
86
+ * with its own fill (the ink at 6%), a 1 x 24 separator in the tertiary label, 22pt symbols; a pressed segment
87
+ * darkens (15%) at once and fades back in 150ms. Android has no stepper of its own: the same capsule in Material's
88
+ * roles, `surfaceContainerHighest` with the pressed state layer (`onSurface` at 10%), `onSurface` symbols at 38% when
89
+ * they cannot act, and a 48dp target.
90
+ */
91
+ function lookOf(theme: Theme, showValue: boolean) {
92
+ const m = theme.material
93
+ const android = theme.isAndroid
94
+ const height = showValue ? theme.length("--stepper-value-height", 36) : theme.length("--stepper-height", 32)
95
+ const fill = android ? m.surfaceContainerHighest : theme.color(showValue ? "--stepper-value-background" : "--stepper-segment-background")
96
+ return {
97
+ height,
98
+ radius: showValue ? theme.length("--stepper-value-radius", 18) : theme.length("--stepper-radius", 16),
99
+ segmentWidth: showValue ? height : theme.length("--stepper-segment-width", 46.5),
100
+ icon: showValue ? theme.length("--stepper-value-icon-size", 20) : theme.length("--stepper-icon-size", 22),
101
+ minusScale: scaleX(theme.token("--stepper-decrement-icon-scale")),
102
+ target: android ? 48 : theme.length("--stepper-target-size", 44),
103
+ // With the value one fill lies under the whole capsule; without it each segment has its own
104
+ background: showValue ? fill : "transparent",
105
+ segment: showValue ? "transparent" : fill,
106
+ pressed: android
107
+ ? showValue
108
+ ? withAlpha(m.onSurface, 0.1)
109
+ : mix(m.onSurface, fill, 0.1)
110
+ : theme.color(showValue ? "--stepper-value-segment-background-active" : "--stepper-segment-background-active"),
111
+ // The kit's symbols are in the label ink, the color the phone layer gives --color-text (the tokens' own is the desktop gray)
112
+ iconColor: android ? m.onSurface : theme.colors.text,
113
+ iconDisabled: android ? withAlpha(m.onSurface, 0.38) : theme.color("--stepper-icon-disabled-color", theme.colors.labelTertiary),
114
+ separator: android ? m.outlineVariant : theme.color("--stepper-separator-color", theme.colors.labelTertiary),
115
+ separatorInset: theme.length("--stepper-separator-inset", 4),
116
+ value: {
117
+ color: android ? m.onSurface : theme.colors.text,
118
+ disabled: android ? withAlpha(m.onSurface, 0.38) : theme.color("--stepper-value-disabled-color", theme.colors.labelTertiary),
119
+ minWidth: theme.length("--stepper-value-min-width", 24),
120
+ fontSize: theme.length("--stepper-value-font-size", 15),
121
+ lineHeight: theme.length("--stepper-value-line-height", 20),
122
+ },
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Two segments that decrease and increase a number, as the iOS 26 stepper (UIStepper) does, and @plexui/ui's
128
+ * Stepper. It shows no value of its own (`showValue` puts it between the segments, as a cart's quantity): name it
129
+ * with `aria-label`. A press steps at once; held, it repeats after 400ms every 100ms. For a screen reader it is one
130
+ * adjustable element: swipe up or down to step (Android: the increment and decrement actions). On the web it is a
131
+ * spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.
132
+ */
133
+ export function Stepper({
134
+ value: valueProp,
135
+ defaultValue,
136
+ onChange,
137
+ min = 0,
138
+ max = 100,
139
+ step = 1,
140
+ wrap = false,
141
+ autoRepeat = true,
142
+ disabled = false,
143
+ pill = true,
144
+ showValue = false,
145
+ decrementLabel = "Decrease",
146
+ incrementLabel = "Increase",
147
+ onRemove,
148
+ removeLabel = "Remove",
149
+ "aria-label": ariaLabel,
150
+ "aria-labelledby": ariaLabelledBy,
151
+ accessibilityLabel,
152
+ testID,
153
+ style,
154
+ }: StepperProps) {
155
+ const theme = useTheme()
156
+ const look = lookOf(theme, showValue)
157
+ const [internalValue, setInternalValue] = useState(() => defaultValue ?? min)
158
+ const value = valueProp ?? internalValue
159
+ // Timers and handlers read the latest props through refs; an uncontrolled step advances the value at once
160
+ const valueRef = useRef(value)
161
+ const latest = useRef({ onChange, onRemove, min, max, step, wrap, disabled, controlled: valueProp !== undefined })
162
+ useLayoutEffect(() => {
163
+ valueRef.current = value
164
+ latest.current = { onChange, onRemove, min, max, step, wrap, disabled, controlled: valueProp !== undefined }
165
+ })
166
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
167
+ const [pressed, setPressed] = useState<Segment | null>(null)
168
+
169
+ const commit = useCallback((next: number) => {
170
+ if (next === valueRef.current) return false
171
+ // A controlled value changes only when the owner passes it back
172
+ if (!latest.current.controlled) {
173
+ valueRef.current = next
174
+ setInternalValue(next)
175
+ }
176
+ latest.current.onChange?.(next)
177
+ return true
178
+ }, [])
179
+
180
+ const stepBy = useCallback(
181
+ (direction: 1 | -1, times = 1) => {
182
+ let next = valueRef.current
183
+ for (let i = 0; i < times; i++) next = stepValue(next, direction, latest.current)
184
+ return commit(next)
185
+ },
186
+ [commit],
187
+ )
188
+
189
+ const stopRepeat = useCallback(() => {
190
+ clearTimeout(timer.current)
191
+ timer.current = undefined
192
+ setPressed(null)
193
+ }, [])
194
+
195
+ useEffect(() => stopRepeat, [stopRepeat])
196
+
197
+ const atMin = !wrap && value <= min
198
+ const atMax = !wrap && value >= max
199
+ // At the minimum the decrement segment removes the item, when the owner can remove it
200
+ const removes = atMin && onRemove !== undefined
201
+
202
+ const startPress = (segment: Segment) => {
203
+ if (disabled) return
204
+ if (segment === "decrement" && removes) {
205
+ setPressed(segment)
206
+ latest.current.onRemove?.()
207
+ return
208
+ }
209
+ if (segment === "decrement" ? atMin : atMax) return
210
+ setPressed(segment)
211
+ const direction = segment === "decrement" ? -1 : 1
212
+ stepBy(direction)
213
+ if (!autoRepeat) return
214
+ const repeat = () => {
215
+ if (latest.current.disabled || !stepBy(direction)) return stopRepeat()
216
+ timer.current = setTimeout(repeat, REPEAT_INTERVAL)
217
+ }
218
+ timer.current = setTimeout(repeat, REPEAT_DELAY)
219
+ }
220
+
221
+ const keys =
222
+ Platform.OS === "web"
223
+ ? {
224
+ tabIndex: (disabled ? -1 : 0) as 0 | -1,
225
+ onKeyDown: (raw: unknown) => {
226
+ const event = raw as { key: string; altKey?: boolean; ctrlKey?: boolean; metaKey?: boolean; preventDefault: () => void }
227
+ if (disabled || event.altKey || event.ctrlKey || event.metaKey) return
228
+ const actions: Record<string, () => void> = {
229
+ ArrowUp: () => stepBy(1),
230
+ ArrowDown: () => stepBy(-1),
231
+ PageUp: () => stepBy(1, 10),
232
+ PageDown: () => stepBy(-1, 10),
233
+ Home: () => commit(min),
234
+ End: () => commit(max),
235
+ // At the minimum Delete or Backspace removes, as the trash can does; the arrows never do
236
+ ...(removes && { Delete: () => latest.current.onRemove?.(), Backspace: () => latest.current.onRemove?.() }),
237
+ }
238
+ const action = actions[event.key]
239
+ if (!action) return
240
+ event.preventDefault()
241
+ action()
242
+ },
243
+ role: "spinbutton" as const,
244
+ "aria-keyshortcuts": removes ? "Delete" : undefined,
245
+ }
246
+ : {}
247
+
248
+ const onAccessibilityAction = (event: AccessibilityActionEvent) => {
249
+ if (disabled) return
250
+ const name = event.nativeEvent.actionName
251
+ if (name === "increment") stepBy(1)
252
+ else if (name === "decrement") stepBy(-1)
253
+ else if (name === "remove") latest.current.onRemove?.()
254
+ }
255
+
256
+ const segment = (kind: Segment) => {
257
+ const remove = kind === "decrement" && removes
258
+ const atEnd = !remove && (kind === "decrement" ? atMin : atMax)
259
+ return (
260
+ <StepperSegment
261
+ key={kind}
262
+ kind={kind}
263
+ remove={remove}
264
+ inactive={atEnd || disabled}
265
+ disabled={disabled}
266
+ pressed={pressed === kind && !disabled}
267
+ label={remove ? removeLabel : kind === "decrement" ? decrementLabel : incrementLabel}
268
+ look={look}
269
+ showValue={showValue}
270
+ pill={pill}
271
+ reducedMotion={theme.reducedMotion}
272
+ onPressIn={() => startPress(kind)}
273
+ onPressOut={stopRepeat}
274
+ />
275
+ )
276
+ }
277
+
278
+ const radius = pill ? look.height / 2 : look.radius
279
+ return (
280
+ <View
281
+ {...keys}
282
+ accessible
283
+ accessibilityRole="adjustable"
284
+ accessibilityLabel={accessibilityLabel ?? ariaLabel}
285
+ aria-labelledby={ariaLabelledBy}
286
+ accessibilityValue={{ min, max, now: value }}
287
+ accessibilityState={{ disabled }}
288
+ accessibilityActions={[{ name: "increment" }, { name: "decrement" }, ...(removes ? [{ name: "remove", label: removeLabel }] : [])]}
289
+ onAccessibilityAction={onAccessibilityAction}
290
+ aria-valuemin={min}
291
+ aria-valuemax={max}
292
+ aria-valuenow={value}
293
+ aria-disabled={disabled || undefined}
294
+ testID={testID}
295
+ style={[styles.root, { height: look.height, borderRadius: radius, backgroundColor: look.background }, style]}
296
+ >
297
+ {segment("decrement")}
298
+ {/* Drawn over the decrement and under the increment, in the order of the web stepper */}
299
+ {showValue ? null : (
300
+ <View
301
+ pointerEvents="none"
302
+ style={[
303
+ styles.separator,
304
+ {
305
+ top: look.separatorInset,
306
+ height: look.height - 2 * look.separatorInset,
307
+ start: look.segmentWidth - 0.5,
308
+ backgroundColor: look.separator,
309
+ },
310
+ ]}
311
+ />
312
+ )}
313
+ {showValue ? (
314
+ // The adjustable element already reads its value, so the shown one is not read again
315
+ <View pointerEvents="none" importantForAccessibility="no-hide-descendants" accessibilityElementsHidden style={[styles.value, { minWidth: look.value.minWidth }]}>
316
+ <Text
317
+ weight="medium"
318
+ tabularNums
319
+ numberOfLines={1}
320
+ color={disabled ? look.value.disabled : look.value.color}
321
+ style={{ fontSize: look.value.fontSize, lineHeight: look.value.lineHeight }}
322
+ >
323
+ {value}
324
+ </Text>
325
+ </View>
326
+ ) : null}
327
+ {segment("increment")}
328
+ </View>
329
+ )
330
+ }
331
+
332
+ type SegmentProps = {
333
+ kind: Segment
334
+ remove: boolean
335
+ inactive: boolean
336
+ disabled: boolean
337
+ pressed: boolean
338
+ label: string
339
+ look: ReturnType<typeof lookOf>
340
+ showValue: boolean
341
+ pill: boolean
342
+ reducedMotion: boolean
343
+ onPressIn: () => void
344
+ onPressOut: () => void
345
+ }
346
+
347
+ /** A segment: its fill (the pressed one at once, back in 150ms), its symbol and a target of 44pt (48dp) in height. */
348
+ function StepperSegment({ kind, remove, inactive, disabled, pressed, label, look, showValue, pill, reducedMotion, onPressIn, onPressOut }: SegmentProps) {
349
+ const fill = useColorTransition(pressed ? look.pressed : look.segment, { duration: pressed ? 0 : 150, easing: cssEase, reducedMotion })
350
+ const Icon = remove ? RemoveTrash : kind === "decrement" ? Minus : Plus
351
+ const radius = pill ? look.height / 2 : look.radius
352
+ const corners: ViewStyle = showValue
353
+ ? { borderRadius: radius }
354
+ : kind === "decrement"
355
+ ? { borderTopStartRadius: radius, borderBottomStartRadius: radius }
356
+ : { borderTopEndRadius: radius, borderBottomEndRadius: radius }
357
+ const slop = Math.max(0, (look.target - look.height) / 2)
358
+ return (
359
+ <Pressable
360
+ accessible={false}
361
+ focusable={false}
362
+ disabled={disabled}
363
+ aria-label={label}
364
+ hitSlop={{ top: slop, bottom: slop }}
365
+ onPressIn={onPressIn}
366
+ onPressOut={onPressOut}
367
+ style={styles.segmentTarget}
368
+ >
369
+ <Animated.View style={[styles.segment, corners, { width: look.segmentWidth, height: look.height, backgroundColor: fill }]}>
370
+ <Icon
371
+ size={look.icon}
372
+ color={inactive ? look.iconDisabled : look.iconColor}
373
+ style={kind === "decrement" && !remove && look.minusScale !== 1 ? { transform: [{ scaleX: look.minusScale }] } : undefined}
374
+ />
375
+ </Animated.View>
376
+ </Pressable>
377
+ )
378
+ }
379
+
380
+ const styles = StyleSheet.create({
381
+ root: { flexDirection: "row", alignItems: "stretch", alignSelf: "flex-start", flexShrink: 0 },
382
+ separator: { position: "absolute", width: 1, borderRadius: 1 },
383
+ segmentTarget: { flexShrink: 0 },
384
+ segment: { alignItems: "center", justifyContent: "center" },
385
+ value: { alignItems: "center", justifyContent: "center", flexShrink: 0 },
386
+ })
@@ -3,6 +3,7 @@ import { Animated, Easing, Pressable, StyleSheet, View, type StyleProp, type Vie
3
3
  import { spaceToggles, useDescription } from "../../internal/a11y"
4
4
  import { ControlLabel } from "../../internal/ControlLabel"
5
5
  import { RowEndContext, RowHoldContext, rowHold } from "../../internal/row"
6
+ import { androidGray } from "../../theme/material"
6
7
  import { useTheme } from "../../theme/ThemeProvider"
7
8
  import type { SelectionColor, Theme } from "../../theme/types"
8
9
 
@@ -43,18 +44,18 @@ export function iosCheckmarkColor(theme: Theme) {
43
44
  }
44
45
 
45
46
  /**
46
- * The gray of an Android off switch and of the dots past the choice of a stepped slider: #A6ADB3 on white, #606060 at
47
- * night. The nearest neutral grays: --gray-300 (#AFAFAF) and, at night, --gray-500 (#5D5D5D).
47
+ * The gray of an Android off switch and of the dots past the choice of a stepped slider: #A7ADB2 on white, --gray-500
48
+ * (#5D5D5D) at night, as the web's `--android-switch-off`.
48
49
  */
49
50
  export function androidSwitchOff(theme: Theme) {
50
- return theme.color(theme.scheme === "dark" ? "--gray-500" : "--gray-300")
51
+ return androidGray(theme, "switchOff")
51
52
  }
52
53
 
53
54
  /** Android's default ease-in-out (AccelerateDecelerateInterpolator), which an ObjectAnimator runs by default. */
54
55
  export const androidEaseInOut = Easing.inOut(Easing.sin)
55
56
 
56
- /** A List row on Android ends 20dp in from the card's edge: a control at its end moves in from there. */
57
- export const ANDROID_ROW_END = 20
57
+ /** A List row on Android ends 21dp in from the card's edge (`--list-row-inset`): a control at its end moves in from there. */
58
+ export const ANDROID_ROW_END = 21
58
59
  /** A switch row: the switch's 37dp view stands 22dp in from the row's end. */
59
60
  const ANDROID_SWITCH_END = 22
60
61
 
@@ -71,7 +72,7 @@ function useSwitchProgress(theme: Theme, checked: boolean) {
71
72
 
72
73
  /**
73
74
  * A switch: the iOS 26 switch of the phone layer (a 63x28 track, a 37x24 capsule thumb, `--switch-*`), or Android's
74
- * (a 31x14dp track and a 20dp thumb over it, a ring of the track's color around a 16dp knob of the card's color, the
75
+ * (a 31x14dp track and a 20.6dp thumb over it, a 2dp ring of the track's color around a knob of the card's color, the
75
76
  * track's color changing as the thumb moves; a 50dp switch row, the label 11dp from the switch). Props follow
76
77
  * @plexui/ui.
77
78
  */
@@ -210,10 +211,15 @@ function IOSTrack({ theme, checked, disabled, color, progress, held = false }: T
210
211
  )
211
212
  }
212
213
 
213
- /** Android's switch: its view 37x20dp, the track 31x14 in it, the thumb's center 7 to 24 along the track. */
214
+ /**
215
+ * Android's switch: its view 37x20dp, the track 31x14 in it, the 20.6dp thumb (a 2dp ring) reaching 3dp past the
216
+ * track's ends, its center 7.3 to 23.7 along the track (the reference: 31.2x14.1, a 20.6 thumb with a 1.9 ring).
217
+ */
214
218
  const ANDROID_VIEW = { width: 37, height: 20 }
215
219
  const ANDROID_TRACK = { width: 31, height: 14 }
216
220
  const ANDROID_START = (ANDROID_VIEW.width - ANDROID_TRACK.width) / 2
221
+ const ANDROID_THUMB = 20.6
222
+ const ANDROID_RING = 2
217
223
 
218
224
  function AndroidTrack({ theme, color, progress }: TrackProps) {
219
225
  // The knob is the card's color (the white of a card); the track off the gray of an off switch, on the selection
@@ -222,8 +228,8 @@ function AndroidTrack({ theme, color, progress }: TrackProps) {
222
228
  const off = androidSwitchOff(theme)
223
229
  const on = selectionColor(theme, color)
224
230
  const track = progress.interpolate({ inputRange: [0, 1], outputRange: [off, on] })
225
- // The thumb's left edge: its 20dp circle centered 7 and 24 along the track (mirrored in a right-to-left row)
226
- const start = progress.interpolate({ inputRange: [0, 1], outputRange: [ANDROID_START + 7 - 10, ANDROID_START + 24 - 10] })
231
+ // The thumb's start edge: 3dp before the track's start off, 3dp past its end on (mirrored in a right-to-left row)
232
+ const start = progress.interpolate({ inputRange: [0, 1], outputRange: [ANDROID_START - 3, ANDROID_START + ANDROID_TRACK.width + 3 - ANDROID_THUMB] })
227
233
  return (
228
234
  <View style={styles.androidView}>
229
235
  <Animated.View style={[styles.androidTrack, { backgroundColor: track }]} />
@@ -238,10 +244,18 @@ const styles = StyleSheet.create({
238
244
  row: { flexDirection: "row", alignItems: "center", alignSelf: "stretch" },
239
245
  grow: { flex: 1, minWidth: 0 },
240
246
  dim: { opacity: 0.5 },
241
- // The row ends 20dp in; Android's switch stands 22dp in
247
+ // The row ends 21dp in; Android's switch stands 22dp in
242
248
  androidRowEnd: { marginEnd: ANDROID_SWITCH_END - ANDROID_ROW_END },
243
249
  androidView: { width: ANDROID_VIEW.width, height: ANDROID_VIEW.height, justifyContent: "center" },
244
250
  androidTrack: { position: "absolute", start: ANDROID_START, top: (ANDROID_VIEW.height - ANDROID_TRACK.height) / 2, width: ANDROID_TRACK.width, height: ANDROID_TRACK.height, borderRadius: ANDROID_TRACK.height / 2 },
245
- androidThumb: { position: "absolute", top: 0, width: 20, height: 20, borderRadius: 10, alignItems: "center", justifyContent: "center" },
246
- androidKnob: { width: 16, height: 16, borderRadius: 8 },
251
+ androidThumb: {
252
+ position: "absolute",
253
+ top: (ANDROID_VIEW.height - ANDROID_THUMB) / 2,
254
+ width: ANDROID_THUMB,
255
+ height: ANDROID_THUMB,
256
+ borderRadius: ANDROID_THUMB / 2,
257
+ alignItems: "center",
258
+ justifyContent: "center",
259
+ },
260
+ androidKnob: { width: ANDROID_THUMB - 2 * ANDROID_RING, height: ANDROID_THUMB - 2 * ANDROID_RING, borderRadius: ANDROID_THUMB / 2 - ANDROID_RING },
247
261
  })