@plexui/react-native 0.2.25 → 0.2.26

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 (52) hide show
  1. package/README.md +3 -0
  2. package/dist/es/components/BottomActions/BottomActions.js +2 -2
  3. package/dist/es/components/BottomSheet/BottomSheet.js +7 -3
  4. package/dist/es/components/Button/Button.js +10 -6
  5. package/dist/es/components/Card/Card.js +9 -2
  6. package/dist/es/components/Checkbox/Checkbox.js +2 -2
  7. package/dist/es/components/Indicator/CircularProgress.js +11 -5
  8. package/dist/es/components/List/List.js +44 -9
  9. package/dist/es/components/Menu/Menu.js +15 -5
  10. package/dist/es/components/PageControl/PageControl.js +7 -3
  11. package/dist/es/components/RadioGroup/RadioGroup.js +2 -2
  12. package/dist/es/components/RollingNumber/RollingNumber.js +7 -7
  13. package/dist/es/components/Select/Select.js +4 -2
  14. package/dist/es/components/Switch/Switch.js +2 -2
  15. package/dist/es/components/TextLink/TextLink.js +5 -0
  16. package/dist/es/index.js +1 -1
  17. package/dist/es/internal/a11y.js +12 -0
  18. package/dist/es/internal/row.js +13 -0
  19. package/dist/es/theme/ThemeProvider.js +4 -2
  20. package/dist/es/theme/material.js +2 -0
  21. package/dist/types/components/BottomActions/BottomActions.d.ts +6 -1
  22. package/dist/types/components/Button/Button.d.ts +5 -0
  23. package/dist/types/components/Card/Card.d.ts +5 -1
  24. package/dist/types/components/Indicator/CircularProgress.d.ts +10 -2
  25. package/dist/types/components/List/List.d.ts +11 -1
  26. package/dist/types/components/Menu/Menu.d.ts +10 -4
  27. package/dist/types/components/RollingNumber/RollingNumber.d.ts +3 -1
  28. package/dist/types/index.d.ts +1 -1
  29. package/dist/types/internal/a11y.d.ts +22 -0
  30. package/dist/types/internal/row.d.ts +21 -2
  31. package/dist/types/theme/ThemeProvider.d.ts +3 -2
  32. package/dist/types/theme/material.d.ts +2 -0
  33. package/package.json +1 -1
  34. package/src/components/BottomActions/BottomActions.tsx +7 -2
  35. package/src/components/BottomSheet/BottomSheet.tsx +9 -4
  36. package/src/components/Button/Button.tsx +19 -4
  37. package/src/components/Card/Card.tsx +8 -3
  38. package/src/components/Checkbox/Checkbox.tsx +2 -1
  39. package/src/components/Indicator/CircularProgress.tsx +27 -11
  40. package/src/components/List/List.tsx +55 -5
  41. package/src/components/Menu/Menu.tsx +27 -11
  42. package/src/components/PageControl/PageControl.tsx +7 -3
  43. package/src/components/RadioGroup/RadioGroup.tsx +2 -1
  44. package/src/components/RollingNumber/RollingNumber.tsx +10 -8
  45. package/src/components/Select/Select.tsx +4 -1
  46. package/src/components/Switch/Switch.tsx +2 -1
  47. package/src/components/TextLink/TextLink.tsx +6 -0
  48. package/src/index.ts +1 -1
  49. package/src/internal/a11y.ts +13 -0
  50. package/src/internal/row.ts +14 -2
  51. package/src/theme/ThemeProvider.tsx +7 -4
  52. package/src/theme/material.ts +2 -0
