@plexui/react-native 0.2.25 → 0.2.27
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 +10 -6
- package/dist/es/components/Card/Card.js +9 -2
- package/dist/es/components/Checkbox/Checkbox.js +2 -2
- package/dist/es/components/Chip/Chip.js +19 -11
- package/dist/es/components/Dialog/Dialog.js +18 -6
- package/dist/es/components/EmptyMessage/EmptyMessage.js +2 -2
- package/dist/es/components/Indicator/CircularProgress.js +11 -5
- package/dist/es/components/Input/Input.js +17 -2
- package/dist/es/components/List/List.js +77 -9
- 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 +2 -2
- package/dist/es/components/RollingNumber/RollingNumber.js +7 -7
- package/dist/es/components/ScrollEdge/ScrollEdge.js +12 -6
- package/dist/es/components/Select/Select.js +4 -2
- package/dist/es/components/Switch/Switch.js +2 -2
- package/dist/es/components/TabBar/TabBar.js +15 -0
- package/dist/es/components/TextLink/TextLink.js +23 -3
- package/dist/es/index.js +2 -2
- package/dist/es/internal/a11y.js +12 -0
- package/dist/es/internal/row.js +13 -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 +5 -0
- package/dist/types/components/Card/Card.d.ts +5 -1
- package/dist/types/components/Chip/Chip.d.ts +9 -3
- package/dist/types/components/Dialog/Dialog.d.ts +7 -1
- package/dist/types/components/EmptyMessage/EmptyMessage.d.ts +4 -2
- package/dist/types/components/Indicator/CircularProgress.d.ts +10 -2
- package/dist/types/components/Input/Input.d.ts +8 -1
- package/dist/types/components/List/List.d.ts +36 -1
- package/dist/types/components/Menu/Menu.d.ts +10 -4
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +3 -1
- package/dist/types/components/ScrollEdge/ScrollEdge.d.ts +7 -1
- package/dist/types/components/TabBar/TabBar.d.ts +13 -0
- package/dist/types/components/TextLink/TextLink.d.ts +7 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/internal/a11y.d.ts +22 -0
- package/dist/types/internal/row.d.ts +21 -2
- 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 +19 -4
- package/src/components/Card/Card.tsx +8 -3
- package/src/components/Checkbox/Checkbox.tsx +2 -1
- package/src/components/Chip/Chip.tsx +28 -9
- package/src/components/Dialog/Dialog.tsx +30 -6
- package/src/components/EmptyMessage/EmptyMessage.tsx +12 -3
- package/src/components/Indicator/CircularProgress.tsx +27 -11
- package/src/components/Input/Input.tsx +43 -3
- package/src/components/List/List.tsx +125 -7
- package/src/components/Menu/Menu.tsx +27 -11
- package/src/components/PageControl/PageControl.tsx +7 -3
- package/src/components/RadioGroup/RadioGroup.tsx +2 -1
- package/src/components/RollingNumber/RollingNumber.tsx +10 -8
- package/src/components/ScrollEdge/ScrollEdge.tsx +19 -6
- package/src/components/Select/Select.tsx +4 -1
- package/src/components/Switch/Switch.tsx +2 -1
- package/src/components/TabBar/TabBar.tsx +15 -0
- package/src/components/TextLink/TextLink.tsx +52 -3
- package/src/index.ts +2 -2
- package/src/internal/a11y.ts +13 -0
- package/src/internal/row.ts +14 -2
- 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
|
|
@@ -232,13 +232,15 @@ function Spinner({ color }) {
|
|
|
232
232
|
strokeDasharray: [SPINNER_LENGTH, SPINNER_LENGTH], strokeDashoffset: SPINNER_LENGTH * (1 - arc / 360) }) }) }));
|
|
233
233
|
}
|
|
234
234
|
/** Strings and numbers in a row make one label ("Pressed {count}"); an element (an icon) stands on its own. */
|
|
235
|
-
function renderChildren(children, metrics) {
|
|
235
|
+
function renderChildren(children, metrics, lines = 1) {
|
|
236
236
|
const out = [];
|
|
237
237
|
let label = [];
|
|
238
238
|
const flush = () => {
|
|
239
239
|
if (!label.length)
|
|
240
240
|
return;
|
|
241
|
-
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}`));
|
|
242
244
|
label = [];
|
|
243
245
|
};
|
|
244
246
|
flattenChildren(children).forEach((child, index) => {
|
|
@@ -275,7 +277,7 @@ export function Button(props) {
|
|
|
275
277
|
* the title's line with a 44pt target; Android's 14sp Medium in the accent on the header's line. `style` reaches the
|
|
276
278
|
* row (`justifyContent: "center"` centres the words, as the web's `data-align="center"`).
|
|
277
279
|
*/
|
|
278
|
-
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 }) {
|
|
279
281
|
const theme = useTheme();
|
|
280
282
|
const android = theme.isAndroid;
|
|
281
283
|
const [pressed, setPressed] = useState(false);
|
|
@@ -304,7 +306,7 @@ function ListActionButton({ place, color = "primary", disabled = false, loading
|
|
|
304
306
|
const parts = flattenChildren(children);
|
|
305
307
|
// Words and then an icon: the words take the room, so the icon ends the row
|
|
306
308
|
const trailingIcon = row && parts.length > 1 && isValidElement(parts[parts.length - 1]);
|
|
307
|
-
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}`)));
|
|
308
310
|
const fill = row && pressed && !inert ? (android ? controlHighlight(theme.scheme) : theme.color("--field-row-press-background")) : undefined;
|
|
309
311
|
// The header's words stand on the title's line: their target reaches over and under it to 44 (48 on Android)
|
|
310
312
|
const reach = row ? 0 : Math.max(0, ((android ? 48 : 44) - type.lineHeight) / 2);
|
|
@@ -324,7 +326,7 @@ function ListActionButton({ place, color = "primary", disabled = false, loading
|
|
|
324
326
|
style,
|
|
325
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 }) }) }));
|
|
326
328
|
}
|
|
327
|
-
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 }) {
|
|
328
330
|
const theme = useTheme();
|
|
329
331
|
const bar = useContext(BarItemContext);
|
|
330
332
|
const sized = buttonMetrics(theme, size, shape, uniform);
|
|
@@ -501,7 +503,7 @@ function ButtonBody({ color = "primary", variant = "solid", size = "md", shape =
|
|
|
501
503
|
}
|
|
502
504
|
: { opacity: loading ? 0 : 1 };
|
|
503
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;
|
|
504
|
-
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] }) }));
|
|
505
507
|
const layer = ripple.layer;
|
|
506
508
|
const pressable = {
|
|
507
509
|
accessibilityRole: "button",
|
|
@@ -526,4 +528,6 @@ const styles = StyleSheet.create({
|
|
|
526
528
|
row: { flexDirection: "row", alignItems: "center", justifyContent: "center" },
|
|
527
529
|
fromTop: { alignSelf: "stretch", transformOrigin: "top" },
|
|
528
530
|
grow: { flexGrow: 1, flexShrink: 1 },
|
|
531
|
+
wraps: { flexShrink: 1, minWidth: 0, textAlign: "center" },
|
|
532
|
+
shrinks: { flexShrink: 1, minWidth: 0, maxWidth: "100%" },
|
|
529
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 { RowActionContext, RowEndContext, RowHoldContext, RowStartContext, holdProps, 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";
|
|
@@ -126,7 +126,7 @@ export function Checkbox({ checked: checkedProp, defaultChecked = false, onCheck
|
|
|
126
126
|
const targetSize = theme.isAndroid ? 48 : theme.length("--checkbox-target-size", 44);
|
|
127
127
|
const described = useDescription(description);
|
|
128
128
|
const text = _jsx(ControlLabel, { label: label, description: description, disabled: disabled, descriptionId: described.id });
|
|
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), 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: [
|
|
130
130
|
styles.row,
|
|
131
131
|
hasText ? styles.top : null,
|
|
132
132
|
// Android's gap is in the target's margins
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { holdProps } from "../../internal/row";
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
5
|
+
import { useAndroidGlass } from "../../internal/BarBackdrop";
|
|
5
6
|
import { Pressable } from "../../internal/Pressable";
|
|
6
7
|
import ChevronDownSm from "../../icons/plex/ChevronDownSm";
|
|
7
8
|
import CloseBold from "../../icons/plex/CloseBold";
|
|
@@ -22,7 +23,7 @@ import { Text, textStyle } from "../Text/Text";
|
|
|
22
23
|
*/
|
|
23
24
|
/** The chosen token's way to let go, so that choosing another lets it go */
|
|
24
25
|
let disarmToken = null;
|
|
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, }) {
|
|
26
|
+
export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance = "tag", size = "md", onRemove, removeLabel = "Remove", removeStyle = "token", onLongPress, longPressLabel, disabled = false, testID, style, }) {
|
|
26
27
|
const theme = useTheme();
|
|
27
28
|
const [own, setOwn] = useState(defaultSelected ?? false);
|
|
28
29
|
// iOS's token: an input chip with no cross, chosen by a first press and removed by a second (or by Delete); it is
|
|
@@ -110,13 +111,14 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
110
111
|
}, [blend, blends, selected]);
|
|
111
112
|
const fillPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidFill.off, androidFill.on] }) : fill;
|
|
112
113
|
const labelPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidColor.off, androidColor.on] }) : color;
|
|
113
|
-
const
|
|
114
|
-
const
|
|
114
|
+
const small = !android && size === "sm";
|
|
115
|
+
const height = android ? 32 : small ? 36 : glass ? 44 : 40;
|
|
116
|
+
const label = android ? { fontSize: 14, lineHeight: 18 } : small ? { fontSize: 15, lineHeight: 20 } : { fontSize: 17, lineHeight: 22 };
|
|
115
117
|
const leading = icon;
|
|
116
|
-
// iOS: a 17pt symbol draws about 20 (the label's size)
|
|
117
|
-
const iconSize = android ? 18 : 20;
|
|
118
|
+
// iOS: a 17pt symbol draws about 20 (the label's size), a 15pt one about 17
|
|
119
|
+
const iconSize = android ? 18 : small ? 17 : 20;
|
|
118
120
|
// A menu chip's chevron: Material's 18dp arrow_drop_down, iOS's small chevron.down at the label's weight
|
|
119
|
-
const trailing = trailingIcon ?? (menu ? android ? _jsx(MaterialArrowDropDown, { size: 18 }) : _jsx(ChevronDownSm, { size: 16 }) : null);
|
|
121
|
+
const trailing = trailingIcon ?? (menu ? android ? _jsx(MaterialArrowDropDown, { size: 18 }) : _jsx(ChevronDownSm, { size: small ? 14 : 16 }) : null);
|
|
120
122
|
const leadingColor = color;
|
|
121
123
|
// A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
|
|
122
124
|
const symbolOnly = leading != null && (children == null || children === "") && trailing == null && !onRemove;
|
|
@@ -132,6 +134,10 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
132
134
|
const [pressed, setPressed] = useState(false);
|
|
133
135
|
// iOS's glass filter: a glass capsule (its rim and sheen), filled with the accent once chosen
|
|
134
136
|
const glassLayer = glass && !selected ? _jsx(Glass, { pointerEvents: "none", radius: radius, style: [StyleSheet.absoluteFill, { top: inset, bottom: inset }] }) : null;
|
|
137
|
+
// Android's chip over content (`glass`): it stands on a glass of its size, the Android bar circles' (a see-through
|
|
138
|
+
// card with a rim and a soft shadow), Material's fill and label over it
|
|
139
|
+
const androidGlass = useAndroidGlass("bar");
|
|
140
|
+
const androidBacking = android && appearance === "glass" ? _jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, androidGlass, { top: inset, bottom: inset, borderRadius: radius }] }) : null;
|
|
135
141
|
const layer = glassLayer ?? (_jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: radius, backgroundColor: fillPaint, borderCurve: "continuous" }], children: android && pressed && !disabled ? (_jsx(View, { style: [StyleSheet.absoluteFill, { borderRadius: radius, backgroundColor: selected ? withAlpha(color, 0.12) : theme.scheme === "dark" ? "rgba(255, 255, 255, 0.05)" : "rgba(0, 0, 0, 0.06)" }] })) : null }));
|
|
136
142
|
const box = {
|
|
137
143
|
// The label's own air inside the chip, then the target's outside it: 48 (44) at the regular size, and taller
|
|
@@ -139,9 +145,9 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
139
145
|
minHeight: target,
|
|
140
146
|
paddingVertical: inset + (height - label.lineHeight) / 2,
|
|
141
147
|
// Android: 12 at the sides, 8 before an icon and 6 after it
|
|
142
|
-
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
148
|
+
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : small ? 10 : 12) : android ? 12 : small ? 14 : 16,
|
|
143
149
|
// Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
|
|
144
|
-
paddingRight: symbolOnly ? (height - iconSize) / 2 : cross ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
150
|
+
paddingRight: symbolOnly ? (height - iconSize) / 2 : cross ? 0 : trailing != null ? (android ? 8 : small ? 10 : 12) : android ? 12 : small ? 14 : 16,
|
|
145
151
|
gap: 6,
|
|
146
152
|
opacity: !android && pressed ? 0.7 : 1,
|
|
147
153
|
};
|
|
@@ -152,6 +158,8 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
152
158
|
// Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
|
|
153
159
|
const dim = android && disabled ? styles.dim : null;
|
|
154
160
|
const handlers = {
|
|
161
|
+
// A symbol alone keeps the target's width past its circle (36 on iOS's small chip, 32 on Android's)
|
|
162
|
+
hitSlop: symbolOnly && height < target ? { left: (target - height) / 2, right: (target - height) / 2 } : undefined,
|
|
155
163
|
...(filter ? spaceToggles(press) : {}),
|
|
156
164
|
// A menu chip is a button that opens its menu, even when it shows a chosen filter
|
|
157
165
|
accessibilityRole: filter && !menu ? "checkbox" : "button",
|
|
@@ -192,12 +200,12 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
192
200
|
// An input chip holds its cross beside the chip's own press, never a button inside a button; each takes the
|
|
193
201
|
// target's full height
|
|
194
202
|
if (cross) {
|
|
195
|
-
return (_jsxs(View, { testID: testID, style: [styles.chip, { minHeight: target }, dim, style], children: [layer, interactive ? (_jsx(Pressable, { ...handlers, style: [styles.part, box], children: body })) : (_jsx(View, { style: [styles.part, box], children: body })), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: removeLabel, disabled: disabled, onPress: onRemove, style: [styles.part, android ? { paddingLeft: 4, paddingRight: 8 } : { width: 44, justifyContent: "center" }], children: android ? _jsx(CloseBold, { size: 18, color: color }) : _jsx(XCircleFilled, { size: clearSize, color: theme.color("--mobile-label-tertiary") }) })] }));
|
|
203
|
+
return (_jsxs(View, { testID: testID, style: [styles.chip, { minHeight: target }, dim, style], children: [androidBacking, layer, interactive ? (_jsx(Pressable, { ...handlers, style: [styles.part, box], children: body })) : (_jsx(View, { style: [styles.part, box], children: body })), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: removeLabel, disabled: disabled, onPress: onRemove, style: [styles.part, android ? { paddingLeft: 4, paddingRight: 8 } : { width: 44, justifyContent: "center" }], children: android ? _jsx(CloseBold, { size: 18, color: color }) : _jsx(XCircleFilled, { size: clearSize, color: theme.color("--mobile-label-tertiary") }) })] }));
|
|
196
204
|
}
|
|
197
205
|
if (!interactive) {
|
|
198
|
-
return (_jsxs(View, { testID: testID, style: [styles.chip, styles.part, box, dim, style], children: [layer, body] }));
|
|
206
|
+
return (_jsxs(View, { testID: testID, style: [styles.chip, styles.part, box, dim, style], children: [androidBacking, layer, body] }));
|
|
199
207
|
}
|
|
200
|
-
return (_jsxs(Pressable, { ...handlers, testID: testID, style: [styles.chip, styles.part, box, dim, style], children: [layer, body] }));
|
|
208
|
+
return (_jsxs(Pressable, { ...handlers, testID: testID, style: [styles.chip, styles.part, box, dim, style], children: [androidBacking, layer, body] }));
|
|
201
209
|
}
|
|
202
210
|
const styles = StyleSheet.create({
|
|
203
211
|
chip: { flexDirection: "row", alignItems: "stretch", alignSelf: "flex-start" },
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useId, useState } from "react";
|
|
2
|
+
import { createContext, useContext, useId, useState } from "react";
|
|
3
3
|
import { Animated, KeyboardAvoidingView, Platform, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
6
6
|
import { Glass } from "../../internal/Glass";
|
|
7
7
|
import { useRipple } from "../../internal/ripple";
|
|
8
|
+
import { buttonColors } from "../Button/Button";
|
|
8
9
|
import { useKeyboardHeight } from "../../internal/keyboard";
|
|
9
10
|
import { androidDialogMotion, canTransformGlass, glassOpacity, iosDim, Overlay, ANDROID_DIALOG, ANDROID_DIM } from "../../internal/Overlay";
|
|
10
11
|
import { withAlpha, dangerText } from "../../theme/material";
|
|
11
12
|
import { ThemeProvider, useTheme } from "../../theme/ThemeProvider";
|
|
12
13
|
import { Text } from "../Text/Text";
|
|
14
|
+
/** The dialog's `actionColor`, for its action buttons. */
|
|
15
|
+
const ActionColorContext = createContext("accent");
|
|
13
16
|
/**
|
|
14
17
|
* A dialog that asks for a decision: on iOS the alert of iOS 26 (UIAlertController `.alert`: 320 wide, glass, radius
|
|
15
18
|
* 34, capsule actions 48 tall, `--dialog-alert-*`, Dialog.module.css), on Android a flat alert (at most 356 wide,
|
|
16
19
|
* radius 21, a Medium 20 title over 16 text, text buttons in the accent at the end, Android's dialog animation). The
|
|
17
20
|
* web Dialog's `mobileVariant="alert"` as one call; a sheet is `BottomSheet`.
|
|
18
21
|
*/
|
|
19
|
-
export function Dialog({
|
|
22
|
+
export function Dialog({ actionColor = "accent", ...props }) {
|
|
23
|
+
return (_jsx(ActionColorContext.Provider, { value: actionColor, children: _jsx(DialogView, { ...props }) }));
|
|
24
|
+
}
|
|
25
|
+
function DialogView({ open, onOpenChange, title, description, actions = [], children, mobileLayout, dismissible, testID }) {
|
|
20
26
|
const theme = useTheme();
|
|
21
27
|
const close = () => onOpenChange(false);
|
|
22
28
|
const run = (action) => {
|
|
@@ -169,18 +175,23 @@ function IOSAction({ theme, action, run, type, grow }) {
|
|
|
169
175
|
// a preferredAction (iOS 27.2: 0082f7 on every row); disabled, the phone's disabled fill (Button.module.css). A
|
|
170
176
|
// destructive one keeps the alert's fill and its red label
|
|
171
177
|
const accent = action.preferred && action.variant !== "destructive";
|
|
178
|
+
const primary = useContext(ActionColorContext) === "primary";
|
|
172
179
|
const height = theme.length("--dialog-alert-action-height", 48);
|
|
173
180
|
const fill = accent
|
|
174
181
|
? action.disabled
|
|
175
182
|
? theme.color("--button-mobile-disabled-background", theme.color("--color-background-disabled"))
|
|
176
|
-
:
|
|
183
|
+
: primary
|
|
184
|
+
? theme.color("--color-background-primary-solid")
|
|
185
|
+
: theme.color("--toolbar-prominent-background")
|
|
177
186
|
: theme.color("--dialog-alert-fill");
|
|
178
187
|
const text = action.disabled
|
|
179
188
|
? theme.color("--mobile-label-tertiary")
|
|
180
189
|
: action.variant === "destructive"
|
|
181
190
|
? theme.color("--color-text-danger")
|
|
182
191
|
: accent
|
|
183
|
-
?
|
|
192
|
+
? primary
|
|
193
|
+
? theme.color("--color-text-primary-solid")
|
|
194
|
+
: theme.color("--toolbar-prominent-color")
|
|
184
195
|
: theme.colors.text;
|
|
185
196
|
const lit = accent && !action.disabled;
|
|
186
197
|
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!action.disabled }, disabled: action.disabled, onPress: () => run(action), testID: action.testID, style: ({ pressed }) => [
|
|
@@ -188,7 +199,7 @@ function IOSAction({ theme, action, run, type, grow }) {
|
|
|
188
199
|
{
|
|
189
200
|
minHeight: height,
|
|
190
201
|
borderRadius: height / 2,
|
|
191
|
-
backgroundColor: lit && pressed ? theme.color("--toolbar-prominent-background-active") : fill,
|
|
202
|
+
backgroundColor: lit && pressed ? theme.color(primary ? "--color-background-primary-solid-active" : "--toolbar-prominent-background-active") : fill,
|
|
192
203
|
opacity: pressed && !lit ? 0.7 : 1,
|
|
193
204
|
},
|
|
194
205
|
grow ? styles.grow : null,
|
|
@@ -234,7 +245,8 @@ function AndroidDialog({ theme, title, description, actions, run, ids, children,
|
|
|
234
245
|
* ripple of the label's color at 10% from the touch point, clipped to its 20dp pill (the platform's on a device).
|
|
235
246
|
*/
|
|
236
247
|
function AndroidDialogButton({ theme, action, run, onWidth }) {
|
|
237
|
-
const
|
|
248
|
+
const primary = useContext(ActionColorContext) === "primary";
|
|
249
|
+
const color = action.variant === "destructive" ? dangerText(theme) : primary ? buttonColors(theme, "primary", "ghost", false, false).text : theme.material.primary;
|
|
238
250
|
const press = withAlpha(color, 0.1);
|
|
239
251
|
const nativeRipple = Platform.OS === "android";
|
|
240
252
|
const ripple = useRipple(press, !nativeRipple, theme.reducedMotion);
|
|
@@ -45,7 +45,7 @@ function EmptyMessageIcon({ children, color = "secondary", size }) {
|
|
|
45
45
|
return (_jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: { marginBottom: gap }, children: _jsx(IconDefaultsProvider, { size: theme.length("--empty-message-icon-size", 48), color: toneColor(theme, color), children: children }) }));
|
|
46
46
|
}
|
|
47
47
|
EmptyMessageIcon.displayName = "EmptyMessage.Icon";
|
|
48
|
-
function EmptyMessageTitle({ children, color }) {
|
|
48
|
+
function EmptyMessageTitle({ children, color, style, }) {
|
|
49
49
|
const { theme, size, align } = useEmpty("EmptyMessage.Title");
|
|
50
50
|
const compact = size === "sm";
|
|
51
51
|
// Android's empty view: the title Medium 20 (16 in the compact message)
|
|
@@ -59,7 +59,7 @@ function EmptyMessageTitle({ children, color }) {
|
|
|
59
59
|
return (_jsx(Text, { accessibilityRole: "header", weight: theme.isAndroid ? "medium" : compact ? "semibold" : "bold", color: color && color !== "secondary" ? toneColor(theme, color) : undefined,
|
|
60
60
|
// `left` is the start: React Native turns it to the right in a right-to-left layout. `auto` took the alignment of
|
|
61
61
|
// the page around it on the web, where a centered page left a start-aligned message centered
|
|
62
|
-
style: { fontSize: type.fontSize, lineHeight: type.lineHeight, textAlign: align === "center" ? "center" : "left", marginBottom: compact ? space(theme, 1) : 0 }, children: children }));
|
|
62
|
+
style: [{ fontSize: type.fontSize, lineHeight: type.lineHeight, textAlign: align === "center" ? "center" : "left", marginBottom: compact ? space(theme, 1) : 0 }, style], children: children }));
|
|
63
63
|
}
|
|
64
64
|
EmptyMessageTitle.displayName = "EmptyMessage.Title";
|
|
65
65
|
function EmptyMessageDescription({ children }) {
|
|
@@ -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
|
}
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Animated, Easing, PixelRatio, Platform, StyleSheet, Text as NativeText, TextInput, View, processColor } from "react-native";
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
|
+
import { Text } from "../Text/Text";
|
|
5
6
|
import XCircleFilled from "../../icons/plex/XCircleFilled";
|
|
6
7
|
import { useAndroidGlass } from "../../internal/BarBackdrop";
|
|
7
8
|
import { FieldStack, FloatLabelContext } from "../../internal/fieldStack";
|
|
@@ -574,15 +575,29 @@ function FieldBox({ glass, raised, radius, shift, style, ...rest }) {
|
|
|
574
575
|
* description or error under it (15/20, 4pt below, `--mobile-field-error-*`); Android is the outlined field with its
|
|
575
576
|
* floating label (on the line of an outlined field) and the help under it (14, 14dp in).
|
|
576
577
|
*/
|
|
577
|
-
export function TextField({ label, description, errorMessage, required, invalid, ...input }) {
|
|
578
|
+
export function TextField({ label, description, errorMessage, required, invalid, labelAction, counter = false, ...input }) {
|
|
578
579
|
const theme = useTheme();
|
|
579
|
-
|
|
580
|
+
const [typed, setTyped] = useState((input.defaultValue ?? "").length);
|
|
581
|
+
const count = input.value != null ? input.value.length : typed;
|
|
582
|
+
const counterText = counter && input.maxLength != null ? (_jsxs(Text, { color: "secondary", accessibilityLabel: `${count} of ${input.maxLength}`, style: [
|
|
583
|
+
theme.isAndroid ? styles.androidCounter : styles.iosCounter,
|
|
584
|
+
{ opacity: input.disabled ? 0.5 : 1 },
|
|
585
|
+
theme.isAndroid ? { color: theme.colors.textSecondary } : null,
|
|
586
|
+
], children: [count, "/", input.maxLength] })) : null;
|
|
587
|
+
const end = labelAction != null && counterText != null ? (_jsxs(View, { style: styles.endRow, children: [labelAction, counterText] })) : (labelAction ?? counterText);
|
|
588
|
+
// The count follows every edit, so a counter shown later reads the text as it is
|
|
589
|
+
const field = { ...input, onChangeText: (next) => (setTyped(next.length), input.onChangeText?.(next)) };
|
|
590
|
+
return (_jsx(FieldStack, { label: label, labelAction: end ?? undefined, required: required, description: description, errorMessage: errorMessage, invalid: invalid, disabled: input.disabled, floating: theme.isAndroid, describedBy: input["aria-describedby"], hint: input.accessibilityHint, children: ({ described, invalid: bad, shake }) => theme.isAndroid ? (_jsx(InputField, { ...field, ...described, label: label, required: required, invalid: bad, shift: shake })) : (_jsx(InputField, { ...field, ...described, accessibilityLabel: input.accessibilityLabel ?? (typeof label === "string" ? label : undefined), required: required, invalid: bad })) }));
|
|
580
591
|
}
|
|
581
592
|
const FIELD_START = { side: "start", row: false };
|
|
582
593
|
const FIELD_END = { side: "end", row: false };
|
|
583
594
|
const ROW_START = { side: "start", row: true };
|
|
584
595
|
const ROW_END = { side: "end", row: true };
|
|
585
596
|
const styles = StyleSheet.create({
|
|
597
|
+
// Material's counter: the help's type, at the end of its line, 16 from the help and 14 in from the field's end
|
|
598
|
+
androidCounter: { fontSize: 14, lineHeight: 18, paddingStart: 16, paddingEnd: 14, paddingTop: 6, fontVariant: ["tabular-nums"] },
|
|
599
|
+
iosCounter: { fontSize: 15, lineHeight: 20, fontVariant: ["tabular-nums"] },
|
|
600
|
+
endRow: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
586
601
|
adornmentButton: { alignItems: "center", justifyContent: "center" },
|
|
587
602
|
// Centered in the 48dp target
|
|
588
603
|
adornmentPressed: { position: "absolute", top: 4, start: 4, width: 40, height: 40, borderRadius: 20 },
|