@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
package/README.md
CHANGED
|
@@ -59,6 +59,9 @@ export default function App() {
|
|
|
59
59
|
>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
A nested `ThemeProvider` keeps its parent's brand and lays its own over it; `brand={null}` draws its subtree in Plex
|
|
63
|
+
UI's own colors and radii (a stand-in for a system prompt, which is in the system's colors, never the app's).
|
|
64
|
+
|
|
62
65
|
`useTheme()` gives any token resolved for the current scheme: `theme.color("--color-text")`,
|
|
63
66
|
`theme.length("--button-size-md")`, and Material 3 roles on `theme.material`.
|
|
64
67
|
|
|
@@ -13,7 +13,7 @@ import { Button } from "../Button/Button";
|
|
|
13
13
|
* action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
|
|
14
14
|
* 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
|
|
15
15
|
*/
|
|
16
|
-
export function BottomActions({ children, floating = false, background = "soft", canvasColor, testID, style }) {
|
|
16
|
+
export function BottomActions({ children, floating = false, background = "soft", canvasColor, secondary = false, testID, style }) {
|
|
17
17
|
const theme = useTheme();
|
|
18
18
|
const insets = useSafeAreaInsets();
|
|
19
19
|
const android = theme.isAndroid;
|
|
@@ -28,7 +28,7 @@ export function BottomActions({ children, floating = false, background = "soft",
|
|
|
28
28
|
return child;
|
|
29
29
|
const props = child.props;
|
|
30
30
|
// The second action: iOS 26's glass capsule of the main one's size, Android's ghost button
|
|
31
|
-
const second = index > 0 && props.variant === undefined
|
|
31
|
+
const second = (index > 0 || secondary) && props.variant === undefined
|
|
32
32
|
? android
|
|
33
33
|
? { variant: "ghost", color: props.color ?? "secondary" }
|
|
34
34
|
: { variant: "soft", color: props.color ?? "secondary", mobileMaterial: props.mobileMaterial ?? "glass" }
|
|
@@ -220,6 +220,8 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
220
220
|
const margin = theme.length("--mobile-layout-margin", 16);
|
|
221
221
|
// Android: content scrolled under the bar fades out under it; the footer's height sets the room under the content
|
|
222
222
|
const [scrolled, setScrolled] = useState(false);
|
|
223
|
+
// The Android bar's height: 69 with a title on one line, a line more when it wraps to a second
|
|
224
|
+
const [androidBarHeight, setAndroidBarHeight] = useState(ANDROID_BAR_HEIGHT);
|
|
223
225
|
const [footerHeight, setFooterHeight] = useState(0);
|
|
224
226
|
// Android's sheet has no handle: the whole sheet takes the drag. With a title its bar is the reference's sheet bar,
|
|
225
227
|
// over the content: Close in a 46dp glass circle 12 under the top edge and 12 from the side (in line with the
|
|
@@ -227,7 +229,7 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
227
229
|
// (69 in all). Content scrolled under it shows through the sheet's color at
|
|
228
230
|
// 63% over a light blur, let go over its last 32dp (12 past the bar), with no line
|
|
229
231
|
const barItem = useMemoBarItem(background);
|
|
230
|
-
const header = android ? (title != null ? (_jsxs(View, { onStartShouldSetResponderCapture: gesture.chrome, style: styles.androidBar, children: [_jsx(SheetBarFade, { fill: background, shown: scrolled }), _jsx(View, { style: styles.androidCircle, children: dismissible ? (_jsx(BarItemContext.Provider, { value: barItem, children: _jsx(NavigationButton, { action: "close", accessibilityLabel: closeLabel, onPress: close }) })) : null }), _jsx(View, { style: styles.androidHeading, children: _jsx(Text, { nativeID: titleId, accessibilityRole: "header", weight: "medium", align: "center", numberOfLines:
|
|
232
|
+
const header = android ? (title != null ? (_jsxs(View, { onStartShouldSetResponderCapture: gesture.chrome, onLayout: (event) => setAndroidBarHeight(Math.max(ANDROID_BAR_HEIGHT, event.nativeEvent.layout.height)), style: styles.androidBar, children: [_jsx(SheetBarFade, { fill: background, shown: scrolled }), _jsx(View, { style: styles.androidCircle, children: dismissible ? (_jsx(BarItemContext.Provider, { value: barItem, children: _jsx(NavigationButton, { action: "close", accessibilityLabel: closeLabel, onPress: close }) })) : null }), _jsx(View, { style: styles.androidHeading, children: _jsx(Text, { nativeID: titleId, accessibilityRole: "header", weight: "medium", align: "center", numberOfLines: 2, color: m.onSurface, style: { fontSize: titleType.fontSize, lineHeight: titleType.lineHeight }, children: title }) }), _jsx(View, { style: styles.androidCircle })] })) : (_jsx(View, { onStartShouldSetResponderCapture: gesture.chrome, style: styles.androidGrip }))) : dismissible || title != null ? (
|
|
231
233
|
// The web's phone Sheet bar: one 44 row 16 under the top edge, Close at the leading edge and the title alone centered
|
|
232
234
|
// The bar is the web's Toolbar: 16 above the row and --toolbar-padding-bottom under it
|
|
233
235
|
_jsxs(View, { ...responder.panHandlers, style: [styles.iosBar, { paddingTop: theme.length("--dialog-sheet-action-inset-block", 16), paddingBottom: theme.length("--toolbar-padding-bottom", 10), paddingHorizontal: margin }], children: [_jsx(View, { style: { width: closeSize, height: closeSize }, children: dismissible ? _jsx(NavigationButton, { action: "close", accessibilityLabel: closeLabel, onPress: close }) : null }), _jsx(View, { style: [styles.iosHeading, { minHeight: closeSize }], children: title != null ? (_jsx(Text, { nativeID: titleId, accessibilityRole: "header", weight: "semibold", align: "center", style: { fontSize: titleType.fontSize, lineHeight: titleType.lineHeight }, children: title })) : null }), _jsx(View, { style: { width: closeSize } })] })) : null;
|
|
@@ -282,7 +284,8 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
282
284
|
styles.androidContent,
|
|
283
285
|
// A screen whose gutter is Material's compact 16 sets it with --bottom-sheet-android-padding-inline
|
|
284
286
|
{ paddingHorizontal: androidInline },
|
|
285
|
-
|
|
287
|
+
// 2 under the bar: 71 under a one-line title
|
|
288
|
+
title != null ? { paddingTop: androidBarHeight + 2 } : null,
|
|
286
289
|
// Over a footer: 8 above its height, which reaches over the sheet's bottom padding
|
|
287
290
|
footer ? { paddingBottom: 8 + Math.max(0, footerHeight - insets.bottom - keyboard) } : null,
|
|
288
291
|
]
|
|
@@ -335,6 +338,8 @@ function SheetBarFade({ fill, shown }) {
|
|
|
335
338
|
* `BottomSheet.Footer` pins actions under the content.
|
|
336
339
|
*/
|
|
337
340
|
export const BottomSheet = Object.assign(BottomSheetRoot, { Footer: BottomSheetFooter });
|
|
341
|
+
/** An Android sheet's bar: Close's 46dp circle 12 under the top edge and 11 over the bar's end. */
|
|
342
|
+
const ANDROID_BAR_HEIGHT = 12 + 46 + 11;
|
|
338
343
|
const styles = StyleSheet.create({
|
|
339
344
|
bottom: { flex: 1, justifyContent: "flex-end", alignItems: "center" },
|
|
340
345
|
sheet: { alignSelf: "stretch", overflow: "hidden", borderCurve: "continuous", marginHorizontal: "auto", width: "100%" },
|
|
@@ -353,7 +358,6 @@ const styles = StyleSheet.create({
|
|
|
353
358
|
// The content 12 from the sides (as a page's groups), 16 over the navigation bar; under a bar 13 under its circles
|
|
354
359
|
// (71 from the sheet's top, 2 under the bar)
|
|
355
360
|
androidContent: { paddingHorizontal: 12, paddingTop: 4, paddingBottom: 16 },
|
|
356
|
-
androidContentUnderBar: { paddingTop: 12 + 46 + 13 },
|
|
357
361
|
iosFooter: { gap: 10, paddingTop: 12 },
|
|
358
362
|
iosFooterEdge: { position: "absolute", top: -15, left: 0, right: 0, bottom: 0 },
|
|
359
363
|
// Android's sheet actions: 48dp buttons 4 apart, 12 from the sides and above, 12 over the gesture bar, over the
|
|
@@ -81,13 +81,17 @@ function iosPress(theme, variant, colors) {
|
|
|
81
81
|
const pressed = variant === "solid" ? lighten(theme, colors.background) : variant === "ghost" ? colors.background : withAlpha(colors.background, 0.7);
|
|
82
82
|
return { ...colors, pressed, pressedText: lighten(theme, colors.text) };
|
|
83
83
|
}
|
|
84
|
-
export function buttonColors(theme, color, variant, disabled, selected
|
|
84
|
+
export function buttonColors(theme, color, variant, disabled, selected) {
|
|
85
85
|
const c = (name) => theme.color(`--color-${name}`);
|
|
86
86
|
if (disabled) {
|
|
87
87
|
if (theme.isAndroid) {
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
// Material 3's disabled button: the container the on-surface color at 12% (a filled or a tonal one; none for a
|
|
89
|
+
// text button, an outlined one's outline at 12%), the label at 38%, whatever the button's color, so it reads as
|
|
90
|
+
// disabled on a dark surface too
|
|
91
|
+
const onSurface = theme.material.onSurface;
|
|
92
|
+
const veil = withAlpha(onSurface, 0.12);
|
|
93
|
+
const flat = variant === "ghost" || variant === "outline";
|
|
94
|
+
return { background: flat ? "transparent" : veil, pressed: flat ? "transparent" : veil, text: withAlpha(onSurface, 0.38), border: variant === "outline" ? veil : undefined };
|
|
91
95
|
}
|
|
92
96
|
// The phone CSS: the tertiary label in every style (iOS 27's disabled content-area button), the fill of a gray
|
|
93
97
|
// button behind a solid or soft one
|
|
@@ -228,13 +232,15 @@ function Spinner({ color }) {
|
|
|
228
232
|
strokeDasharray: [SPINNER_LENGTH, SPINNER_LENGTH], strokeDashoffset: SPINNER_LENGTH * (1 - arc / 360) }) }) }));
|
|
229
233
|
}
|
|
230
234
|
/** Strings and numbers in a row make one label ("Pressed {count}"); an element (an icon) stands on its own. */
|
|
231
|
-
function renderChildren(children, metrics) {
|
|
235
|
+
function renderChildren(children, metrics, lines = 1) {
|
|
232
236
|
const out = [];
|
|
233
237
|
let label = [];
|
|
234
238
|
const flush = () => {
|
|
235
239
|
if (!label.length)
|
|
236
240
|
return;
|
|
237
|
-
out.push(_jsx(Text, { numberOfLines:
|
|
241
|
+
out.push(_jsx(Text, { numberOfLines: lines, weight: metrics.weight,
|
|
242
|
+
// A label on more lines than one shrinks to the button and centers its lines
|
|
243
|
+
style: [{ fontSize: metrics.fontSize, lineHeight: metrics.lineHeight }, lines > 1 ? styles.wraps : null], children: label.join("") }, `label-${out.length}`));
|
|
238
244
|
label = [];
|
|
239
245
|
};
|
|
240
246
|
flattenChildren(children).forEach((child, index) => {
|
|
@@ -271,7 +277,7 @@ export function Button(props) {
|
|
|
271
277
|
* the title's line with a 44pt target; Android's 14sp Medium in the accent on the header's line. `style` reaches the
|
|
272
278
|
* row (`justifyContent: "center"` centres the words, as the web's `data-align="center"`).
|
|
273
279
|
*/
|
|
274
|
-
function ListActionButton({ place, color = "primary", disabled = false, loading = false, inert: inertProp = loading, children, style, onPressIn, onPressOut, accessibilityState, ...rest }) {
|
|
280
|
+
function ListActionButton({ place, color = "primary", disabled = false, loading = false, inert: inertProp = loading, labelLines, children, style, onPressIn, onPressOut, accessibilityState, ...rest }) {
|
|
275
281
|
const theme = useTheme();
|
|
276
282
|
const android = theme.isAndroid;
|
|
277
283
|
const [pressed, setPressed] = useState(false);
|
|
@@ -300,7 +306,7 @@ function ListActionButton({ place, color = "primary", disabled = false, loading
|
|
|
300
306
|
const parts = flattenChildren(children);
|
|
301
307
|
// Words and then an icon: the words take the room, so the icon ends the row
|
|
302
308
|
const trailingIcon = row && parts.length > 1 && isValidElement(parts[parts.length - 1]);
|
|
303
|
-
const content = parts.map((part, index) => typeof part === "string" || typeof part === "number" ? (_jsx(Text, { weight: android && !row ? "medium" : "regular", numberOfLines: row ? undefined : 1, style: [type, trailingIcon && index < parts.length - 1 ? styles.grow : null], children: part }, `label-${index}`)) : (_jsx(Fragment, { children: part }, `part-${index}`)));
|
|
309
|
+
const content = parts.map((part, index) => typeof part === "string" || typeof part === "number" ? (_jsx(Text, { weight: android && !row ? "medium" : "regular", numberOfLines: labelLines ?? (row ? undefined : 1), style: [type, trailingIcon && index < parts.length - 1 ? styles.grow : null, labelLines != null && labelLines > 1 && !row ? styles.shrinks : null], children: part }, `label-${index}`)) : (_jsx(Fragment, { children: part }, `part-${index}`)));
|
|
304
310
|
const fill = row && pressed && !inert ? (android ? controlHighlight(theme.scheme) : theme.color("--field-row-press-background")) : undefined;
|
|
305
311
|
// The header's words stand on the title's line: their target reaches over and under it to 44 (48 on Android)
|
|
306
312
|
const reach = row ? 0 : Math.max(0, ((android ? 48 : 44) - type.lineHeight) / 2);
|
|
@@ -320,7 +326,7 @@ function ListActionButton({ place, color = "primary", disabled = false, loading
|
|
|
320
326
|
style,
|
|
321
327
|
], children: _jsx(TextColorProvider, { value: ink, children: _jsx(IconDefaultsProvider, { size: android ? 24 : row ? theme.length("--field-row-icon-symbol-size", 24) : theme.length("--control-icon-size-md", 20), color: ink, children: loading ? _jsx(ActivityIndicator, { color: ink, size: "small" }) : content }) }) }));
|
|
322
328
|
}
|
|
323
|
-
function ButtonBody({ color = "primary", variant = "solid", size = "md", shape = "round", mobileMaterial, uniform = false, block = false, selected = false, loading = false, disabled = false, inert: inertProp = loading, iconSize, gutterSize, opticallyAlign, children, style, onPressIn, onPressOut, accessibilityState, ...rest }) {
|
|
329
|
+
function ButtonBody({ color = "primary", variant = "solid", size = "md", shape = "round", mobileMaterial, uniform = false, block = false, labelLines = 1, selected = false, loading = false, disabled = false, inert: inertProp = loading, iconSize, gutterSize, opticallyAlign, children, style, onPressIn, onPressOut, accessibilityState, ...rest }) {
|
|
324
330
|
const theme = useTheme();
|
|
325
331
|
const bar = useContext(BarItemContext);
|
|
326
332
|
const sized = buttonMetrics(theme, size, shape, uniform);
|
|
@@ -355,7 +361,7 @@ function ButtonBody({ color = "primary", variant = "solid", size = "md", shape =
|
|
|
355
361
|
// its buttons on glass and its plain ones; the token alone gives the Regular of the plain button
|
|
356
362
|
weight: theme.isIOS && variant !== "ghost" ? "medium" : base.weight,
|
|
357
363
|
};
|
|
358
|
-
const colors = barColors(theme, buttonColors(theme, color, variant, disabled, selected
|
|
364
|
+
const colors = barColors(theme, buttonColors(theme, color, variant, disabled, selected), { bar, prominent: accentAction, neutral, disabled, selected, flat: mobileMaterial === "flat" });
|
|
359
365
|
// In a bar every neutral soft or ghost button is glass, as on iOS 26, unless it asks to stay flat or is selected.
|
|
360
366
|
// A disabled glass button keeps its glass, as the phone CSS's
|
|
361
367
|
const wantsGlass = bar ? mobileMaterial !== "flat" && neutral && !selected && !bar.inGroup : mobileMaterial === "glass" && neutral;
|
|
@@ -432,22 +438,8 @@ function ButtonBody({ color = "primary", variant = "solid", size = "md", shape =
|
|
|
432
438
|
const background = pressed && theme.isIOS ? colors.pressed : colors.background;
|
|
433
439
|
// A glass button keeps its own press: only its glass changes
|
|
434
440
|
const text = pressed && !inert && theme.isIOS && !glass && colors.pressedText ? colors.pressedText : colors.text;
|
|
435
|
-
//
|
|
436
|
-
|
|
437
|
-
const fades = android && !bar;
|
|
438
|
-
const ink = fades && disabled ? buttonColors(theme, color, variant, false, selected, uniform).text : text;
|
|
439
|
-
const [dim] = useState(() => new Animated.Value(fades && disabled ? 0.5 : 1));
|
|
440
|
-
useEffect(() => {
|
|
441
|
-
const to = fades && disabled ? 0.5 : 1;
|
|
442
|
-
if (still || !fades) {
|
|
443
|
-
dim.stopAnimation();
|
|
444
|
-
dim.setValue(to);
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
const animation = Animated.timing(dim, { toValue: to, duration: 300, easing: curves.accelerateDecelerate, useNativeDriver: false });
|
|
448
|
-
animation.start();
|
|
449
|
-
return () => animation.stop();
|
|
450
|
-
}, [dim, disabled, fades, still]);
|
|
441
|
+
// Material 3's disabled label is the on-surface color at 38% (buttonColors), drawn as it is
|
|
442
|
+
const ink = text;
|
|
451
443
|
// Android's loading, both ways in 320ms on an ease-out quint: the label rises 24dp, flattens to 60% toward the
|
|
452
444
|
// button's top and fades out, as the spinner rises 24dp into its place and fades in
|
|
453
445
|
const [swap] = useState(() => new Animated.Value(loading ? 1 : 0));
|
|
@@ -506,12 +498,12 @@ function ButtonBody({ color = "primary", variant = "solid", size = "md", shape =
|
|
|
506
498
|
// The label scales from the button's top edge: on Android its row spans the button's height
|
|
507
499
|
const labelMotion = android
|
|
508
500
|
? {
|
|
509
|
-
opacity:
|
|
501
|
+
opacity: swap.interpolate({ inputRange: [0, 1], outputRange: [1, 0] }),
|
|
510
502
|
transform: [{ translateY: swap.interpolate({ inputRange: [0, 1], outputRange: [0, -24] }) }, { scaleY: swap.interpolate({ inputRange: [0, 1], outputRange: [1, 0.6] }) }],
|
|
511
503
|
}
|
|
512
504
|
: { opacity: loading ? 0 : 1 };
|
|
513
505
|
const spinner = android ? (loading || leaving ? (_jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, styles.row, { opacity: swap, transform: [{ translateY: swap.interpolate({ inputRange: [0, 1], outputRange: [24, 0] }) }] }], children: _jsx(Spinner, { color: ink }) })) : null) : loading ? (_jsx(ActivityIndicator, { style: StyleSheet.absoluteFill, color: text, size: metrics.indicator > 20 ? "large" : "small" })) : null;
|
|
514
|
-
const content = (_jsx(TextColorProvider, { value: ink, children: _jsxs(IconDefaultsProvider, { size: metrics.iconSize, color: ink, children: [_jsx(Animated.View, { style: [styles.row, android ? styles.fromTop : null, { gap: metrics.gap }, labelMotion], children: renderChildren(children, metrics) }), spinner] }) }));
|
|
506
|
+
const content = (_jsx(TextColorProvider, { value: ink, children: _jsxs(IconDefaultsProvider, { size: metrics.iconSize, color: ink, children: [_jsx(Animated.View, { style: [styles.row, android ? styles.fromTop : null, labelLines > 1 ? styles.shrinks : null, { gap: metrics.gap }, labelMotion], children: renderChildren(children, metrics, labelLines) }), spinner] }) }));
|
|
515
507
|
const layer = ripple.layer;
|
|
516
508
|
const pressable = {
|
|
517
509
|
accessibilityRole: "button",
|
|
@@ -536,4 +528,6 @@ const styles = StyleSheet.create({
|
|
|
536
528
|
row: { flexDirection: "row", alignItems: "center", justifyContent: "center" },
|
|
537
529
|
fromTop: { alignSelf: "stretch", transformOrigin: "top" },
|
|
538
530
|
grow: { flexGrow: 1, flexShrink: 1 },
|
|
531
|
+
wraps: { flexShrink: 1, minWidth: 0, textAlign: "center" },
|
|
532
|
+
shrinks: { flexShrink: 1, minWidth: 0, maxWidth: "100%" },
|
|
539
533
|
});
|
|
@@ -4,7 +4,7 @@ import { Image, Platform, StyleSheet, View } from "react-native";
|
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
5
|
import { flattenChildren } from "../../internal/children";
|
|
6
6
|
import { space } from "../../internal/spacing";
|
|
7
|
-
import { controlHighlight, withAlpha } from "../../theme/material";
|
|
7
|
+
import { barShadow, controlHighlight, elevationShadow, withAlpha } from "../../theme/material";
|
|
8
8
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
9
9
|
import { materialType } from "../../theme/typography";
|
|
10
10
|
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
@@ -31,6 +31,9 @@ export function cardSurface(theme, variant) {
|
|
|
31
31
|
return { backgroundColor: theme.colors.groupedSurface };
|
|
32
32
|
if (variant === "solid")
|
|
33
33
|
return { backgroundColor: theme.material.surfaceContainerHigh };
|
|
34
|
+
// Material's elevated card: the low container lifted at level 1
|
|
35
|
+
if (variant === "elevated")
|
|
36
|
+
return { backgroundColor: theme.material.surfaceContainerLow, boxShadow: elevationShadow.level1 };
|
|
34
37
|
return { backgroundColor: "transparent" };
|
|
35
38
|
}
|
|
36
39
|
// On a phone an outline card is a section of an inset grouped list (no border, the section's fill: the grouped
|
|
@@ -40,6 +43,10 @@ export function cardSurface(theme, variant) {
|
|
|
40
43
|
return { backgroundColor: theme.colors.groupedSurface };
|
|
41
44
|
if (variant === "solid")
|
|
42
45
|
return { backgroundColor: theme.color("--card-solid-section-background", theme.colors.surfaceSecondary) };
|
|
46
|
+
// Lifted off the page by the soft shadow of a floating control (2 down, 8 across, 6% black; 30% on a dark screen),
|
|
47
|
+
// so a card laid over another reads as on top
|
|
48
|
+
if (variant === "elevated")
|
|
49
|
+
return { backgroundColor: theme.colors.groupedSurface, boxShadow: barShadow(theme.scheme) };
|
|
43
50
|
return { backgroundColor: "transparent" };
|
|
44
51
|
}
|
|
45
52
|
/**
|
|
@@ -70,7 +77,7 @@ function CardRoot({ children, variant = "outline", size = "md", color, onPress,
|
|
|
70
77
|
const body = parts.map((child, index) => isValidElement(child) && child.type === CardMedia
|
|
71
78
|
? cloneElement(child, { first: index === 0, last: index === parts.length - 1 })
|
|
72
79
|
: child);
|
|
73
|
-
const box = [styles.card, { padding, gap, borderRadius: radius }, ghost && !tint ? styles.ghost : null, tint ? { backgroundColor: tint.fill } : cardSurface(theme, variant), style];
|
|
80
|
+
const box = [styles.card, { padding, gap, borderRadius: radius }, ghost && !tint ? styles.ghost : null, tint ? { backgroundColor: tint.fill, ...(variant === "elevated" ? { boxShadow: cardSurface(theme, variant).boxShadow } : null) } : cardSurface(theme, variant), style];
|
|
74
81
|
const content = tint ? (_jsx(Context.Provider, { value: { padding, inset, radius, theme, ink: tint.ink }, children: _jsx(TextColorProvider, { value: tint.ink, children: _jsx(IconDefaultsProvider, { color: tint.ink, children: body }) }) })) : (_jsx(Context.Provider, { value: { padding, inset, radius, theme }, children: body }));
|
|
75
82
|
if (onPress || interactive) {
|
|
76
83
|
// Android: the press of a row in a section (the settings list selector), as a List row's
|
|
@@ -7,7 +7,7 @@ import CheckMd from "../../icons/plex/CheckMd";
|
|
|
7
7
|
import Minus from "../../icons/plex/Minus";
|
|
8
8
|
import { spaceToggles, useDescription } from "../../internal/a11y";
|
|
9
9
|
import { ControlLabel, controlLabelLine } from "../../internal/ControlLabel";
|
|
10
|
-
import { RowEndContext, RowHoldContext, RowStartContext, rowHold } from "../../internal/row";
|
|
10
|
+
import { RowActionContext, RowEndContext, RowHoldContext, RowStartContext, holdProps, rowHint, rowHold } from "../../internal/row";
|
|
11
11
|
import { androidGray, withAlpha } from "../../theme/material";
|
|
12
12
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
13
13
|
import { ANDROID_ROW_END, iosCheckmarkColor, selectionColor } from "../Switch/Switch";
|
|
@@ -35,6 +35,8 @@ export function Checkbox({ checked: checkedProp, defaultChecked = false, onCheck
|
|
|
35
35
|
const atRowStart = useContext(RowStartContext) && label == null && description == null;
|
|
36
36
|
const inRow = useContext(RowEndContext) != null && label == null && description == null && !atRowStart;
|
|
37
37
|
const hold = useContext(RowHoldContext);
|
|
38
|
+
// A row's touch and hold, held here, where the row's touches and its screen reader focus are
|
|
39
|
+
const rowAction = useContext(RowActionContext);
|
|
38
40
|
const [own, setOwn] = useState(defaultChecked);
|
|
39
41
|
const state = checkedProp ?? own;
|
|
40
42
|
const on = state !== false;
|
|
@@ -124,7 +126,7 @@ export function Checkbox({ checked: checkedProp, defaultChecked = false, onCheck
|
|
|
124
126
|
const targetSize = theme.isAndroid ? 48 : theme.length("--checkbox-target-size", 44);
|
|
125
127
|
const described = useDescription(description);
|
|
126
128
|
const text = _jsx(ControlLabel, { label: label, description: description, disabled: disabled, descriptionId: described.id });
|
|
127
|
-
return (_jsxs(Pressable, { ...described.props, ...spaceToggles(toggle), accessibilityRole: "checkbox", accessibilityLabel: accessibilityLabel ?? (typeof label === "string" ? label : undefined), accessibilityState: { checked: state === "indeterminate" ? "mixed" : state, disabled }, "aria-checked": state === "indeterminate" ? "mixed" : state, "aria-invalid": invalid || undefined, disabled: disabled, ...rowHold(hold), onPress: toggle, testID: testID, style: [
|
|
129
|
+
return (_jsxs(Pressable, { ...described.props, ...spaceToggles(toggle), accessibilityRole: "checkbox", accessibilityLabel: accessibilityLabel ?? (typeof label === "string" ? label : undefined), accessibilityState: { checked: state === "indeterminate" ? "mixed" : state, disabled }, "aria-checked": state === "indeterminate" ? "mixed" : state, "aria-invalid": invalid || undefined, disabled: disabled, ...rowHold(hold), ...holdProps({}, inRow || atRowStart ? rowAction : null), ...rowHint(rowAction, described), onPress: toggle, testID: testID, style: [
|
|
128
130
|
styles.row,
|
|
129
131
|
hasText ? styles.top : null,
|
|
130
132
|
// Android's gap is in the target's margins
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { holdProps } from "../../internal/row";
|
|
2
3
|
import { useEffect, useState } from "react";
|
|
3
4
|
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
5
|
import { Pressable } from "../../internal/Pressable";
|
|
@@ -21,7 +22,7 @@ import { Text, textStyle } from "../Text/Text";
|
|
|
21
22
|
*/
|
|
22
23
|
/** The chosen token's way to let go, so that choosing another lets it go */
|
|
23
24
|
let disarmToken = null;
|
|
24
|
-
export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance = "tag", onRemove, removeLabel = "Remove", removeStyle = "token", disabled = false, testID, style, }) {
|
|
25
|
+
export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance = "tag", onRemove, removeLabel = "Remove", removeStyle = "token", onLongPress, longPressLabel, disabled = false, testID, style, }) {
|
|
25
26
|
const theme = useTheme();
|
|
26
27
|
const [own, setOwn] = useState(defaultSelected ?? false);
|
|
27
28
|
// iOS's token: an input chip with no cross, chosen by a first press and removed by a second (or by Delete); it is
|
|
@@ -147,7 +148,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
147
148
|
const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, symbolOnly ? null : android ? (
|
|
148
149
|
// Text's own face and tracking, in a color that blends
|
|
149
150
|
_jsx(Animated.Text, { numberOfLines: 1, selectable: false, style: [textStyle(theme, { weight: "regular" }), { fontSize: label.fontSize, lineHeight: label.lineHeight, letterSpacing: theme.tracking(label.fontSize), color: labelPaint }], children: children })) : (_jsx(Text, { color: color, weight: "regular", numberOfLines: 1, selectable: false, style: { fontSize: label.fontSize, lineHeight: label.lineHeight }, children: children })), trailing != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: trailing }) })) : null] }));
|
|
150
|
-
const interactive = filter || !!onPress || token;
|
|
151
|
+
const interactive = filter || !!onPress || !!onLongPress || token;
|
|
151
152
|
// Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
|
|
152
153
|
const dim = android && disabled ? styles.dim : null;
|
|
153
154
|
const handlers = {
|
|
@@ -172,11 +173,6 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
172
173
|
// A token: VoiceOver's action and a keyboard's Delete remove it; leaving it lets the selection go
|
|
173
174
|
...(token
|
|
174
175
|
? {
|
|
175
|
-
accessibilityActions: [{ name: "delete", label: removeLabel }],
|
|
176
|
-
onAccessibilityAction: (event) => {
|
|
177
|
-
if (event.nativeEvent.actionName === "delete" && !disabled)
|
|
178
|
-
onRemove?.();
|
|
179
|
-
},
|
|
180
176
|
onBlur: () => armed && setArmed(false),
|
|
181
177
|
onKeyDown: (event) => {
|
|
182
178
|
if ((event.nativeEvent.key === "Backspace" || event.nativeEvent.key === "Delete") && !disabled)
|
|
@@ -185,6 +181,11 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
185
181
|
"aria-keyshortcuts": "Delete Backspace",
|
|
186
182
|
}
|
|
187
183
|
: {}),
|
|
184
|
+
// A token's delete action for VoiceOver, and a hold of its own (what a word means), named for a screen reader
|
|
185
|
+
...holdProps({ run: disabled ? undefined : onLongPress, label: longPressLabel }, null, token ? [{ name: "delete", label: removeLabel }] : [], (event) => {
|
|
186
|
+
if (event.nativeEvent.actionName === "delete" && !disabled)
|
|
187
|
+
onRemove?.();
|
|
188
|
+
}),
|
|
188
189
|
onPressIn: () => setPressed(true),
|
|
189
190
|
onPressOut: () => setPressed(false),
|
|
190
191
|
};
|
|
@@ -60,21 +60,27 @@ const DASH = 50;
|
|
|
60
60
|
* of its own for this, so both draw the Plex ring; a new value moves the arc in 300ms (ease) on iOS, as the web's
|
|
61
61
|
* transition, and in Android's determinate radial progress time (200ms, decelerating); at once with reduced motion.
|
|
62
62
|
*/
|
|
63
|
-
export function CircularProgress({ maxDuration = 15000, done = false, progress: progressProp, size = 28, strokeWidth, trackActiveColor, trackColor, "aria-label": ariaLabel, accessibilityLabel, testID, style, }) {
|
|
63
|
+
export function CircularProgress({ maxDuration = 15000, done = false, progress: progressProp, size = 28, strokeWidth, ring = "inset", duration, trackActiveColor, trackColor, "aria-label": ariaLabel, accessibilityLabel, testID, style, }) {
|
|
64
64
|
const theme = useTheme();
|
|
65
65
|
const simulated = useSimulatedProgress(maxDuration, progressProp !== undefined || done);
|
|
66
66
|
const progress = Math.max(0, Math.min(100, progressProp ?? simulated));
|
|
67
67
|
const shown = useTweenedNumber(progress, {
|
|
68
|
-
duration: theme.isAndroid ? 200 : 300,
|
|
68
|
+
duration: duration ?? (theme.isAndroid ? 200 : 300),
|
|
69
69
|
easing: theme.isAndroid ? curves.decelerate : cssEase,
|
|
70
70
|
reducedMotion: theme.reducedMotion,
|
|
71
71
|
});
|
|
72
|
-
const
|
|
72
|
+
const edge = ring === "edge";
|
|
73
|
+
const stroke = edge ? Math.min(size / 2, strokeWidth ?? 2) : strokeWidth ? Math.min(4, strokeWidth) : 2;
|
|
74
|
+
// The drawing: 20 units with a ring of 8 inset, or the box itself with the ring's outside on its edge
|
|
75
|
+
const box = edge ? size : 20;
|
|
76
|
+
const center = box / 2;
|
|
77
|
+
const radius = edge ? Math.max(0, (size - stroke) / 2) : 8;
|
|
78
|
+
const dash = edge ? 2 * Math.PI * radius : DASH;
|
|
73
79
|
// The web's `light-dark(#deede9, var(--green-a50))`: a light green, the green at 15% at night
|
|
74
80
|
const track = resolve(theme, trackColor, theme.scheme === "dark" ? theme.color("--green-a50") : "#DEEDE9");
|
|
75
81
|
const active = resolve(theme, trackActiveColor, theme.color("--green-500"));
|
|
76
82
|
const name = accessibilityLabel ?? ariaLabel;
|
|
77
|
-
return (_jsx(View, { accessible: name != null, accessibilityRole: name != null ? "progressbar" : undefined, accessibilityLabel: name, accessibilityValue: name != null ? { min: 0, max: 100, now: Math.round(progress) } : undefined, importantForAccessibility: name != null ? undefined : "no-hide-descendants", accessibilityElementsHidden: name == null, testID: testID, style: [{ width: size, height: size }, style], children: _jsxs(Svg, { width: size, height: size, viewBox:
|
|
83
|
+
return (_jsx(View, { accessible: name != null, accessibilityRole: name != null ? "progressbar" : undefined, accessibilityLabel: name, accessibilityValue: name != null ? { min: 0, max: 100, now: Math.round(progress) } : undefined, importantForAccessibility: name != null ? undefined : "no-hide-descendants", accessibilityElementsHidden: name == null, testID: testID, style: [{ width: size, height: size }, style], children: _jsxs(Svg, { width: size, height: size, viewBox: `0 0 ${box} ${box}`, children: [_jsx(Circle, { cx: center, cy: center, r: radius, fill: "none", stroke: track, strokeWidth: stroke }), _jsx(Circle, { cx: center, cy: center, r: radius, fill: "none", stroke: active, strokeWidth: stroke, strokeLinecap: "round", strokeDasharray: [dash, dash], strokeDashoffset: dash - dash * (shown / 100),
|
|
78
84
|
// The dash starts at 12 o'clock, as the web's ring turned back a quarter
|
|
79
|
-
transform:
|
|
85
|
+
transform: `rotate(-90 ${center} ${center})` })] }) }));
|
|
80
86
|
}
|
|
@@ -4,12 +4,12 @@ import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
5
|
import Disclosure from "../../icons/plex/Disclosure";
|
|
6
6
|
import ExclamationMarkCircle from "../../icons/plex/ExclamationMarkCircle";
|
|
7
|
-
import { spaceToggles, useDescription } from "../../internal/a11y";
|
|
7
|
+
import { describedBy, spaceToggles, useDescription, useHint } from "../../internal/a11y";
|
|
8
8
|
import { useRipple } from "../../internal/ripple";
|
|
9
9
|
import { flattenChildren, textOf } from "../../internal/children";
|
|
10
10
|
import { cssBox } from "../../internal/cssBox";
|
|
11
11
|
import { mirrored, useRTL } from "../../internal/direction";
|
|
12
|
-
import { RowEndContext, RowFrameContext, RowHoldContext, RowStartContext } from "../../internal/row";
|
|
12
|
+
import { RowActionContext, RowEndContext, RowFrameContext, RowHoldContext, RowStartContext, holdProps } from "../../internal/row";
|
|
13
13
|
import { accentText, controlHighlight, dangerText, divider, withAlpha } from "../../theme/material";
|
|
14
14
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
15
15
|
import { Button, ListActionContext } from "../Button/Button";
|
|
@@ -28,17 +28,40 @@ export function useInList() {
|
|
|
28
28
|
const ANDROID_CARD_RADIUS = 16;
|
|
29
29
|
/** The start and end of an Android row's text, 21dp in from the card's edge (`--list-row-inset`). */
|
|
30
30
|
const ANDROID_INSET = 21;
|
|
31
|
+
/**
|
|
32
|
+
* Where a List's rows start their text inside the card and how round the card is, for a card built beside a List
|
|
33
|
+
* that must line up with it: iOS `--list-row-inset` (20) and `--field-group-radius` (26), Android 21 and 16.
|
|
34
|
+
*/
|
|
35
|
+
export function useListMetrics() {
|
|
36
|
+
const theme = useTheme();
|
|
37
|
+
return theme.isAndroid
|
|
38
|
+
? { rowInset: ANDROID_INSET, radius: ANDROID_CARD_RADIUS }
|
|
39
|
+
: { rowInset: theme.length("--list-row-inset", 20), radius: theme.length("--field-group-radius", 26) };
|
|
40
|
+
}
|
|
31
41
|
const PlaceContext = createContext({ first: true, last: true, top: 0, bottom: 0 });
|
|
42
|
+
/**
|
|
43
|
+
* How far a line's baseline stands over the line's bottom: half the leading under the face's box, and its descent.
|
|
44
|
+
* 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.
|
|
45
|
+
*/
|
|
46
|
+
const baselineOverBottom = (fontSize, lineHeight) => (lineHeight - fontSize * 1.21) / 2 + fontSize * 0.24;
|
|
32
47
|
/**
|
|
33
48
|
* 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
|
|
34
|
-
* line: iOS 17/22 on its last line, Android the header's 15sp on its 40dp row. Its own style still wins
|
|
49
|
+
* line: iOS 17/22 on its last line, Android the header's 15sp on its 40dp row. Its own style still wins; on iOS
|
|
50
|
+
* (`onBaseline`) a Text in a type of its own is lifted onto the title's baseline.
|
|
35
51
|
*/
|
|
36
|
-
function headerAction(action, type, color) {
|
|
52
|
+
function headerAction(action, type, color, onBaseline = false) {
|
|
37
53
|
if (typeof action === "string" || typeof action === "number") {
|
|
38
54
|
return (_jsx(Text, { color: color, tabularNums: true, style: type, children: action }));
|
|
39
55
|
}
|
|
40
56
|
if (isValidElement(action) && action.type === Text) {
|
|
41
|
-
|
|
57
|
+
// A count in a type of its own (a 15/20 subheadline beside the 17/22 title) is lifted onto the title's baseline,
|
|
58
|
+
// the row still set at its bottoms so the count stays on the title's last line
|
|
59
|
+
const header = StyleSheet.flatten(type) ?? {};
|
|
60
|
+
const own = StyleSheet.flatten([type, action.props.style]) ?? {};
|
|
61
|
+
const lift = onBaseline && typeof header.fontSize === "number" && typeof header.lineHeight === "number" && typeof own.fontSize === "number" && typeof own.lineHeight === "number"
|
|
62
|
+
? baselineOverBottom(header.fontSize, header.lineHeight) - baselineOverBottom(own.fontSize, own.lineHeight)
|
|
63
|
+
: 0;
|
|
64
|
+
return cloneElement(action, { style: [type, action.props.style, lift !== 0 ? { marginBottom: lift } : null] });
|
|
42
65
|
}
|
|
43
66
|
return action;
|
|
44
67
|
}
|
|
@@ -95,7 +118,7 @@ export function List({ children, header, description, footer, error, surface = "
|
|
|
95
118
|
}, children: [header != null || action != null ? (_jsxs(View, { style: action != null ? styles.iosHeaderRow : null, children: [header == null ? _jsx(View, { style: styles.grow }) : null, header == null ? null : _jsx(Text, { accessibilityRole: "header", weight: "semibold", color: increased ? theme.colors.text : theme.colors.labelSecondary, style: [
|
|
96
119
|
increased ? { fontSize: 20, lineHeight: 25 } : { fontSize: theme.length("--field-group-title-font-size", 17), lineHeight: theme.length("--field-group-title-line-height", 22) },
|
|
97
120
|
action != null ? styles.grow : null,
|
|
98
|
-
], children: header }), action != null ? (_jsx(ListActionContext.Provider, { value: "header", children: headerAction(action, { fontSize: theme.length("--field-group-title-font-size", 17), lineHeight: theme.length("--field-group-title-line-height", 22) }, theme.colors.labelSecondary) })) : null] })) : null, description != null ? (_jsx(Text, { color: theme.colors.labelSecondary, style: { fontSize: theme.length("--field-group-description-font-size", 15), lineHeight: theme.length("--field-group-description-line-height", 20) }, children: description })) : null] })) : null, _jsx(View, { accessibilityRole: "list", "aria-label": label, style: [styles.iosGroup, { borderRadius: theme.length("--field-group-radius", 26), backgroundColor: surface === "plain" ? theme.color("--field-group-background", theme.colors.surfaceSecondary) : theme.colors.groupedSurface }], children: _jsx(ListOptionsContext.Provider, { value: options, children: body }) }), error != null || footer != null ? (
|
|
121
|
+
], children: header }), action != null ? (_jsx(ListActionContext.Provider, { value: "header", children: headerAction(action, { fontSize: theme.length("--field-group-title-font-size", 17), lineHeight: theme.length("--field-group-title-line-height", 22) }, theme.colors.labelSecondary, true) })) : null] })) : null, description != null ? (_jsx(Text, { color: theme.colors.labelSecondary, style: { fontSize: theme.length("--field-group-description-font-size", 15), lineHeight: theme.length("--field-group-description-line-height", 20) }, children: description })) : null] })) : null, _jsx(View, { accessibilityRole: "list", "aria-label": label, style: [styles.iosGroup, { borderRadius: theme.length("--field-group-radius", 26), backgroundColor: surface === "plain" ? theme.color("--field-group-background", theme.colors.surfaceSecondary) : theme.colors.groupedSurface }], children: _jsx(ListOptionsContext.Provider, { value: options, children: body }) }), error != null || footer != null ? (
|
|
99
122
|
// An error takes the footer's place and type (13/16, 8 under the section), only in the danger color
|
|
100
123
|
_jsx(Text, { color: error != null ? errorColor(theme) : theme.colors.labelSecondary, accessibilityLiveRegion: error != null ? "polite" : undefined, style: {
|
|
101
124
|
fontSize: theme.length("--field-group-footer-font-size", 13),
|
|
@@ -118,7 +141,7 @@ export function List({ children, header, description, footer, error, surface = "
|
|
|
118
141
|
* in (a multi-select list); a 1px divider from the text's start to the card's end, none under a row with a tile (a
|
|
119
142
|
* tiled row draws none).
|
|
120
143
|
*/
|
|
121
|
-
export function ListItem({ label, description, leading, leadingColor, value, valuePlacement = "end", valueColor, trailing, error, checked: checkedProp, defaultChecked, onCheckedChange, disclosure, onPress, onLongPress, disabled = false, destructive = false, accessibilityLabel, testID, }) {
|
|
144
|
+
export function ListItem({ label, description, leading, leadingColor, value, valuePlacement = "end", valueColor, trailing, error, checked: checkedProp, defaultChecked, onCheckedChange, disclosure, onPress, onLongPress, longPressLabel, disabled = false, destructive = false, accessibilityLabel, accessibilityHint, testID, }) {
|
|
122
145
|
const theme = useTheme();
|
|
123
146
|
const { last, top, bottom } = useContext(PlaceContext);
|
|
124
147
|
// A menu opened from the row finds the row (Android lights it over the dim of the screen)
|
|
@@ -163,7 +186,14 @@ export function ListItem({ label, description, leading, leadingColor, value, val
|
|
|
163
186
|
}, []);
|
|
164
187
|
const handed = !switchRow && !onPress && !control && !disabled ? endPress : null;
|
|
165
188
|
const press = switchRow ? toggle : (onPress ?? control?.toggle ?? handed ?? undefined);
|
|
189
|
+
const hinted = useHint(accessibilityHint);
|
|
190
|
+
// On the web the hint is an unseen text the row's element, or the control that takes its focus, is described by
|
|
191
|
+
const hintNode = hinted.id != null ? _jsx(Text, { nativeID: hinted.id, style: styles.unseen, children: accessibilityHint }) : null;
|
|
166
192
|
const endOwnsFocus = control != null || handed != null || (endHands && press == null);
|
|
193
|
+
// 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
|
|
194
|
+
// opens a page keeps to its own words
|
|
195
|
+
const controlHint = endOwnsFocus ? accessibilityHint : undefined;
|
|
196
|
+
const rowAction = useMemo(() => (onLongPress == null && controlHint == null ? null : { run: disabled ? undefined : onLongPress, label: longPressLabel, hint: controlHint, hintId: hinted.id }), [controlHint, disabled, hinted.id, longPressLabel, onLongPress]);
|
|
167
197
|
// A destructive row is an action, not a page (Settings' Sign Out has no chevron)
|
|
168
198
|
const chevron = disclosure ?? (!!onPress && !switchRow && trailing == null && !destructive);
|
|
169
199
|
const name = accessibilityLabel ?? ([textOf(label), textOf(value)].filter(Boolean).join(", ") || undefined);
|
|
@@ -199,14 +229,18 @@ export function ListItem({ label, description, leading, leadingColor, value, val
|
|
|
199
229
|
// Android's rows press in the list selector: the native ripple on a device, the drawn one on the web
|
|
200
230
|
const highlight = controlHighlight(theme.scheme);
|
|
201
231
|
const drawn = theme.isAndroid && !nativeRipple;
|
|
202
|
-
return (_jsx(Pressable, { ref: frameNode, collapsable: false, ...described.props, ...(
|
|
232
|
+
return (_jsx(Pressable, { ref: frameNode, collapsable: false, ...described.props, ...(endOwnsFocus || accessibilityHint == null
|
|
233
|
+
? null
|
|
234
|
+
: Platform.OS === "web"
|
|
235
|
+
? { "aria-describedby": describedBy(described.id, hinted.id) }
|
|
236
|
+
: hinted.props), ...(switchRow ? spaceToggles(toggle) : null),
|
|
203
237
|
// A row that toggles its control is not a second element for a screen reader or a Tab stop: the control is
|
|
204
|
-
accessible: endOwnsFocus ? false : undefined, focusable: endOwnsFocus ? false : undefined, tabIndex: endOwnsFocus ? -1 : undefined, accessibilityRole: endOwnsFocus ? undefined : switchRow ? "switch" : "button", accessibilityLabel: endOwnsFocus ? undefined : name, accessibilityState: endOwnsFocus ? undefined : switchRow ? { checked, disabled } : { disabled }, "aria-checked": switchRow ? checked : undefined, disabled: disabled || (press == null && onLongPress == null), onPress: press,
|
|
238
|
+
accessible: endOwnsFocus ? false : undefined, focusable: endOwnsFocus ? false : undefined, tabIndex: endOwnsFocus ? -1 : undefined, accessibilityRole: endOwnsFocus ? undefined : switchRow ? "switch" : "button", accessibilityLabel: endOwnsFocus ? undefined : name, accessibilityState: endOwnsFocus ? undefined : switchRow ? { checked, disabled } : { disabled }, "aria-checked": switchRow ? checked : undefined, disabled: disabled || (press == null && onLongPress == null), onPress: press, ...holdProps({ run: onLongPress, label: longPressLabel }, null), onPressIn: drawn ? ripple.start : undefined, onPressOut: drawn ? ripple.end : undefined, android_ripple: nativeRipple ? { color: highlight, foreground: true } : undefined, testID: testID, style: row, children: ({ pressed }) => (_jsx(RowHoldContext.Provider, { value: disabled ? null : theme.isAndroid ? hold : setHeld, children: _jsxs(RowActionContext.Provider, { value: rowAction, children: [hintNode, ripple.layer, theme.isAndroid ? null : _jsx(RowHighlight, { on: (pressed || held) && lit, last: last }), content(pressed || held)] }) })) }));
|
|
205
239
|
}
|
|
206
240
|
// A row that only shows (a detail, a value) is one element named by `accessibilityLabel` when it has one; with a
|
|
207
241
|
// control at its end it stays a group, so the control is still reached
|
|
208
242
|
const named = accessibilityLabel != null && trailing == null && found == null;
|
|
209
|
-
return (
|
|
243
|
+
return (_jsxs(View, { ref: frameNode, collapsable: false, testID: testID, accessible: named || undefined, accessibilityLabel: accessibilityLabel, ...(named ? hinted.props : null), accessibilityRole: named && Platform.OS !== "web" ? "text" : undefined, role: named && Platform.OS === "web" ? "group" : undefined, style: row, children: [named ? hintNode : null, content(false)] }));
|
|
210
244
|
}
|
|
211
245
|
/** A Button among a List's rows: the row is the button (`ListActionContext`), the hairline under it from the text's start. */
|
|
212
246
|
function ActionRow({ children }) {
|
|
@@ -509,6 +543,7 @@ const styles = StyleSheet.create({
|
|
|
509
543
|
androidEndEdge: { marginStart: "auto" },
|
|
510
544
|
endAtEdge: { justifyContent: "flex-end" },
|
|
511
545
|
iosHeaderRow: { flexDirection: "row", alignItems: "flex-end", gap: 16 },
|
|
546
|
+
unseen: { display: "none" },
|
|
512
547
|
androidHeaderRow: { flexDirection: "row", alignItems: "flex-start", minHeight: 40, paddingHorizontal: ANDROID_INSET, paddingTop: 14, paddingBottom: 6, gap: 16 },
|
|
513
548
|
androidHeaderTitle: { flex: 1, minWidth: 0, fontSize: 15, lineHeight: 20 },
|
|
514
549
|
androidHeaderTitleType: { fontSize: 15, lineHeight: 20 },
|
|
@@ -263,9 +263,11 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
|
|
|
263
263
|
moveTo(step, 1, true);
|
|
264
264
|
};
|
|
265
265
|
const collapse = () => moveTo(step, 0, false, () => setSub(null));
|
|
266
|
-
|
|
266
|
+
// A multiple choice keeps the submenu open: its items follow the app's state while it shows
|
|
267
|
+
const refreshSub = (owner, items) => setSub((current) => (current == null || current.owner !== owner || current.items === items ? current : { ...current, items }));
|
|
268
|
+
const surface = { close: onClose, check, multiple, openSub, refreshSub, subOpen: sub != null };
|
|
267
269
|
const content = _jsx(SurfaceContext.Provider, { value: surface, children: children });
|
|
268
|
-
const subItems = sub != null ? _jsx(SurfaceContext.Provider, { value: { close: onClose, check: hasCheckedItems(sub.items) }, children: sub.items }) : null;
|
|
270
|
+
const subItems = sub != null ? _jsx(SurfaceContext.Provider, { value: { close: onClose, check: hasCheckedItems(sub.items), multiple }, children: sub.items }) : null;
|
|
269
271
|
const scale = !theme.reducedMotion && canTransformGlass;
|
|
270
272
|
// The web's keyboard, as the WAI-ARIA menu pattern: focus starts at the chosen item (else the first), the arrows
|
|
271
273
|
// move to the next one and stop at the ends, Home and End go to the first and the last
|
|
@@ -622,9 +624,10 @@ function AndroidMenuSurface({ open, anchor, row, header = false, onClose, align
|
|
|
622
624
|
},
|
|
623
625
|
});
|
|
624
626
|
});
|
|
625
|
-
const
|
|
627
|
+
const refreshSub = (owner, items) => setSub((current) => (current == null || current.owner !== owner || current.items === items ? current : { ...current, items }));
|
|
628
|
+
const surface = { close: onClose, check, multiple, openSub, refreshSub, subOpen: sub != null, header };
|
|
626
629
|
// The submenu's page: Back, the 8dp band, the items
|
|
627
|
-
const subItems = sub != null ? (_jsxs(SurfaceContext.Provider, { value: { close: onClose, check: hasCheckedItems(sub.items), header }, children: [_jsx(MenuRow, { icon: _jsx(ArrowLeftLg, {}), stay: collapse, children: sub.backLabel }), _jsx(MenuSeparator, {}), sub.items] })) : null;
|
|
630
|
+
const subItems = sub != null ? (_jsxs(SurfaceContext.Provider, { value: { close: onClose, check: hasCheckedItems(sub.items), multiple, header }, children: [_jsx(MenuRow, { icon: _jsx(ArrowLeftLg, {}), stay: collapse, children: sub.backLabel }), _jsx(MenuSeparator, {}), sub.items] })) : null;
|
|
628
631
|
// The web's keyboard, as the WAI-ARIA menu pattern, over the page in front
|
|
629
632
|
const panel = useRef(null);
|
|
630
633
|
const mainPage = useRef(null);
|
|
@@ -890,8 +893,15 @@ function MenuSubTrigger({ children, icon, disabled, testID }) {
|
|
|
890
893
|
const open = () => {
|
|
891
894
|
if (!sub)
|
|
892
895
|
return;
|
|
893
|
-
measure(row.current, (box) => surface.openSub?.({ label: children, items: sub.children, backLabel: sub.backLabel ?? "Back", y: box.y }));
|
|
896
|
+
measure(row.current, (box) => surface.openSub?.({ label: children, items: sub.children, backLabel: sub.backLabel ?? "Back", y: box.y, owner: row }));
|
|
894
897
|
};
|
|
898
|
+
// The submenu this row opened follows the app's state while it shows (a multiple choice keeps it open)
|
|
899
|
+
const items = sub?.children;
|
|
900
|
+
const { subOpen, refreshSub } = surface;
|
|
901
|
+
useEffect(() => {
|
|
902
|
+
if (subOpen)
|
|
903
|
+
refreshSub?.(row, items);
|
|
904
|
+
}, [items, subOpen, refreshSub]);
|
|
895
905
|
return (_jsx(MenuRow, { icon: icon, disabled: disabled, testID: testID, rowRef: row, stay: open, opens: true, expanded: surface.subOpen, children: children }));
|
|
896
906
|
}
|
|
897
907
|
MenuSubTrigger.displayName = "Menu.SubTrigger";
|
|
@@ -124,8 +124,10 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, positio
|
|
|
124
124
|
const gap = small ? 4 : android ? ANDROID_GAP : theme.length("--page-control-gap", 8);
|
|
125
125
|
const padding = small ? 6 : theme.length("--page-control-padding-inline", 12);
|
|
126
126
|
const pitch = dot + gap;
|
|
127
|
-
// Android draws every page's dot at full size;
|
|
128
|
-
|
|
127
|
+
// Android draws every page's dot at full size up to ANDROID_MAX_DOTS; past that, and on iOS from seven pages, the
|
|
128
|
+
// dots are a window that holds the current page, so a long run of pages never runs off the screen
|
|
129
|
+
const windowed = !android || count > ANDROID_MAX_DOTS;
|
|
130
|
+
const sizes = windowed ? pageControlDots(count, clampIndex(typeof positionProp === "number" ? Math.round(positionProp) : near, count)) : Array.from({ length: Math.max(0, count) }, () => "full");
|
|
129
131
|
// The small and smaller ends keep their share of a full dot (6 and 4 of 8 on iOS)
|
|
130
132
|
const dotSize = (kind) => kind === "full"
|
|
131
133
|
? dot
|
|
@@ -152,7 +154,7 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, positio
|
|
|
152
154
|
const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary);
|
|
153
155
|
// Android's current dot is drawn over the gray ones (it stretches between pages) unless the pages' scroll drives the
|
|
154
156
|
// dots, when their color crosses over as on iOS; a pill is a dot of its own
|
|
155
|
-
const worm = android && !pill && positionProp == null;
|
|
157
|
+
const worm = android && !pill && positionProp == null && !windowed;
|
|
156
158
|
// Android draws no capsule, not even for `prominent`
|
|
157
159
|
const capsuleHeight = small ? 16 : theme.length("--page-control-height", 24);
|
|
158
160
|
const target = android ? 48 : theme.length("--page-control-target-size", 44);
|
|
@@ -234,6 +236,8 @@ const ANDROID_SLIDE = { duration: 300, easing: Easing.bezier(0.2, 0, 0, 1) };
|
|
|
234
236
|
/** Android's page dots: 5dp, 11dp from one to the next. */
|
|
235
237
|
const ANDROID_DOT = 5;
|
|
236
238
|
const ANDROID_GAP = 6;
|
|
239
|
+
/** The most pages whose dots Android draws all; more take the window of dots the iOS kit keeps. */
|
|
240
|
+
const ANDROID_MAX_DOTS = 9;
|
|
237
241
|
/**
|
|
238
242
|
* A page change the pager settles on its own (a tap, a change from code): one page in 200ms, on an ease-out quint
|
|
239
243
|
* standing in for the pager's 1 + (t − 1)⁵.
|