@@ -15,8 +15,16 @@ export type CircularProgressProps = {
15
15
  progress?: number
16
16
  /** Size of the indicator, in pixels. @default 28 */
17
17
  size?: number
18
- /** Stroke width of the ring, in pixels of its 20px drawing, between 1 and 4. @default 2 */
18
+ /** Stroke width of the ring, in pixels of its 20px drawing, between 1 and 4 (with `ring="edge"`, in pixels of `size`). @default 2 */
19
19
  strokeWidth?: number
20
+ /**
21
+ * Where the ring stands in its box: `"inset"`, the web's drawing (a ring of radius 8 in 20, so 28 across draws a
22
+ * ring of about 24); `"edge"`, the ring's outside on the box's edge, `size` the ring's own size.
23
+ * @default "inset"
24
+ */
25
+ ring?: "inset" | "edge"
26
+ /** How long a new value takes to draw, in ms. @default 300 on iOS, 200 on Android */
27
+ duration?: number
20
28
  /** Color of the active progress track (stroke): a color or a token, such as `"var(--gray-1000)"`. */
21
29
  trackActiveColor?: string
22
30
  /** Color of the base track (background stroke): a color or a token, such as `"var(--alpha-15)"`. */
@@ -89,6 +97,8 @@ export function CircularProgress({
89
97
  progress: progressProp,
90
98
  size = 28,
91
99
  strokeWidth,
100
+ ring = "inset",
101
+ duration,
92
102
  trackActiveColor,
93
103
  trackColor,
94
104
  "aria-label": ariaLabel,
@@ -100,11 +110,17 @@ export function CircularProgress({
100
110
  const simulated = useSimulatedProgress(maxDuration, progressProp !== undefined || done)
101
111
  const progress = Math.max(0, Math.min(100, progressProp ?? simulated))
102
112
  const shown = useTweenedNumber(progress, {
103
- duration: theme.isAndroid ? 200 : 300,
113
+ duration: duration ?? (theme.isAndroid ? 200 : 300),
104
114
  easing: theme.isAndroid ? curves.decelerate : cssEase,
105
115
  reducedMotion: theme.reducedMotion,
106
116
  })
107
- const stroke = strokeWidth ? Math.min(4, strokeWidth) : 2
117
+ const edge = ring === "edge"
118
+ const stroke = edge ? Math.min(size / 2, strokeWidth ?? 2) : strokeWidth ? Math.min(4, strokeWidth) : 2
119
+ // The drawing: 20 units with a ring of 8 inset, or the box itself with the ring's outside on its edge
120
+ const box = edge ? size : 20
121
+ const center = box / 2
122
+ const radius = edge ? Math.max(0, (size - stroke) / 2) : 8
123
+ const dash = edge ? 2 * Math.PI * radius : DASH
108
124
  // The web's `light-dark(#deede9, var(--green-a50))`: a light green, the green at 15% at night
109
125
  const track = resolve(theme, trackColor, theme.scheme === "dark" ? theme.color("--green-a50") : "#DEEDE9")
110
126
  const active = resolve(theme, trackActiveColor, theme.color("--green-500"))
@@ -120,20 +136,20 @@ export function CircularProgress({
120
136
  testID={testID}
121
137
  style={[{ width: size, height: size }, style]}
122
138
  >
123
- <Svg width={size} height={size} viewBox="0 0 20 20">
124
- <Circle cx={10} cy={10} r={8} fill="none" stroke={track} strokeWidth={stroke} />
139
+ <Svg width={size} height={size} viewBox={`0 0 ${box} ${box}`}>
140
+ <Circle cx={center} cy={center} r={radius} fill="none" stroke={track} strokeWidth={stroke} />
125
141
  <Circle
126
- cx={10}
127
- cy={10}
128
- r={8}
142
+ cx={center}
143
+ cy={center}
144
+ r={radius}
129
145
  fill="none"
130
146
  stroke={active}
131
147
  strokeWidth={stroke}
132
148
  strokeLinecap="round"
133
- strokeDasharray={[DASH, DASH]}
134
- strokeDashoffset={DASH - DASH * (shown / 100)}
149
+ strokeDasharray={[dash, dash]}
150
+ strokeDashoffset={dash - dash * (shown / 100)}
135
151
  // The dash starts at 12 o'clock, as the web's ring turned back a quarter
136
- transform="rotate(-90 10 10)"
152
+ transform={`rotate(-90 ${center} ${center})`}
137
153
  />
138
154
  </Svg>
139
155
  </View>
@@ -3,7 +3,7 @@ import { Animated, Easing, Platform, StyleSheet, View, type GestureResponderEven
3
3
  import { Pressable } from "../../internal/Pressable"
4
4
  import Disclosure from "../../icons/plex/Disclosure"
5
5
  import ExclamationMarkCircle from "../../icons/plex/ExclamationMarkCircle"
6
- import { spaceToggles, useDescription } from "../../internal/a11y"
6
+ import { describedBy, spaceToggles, useDescription, useHint } from "../../internal/a11y"
7
7
  import { useRipple } from "../../internal/ripple"
8
8
  import { flattenChildren, textOf } from "../../internal/children"
9
9
  import { cssBox } from "../../internal/cssBox"
@@ -75,15 +75,33 @@ const ANDROID_CARD_RADIUS = 16
75
75
  /** The start and end of an Android row's text, 21dp in from the card's edge (`--list-row-inset`). */
76
76
  const ANDROID_INSET = 21
77
77
 
78
+ /**
79
+ * Where a List's rows start their text inside the card and how round the card is, for a card built beside a List
80
+ * that must line up with it: iOS `--list-row-inset` (20) and `--field-group-radius` (26), Android 21 and 16.
81
+ */
82
+ export function useListMetrics(): { rowInset: number; radius: number } {
83
+ const theme = useTheme()
84
+ return theme.isAndroid
85
+ ? { rowInset: ANDROID_INSET, radius: ANDROID_CARD_RADIUS }
86
+ : { rowInset: theme.length("--list-row-inset", 20), radius: theme.length("--field-group-radius", 26) }
87
+ }
88
+
78
89
  /** A row's place in its section, and the radius of the corners it shares with the section's card (none in a plain list). */
79
90
  type RowPlace = { first: boolean; last: boolean; top: number; bottom: number }
80
91
  const PlaceContext = createContext<RowPlace>({ first: true, last: true, top: 0, bottom: 0 })
81
92
 
93
+ /**
94
+ * How far a line's baseline stands over the line's bottom: half the leading under the face's box, and its descent.
95
+ * The kit's faces (Inter, SF Pro, Roboto) draw about 1.21 of the size from ascent to descent, 0.24 of it a descent.
96
+ */
97
+ const baselineOverBottom = (fontSize: number, lineHeight: number) => (lineHeight - fontSize * 1.21) / 2 + fontSize * 0.24
98
+
82
99
  /**
83
100
  * A header's action that is not a Button (a count such as "2/3") takes the header's type, so it stands on the title's
84
- * line: iOS 17/22 on its last line, Android the header's 15sp on its 40dp row. Its own style still wins.
101
+ * line: iOS 17/22 on its last line, Android the header's 15sp on its 40dp row. Its own style still wins; on iOS
102
+ * (`onBaseline`) a Text in a type of its own is lifted onto the title's baseline.
85
103
  */
86
- function headerAction(action: ReactNode, type: StyleProp<TextStyle>, color: string): ReactNode {
104
+ function headerAction(action: ReactNode, type: StyleProp<TextStyle>, color: string, onBaseline = false): ReactNode {
87
105
  if (typeof action === "string" || typeof action === "number") {
88
106
  return (
89
107
  <Text color={color} tabularNums style={type}>
@@ -92,7 +110,15 @@ function headerAction(action: ReactNode, type: StyleProp<TextStyle>, color: stri
92
110
  )
93
111
  }
94
112
  if (isValidElement<{ style?: StyleProp<TextStyle> }>(action) && action.type === Text) {
95
- return cloneElement(action, { style: [type, action.props.style] })
113
+ // A count in a type of its own (a 15/20 subheadline beside the 17/22 title) is lifted onto the title's baseline,
114
+ // the row still set at its bottoms so the count stays on the title's last line
115
+ const header = StyleSheet.flatten(type) ?? {}
116
+ const own = StyleSheet.flatten([type, action.props.style]) ?? {}
117
+ const lift =
118
+ onBaseline && typeof header.fontSize === "number" && typeof header.lineHeight === "number" && typeof own.fontSize === "number" && typeof own.lineHeight === "number"
119
+ ? baselineOverBottom(header.fontSize, header.lineHeight) - baselineOverBottom(own.fontSize, own.lineHeight)
120
+ : 0
121
+ return cloneElement(action, { style: [type, action.props.style, lift !== 0 ? { marginBottom: lift } : null] })
96
122
  }
97
123
  return action
98
124
  }
@@ -246,6 +272,7 @@ export function List({
246
272
  action,
247
273
  { fontSize: theme.length("--field-group-title-font-size", 17), lineHeight: theme.length("--field-group-title-line-height", 22) },
248
274
  theme.colors.labelSecondary,
275
+ true,
249
276
  )}
250
277
  </ListActionContext.Provider>
251
278
  ) : null}
@@ -349,6 +376,8 @@ export type ListItemProps = {
349
376
  /** A row in red, as a destructive action row. */
350
377
  destructive?: boolean
351
378
  accessibilityLabel?: string
379
+ /** What a press does, read after the name ("Edit date of birth"): on the row, or on the control that takes its focus. */
380
+ accessibilityHint?: string
352
381
  testID?: string
353
382
  }
354
383
 
@@ -384,6 +413,7 @@ export function ListItem({
384
413
  disabled = false,
385
414
  destructive = false,
386
415
  accessibilityLabel,
416
+ accessibilityHint,
387
417
  testID,
388
418
  }: ListItemProps) {
389
419
  const theme = useTheme()
@@ -429,7 +459,17 @@ export function ListItem({
429
459
  }, [])
430
460
  const handed = !switchRow && !onPress && !control && !disabled ? endPress : null
431
461
  const press = switchRow ? toggle : (onPress ?? control?.toggle ?? handed ?? undefined)
462
+ const hinted = useHint(accessibilityHint)
463
+ // On the web the hint is an unseen text the row's element, or the control that takes its focus, is described by
464
+ const hintNode = hinted.id != null ? <Text nativeID={hinted.id} style={styles.unseen}>{accessibilityHint}</Text> : null
432
465
  const endOwnsFocus = control != null || handed != null || (endHands && press == null)
466
+ // The hint goes to the control at the end only when it takes the row's focus: a switch of its own beside a row that
467
+ // opens a page keeps to its own words
468
+ const controlHint = endOwnsFocus ? accessibilityHint : undefined
469
+ const rowAction = useMemo(
470
+ () => (onLongPress == null && controlHint == null ? null : { run: disabled ? undefined : onLongPress, label: longPressLabel, hint: controlHint, hintId: hinted.id }),
471
+ [controlHint, disabled, hinted.id, longPressLabel, onLongPress],
472
+ )
433
473
  // A destructive row is an action, not a page (Settings' Sign Out has no chevron)
434
474
  const chevron = disclosure ?? (!!onPress && !switchRow && trailing == null && !destructive)
435
475
  const name = accessibilityLabel ?? ([textOf(label), textOf(value)].filter(Boolean).join(", ") || undefined)
@@ -485,6 +525,12 @@ export function ListItem({
485
525
  ref={frameNode as never}
486
526
  collapsable={false}
487
527
  {...described.props}
528
+ // The hint over the description's (a phone's one hint), or beside it on the web
529
+ {...(endOwnsFocus || accessibilityHint == null
530
+ ? null
531
+ : Platform.OS === "web"
532
+ ? { "aria-describedby": describedBy(described.id, hinted.id) }
533
+ : hinted.props)}
488
534
  {...(switchRow ? spaceToggles(toggle) : null)}
489
535
  // A row that toggles its control is not a second element for a screen reader or a Tab stop: the control is
490
536
  accessible={endOwnsFocus ? false : undefined}
@@ -505,7 +551,8 @@ export function ListItem({
505
551
  >
506
552
  {({ pressed }) => (
507
553
  <RowHoldContext.Provider value={disabled ? null : theme.isAndroid ? hold : setHeld}>
508
- <RowActionContext.Provider value={disabled || onLongPress == null ? null : { run: onLongPress, label: longPressLabel }}>
554
+ <RowActionContext.Provider value={rowAction}>
555
+ {hintNode}
509
556
  {ripple.layer}
510
557
  {theme.isAndroid ? null : <RowHighlight on={(pressed || held) && lit} last={last} />}
511
558
  {content(pressed || held)}
@@ -525,10 +572,12 @@ export function ListItem({
525
572
  testID={testID}
526
573
  accessible={named || undefined}
527
574
  accessibilityLabel={accessibilityLabel}
575
+ {...(named ? hinted.props : null)}
528
576
  accessibilityRole={named && Platform.OS !== "web" ? "text" : undefined}
529
577
  role={named && Platform.OS === "web" ? "group" : undefined}
530
578
  style={row}
531
579
  >
580
+ {named ? hintNode : null}
532
581
  {content(false)}
533
582
  </View>
534
583
  )
@@ -1096,6 +1145,7 @@ const styles = StyleSheet.create({
1096
1145
  androidEndEdge: { marginStart: "auto" },
1097
1146
  endAtEdge: { justifyContent: "flex-end" },
1098
1147
  iosHeaderRow: { flexDirection: "row", alignItems: "flex-end", gap: 16 },
1148
+ unseen: { display: "none" },
1099
1149
  androidHeaderRow: { flexDirection: "row", alignItems: "flex-start", minHeight: 40, paddingHorizontal: ANDROID_INSET, paddingTop: 14, paddingBottom: 6, gap: 16 },
1100
1150
  androidHeaderTitle: { flex: 1, minWidth: 0, fontSize: 15, lineHeight: 20 },
1101
1151
  androidHeaderTitleType: { fontSize: 15, lineHeight: 20 },
@@ -50,7 +50,7 @@ type MenuContextValue = {
50
50
  const MenuContext = createContext<MenuContextValue | null>(null)
51
51
 
52
52
  /** Closes the menu once an item is chosen; also used by Select. */
53
- const SurfaceContext = createContext<{ close: () => void; check: boolean; multiple?: boolean; openSub?: (sub: OpenSub) => void; subOpen?: boolean; header?: boolean }>({ close: () => {}, check: false })
53
+ const SurfaceContext = createContext<{ close: () => void; check: boolean; multiple?: boolean; openSub?: (sub: OpenSub) => void; refreshSub?: (owner: object, items: ReactNode) => void; subOpen?: boolean; header?: boolean }>({ close: () => {}, check: false })
54
54
 
55
55
  export type MenuProps = {
56
56
  children: ReactNode
@@ -190,6 +190,16 @@ export type MenuContentProps = {
190
190
  align?: "start" | "end"
191
191
  /** @default 250 on iOS; on Android the popup fits its items, 196 to 288 */
192
192
  width?: number
193
+ /**
194
+ * Several options to pick: a press on an item with `checked` checks or unchecks it and the menu stays open; its items
195
+ * read as checkboxes. @default false
196
+ */
197
+ multiple?: boolean
198
+ /**
199
+ * The menu opens over its trigger, as Android's popup and the web's phone menu; `false` opens it under the trigger,
200
+ * its top at the trigger's bottom edge, as Material's dropdown menu under a chip. @default true
201
+ */
202
+ cover?: boolean
193
203
  "aria-label"?: string
194
204
  testID?: string
195
205
  }
@@ -212,10 +222,6 @@ type SurfaceProps = MenuContentProps & {
212
222
  anchor: MenuAnchor | null
213
223
  onClose: () => void
214
224
  check?: boolean
215
- /** Select's `multiple`: a press checks or unchecks an option and the menu stays open. */
216
- multiple?: boolean
217
- /** The menu opens over its trigger, as Android's popup and the web's phone menu (a dropdown field's list opens under it). @default true */
218
- cover?: boolean
219
225
  /** The List row the menu opens from: on Android the screen dims around it and the popup stands under it. */
220
226
  row?: MenuRow | null
221
227
  /** Opened from a bar's button: on Android the header menu, in the bar's glass. */
@@ -329,9 +335,11 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
329
335
  moveTo(step, 1, true)
330
336
  }
331
337
  const collapse = () => moveTo(step, 0, false, () => setSub(null))
332
- const surface = { close: onClose, check, multiple, openSub, subOpen: sub != null }
338
+ // A multiple choice keeps the submenu open: its items follow the app's state while it shows
339
+ const refreshSub = (owner: object, items: ReactNode) => setSub((current) => (current == null || current.owner !== owner || current.items === items ? current : { ...current, items }))
340
+ const surface = { close: onClose, check, multiple, openSub, refreshSub, subOpen: sub != null }
333
341
  const content = <SurfaceContext.Provider value={surface}>{children}</SurfaceContext.Provider>
334
- const subItems = sub != null ? <SurfaceContext.Provider value={{ close: onClose, check: hasCheckedItems(sub.items) }}>{sub.items}</SurfaceContext.Provider> : null
342
+ const subItems = sub != null ? <SurfaceContext.Provider value={{ close: onClose, check: hasCheckedItems(sub.items), multiple }}>{sub.items}</SurfaceContext.Provider> : null
335
343
  const scale = !theme.reducedMotion && canTransformGlass
336
344
  // The web's keyboard, as the WAI-ARIA menu pattern: focus starts at the chosen item (else the first), the arrows
337
345
  // move to the next one and stop at the ends, Home and End go to the first and the last
@@ -808,11 +816,12 @@ function AndroidMenuSurface({ open, anchor, row, header = false, onClose, align
808
816
  },
809
817
  })
810
818
  })
811
- const surface = { close: onClose, check, multiple, openSub, subOpen: sub != null, header }
819
+ const refreshSub = (owner: object, items: ReactNode) => setSub((current) => (current == null || current.owner !== owner || current.items === items ? current : { ...current, items }))
820
+ const surface = { close: onClose, check, multiple, openSub, refreshSub, subOpen: sub != null, header }
812
821
  // The submenu's page: Back, the 8dp band, the items
813
822
  const subItems =
814
823
  sub != null ? (
815
- <SurfaceContext.Provider value={{ close: onClose, check: hasCheckedItems(sub.items), header }}>
824
+ <SurfaceContext.Provider value={{ close: onClose, check: hasCheckedItems(sub.items), multiple, header }}>
816
825
  <MenuRow icon={<ArrowLeftLg />} stay={collapse}>
817
826
  {sub.backLabel}
818
827
  </MenuRow>
@@ -1235,7 +1244,8 @@ function MenuRow({ children, icon, description, danger = false, disabled = false
1235
1244
  const inlineExtra = (theme: Theme) => theme.length("--menu-padding-inline", 16) - theme.length("--menu-gutter", 10)
1236
1245
 
1237
1246
  /** The heading of a submenu stays and its items scroll; the menu's own items are a submenu's `items`. */
1238
- type OpenSub = { label: ReactNode; items: ReactNode; backLabel: string; y: number }
1247
+ /** An open submenu; `owner` is the row that opened it, the only one whose items it follows. */
1248
+ type OpenSub = { label: ReactNode; items: ReactNode; backLabel: string; y: number; owner?: object }
1239
1249
 
1240
1250
  export type MenuSubContentProps = {
1241
1251
  /** The submenu's items: Menu.Item, Menu.Separator, Menu.Label. */
@@ -1270,8 +1280,14 @@ function MenuSubTrigger({ children, icon, disabled, testID }: MenuSubTriggerProp
1270
1280
  const row = useRef<unknown>(null)
1271
1281
  const open = () => {
1272
1282
  if (!sub) return
1273
- measure(row.current as Measurable | null, (box) => surface.openSub?.({ label: children, items: sub.children, backLabel: sub.backLabel ?? "Back", y: box.y }))
1283
+ measure(row.current as Measurable | null, (box) => surface.openSub?.({ label: children, items: sub.children, backLabel: sub.backLabel ?? "Back", y: box.y, owner: row }))
1274
1284
  }
1285
+ // The submenu this row opened follows the app's state while it shows (a multiple choice keeps it open)
1286
+ const items = sub?.children
1287
+ const { subOpen, refreshSub } = surface
1288
+ useEffect(() => {
1289
+ if (subOpen) refreshSub?.(row, items)
1290
+ }, [items, subOpen, refreshSub])
1275
1291
  return (
1276
1292
  <MenuRow icon={icon} disabled={disabled} testID={testID} rowRef={row} stay={open} opens expanded={surface.subOpen}>
1277
1293
  {children}
@@ -199,8 +199,10 @@ export function PageControl({
199
199
  const gap = small ? 4 : android ? ANDROID_GAP : theme.length("--page-control-gap", 8)
200
200
  const padding = small ? 6 : theme.length("--page-control-padding-inline", 12)
201
201
  const pitch = dot + gap
202
- // Android draws every page's dot at full size; the iOS kit shrinks the ends from seven pages
203
- const sizes = android ? Array.from({ length: Math.max(0, count) }, (): PageControlDotSize => "full") : pageControlDots(count, clampIndex(typeof positionProp === "number" ? Math.round(positionProp) : near, count))
202
+ // Android draws every page's dot at full size up to ANDROID_MAX_DOTS; past that, and on iOS from seven pages, the
203
+ // dots are a window that holds the current page, so a long run of pages never runs off the screen
204
+ const windowed = !android || count > ANDROID_MAX_DOTS
205
+ const sizes = windowed ? pageControlDots(count, clampIndex(typeof positionProp === "number" ? Math.round(positionProp) : near, count)) : Array.from({ length: Math.max(0, count) }, (): PageControlDotSize => "full")
204
206
  // The small and smaller ends keep their share of a full dot (6 and 4 of 8 on iOS)
205
207
  const dotSize = (kind: PageControlDotSize) =>
206
208
  kind === "full"
@@ -226,7 +228,7 @@ export function PageControl({
226
228
  const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary)
227
229
  // Android's current dot is drawn over the gray ones (it stretches between pages) unless the pages' scroll drives the
228
230
  // dots, when their color crosses over as on iOS; a pill is a dot of its own
229
- const worm = android && !pill && positionProp == null
231
+ const worm = android && !pill && positionProp == null && !windowed
230
232
  // Android draws no capsule, not even for `prominent`
231
233
  const capsuleHeight = small ? 16 : theme.length("--page-control-height", 24)
232
234
  const target = android ? 48 : theme.length("--page-control-target-size", 44)
@@ -345,6 +347,8 @@ const ANDROID_SLIDE = { duration: 300, easing: Easing.bezier(0.2, 0, 0, 1) }
345
347
  /** Android's page dots: 5dp, 11dp from one to the next. */
346
348
  const ANDROID_DOT = 5
347
349
  const ANDROID_GAP = 6
350
+ /** The most pages whose dots Android draws all; more take the window of dots the iOS kit keeps. */
351
+ const ANDROID_MAX_DOTS = 9
348
352
  /**
349
353
  * A page change the pager settles on its own (a tap, a change from code): one page in 200ms, on an ease-out quint
350
354
  * standing in for the pager's 1 + (t − 1)⁵.
@@ -5,7 +5,7 @@ import CheckMd from "../../icons/plex/CheckMd"
5
5
  import { useDescription } from "../../internal/a11y"
6
6
  import { ControlLabel } from "../../internal/ControlLabel"
7
7
  import { isRTL, nextKey } from "../../internal/direction"
8
- import { RowActionContext, RowEndContext, RowHoldContext, RowStartContext, holdProps, rowHold } from "../../internal/row"
8
+ import { RowActionContext, RowEndContext, RowHoldContext, RowStartContext, holdProps, rowHint, rowHold } from "../../internal/row"
9
9
  import { mix } from "../../theme/material"
10
10
  import { useTheme } from "../../theme/ThemeProvider"
11
11
  import { ANDROID_ROW_END, androidEaseInOut, iosCheckmarkColor, selectionColor } from "../Switch/Switch"
@@ -150,6 +150,7 @@ function RadioGroupItem({ value, children, description, disabled: itemDisabled =
150
150
  disabled={disabled}
151
151
  {...rowHold(hold)}
152
152
  {...holdProps({ run: disabled ? undefined : onLongPress, label: longPressLabel }, inRow || atStart ? rowAction : null)}
153
+ {...rowHint(rowAction, described)}
153
154
  onPress={() => !selected && context.select(value)}
154
155
  testID={testID}
155
156
  style={[
@@ -14,6 +14,8 @@ export type RollingNumberProps = Omit<TextProps, "children"> & {
14
14
  format?: Intl.NumberFormatOptions
15
15
  /** The style of the row of characters. */
16
16
  containerStyle?: StyleProp<ViewStyle>
17
+ /** How long a change takes, in ms. @default `--rolling-number-duration` (600) on iOS, 320 on Android */
18
+ duration?: number
17
19
  }
18
20
 
19
21
  type Character = { character: string; digit: number | null; key: string }
@@ -63,7 +65,7 @@ export const rollingNumberParts = (value: number, locales: Intl.LocalesArgument
63
65
  * 0.3 of the font size while the new one comes in, in 320ms (ease-out quint), up for a larger number. With reduced
64
66
  * motion it changes at once. A screen reader reads the written number.
65
67
  */
66
- export function RollingNumber({ value, locales, format, containerStyle, style, size, variant, weight, mono, testID, accessibilityLabel, ...text }: RollingNumberProps) {
68
+ export function RollingNumber({ value, locales, format, containerStyle, duration, style, size, variant, weight, mono, testID, accessibilityLabel, ...text }: RollingNumberProps) {
67
69
  const theme = useTheme()
68
70
  const { text: written, glyphs, characters } = rollingNumberParts(value, locales, format)
69
71
  const flat = StyleSheet.flatten(style) as TextStyle | undefined
@@ -86,13 +88,13 @@ export function RollingNumber({ value, locales, format, containerStyle, style, s
86
88
  >
87
89
  {characters.map(({ character, digit, key }) =>
88
90
  theme.isAndroid ? (
89
- <Changing key={key} character={character} up={last.up} lift={0.3 * fontSize} reduced={theme.reducedMotion} text={glyphProps} />
91
+ <Changing key={key} character={character} up={last.up} lift={0.3 * fontSize} reduced={theme.reducedMotion} duration={duration ?? 320} text={glyphProps} />
90
92
  ) : digit === null ? (
91
93
  <Text key={key} {...glyphProps}>
92
94
  {character}
93
95
  </Text>
94
96
  ) : (
95
- <Reel key={key} digit={digit} character={character} glyphs={glyphs} lineHeight={lineHeight} text={glyphProps} />
97
+ <Reel key={key} digit={digit} character={character} glyphs={glyphs} lineHeight={lineHeight} duration={duration} text={glyphProps} />
96
98
  ),
97
99
  )}
98
100
  </View>
@@ -100,11 +102,11 @@ export function RollingNumber({ value, locales, format, containerStyle, style, s
100
102
  }
101
103
 
102
104
  /** iOS's reel: the digit itself, hidden, keeps the width and height; a column of 0 to 9 turns over it. */
103
- function Reel({ digit, character, glyphs, lineHeight, text }: { digit: number; character: string; glyphs: string[]; lineHeight: number; text: TextProps }) {
105
+ function Reel({ digit, character, glyphs, lineHeight, duration, text }: { digit: number; character: string; glyphs: string[]; lineHeight: number; duration?: number; text: TextProps }) {
104
106
  const theme = useTheme()
105
107
  const [line, setLine] = useState(lineHeight)
106
108
  const position = useTransitionValue(digit, {
107
- duration: theme.duration("--rolling-number-duration", 600),
109
+ duration: duration ?? theme.duration("--rolling-number-duration", 600),
108
110
  easing: cssEasing(theme.token("--rolling-number-ease"), curves.easeInOut),
109
111
  native: true,
110
112
  reducedMotion: theme.reducedMotion,
@@ -132,7 +134,7 @@ function Reel({ digit, character, glyphs, lineHeight, text }: { digit: number; c
132
134
  }
133
135
 
134
136
  /** Android's animated text: a new character comes in as the old one leaves, both fading and moving by `lift`. */
135
- function Changing({ character, up, lift, reduced, text }: { character: string; up: boolean; lift: number; reduced: boolean; text: TextProps }) {
137
+ function Changing({ character, up, lift, reduced, duration, text }: { character: string; up: boolean; lift: number; reduced: boolean; duration: number; text: TextProps }) {
136
138
  const [pair, setPair] = useState({ old: null as string | null, now: character, up })
137
139
  if (pair.now !== character) setPair({ old: pair.now, now: character, up })
138
140
  const [progress] = useState(() => new Animated.Value(1))
@@ -142,12 +144,12 @@ function Changing({ character, up, lift, reduced, text }: { character: string; u
142
144
  }, [pair, progress, reduced])
143
145
  useEffect(() => {
144
146
  if (pair.old == null || reduced) return
145
- const animation = Animated.timing(progress, { toValue: 1, duration: 320, easing: curves.easeOutQuint, useNativeDriver: nativeDriver, isInteraction: false })
147
+ const animation = Animated.timing(progress, { toValue: 1, duration, easing: curves.easeOutQuint, useNativeDriver: nativeDriver, isInteraction: false })
146
148
  animation.start(({ finished }) => {
147
149
  if (finished) setPair((current) => (current === pair ? { ...current, old: null } : current))
148
150
  })
149
151
  return () => animation.stop()
150
- }, [pair, progress, reduced])
152
+ }, [duration, pair, progress, reduced])
151
153
  const direction = pair.up ? 1 : -1
152
154
  return (
153
155
  <View>
@@ -5,7 +5,7 @@ import Svg, { Path } from "react-native-svg"
5
5
  import ChevronUpDown from "../../icons/plex/ChevronUpDown"
6
6
  import { spaceToggles } from "../../internal/a11y"
7
7
  import { useRipple } from "../../internal/ripple"
8
- import { RowEndContext, RowFrameContext, RowHoldContext, rowHold } from "../../internal/row"
8
+ import { RowActionContext, RowEndContext, RowFrameContext, RowHoldContext, rowHint, rowHold } from "../../internal/row"
9
9
  import { androidSelector, withAlpha } from "../../theme/material"
10
10
  import { MaterialArrowDropDown } from "../Icon/material"
11
11
  import { useTheme } from "../../theme/ThemeProvider"
@@ -147,6 +147,8 @@ export function Select<T extends SelectOption>(props: SelectProps<T>) {
147
147
  const look = fieldLook(theme, { variant, size, pill }, { focused: open, filled: shownLabel != null, disabled, invalid })
148
148
  const row = useContext(RowEndContext)
149
149
  const hold = useContext(RowHoldContext)
150
+ // At a row's end the select takes the row's focus, and with it the row's hint
151
+ const rowAction = useContext(RowActionContext)
150
152
  const rowEnd = row != null
151
153
  const inRow = rowEnd && !android
152
154
  // At the end of an Android row the select is the row's value, as in an Android value row. On both platforms a press
@@ -177,6 +179,7 @@ export function Select<T extends SelectOption>(props: SelectProps<T>) {
177
179
  <Pressable
178
180
  accessibilityRole="button"
179
181
  accessibilityLabel={ariaLabel ? `${ariaLabel}, ${shownLabel ?? placeholder}` : undefined}
182
+ {...(row != null ? rowHint(rowAction, { props: {} }) : null)}
180
183
  accessibilityState={{ disabled, expanded: open }}
181
184
  aria-haspopup={dialog ? "dialog" : "menu"}
182
185
  aria-expanded={open}
@@ -3,7 +3,7 @@ import { Animated, Easing, StyleSheet, View, type StyleProp, type ViewStyle } fr
3
3
  import { Pressable } from "../../internal/Pressable"
4
4
  import { spaceToggles, useDescription } from "../../internal/a11y"
5
5
  import { ControlLabel } from "../../internal/ControlLabel"
6
- import { RowActionContext, RowEndContext, RowHoldContext, holdProps, rowHold } from "../../internal/row"
6
+ import { RowActionContext, RowEndContext, RowHoldContext, holdProps, rowHint, rowHold } from "../../internal/row"
7
7
  import { androidGray } from "../../theme/material"
8
8
  import { useTheme } from "../../theme/ThemeProvider"
9
9
  import type { SelectionColor, Theme } from "../../theme/types"
@@ -128,6 +128,7 @@ export function Switch({
128
128
  disabled={disabled}
129
129
  {...rowHold(hold)}
130
130
  {...holdProps({}, rowEnd ? rowAction : null)}
131
+ {...rowHint(rowAction, described)}
131
132
  onPress={toggle}
132
133
  testID={testID}
133
134
  // Android's switch row: 50dp, the text ending 11dp before the switch's 37dp view
@@ -26,6 +26,9 @@ export type TextLinkProps = {
26
26
 
27
27
  const EXTERNAL = /^https?:\/\//
28
28
 
29
+ /** The underline's distance under the letters on the web: the token, else a tenth of the type. */
30
+ const underlineOffset = (value: unknown) => (typeof value === "number" ? value : typeof value === "string" && value !== "" ? value : "0.1em")
31
+
29
32
  /**
30
33
  * A link in running text, as @plexui/ui's TextLink: put it inside a `Text`, whose face, size and color it takes
31
34
  * (the web's `currentcolor`), underlined; `primary` colors it with `--link-primary-text-color` and drops the underline.
@@ -60,6 +63,9 @@ export function TextLink({ children, href, primary = false, underline = !primary
60
63
  style={[
61
64
  primary ? { color: theme.color("--link-primary-text-color", theme.colors.textAccent) } : null,
62
65
  underline ? { textDecorationLine: "underline" } : null,
66
+ // The web sets the line a tenth of the type under the letters (`--link-underline-decoration-offset`), clear of
67
+ // the descenders; a phone draws it where the platform does
68
+ underline && Platform.OS === "web" ? ({ textUnderlineOffset: underlineOffset(theme.token("--link-underline-decoration-offset")) } as TextStyle) : null,
63
69
  weight ? theme.font(weight) : null,
64
70
  highlight,
65
71
  style,
package/src/index.ts CHANGED
@@ -95,7 +95,7 @@ export { Badge, type BadgeColor, type BadgeProps, type BadgeSize, type BadgeVari
95
95
  export { BottomActions, type BottomActionsBackground, type BottomActionsProps } from "./components/BottomActions/BottomActions"
96
96
  export { IntroHeader, type IntroHeaderAlign, type IntroHeaderProps } from "./components/IntroHeader/IntroHeader"
97
97
  export { Card, cardColors, type CardColor, type CardMediaProps, type CardProps, type CardSize, type CardVariant } from "./components/Card/Card"
98
- export { List, ListItem, type ListItemProps, type ListProps } from "./components/List/List"
98
+ export { List, ListItem, useListMetrics, type ListItemProps, type ListProps } from "./components/List/List"
99
99
  export { Chip, type ChipProps } from "./components/Chip/Chip"
100
100
  export { Skeleton, type SkeletonProps } from "./components/Skeleton/Skeleton"
101
101
  export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment, type ProgressSize } from "./components/Progress/Progress"
@@ -4,6 +4,19 @@ import { textOf } from "./children"
4
4
 
5
5
  type KeyEvent = { key: string; preventDefault: () => void }
6
6
 
7
+ /**
8
+ * A hint (what a press does) for a screen reader: `accessibilityHint` on a phone; on the web, where React Native Web
9
+ * drops that prop, the id of an unseen text (`nodeProps`, the text's `nativeID`) that `aria-describedby` points at.
10
+ */
11
+ export function useHint(hint: string | undefined) {
12
+ const id = useId()
13
+ if (hint == null || hint === "") return { id: undefined, props: {} }
14
+ return { id: Platform.OS === "web" ? id : undefined, props: Platform.OS === "web" ? { "aria-describedby": id } : { accessibilityHint: hint } }
15
+ }
16
+
17
+ /** Ids for `aria-describedby`, the empty ones left out. */
18
+ export const describedBy = (...ids: (string | undefined)[]) => ids.filter(Boolean).join(" ") || undefined
19
+
7
20
  /**
8
21
  * The description of a control for a screen reader: read after its label and state, as VoiceOver and TalkBack
9
22
  * read a hint, and tied to the text by `aria-describedby` on the web. Give `id` to the description's text as its
@@ -1,5 +1,5 @@
1
1
  import { createContext } from "react"
2
- import type { GestureResponderEvent } from "react-native"
2
+ import { Platform, type GestureResponderEvent } from "react-native"
3
3
 
4
4
  /** The end of a List row, as its control sees it. */
5
5
  export type RowEnd = {
@@ -69,7 +69,8 @@ export function rowHold(hold: ((held: boolean, event?: GestureResponderEvent) =>
69
69
  }
70
70
 
71
71
  /** A List row's touch and hold, for the control at its end, which takes the row's touches and its screen reader focus. */
72
- export type RowAction = { run: () => void; label?: string }
72
+ /** A row's touch and hold (`run`, named by `label`) and its press's hint, for the control that takes the row's focus. */
73
+ export type RowAction = { run?: () => void; label?: string; hint?: string; hintId?: string }
73
74
 
74
75
  /**
75
76
  * Set by a row with `onLongPress`: a control at its end that takes its own touches (a checkbox, a switch, a choice)
@@ -103,3 +104,14 @@ export function holdProps(
103
104
  },
104
105
  }
105
106
  }
107
+
108
+ /**
109
+ * The row's hint on the control that takes the row's focus, kept with the control's own description: a phone reads
110
+ * both as one hint; on the web the control is described by its description and the row's unseen hint text.
111
+ */
112
+ export function rowHint(row: RowAction | null, described: { id?: string; props: { accessibilityHint?: string } }) {
113
+ if (row?.hint == null) return null
114
+ if (Platform.OS === "web") return row.hintId != null ? { "aria-describedby": [described.id, row.hintId].filter(Boolean).join(" ") } : null
115
+ const own = described.props.accessibilityHint
116
+ return { accessibilityHint: own ? `${own}. ${row.hint}` : row.hint }
117
+ }
@@ -24,9 +24,10 @@ export type ThemeProviderProps = {
24
24
  selectionColor?: SelectionColor
25
25
  /**
26
26
  * The product's brand: colors, faces and radii over the Plex UI defaults. A nested ThemeProvider keeps its
27
- * parent's brand and lays its own over it.
27
+ * parent's brand and lays its own over it; `null` draws its subtree in Plex UI's own colors and radii, not the
28
+ * parent's brand (a stand-in for a system prompt, which is in the system's colors, never the app's). Faces stay.
28
29
  */
29
- brand?: BrandTheme
30
+ brand?: BrandTheme | null
30
31
  /**
31
32
  * Faces of the kit (a nested ThemeProvider takes its parent's). Without them the platform's own face is used; see
32
33
  * `interFonts` and `robotoFonts`. Faces per drawn platform, `{ ios, android }`, take the one of `platform`: the
@@ -261,8 +262,10 @@ export function ThemeProvider({ scheme, platform, selectionColor, brand, fonts:
261
262
  // The phone layers of the CSS apply up to 767px: a tablet keeps the touch sizes. Only the bands of the CSS matter.
262
263
  const band = width >= 414 ? 414 : 393
263
264
  const highDensity = PixelRatio.get() >= 1.5
264
- const own = brandOverrides(brand)
265
- const overrides = parent?.overrides || own ? { ...parent?.overrides, ...own } : undefined
265
+ const own = brandOverrides(brand ?? undefined)
266
+ // `brand={null}` starts again from Plex UI's tokens rather than from the parent's brand
267
+ const inherited = brand === null ? undefined : parent?.overrides
268
+ const overrides = inherited || own ? { ...inherited, ...own } : undefined
266
269
  const overridesKey = JSON.stringify(overrides ?? null)
267
270
  const resolver = useMemo(() => {
268
271
  const context: TokenContext = { width: band, highDensity, reducedMotion }
@@ -236,6 +236,8 @@ export const elevationShadow = {
236
236
  bar: "0 2px 8px rgba(0, 0, 0, 0.06)",
237
237
  /** The same over a dark screen, where a light shadow does not show: the controls stand apart by their fill. */
238
238
  barDark: "0 2px 8px rgba(0, 0, 0, 0.3)",
239
+ /** Level 1: an elevated card. */
240
+ level1: "0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15)",
239
241
  level2: "0 2px 6px 2px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.3)",
240
242
  level3: "0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 8px 3px rgba(0, 0, 0, 0.15)",
241
243
  } as const