@plexui/react-native 0.2.24 → 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.
- package/README.md +3 -0
- package/dist/es/components/BottomActions/BottomActions.js +2 -2
- package/dist/es/components/BottomSheet/BottomSheet.js +7 -3
- package/dist/es/components/Button/Button.js +22 -28
- package/dist/es/components/Card/Card.js +9 -2
- package/dist/es/components/Checkbox/Checkbox.js +4 -2
- package/dist/es/components/Chip/Chip.js +8 -7
- package/dist/es/components/Indicator/CircularProgress.js +11 -5
- package/dist/es/components/List/List.js +45 -10
- package/dist/es/components/Menu/Menu.js +15 -5
- package/dist/es/components/PageControl/PageControl.js +7 -3
- package/dist/es/components/RadioGroup/RadioGroup.js +5 -3
- package/dist/es/components/RollingNumber/RollingNumber.js +7 -7
- package/dist/es/components/Select/Select.js +4 -2
- package/dist/es/components/Switch/Switch.js +4 -2
- package/dist/es/components/TextLink/TextLink.js +5 -0
- package/dist/es/icons/plex/VerifiedFilled.js +3 -0
- package/dist/es/icons/plex/index.js +1 -0
- package/dist/es/index.js +1 -1
- package/dist/es/internal/a11y.js +12 -0
- package/dist/es/internal/row.js +40 -0
- package/dist/es/theme/ThemeProvider.js +4 -2
- package/dist/es/theme/material.js +2 -0
- package/dist/types/components/BottomActions/BottomActions.d.ts +6 -1
- package/dist/types/components/Button/Button.d.ts +6 -1
- package/dist/types/components/Card/Card.d.ts +5 -1
- package/dist/types/components/Chip/Chip.d.ts +5 -1
- package/dist/types/components/Indicator/CircularProgress.d.ts +10 -2
- package/dist/types/components/List/List.d.ts +16 -1
- package/dist/types/components/Menu/Menu.d.ts +10 -4
- package/dist/types/components/RadioGroup/RadioGroup.d.ts +5 -1
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +3 -1
- package/dist/types/icons/plex/VerifiedFilled.d.ts +2 -0
- package/dist/types/icons/plex/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/a11y.d.ts +22 -0
- package/dist/types/internal/row.d.ts +69 -1
- package/dist/types/theme/ThemeProvider.d.ts +3 -2
- package/dist/types/theme/material.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/BottomActions/BottomActions.tsx +7 -2
- package/src/components/BottomSheet/BottomSheet.tsx +9 -4
- package/src/components/Button/Button.tsx +31 -26
- package/src/components/Card/Card.tsx +8 -3
- package/src/components/Checkbox/Checkbox.tsx +5 -1
- package/src/components/Chip/Chip.tsx +17 -5
- package/src/components/Indicator/CircularProgress.tsx +27 -11
- package/src/components/List/List.tsx +67 -12
- package/src/components/Menu/Menu.tsx +27 -11
- package/src/components/PageControl/PageControl.tsx +7 -3
- package/src/components/RadioGroup/RadioGroup.tsx +10 -2
- package/src/components/RollingNumber/RollingNumber.tsx +10 -8
- package/src/components/Select/Select.tsx +4 -1
- package/src/components/Switch/Switch.tsx +5 -1
- package/src/components/TextLink/TextLink.tsx +6 -0
- package/src/icons/plex/VerifiedFilled.ts +4 -0
- package/src/icons/plex/index.ts +1 -0
- package/src/index.ts +1 -1
- package/src/internal/a11y.ts +13 -0
- package/src/internal/row.ts +49 -1
- package/src/theme/ThemeProvider.tsx +7 -4
- package/src/theme/material.ts +2 -0
|
@@ -3,12 +3,12 @@ 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"
|
|
10
10
|
import { mirrored, useRTL } from "../../internal/direction"
|
|
11
|
-
import { RowEndContext, RowFrameContext, RowHoldContext, RowStartContext, type RowEnd, type RowFrame } from "../../internal/row"
|
|
11
|
+
import { RowActionContext, RowEndContext, RowFrameContext, RowHoldContext, RowStartContext, holdProps, type RowEnd, type RowFrame } from "../../internal/row"
|
|
12
12
|
import { accentText, controlHighlight, dangerText, divider, withAlpha } from "../../theme/material"
|
|
13
13
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
14
14
|
import type { Theme } from "../../theme/types"
|
|
@@ -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
|
-
|
|
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}
|
|
@@ -340,10 +367,17 @@ export type ListItemProps = {
|
|
|
340
367
|
onPress?: () => void
|
|
341
368
|
/** A touch and hold on the row (half a second): a ContextMenu around the row sets it. */
|
|
342
369
|
onLongPress?: () => void
|
|
370
|
+
/**
|
|
371
|
+
* The name a screen reader gives the hold's action ("Show meaning"), or it reads the bare action. A control at the
|
|
372
|
+
* row's end that takes the row's focus (a checkbox, a switch, a choice) carries the action and holds for the row.
|
|
373
|
+
*/
|
|
374
|
+
longPressLabel?: string
|
|
343
375
|
disabled?: boolean
|
|
344
376
|
/** A row in red, as a destructive action row. */
|
|
345
377
|
destructive?: boolean
|
|
346
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
|
|
347
381
|
testID?: string
|
|
348
382
|
}
|
|
349
383
|
|
|
@@ -375,9 +409,11 @@ export function ListItem({
|
|
|
375
409
|
disclosure,
|
|
376
410
|
onPress,
|
|
377
411
|
onLongPress,
|
|
412
|
+
longPressLabel,
|
|
378
413
|
disabled = false,
|
|
379
414
|
destructive = false,
|
|
380
415
|
accessibilityLabel,
|
|
416
|
+
accessibilityHint,
|
|
381
417
|
testID,
|
|
382
418
|
}: ListItemProps) {
|
|
383
419
|
const theme = useTheme()
|
|
@@ -423,7 +459,17 @@ export function ListItem({
|
|
|
423
459
|
}, [])
|
|
424
460
|
const handed = !switchRow && !onPress && !control && !disabled ? endPress : null
|
|
425
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
|
|
426
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
|
+
)
|
|
427
473
|
// A destructive row is an action, not a page (Settings' Sign Out has no chevron)
|
|
428
474
|
const chevron = disclosure ?? (!!onPress && !switchRow && trailing == null && !destructive)
|
|
429
475
|
const name = accessibilityLabel ?? ([textOf(label), textOf(value)].filter(Boolean).join(", ") || undefined)
|
|
@@ -479,6 +525,12 @@ export function ListItem({
|
|
|
479
525
|
ref={frameNode as never}
|
|
480
526
|
collapsable={false}
|
|
481
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)}
|
|
482
534
|
{...(switchRow ? spaceToggles(toggle) : null)}
|
|
483
535
|
// A row that toggles its control is not a second element for a screen reader or a Tab stop: the control is
|
|
484
536
|
accessible={endOwnsFocus ? false : undefined}
|
|
@@ -490,10 +542,7 @@ export function ListItem({
|
|
|
490
542
|
aria-checked={switchRow ? checked : undefined}
|
|
491
543
|
disabled={disabled || (press == null && onLongPress == null)}
|
|
492
544
|
onPress={press}
|
|
493
|
-
|
|
494
|
-
delayLongPress={onLongPress ? 500 : undefined}
|
|
495
|
-
accessibilityActions={onLongPress ? [{ name: "longpress" }] : undefined}
|
|
496
|
-
onAccessibilityAction={onLongPress ? (event) => event.nativeEvent.actionName === "longpress" && onLongPress() : undefined}
|
|
545
|
+
{...holdProps({ run: onLongPress, label: longPressLabel }, null)}
|
|
497
546
|
onPressIn={drawn ? ripple.start : undefined}
|
|
498
547
|
onPressOut={drawn ? ripple.end : undefined}
|
|
499
548
|
android_ripple={nativeRipple ? { color: highlight, foreground: true } : undefined}
|
|
@@ -502,9 +551,12 @@ export function ListItem({
|
|
|
502
551
|
>
|
|
503
552
|
{({ pressed }) => (
|
|
504
553
|
<RowHoldContext.Provider value={disabled ? null : theme.isAndroid ? hold : setHeld}>
|
|
505
|
-
{
|
|
506
|
-
|
|
507
|
-
|
|
554
|
+
<RowActionContext.Provider value={rowAction}>
|
|
555
|
+
{hintNode}
|
|
556
|
+
{ripple.layer}
|
|
557
|
+
{theme.isAndroid ? null : <RowHighlight on={(pressed || held) && lit} last={last} />}
|
|
558
|
+
{content(pressed || held)}
|
|
559
|
+
</RowActionContext.Provider>
|
|
508
560
|
</RowHoldContext.Provider>
|
|
509
561
|
)}
|
|
510
562
|
</Pressable>
|
|
@@ -520,10 +572,12 @@ export function ListItem({
|
|
|
520
572
|
testID={testID}
|
|
521
573
|
accessible={named || undefined}
|
|
522
574
|
accessibilityLabel={accessibilityLabel}
|
|
575
|
+
{...(named ? hinted.props : null)}
|
|
523
576
|
accessibilityRole={named && Platform.OS !== "web" ? "text" : undefined}
|
|
524
577
|
role={named && Platform.OS === "web" ? "group" : undefined}
|
|
525
578
|
style={row}
|
|
526
579
|
>
|
|
580
|
+
{named ? hintNode : null}
|
|
527
581
|
{content(false)}
|
|
528
582
|
</View>
|
|
529
583
|
)
|
|
@@ -1091,6 +1145,7 @@ const styles = StyleSheet.create({
|
|
|
1091
1145
|
androidEndEdge: { marginStart: "auto" },
|
|
1092
1146
|
endAtEdge: { justifyContent: "flex-end" },
|
|
1093
1147
|
iosHeaderRow: { flexDirection: "row", alignItems: "flex-end", gap: 16 },
|
|
1148
|
+
unseen: { display: "none" },
|
|
1094
1149
|
androidHeaderRow: { flexDirection: "row", alignItems: "flex-start", minHeight: 40, paddingHorizontal: ANDROID_INSET, paddingTop: 14, paddingBottom: 6, gap: 16 },
|
|
1095
1150
|
androidHeaderTitle: { flex: 1, minWidth: 0, fontSize: 15, lineHeight: 20 },
|
|
1096
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
|
-
|
|
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
|
|
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
|
-
|
|
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;
|
|
203
|
-
|
|
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 { RowEndContext, RowHoldContext, RowStartContext, 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"
|
|
@@ -30,6 +30,10 @@ export type RadioGroupItemProps = {
|
|
|
30
30
|
disabled?: boolean
|
|
31
31
|
/** Where the mark stands against the label. @default "left" */
|
|
32
32
|
orientation?: "left" | "right"
|
|
33
|
+
/** A touch and hold on the option (half a second): what a term means, say. */
|
|
34
|
+
onLongPress?: () => void
|
|
35
|
+
/** The name a screen reader gives the hold's action ("Show meaning"). */
|
|
36
|
+
longPressLabel?: string
|
|
33
37
|
"aria-label"?: string
|
|
34
38
|
testID?: string
|
|
35
39
|
}
|
|
@@ -72,7 +76,7 @@ function RadioGroupRoot<T extends string>({ value: valueProp, defaultValue, onCh
|
|
|
72
76
|
}
|
|
73
77
|
RadioGroupRoot.displayName = "RadioGroup"
|
|
74
78
|
|
|
75
|
-
function RadioGroupItem({ value, children, description, disabled: itemDisabled = false, orientation = "left", "aria-label": ariaLabel, testID }: RadioGroupItemProps) {
|
|
79
|
+
function RadioGroupItem({ value, children, description, disabled: itemDisabled = false, orientation = "left", onLongPress, longPressLabel, "aria-label": ariaLabel, testID }: RadioGroupItemProps) {
|
|
76
80
|
const theme = useTheme()
|
|
77
81
|
const context = useContext(RadioContext)
|
|
78
82
|
if (!context) throw new Error("RadioGroup.Item must be inside a RadioGroup")
|
|
@@ -85,6 +89,8 @@ function RadioGroupItem({ value, children, description, disabled: itemDisabled =
|
|
|
85
89
|
// Or at its start (a list with the marks first): the mark alone, as wide as its ring or its checkmark's column
|
|
86
90
|
const atStart = useContext(RowStartContext) && !hasText
|
|
87
91
|
const hold = useContext(RowHoldContext)
|
|
92
|
+
// A row's touch and hold, held here, where the row's touches and its screen reader focus are
|
|
93
|
+
const rowAction = useContext(RowActionContext)
|
|
88
94
|
// The radio button runs 0 to 1 in 200ms on Android's default ease-in-out: the first half fills the ring inward
|
|
89
95
|
// in its gray, the second shrinks the fill to the dot while it turns the on color; unchoosing runs it back. A
|
|
90
96
|
// disabled option snaps. Android only: iOS shows a list row's checkmark, which does not animate
|
|
@@ -143,6 +149,8 @@ function RadioGroupItem({ value, children, description, disabled: itemDisabled =
|
|
|
143
149
|
aria-checked={selected}
|
|
144
150
|
disabled={disabled}
|
|
145
151
|
{...rowHold(hold)}
|
|
152
|
+
{...holdProps({ run: disabled ? undefined : onLongPress, label: longPressLabel }, inRow || atStart ? rowAction : null)}
|
|
153
|
+
{...rowHint(rowAction, described)}
|
|
146
154
|
onPress={() => !selected && context.select(value)}
|
|
147
155
|
testID={testID}
|
|
148
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
|
|
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 { RowEndContext, RowHoldContext, 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"
|
|
@@ -97,6 +97,8 @@ export function Switch({
|
|
|
97
97
|
// At the end of an Android List row with no text of its own: Android's switch stands 22dp from the row's end
|
|
98
98
|
const rowEnd = useContext(RowEndContext) != null
|
|
99
99
|
const hold = useContext(RowHoldContext)
|
|
100
|
+
// A row's touch and hold, held here, where the row's touches and its screen reader focus are
|
|
101
|
+
const rowAction = useContext(RowActionContext)
|
|
100
102
|
const toggle = () => {
|
|
101
103
|
if (disabled) return
|
|
102
104
|
if (checkedProp === undefined) setOwn(!checked)
|
|
@@ -125,6 +127,8 @@ export function Switch({
|
|
|
125
127
|
aria-checked={checked}
|
|
126
128
|
disabled={disabled}
|
|
127
129
|
{...rowHold(hold)}
|
|
130
|
+
{...holdProps({}, rowEnd ? rowAction : null)}
|
|
131
|
+
{...rowHint(rowAction, described)}
|
|
128
132
|
onPress={toggle}
|
|
129
133
|
testID={testID}
|
|
130
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,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Generated by scripts/build-icons.mjs. Do not edit.
|
|
2
|
+
import { createIcon } from "../../components/Icon/createIcon"
|
|
3
|
+
|
|
4
|
+
export default createIcon("VerifiedFilled", "0 0 24 24", [["path",{"d":"M12.01 2.011a3.2 3.2 0 0 1 2.113 .797l.154 .145l.698 .698a1.2 1.2 0 0 0 .71 .341l.135 .008h1a3.2 3.2 0 0 1 3.195 3.018l.005 .182v1c0 .27 .092 .533 .258 .743l.09 .1l.697 .698a3.2 3.2 0 0 1 .147 4.382l-.145 .154l-.698 .698a1.2 1.2 0 0 0 -.341 .71l-.008 .135v1a3.2 3.2 0 0 1 -3.018 3.195l-.182 .005h-1a1.2 1.2 0 0 0 -.743 .258l-.1 .09l-.698 .697a3.2 3.2 0 0 1 -4.382 .147l-.154 -.145l-.698 -.698a1.2 1.2 0 0 0 -.71 -.341l-.135 -.008h-1a3.2 3.2 0 0 1 -3.195 -3.018l-.005 -.182v-1a1.2 1.2 0 0 0 -.258 -.743l-.09 -.1l-.697 -.698a3.2 3.2 0 0 1 -.147 -4.382l.145 -.154l.698 -.698a1.2 1.2 0 0 0 .341 -.71l.008 -.135v-1l.005 -.182a3.2 3.2 0 0 1 3.013 -3.013l.182 -.005h1a1.2 1.2 0 0 0 .743 -.258l.1 -.09l.698 -.697a3.2 3.2 0 0 1 2.269 -.944zm3.697 7.282a1 1 0 0 0 -1.414 0l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.32 1.497l2 2l.094 .083a1 1 0 0 0 1.32 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z","fill":0}]])
|
package/src/icons/plex/index.ts
CHANGED
|
@@ -630,6 +630,7 @@ export { default as VariationV41 } from "./VariationV41"
|
|
|
630
630
|
export { default as VariationV42 } from "./VariationV42"
|
|
631
631
|
export { default as VariationV43 } from "./VariationV43"
|
|
632
632
|
export { default as VariationV44 } from "./VariationV44"
|
|
633
|
+
export { default as VerifiedFilled } from "./VerifiedFilled"
|
|
633
634
|
export { default as VersionsV1 } from "./VersionsV1"
|
|
634
635
|
export { default as Video } from "./Video"
|
|
635
636
|
export { default as VideoCaption } from "./VideoCaption"
|
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"
|
package/src/internal/a11y.ts
CHANGED
|
@@ -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
|
package/src/internal/row.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext } from "react"
|
|
2
|
-
import type
|
|
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 = {
|
|
@@ -67,3 +67,51 @@ export function rowHold(hold: ((held: boolean, event?: GestureResponderEvent) =>
|
|
|
67
67
|
// The touch goes with the hold: Android's row ripples from it
|
|
68
68
|
return hold ? { onPressIn: (event: GestureResponderEvent) => hold(true, event), onPressOut: () => hold(false) } : null
|
|
69
69
|
}
|
|
70
|
+
|
|
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
|
+
/** 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 }
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Set by a row with `onLongPress`: a control at its end that takes its own touches (a checkbox, a switch, a choice)
|
|
77
|
+
* holds for the row, and a screen reader, which reaches the control and never the row, finds the action there.
|
|
78
|
+
*/
|
|
79
|
+
export const RowActionContext = createContext<RowAction | null>(null)
|
|
80
|
+
|
|
81
|
+
type AccessibilityActionEvent = { nativeEvent: { actionName: string } }
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A control's touch and hold: its own `onLongPress`, or its row's. Half a second, as UIKit's and a ContextMenu's;
|
|
85
|
+
* a screen reader's `longpress` action named by `label` (VoiceOver reads it, "Show meaning", not the bare name).
|
|
86
|
+
* Merges the control's own actions (`actions`, handled by `onAction`).
|
|
87
|
+
*/
|
|
88
|
+
export function holdProps(
|
|
89
|
+
own: { run?: () => void; label?: string },
|
|
90
|
+
row: RowAction | null,
|
|
91
|
+
actions: { name: string; label?: string }[] = [],
|
|
92
|
+
onAction?: (event: AccessibilityActionEvent) => void,
|
|
93
|
+
) {
|
|
94
|
+
const run = own.run ?? row?.run
|
|
95
|
+
if (run == null) return actions.length > 0 ? { accessibilityActions: actions, onAccessibilityAction: onAction } : {}
|
|
96
|
+
const label = own.run != null ? own.label : row?.label
|
|
97
|
+
return {
|
|
98
|
+
onLongPress: run,
|
|
99
|
+
delayLongPress: 500,
|
|
100
|
+
accessibilityActions: [...actions, { name: "longpress", ...(label != null ? { label } : null) }],
|
|
101
|
+
onAccessibilityAction: (event: AccessibilityActionEvent) => {
|
|
102
|
+
if (event.nativeEvent.actionName === "longpress") run()
|
|
103
|
+
else onAction?.(event)
|
|
104
|
+
},
|
|
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
|
-
|
|
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 }
|