@plexui/react-native 0.2.1 → 0.2.3

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.
@@ -1,7 +1,9 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Children, cloneElement, isValidElement } from "react";
3
3
  import { StyleSheet, View } from "react-native";
4
4
  import { useSafeAreaInsets } from "react-native-safe-area-context";
5
+ import { ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, SoftBottomEdge } from "../../internal/BarBackdrop";
6
+ import { withAlpha } from "../../theme/material";
5
7
  import { useTheme } from "../../theme/ThemeProvider";
6
8
  import { Button } from "../Button/Button";
7
9
  /**
@@ -11,7 +13,7 @@ import { Button } from "../Button/Button";
11
13
  * action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
12
14
  * 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
13
15
  */
14
- export function BottomActions({ children, floating = false, testID, style }) {
16
+ export function BottomActions({ children, floating = false, canvasColor, testID, style }) {
15
17
  const theme = useTheme();
16
18
  const insets = useSafeAreaInsets();
17
19
  const android = theme.isAndroid;
@@ -19,16 +21,28 @@ export function BottomActions({ children, floating = false, testID, style }) {
19
21
  // iOS: 2pt over the safe area (34 on a Face ID iPhone); a phone with a home button has none, so 16 there
20
22
  const bottom = android ? Math.max(insets.bottom, 0) + 16 : insets.bottom > 0 ? insets.bottom + 2 : 16;
21
23
  const height = android ? 48 : 52;
22
- const actions = Children.toArray(children).map((child) => isValidElement(child) && child.type === Button
23
- ? cloneElement(child, {
24
- block: child.props.block ?? true,
25
- size: child.props.size ?? "3xl",
26
- style: [{ minHeight: height, borderRadius: height / 2 }, child.props.style],
27
- })
28
- : child);
29
- return (_jsx(View, { testID: testID, pointerEvents: "box-none", style: [styles.bar, { paddingHorizontal: side, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style], children: actions }));
24
+ const canvas = canvasColor ?? theme.colors.background;
25
+ const paddingTop = 8;
26
+ const actions = Children.toArray(children).map((child, index) => {
27
+ if (!isValidElement(child) || child.type !== Button)
28
+ return child;
29
+ const props = child.props;
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
32
+ ? android
33
+ ? { variant: "ghost", color: props.color ?? "secondary" }
34
+ : { variant: "soft", color: props.color ?? "secondary", mobileMaterial: props.mobileMaterial ?? "glass" }
35
+ : null;
36
+ return cloneElement(child, {
37
+ ...second,
38
+ block: props.block ?? true,
39
+ size: props.size ?? "3xl",
40
+ style: [{ minHeight: height, borderRadius: height / 2 }, props.style],
41
+ });
42
+ });
43
+ return (_jsxs(View, { testID: testID, pointerEvents: "box-none", style: [styles.bar, { paddingHorizontal: side, paddingTop, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style], children: [floating ? (android ? (_jsx(SoftBottomEdge, { fill: withAlpha(canvas, ANDROID_FADE_ALPHA), top: paddingTop - 13 + 60, tail: 60, blur: 0, stops: ANDROID_FADE_STOPS })) : (_jsx(SoftBottomEdge, { fill: canvas, top: paddingTop, tail: 27, blur: theme.length("--toolbar-edge-blur-small", 3) }))) : null, actions] }));
30
44
  }
31
45
  const styles = StyleSheet.create({
32
- bar: { alignSelf: "stretch", paddingTop: 8 },
46
+ bar: { alignSelf: "stretch" },
33
47
  floating: { position: "absolute", left: 0, right: 0, bottom: 0 },
34
48
  });
@@ -3,6 +3,7 @@ import { useEffect, useState } from "react";
3
3
  import { Animated, Easing, Platform, Pressable, StyleSheet, View } from "react-native";
4
4
  import ChevronDownSm from "../../icons/plex/ChevronDownSm";
5
5
  import CloseBold from "../../icons/plex/CloseBold";
6
+ import XCircleFilled from "../../icons/plex/XCircleFilled";
6
7
  import { spaceToggles } from "../../internal/a11y";
7
8
  import { Glass } from "../../internal/Glass";
8
9
  import { withAlpha } from "../../theme/material";
@@ -17,14 +18,46 @@ import { Text, textStyle } from "../Text/Text";
17
18
  * one in the app's accent (its tint) with a white label. The web has
18
19
  * no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
19
20
  */
20
- export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance = "tag", onRemove, removeLabel = "Remove", disabled = false, testID, style, }) {
21
+ /** The chosen token's way to let go, so that choosing another lets it go */
22
+ let disarmToken = null;
23
+ 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, }) {
21
24
  const theme = useTheme();
22
25
  const [own, setOwn] = useState(defaultSelected ?? false);
23
- const filter = selectedProp !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined;
24
- const selected = filter ? (selectedProp ?? own) : false;
26
+ // iOS's token: an input chip with no cross, chosen by a first press and removed by a second (or by Delete); it is
27
+ // never a filter as well
28
+ const token = !theme.isAndroid && onRemove != null && removeStyle === "token";
29
+ const filter = !token && (selectedProp !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined);
30
+ const [armed, setArmedState] = useState(false);
31
+ // One token is chosen at a time, as in a token field: choosing one lets the last one go (a tap on a native view
32
+ // never moves focus, so a blur alone cannot)
33
+ const [disarm] = useState(() => () => setArmedState(false));
34
+ const setArmed = (on) => {
35
+ if (on) {
36
+ if (disarmToken !== disarm)
37
+ disarmToken?.();
38
+ disarmToken = disarm;
39
+ }
40
+ else if (disarmToken === disarm) {
41
+ disarmToken = null;
42
+ }
43
+ setArmedState(on);
44
+ };
45
+ useEffect(() => () => {
46
+ if (disarmToken === disarm)
47
+ disarmToken = null;
48
+ }, [disarm]);
49
+ const selected = filter ? (selectedProp ?? own) : token && armed;
25
50
  const press = () => {
26
51
  if (disabled)
27
52
  return;
53
+ if (token) {
54
+ if (armed) {
55
+ setArmed(false);
56
+ onRemove?.();
57
+ return;
58
+ }
59
+ setArmed(true);
60
+ }
28
61
  if (filter) {
29
62
  if (selectedProp === undefined)
30
63
  setOwn(!selected);
@@ -85,6 +118,9 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
85
118
  const leadingColor = color;
86
119
  // A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
87
120
  const symbolOnly = leading != null && (children == null || children === "") && trailing == null && !onRemove;
121
+ // An input chip's cross stands in a target of its own after the chip's press: on iOS the field's clear button
122
+ const cross = onRemove != null && !token;
123
+ const clearSize = 17 * 1.2;
88
124
  // The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
89
125
  // HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
90
126
  const target = android ? 48 : 44;
@@ -103,14 +139,14 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
103
139
  // Android: 12 at the sides, 8 before an icon and 6 after it
104
140
  paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
105
141
  // Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
106
- paddingRight: symbolOnly ? (height - iconSize) / 2 : onRemove ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
142
+ paddingRight: symbolOnly ? (height - iconSize) / 2 : cross ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
107
143
  gap: 6,
108
144
  opacity: !android && pressed ? 0.7 : 1,
109
145
  };
110
146
  const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, symbolOnly ? null : android ? (
111
147
  // Text's own face and tracking, in a color that blends
112
- _jsx(Animated.Text, { numberOfLines: 1, 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, style: { fontSize: label.fontSize, lineHeight: label.lineHeight }, children: children })), trailing != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: trailing }) })) : null] }));
113
- const interactive = filter || !!onPress;
148
+ _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] }));
149
+ const interactive = filter || !!onPress || token;
114
150
  // Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
115
151
  const dim = android && disabled ? styles.dim : null;
116
152
  const handlers = {
@@ -118,19 +154,43 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
118
154
  // A menu chip is a button that opens its menu, even when it shows a chosen filter
119
155
  accessibilityRole: filter && !menu ? "checkbox" : "button",
120
156
  accessibilityLabel,
121
- accessibilityState: { disabled, checked: filter && !menu ? selected : undefined, selected: filter && menu && Platform.OS !== "web" ? selected : undefined, expanded },
157
+ accessibilityState: {
158
+ disabled,
159
+ checked: filter && !menu ? selected : undefined,
160
+ // A chosen token says so before the next press removes it
161
+ selected: token ? armed : filter && menu && Platform.OS !== "web" ? selected : undefined,
162
+ expanded,
163
+ },
122
164
  "aria-checked": filter && !menu ? selected : undefined,
165
+ // react-native-web drops `selected` on a button: the web reads a chosen token as pressed
166
+ "aria-pressed": token && Platform.OS === "web" ? armed : undefined,
123
167
  "aria-haspopup": menu ? (menu === true ? "menu" : menu) : undefined,
124
168
  "aria-expanded": menu ? expanded : undefined,
125
169
  disabled,
126
170
  onPress: press,
171
+ // A token: VoiceOver's action and a keyboard's Delete remove it; leaving it lets the selection go
172
+ ...(token
173
+ ? {
174
+ accessibilityActions: [{ name: "delete", label: removeLabel }],
175
+ onAccessibilityAction: (event) => {
176
+ if (event.nativeEvent.actionName === "delete" && !disabled)
177
+ onRemove?.();
178
+ },
179
+ onBlur: () => armed && setArmed(false),
180
+ onKeyDown: (event) => {
181
+ if ((event.nativeEvent.key === "Backspace" || event.nativeEvent.key === "Delete") && !disabled)
182
+ onRemove?.();
183
+ },
184
+ "aria-keyshortcuts": "Delete Backspace",
185
+ }
186
+ : {}),
127
187
  onPressIn: () => setPressed(true),
128
188
  onPressOut: () => setPressed(false),
129
189
  };
130
190
  // An input chip holds its cross beside the chip's own press, never a button inside a button; each takes the
131
191
  // target's full height
132
- if (onRemove) {
133
- 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, { paddingLeft: android ? 4 : 6, paddingRight: android ? 8 : 10 }], children: _jsx(CloseBold, { size: android ? 18 : 14, color: color }) })] }));
192
+ if (cross) {
193
+ 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") }) })] }));
134
194
  }
135
195
  if (!interactive) {
136
196
  return (_jsxs(View, { testID: testID, style: [styles.chip, styles.part, box, dim, style], children: [layer, body] }));
@@ -107,31 +107,45 @@ export function ChoiceDialog({ open, onClose, title, cancelLabel, okLabel, onOk,
107
107
  ]
108
108
  : [{ label: cancelLabel, testID: testID ? `${testID}-cancel` : undefined }], run: run, ids: ids, list: _jsx(View, { ...listProps, children: children }) }) }));
109
109
  }
110
+ /** An iOS alert action's label inset from its capsule's ends. */
111
+ const IOS_ACTION_INSET = 16;
110
112
  function IOSAlert({ theme, title, description, actions, run, ids, layout, children }) {
111
113
  const { width: screen } = useWindowDimensions();
112
114
  const width = Math.min(theme.length("--dialog-alert-width", 320), screen - 32);
113
115
  const radius = theme.length("--dialog-alert-radius", 34);
114
- const inline = layout === "inline" || (layout !== "stacked" && actions.length <= 2);
116
+ const padding = theme.length("--dialog-alert-padding", 16);
117
+ const gap = theme.length("--dialog-alert-action-gap", 8);
118
+ // Two actions stand side by side while each label fits its half on one line; iOS never wraps an alert button's
119
+ // label, so a longer one stacks them at the full width (UIAlertController). Each label is measured on one line
120
+ const [labels, setLabels] = useState([]);
121
+ const half = (width - padding * 2 - gap) / 2 - IOS_ACTION_INSET * 2;
122
+ const fits = actions.every((_, index) => labels[index] == null || labels[index] <= half + 0.5);
123
+ const inline = layout === "inline" || (layout !== "stacked" && actions.length <= 2 && fits);
115
124
  // The cancel action stands first of two side by side, as UIAlertController; a stack keeps the order written, as the
116
125
  // web's alert footer does. Each keeps its place in `actions` as its key, since two actions may share a label
117
126
  const indexed = actions.map((action, index) => ({ action, index }));
118
127
  const cancel = indexed.filter(({ action }) => action.variant === "cancel");
119
128
  const others = indexed.filter(({ action }) => action.variant !== "cancel");
120
- const ordered = inline ? [...cancel, ...others] : indexed;
121
- const gap = theme.length("--dialog-alert-action-gap", 8);
129
+ // Two stacked because their labels do not fit: Cancel last, at the bottom, as UIAlertController stacks them
130
+ const autoStacked = !inline && layout == null && actions.length === 2;
131
+ const ordered = inline ? [...cancel, ...others] : autoStacked ? [...others, ...cancel] : indexed;
122
132
  const type = { fontSize: theme.length("--dialog-mobile-type-size", 17), lineHeight: theme.length("--dialog-mobile-type-leading", 22) };
123
- return (_jsxs(Glass, { radius: radius, elevation: "raised", fillToken: "--dialog-alert-background", style: { width, flexShrink: 1, padding: theme.length("--dialog-alert-padding", 16), gap: 10 }, children: [_jsxs(ScrollView, { style: styles.scroll, contentContainerStyle: { gap: 10 }, bounces: false, children: [_jsxs(View, { style: { paddingTop: 5, paddingHorizontal: 15, paddingBottom: 5.5, gap: 5.67 }, children: [_jsx(Text, { nativeID: ids.title, weight: "semibold", style: [type, { textAlign: description == null ? "center" : "auto" }], accessibilityRole: "header", children: title }), description != null ? (_jsx(Text, { nativeID: ids.description, color: theme.color("--dialog-alert-message-color"), style: { fontSize: 15, lineHeight: 20 }, children: description })) : null] }), children != null ? (
133
+ return (_jsxs(Glass, { radius: radius, elevation: "raised", fillToken: "--dialog-alert-background", style: { width, flexShrink: 1, padding, gap: 10 }, children: [layout == null && actions.length === 2 ? (
134
+ // The labels on one line, unseen, to tell whether two fit side by side
135
+ _jsx(View, { pointerEvents: "none", "aria-hidden": true, style: styles.measure, children: actions.map((action, index) => (_jsx(Text, { weight: action.preferred ? "semibold" : "medium", numberOfLines: 1, style: type, onLayout: (event) => {
136
+ const next = event.nativeEvent.layout.width;
137
+ setLabels((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next })));
138
+ }, children: action.label }, index))) })) : null, _jsxs(ScrollView, { style: styles.scroll, contentContainerStyle: { gap: 10 }, bounces: false, children: [_jsxs(View, { style: { paddingTop: 5, paddingHorizontal: 15, paddingBottom: 5.5, gap: 5.67 }, children: [_jsx(Text, { nativeID: ids.title, weight: "semibold", style: [type, { textAlign: description == null ? "center" : "auto" }], accessibilityRole: "header", children: title }), description != null ? (_jsx(Text, { nativeID: ids.description, color: theme.color("--dialog-alert-message-color"), style: { fontSize: 15, lineHeight: 20 }, children: description })) : null] }), children != null ? (
124
139
  // A field fills the alert as its actions do: the largest control size is the alert's 48 there
125
140
  // (Dialog.module.css sets --control-size-3xl to --dialog-alert-field-height in the alert's body)
126
141
  _jsx(ThemeProvider, { brand: { tokens: { "--control-size-3xl": `${theme.length("--dialog-alert-field-height", 48)}px` } }, children: _jsx(View, { style: { paddingBottom: 10, marginHorizontal: -1 }, children: children }) })) : null] }), ordered.length ? (_jsx(View, { style: [{ gap, marginTop: children != null ? 0 : 4 }, inline ? styles.row : null], children: ordered.map(({ action, index }) => (_jsx(IOSAction, { theme: theme, action: action, run: run, type: type, grow: inline }, index))) })) : null] }));
127
142
  }
128
143
  function IOSAction({ theme, action, run, type, grow }) {
129
- // The preferred action is the accent with a white label, its sheen and edge, as a bar's prominent button
130
- // (Dialog.module.css: an alert's solid footer action takes the --toolbar-prominent tokens); disabled, the phone's
131
- // disabled fill (Button.module.css). A destructive one keeps the alert's fill and its red label
144
+ // The preferred action is the accent with a white label, one flat color with no sheen and no edge, as native draws
145
+ // a preferredAction (iOS 27.2: 0082f7 on every row); disabled, the phone's disabled fill (Button.module.css). A
146
+ // destructive one keeps the alert's fill and its red label
132
147
  const accent = action.preferred && action.variant !== "destructive";
133
148
  const height = theme.length("--dialog-alert-action-height", 48);
134
- const [measured, setMeasured] = useState(height);
135
149
  const fill = accent
136
150
  ? action.disabled
137
151
  ? theme.color("--button-mobile-disabled-background", theme.color("--color-background-disabled"))
@@ -145,29 +159,16 @@ function IOSAction({ theme, action, run, type, grow }) {
145
159
  ? theme.color("--toolbar-prominent-color")
146
160
  : theme.colors.text;
147
161
  const lit = accent && !action.disabled;
148
- const shadow = lit ? theme.token("--toolbar-prominent-shadow") : undefined;
149
- const sheen = lit ? sheenOf(theme, measured) : undefined;
150
- return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!action.disabled }, disabled: action.disabled, onPress: () => run(action), onLayout: lit ? (event) => setMeasured(event.nativeEvent.layout.height) : undefined, testID: action.testID, style: ({ pressed }) => [
162
+ return (_jsx(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!action.disabled }, disabled: action.disabled, onPress: () => run(action), testID: action.testID, style: ({ pressed }) => [
151
163
  styles.iosAction,
152
164
  {
153
165
  minHeight: height,
154
166
  borderRadius: height / 2,
155
167
  backgroundColor: lit && pressed ? theme.color("--toolbar-prominent-background-active") : fill,
156
168
  opacity: pressed && !lit ? 0.7 : 1,
157
- boxShadow: typeof shadow === "string" ? shadow : undefined,
158
169
  },
159
170
  grow ? styles.grow : null,
160
- ], children: [sheen ? _jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { borderRadius: height / 2, backgroundImage: sheen }] }) : null, _jsx(Text, { color: text, weight: action.preferred ? "semibold" : "medium", style: [type, styles.centered], children: action.label })] }));
161
- }
162
- /**
163
- * `--toolbar-prominent-sheen`, lighter along the top and the bottom edge, for a face of a known height: its
164
- * `calc(100% - 8px)` stop in pixels, since React Native's gradients take no calc().
165
- */
166
- function sheenOf(theme, height) {
167
- const value = theme.token("--toolbar-prominent-sheen");
168
- if (typeof value !== "string" || !value.includes("gradient"))
169
- return undefined;
170
- return value.replace(/calc\(\s*100%\s*-\s*([\d.]+)px\s*\)/g, (_, px) => `${Math.max(0, height - Number(px))}px`);
171
+ ], children: _jsx(Text, { color: text, weight: action.preferred ? "semibold" : "medium", style: [type, styles.centered], children: action.label }) }));
171
172
  }
172
173
  function AndroidDialog({ theme, title, description, actions, run, ids, children, list }) {
173
174
  const m = theme.material;
@@ -219,7 +220,8 @@ const styles = StyleSheet.create({
219
220
  row: { flexDirection: "row" },
220
221
  grow: { flex: 1, flexBasis: 0 },
221
222
  centered: { textAlign: "center" },
222
- iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: 16, borderCurve: "continuous" },
223
+ iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: IOS_ACTION_INSET, borderCurve: "continuous" },
224
+ measure: { position: "absolute", top: 0, left: 0, width: 2000, alignItems: "flex-start", opacity: 0 },
223
225
  // Android's alert: 21dp corners (the catalog's); the text 24 in. Measured on the reference's alerts: the title's
224
226
  // baseline 40 under the top, the message's first 33 under it in lines 18.75 apart (16sp Roboto's), its last 59
225
227
  // over the buttons' (Roboto's font padding sets these 2 to 3 lower than the layout's 19, 10 and 20 would)
@@ -361,6 +361,9 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
361
361
  const required = ownRequired ?? floatLabel?.required;
362
362
  const shift = ownShift ?? floatLabel?.shift;
363
363
  const [focused, setFocused] = useState(false);
364
+ // A Tab to the iOS clear button blurs the field on the web: the button stays while it has focus (a press keeps the
365
+ // field's focus, below)
366
+ const [clearing, setClearing] = useState(false);
364
367
  const [own, setOwn] = useState(defaultValue ?? "");
365
368
  const text = value ?? own;
366
369
  const filled = text.length > 0;
@@ -439,7 +442,13 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
439
442
  // Android's label is in the hint color at rest and in the accent while the field has focus, springing between them
440
443
  const labelColor = invalid ? dangerText(theme) : focused ? focusAccent(theme) : look.placeholder;
441
444
  const labelTint = useSpringColor(labelColor, FIELD_SPRING.stiffness, !floating || theme.reducedMotion);
442
- const showClear = !!onClear && filled && !disabled && !readOnly;
445
+ // iOS shows a form field's clear button while it is edited (UITextField's whileEditing), a search field's while it
446
+ // has text; Android while the field has text
447
+ const searchField = rest.inputMode === "search" || barField != null;
448
+ // A value at a row's end has no clear button on iOS, as Settings' and Contacts' rows: only a value that starts its
449
+ // column or stands on its own line under the label takes one
450
+ const valueRight = !startAligned && (inRow || (fillsRow && valueAtEnd));
451
+ const showClear = !!onClear && filled && !disabled && !readOnly && (theme.isAndroid || ((focused || clearing || searchField) && !valueRight));
443
452
  // Android's search fields keep their clear button in place and show it with the text
444
453
  const androidClear = (search || barSearch) && !!onClear && !disabled && !readOnly;
445
454
  // A 24dp icon stands 12 in, the text 12 past it (48 in); otherwise the text is 14 in (the outlined field), 21 in a
@@ -481,7 +490,11 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
481
490
  // round end (Input.module.css), or keeps its box beside an end adornment
482
491
  const clearMargin = theme.isAndroid
483
492
  ? { marginHorizontal: -(look.clearTarget - look.clearSize) / 2 }
484
- : { marginEnd: endAdornment ? theme.length("--input-clear-target-offset", 0) : look.height / 2 - look.clearTarget / 2 - look.gutter };
493
+ : bare
494
+ ? // In a List row the target reaches over and under the row's line, so the row keeps its height, and its circle
495
+ // ends at the row's end inset, as a form row's clear button
496
+ { marginVertical: -(look.clearTarget - look.text.lineHeight) / 2, marginEnd: -(look.clearTarget - look.clearSize) / 2 }
497
+ : { marginEnd: endAdornment ? theme.length("--input-clear-target-offset", 0) : look.height / 2 - look.clearTarget / 2 - look.gutter };
485
498
  // An adornment stands in a View of its own, centered on the field: a Button in it keeps its own `alignSelf`
486
499
  // ("flex-start", for a column) to that View, not to the field's row, where it would rise to the top of a field taller
487
500
  // than itself (an IconButton's 40dp in a 50dp field)
@@ -523,7 +536,7 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
523
536
  theme.font("regular"),
524
537
  // A label floated inside the field (8 to 24) sets the text under it
525
538
  { paddingTop: padding.top, paddingBottom: padding.bottom },
526
- (inRow && !startAligned) || (fillsRow && valueAtEnd && !startAligned) ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
539
+ valueRight ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
527
540
  // A value in a row that the person cannot edit is the secondary label, as the web's phone rows (iOS's
528
541
  // values of a row that only informs)
529
542
  fillsRow && readOnly && !disabled ? { color: theme.colors.labelSecondary } : null,
@@ -536,7 +549,10 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
536
549
  }, onHiddenPress: () => {
537
550
  if (!locked)
538
551
  input.current?.focus();
539
- } })) : showClear ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Clear", onPress: () => {
552
+ } })) : showClear ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Clear", onFocus: () => setClearing(true), onBlur: () => setClearing(false), ...(Platform.OS === "web" ? { onMouseDown: (event) => event.preventDefault() } : null), onPress: () => {
553
+ // As UIKit's clear button, the field keeps editing; first, so a caller's onClear may still move the focus
554
+ if (!theme.isAndroid && !searchField)
555
+ input.current?.focus();
540
556
  if (value === undefined)
541
557
  setOwn("");
542
558
  onChangeText?.("");
@@ -98,6 +98,26 @@ function ToolbarGroup({ children, style, ...rest }) {
98
98
  ], children: children }) }));
99
99
  }
100
100
  ToolbarGroup.displayName = "Toolbar.Group";
101
+ /**
102
+ * A text in the bar that is not a button: a step of a flow, a count, a status. On iOS it stands in a capsule of the
103
+ * bar's glass as a button would, as SwiftUI draws a Text in a toolbar (iOS 27.2 ref-app tb-status: 48pt in a bottom bar,
104
+ * 15pt Semibold, 8pt from its ends); on Android it is the bar's plain text, 14sp Medium. Read as text, not a control.
105
+ */
106
+ function ToolbarLabel({ children, style, ...rest }) {
107
+ const theme = useTheme();
108
+ const item = useContext(BarItemContext);
109
+ const text = (_jsx(Text, { weight: theme.isAndroid ? "medium" : "semibold", tabularNums: true, numberOfLines: 1, style: theme.isAndroid ? { fontSize: 14, lineHeight: 20 } : { fontSize: theme.length("--toolbar-status-font-size", 15), lineHeight: theme.length("--toolbar-status-line-height", 20) }, children: children }));
110
+ if (theme.isAndroid || !item || item.inGroup) {
111
+ return (_jsx(View, { ...rest, style: [styles.slot, styles.label, item ? { minHeight: item.height, paddingHorizontal: theme.isAndroid ? 8 : 0 } : null, style], children: text }));
112
+ }
113
+ return (_jsx(Glass, { ...rest, elevation: item.raised ? "raised" : "regular", radius: item.height / 2, style: [
114
+ styles.slot,
115
+ styles.label,
116
+ { height: item.height, minWidth: item.height, paddingHorizontal: theme.length("--toolbar-status-padding", 8) },
117
+ style,
118
+ ], children: text }));
119
+ }
120
+ ToolbarLabel.displayName = "Toolbar.Label";
101
121
  /** The title of the bar, and an optional subtitle under it. Announced as a header. */
102
122
  function ToolbarTitle(_) {
103
123
  // Drawn by Toolbar, which knows the title style
@@ -386,11 +406,13 @@ export const Toolbar = Object.assign(ToolbarRoot, {
386
406
  Group: ToolbarGroup,
387
407
  Trailing: ToolbarTrailing,
388
408
  Row: ToolbarRow,
409
+ Label: ToolbarLabel,
389
410
  });
390
411
  const styles = StyleSheet.create({
391
412
  titleImage: { flexDirection: "row", alignItems: "center" },
392
413
  slot: { flexDirection: "row", alignItems: "center" },
393
414
  trailing: { justifyContent: "flex-end" },
415
+ label: { justifyContent: "center" },
394
416
  content: { justifyContent: "center" },
395
417
  // A filling content stretches its control across (a search field, a block button), as a column would
396
418
  fill: { flex: 1, flexDirection: "column", alignItems: "stretch" },
@@ -1,10 +1,20 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { type StyleProp, type ViewStyle } from "react-native";
3
3
  export type BottomActionsProps = {
4
- /** The screen's main action, a Button, and an optional second Button under it (a ghost "Not now"). */
4
+ /**
5
+ * The screen's main action, a Button, and an optional second Button under it ("Not now", "Skip"). A second Button
6
+ * with no `variant` of its own takes the platform's: on iOS 26 a glass capsule of the same size, as Apple's
7
+ * step-by-step sheets set "Skip"; on Android a ghost button.
8
+ */
5
9
  children: ReactNode;
6
- /** Puts the actions over the content (a scroll view under them); off, they take their room at the end of the screen. @default false */
10
+ /**
11
+ * Puts the actions over the content (a scroll view under them), over a soft edge as a bottom Toolbar draws: on iOS
12
+ * the screen's color fading in over 27pt above the actions, over a light blur; on Android the screen's color fading
13
+ * in. Off, they take their room at the end of the screen. @default false
14
+ */
7
15
  floating?: boolean;
16
+ /** The color the floating edge fades into: the screen's (a grouped screen's gray). @default the theme's background */
17
+ canvasColor?: string;
8
18
  testID?: string;
9
19
  style?: StyleProp<ViewStyle>;
10
20
  };
@@ -15,4 +25,4 @@ export type BottomActionsProps = {
15
25
  * action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
16
26
  * 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
17
27
  */
18
- export declare function BottomActions({ children, floating, testID, style }: BottomActionsProps): import("react").JSX.Element;
28
+ export declare function BottomActions({ children, floating, canvasColor, testID, style }: BottomActionsProps): import("react").JSX.Element;
@@ -28,19 +28,21 @@ export type ChipProps = {
28
28
  * either. @default "tag"
29
29
  */
30
30
  appearance?: "tag" | "glass";
31
- /** An input chip: a cross at the end that calls this. */
31
+ /** An input chip: called when the reader takes the value back (a cross on Android; see `removeStyle` on iOS). */
32
32
  onRemove?: () => void;
33
- /** @default "Remove" */
33
+ /** The remove action's name, for screen readers. @default "Remove" */
34
34
  removeLabel?: string;
35
+ /**
36
+ * How an input chip is removed on iOS. `token`, as Apple's tokens (search tokens in Mail, Photos and Files; Mail's
37
+ * recipients): no cross; a press selects the chip in the accent (and lets the last chosen token go) and a second press, or Delete on a
38
+ * keyboard on the web, removes
39
+ * it; VoiceOver offers `removeLabel` as an action. `button`: a cross after the label in the field's clear button
40
+ * (xmark.circle.fill, 17pt in the tertiary label, a 44pt target). Android keeps Material's 18dp cross with either.
41
+ * @default "token"
42
+ */
43
+ removeStyle?: "token" | "button";
35
44
  disabled?: boolean;
36
45
  testID?: string;
37
46
  style?: StyleProp<ViewStyle>;
38
47
  };
39
- /**
40
- * A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
41
- * selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
42
- * an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
43
- * one in the app's accent (its tint) with a white label. The web has
44
- * no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
45
- */
46
- export declare function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance, onRemove, removeLabel, disabled, testID, style, }: ChipProps): import("react").JSX.Element;
48
+ export declare function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance, onRemove, removeLabel, removeStyle, disabled, testID, style, }: ChipProps): import("react").JSX.Element;
@@ -59,6 +59,19 @@ declare function ToolbarGroup({ children, style, ...rest }: ViewProps): import("
59
59
  declare namespace ToolbarGroup {
60
60
  var displayName: string;
61
61
  }
62
+ export type ToolbarLabelProps = ViewProps & {
63
+ /** The text: a step of a flow ("3 of 10"), a count, a status. Its digits keep one width as it changes. */
64
+ children: ReactNode;
65
+ };
66
+ /**
67
+ * A text in the bar that is not a button: a step of a flow, a count, a status. On iOS it stands in a capsule of the
68
+ * bar's glass as a button would, as SwiftUI draws a Text in a toolbar (iOS 27.2 ref-app tb-status: 48pt in a bottom bar,
69
+ * 15pt Semibold, 8pt from its ends); on Android it is the bar's plain text, 14sp Medium. Read as text, not a control.
70
+ */
71
+ declare function ToolbarLabel({ children, style, ...rest }: ToolbarLabelProps): import("react").JSX.Element;
72
+ declare namespace ToolbarLabel {
73
+ var displayName: string;
74
+ }
62
75
  export type ToolbarTitleProps = {
63
76
  /** The title's text. With `image` it may be left out. */
64
77
  children?: ReactNode;
@@ -100,5 +113,6 @@ export declare const Toolbar: typeof ToolbarRoot & {
100
113
  Group: typeof ToolbarGroup;
101
114
  Trailing: typeof ToolbarTrailing;
102
115
  Row: typeof ToolbarRow;
116
+ Label: typeof ToolbarLabel;
103
117
  };
104
118
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/react-native",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Plex UI components for React Native and Expo: iOS 26 and Material 3, on the shared @plexui/styles tokens",
5
5
  "license": "MIT",
6
6
  "homepage": "https://plexui.com",
@@ -1,14 +1,26 @@
1
1
  import { Children, cloneElement, isValidElement, type ReactElement, type ReactNode } from "react"
2
2
  import { StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context"
4
+ import { ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, SoftBottomEdge } from "../../internal/BarBackdrop"
5
+ import { withAlpha } from "../../theme/material"
4
6
  import { useTheme } from "../../theme/ThemeProvider"
5
7
  import { Button, type ButtonProps } from "../Button/Button"
6
8
 
7
9
  export type BottomActionsProps = {
8
- /** The screen's main action, a Button, and an optional second Button under it (a ghost "Not now"). */
10
+ /**
11
+ * The screen's main action, a Button, and an optional second Button under it ("Not now", "Skip"). A second Button
12
+ * with no `variant` of its own takes the platform's: on iOS 26 a glass capsule of the same size, as Apple's
13
+ * step-by-step sheets set "Skip"; on Android a ghost button.
14
+ */
9
15
  children: ReactNode
10
- /** Puts the actions over the content (a scroll view under them); off, they take their room at the end of the screen. @default false */
16
+ /**
17
+ * Puts the actions over the content (a scroll view under them), over a soft edge as a bottom Toolbar draws: on iOS
18
+ * the screen's color fading in over 27pt above the actions, over a light blur; on Android the screen's color fading
19
+ * in. Off, they take their room at the end of the screen. @default false
20
+ */
11
21
  floating?: boolean
22
+ /** The color the floating edge fades into: the screen's (a grouped screen's gray). @default the theme's background */
23
+ canvasColor?: string
12
24
  testID?: string
13
25
  style?: StyleProp<ViewStyle>
14
26
  }
@@ -20,7 +32,7 @@ export type BottomActionsProps = {
20
32
  * action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
21
33
  * 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
22
34
  */
23
- export function BottomActions({ children, floating = false, testID, style }: BottomActionsProps) {
35
+ export function BottomActions({ children, floating = false, canvasColor, testID, style }: BottomActionsProps) {
24
36
  const theme = useTheme()
25
37
  const insets = useSafeAreaInsets()
26
38
  const android = theme.isAndroid
@@ -28,27 +40,44 @@ export function BottomActions({ children, floating = false, testID, style }: Bot
28
40
  // iOS: 2pt over the safe area (34 on a Face ID iPhone); a phone with a home button has none, so 16 there
29
41
  const bottom = android ? Math.max(insets.bottom, 0) + 16 : insets.bottom > 0 ? insets.bottom + 2 : 16
30
42
  const height = android ? 48 : 52
31
- const actions = Children.toArray(children).map((child) =>
32
- isValidElement(child) && child.type === Button
33
- ? cloneElement(child as ReactElement<ButtonProps>, {
34
- block: (child.props as ButtonProps).block ?? true,
35
- size: (child.props as ButtonProps).size ?? "3xl",
36
- style: [{ minHeight: height, borderRadius: height / 2 }, (child.props as ButtonProps).style],
37
- })
38
- : child,
39
- )
43
+ const canvas = canvasColor ?? theme.colors.background
44
+ const paddingTop = 8
45
+ const actions = Children.toArray(children).map((child, index) => {
46
+ if (!isValidElement(child) || child.type !== Button) return child
47
+ const props = child.props as ButtonProps
48
+ // The second action: iOS 26's glass capsule of the main one's size, Android's ghost button
49
+ const second =
50
+ index > 0 && props.variant === undefined
51
+ ? android
52
+ ? { variant: "ghost" as const, color: props.color ?? ("secondary" as const) }
53
+ : { variant: "soft" as const, color: props.color ?? ("secondary" as const), mobileMaterial: props.mobileMaterial ?? ("glass" as const) }
54
+ : null
55
+ return cloneElement(child as ReactElement<ButtonProps>, {
56
+ ...second,
57
+ block: props.block ?? true,
58
+ size: props.size ?? "3xl",
59
+ style: [{ minHeight: height, borderRadius: height / 2 }, props.style],
60
+ })
61
+ })
40
62
  return (
41
63
  <View
42
64
  testID={testID}
43
65
  pointerEvents="box-none"
44
- style={[styles.bar, { paddingHorizontal: side, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style]}
66
+ style={[styles.bar, { paddingHorizontal: side, paddingTop, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style]}
45
67
  >
68
+ {floating ? (
69
+ android ? (
70
+ <SoftBottomEdge fill={withAlpha(canvas, ANDROID_FADE_ALPHA)} top={paddingTop - 13 + 60} tail={60} blur={0} stops={ANDROID_FADE_STOPS} />
71
+ ) : (
72
+ <SoftBottomEdge fill={canvas} top={paddingTop} tail={27} blur={theme.length("--toolbar-edge-blur-small", 3)} />
73
+ )
74
+ ) : null}
46
75
  {actions}
47
76
  </View>
48
77
  )
49
78
  }
50
79
 
51
80
  const styles = StyleSheet.create({
52
- bar: { alignSelf: "stretch", paddingTop: 8 },
81
+ bar: { alignSelf: "stretch" },
53
82
  floating: { position: "absolute", left: 0, right: 0, bottom: 0 },
54
83
  })
@@ -2,6 +2,7 @@ import { useEffect, useState, type ReactNode } from "react"
2
2
  import { Animated, Easing, Platform, Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
3
  import ChevronDownSm from "../../icons/plex/ChevronDownSm"
4
4
  import CloseBold from "../../icons/plex/CloseBold"
5
+ import XCircleFilled from "../../icons/plex/XCircleFilled"
5
6
  import { spaceToggles } from "../../internal/a11y"
6
7
  import { Glass } from "../../internal/Glass"
7
8
  import { withAlpha } from "../../theme/material"
@@ -38,10 +39,19 @@ export type ChipProps = {
38
39
  * either. @default "tag"
39
40
  */
40
41
  appearance?: "tag" | "glass"
41
- /** An input chip: a cross at the end that calls this. */
42
+ /** An input chip: called when the reader takes the value back (a cross on Android; see `removeStyle` on iOS). */
42
43
  onRemove?: () => void
43
- /** @default "Remove" */
44
+ /** The remove action's name, for screen readers. @default "Remove" */
44
45
  removeLabel?: string
46
+ /**
47
+ * How an input chip is removed on iOS. `token`, as Apple's tokens (search tokens in Mail, Photos and Files; Mail's
48
+ * recipients): no cross; a press selects the chip in the accent (and lets the last chosen token go) and a second press, or Delete on a
49
+ * keyboard on the web, removes
50
+ * it; VoiceOver offers `removeLabel` as an action. `button`: a cross after the label in the field's clear button
51
+ * (xmark.circle.fill, 17pt in the tertiary label, a 44pt target). Android keeps Material's 18dp cross with either.
52
+ * @default "token"
53
+ */
54
+ removeStyle?: "token" | "button"
45
55
  disabled?: boolean
46
56
  testID?: string
47
57
  style?: StyleProp<ViewStyle>
@@ -54,6 +64,9 @@ export type ChipProps = {
54
64
  * one in the app's accent (its tint) with a white label. The web has
55
65
  * no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
56
66
  */
67
+ /** The chosen token's way to let go, so that choosing another lets it go */
68
+ let disarmToken: (() => void) | null = null
69
+
57
70
  export function Chip({
58
71
  children,
59
72
  selected: selectedProp,
@@ -68,16 +81,47 @@ export function Chip({
68
81
  appearance = "tag",
69
82
  onRemove,
70
83
  removeLabel = "Remove",
84
+ removeStyle = "token",
71
85
  disabled = false,
72
86
  testID,
73
87
  style,
74
88
  }: ChipProps) {
75
89
  const theme = useTheme()
76
90
  const [own, setOwn] = useState(defaultSelected ?? false)
77
- const filter = selectedProp !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined
78
- const selected = filter ? (selectedProp ?? own) : false
91
+ // iOS's token: an input chip with no cross, chosen by a first press and removed by a second (or by Delete); it is
92
+ // never a filter as well
93
+ const token = !theme.isAndroid && onRemove != null && removeStyle === "token"
94
+ const filter = !token && (selectedProp !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined)
95
+ const [armed, setArmedState] = useState(false)
96
+ // One token is chosen at a time, as in a token field: choosing one lets the last one go (a tap on a native view
97
+ // never moves focus, so a blur alone cannot)
98
+ const [disarm] = useState(() => () => setArmedState(false))
99
+ const setArmed = (on: boolean) => {
100
+ if (on) {
101
+ if (disarmToken !== disarm) disarmToken?.()
102
+ disarmToken = disarm
103
+ } else if (disarmToken === disarm) {
104
+ disarmToken = null
105
+ }
106
+ setArmedState(on)
107
+ }
108
+ useEffect(
109
+ () => () => {
110
+ if (disarmToken === disarm) disarmToken = null
111
+ },
112
+ [disarm],
113
+ )
114
+ const selected = filter ? (selectedProp ?? own) : token && armed
79
115
  const press = () => {
80
116
  if (disabled) return
117
+ if (token) {
118
+ if (armed) {
119
+ setArmed(false)
120
+ onRemove?.()
121
+ return
122
+ }
123
+ setArmed(true)
124
+ }
81
125
  if (filter) {
82
126
  if (selectedProp === undefined) setOwn(!selected)
83
127
  onSelectedChange?.(!selected)
@@ -137,6 +181,9 @@ export function Chip({
137
181
  const leadingColor = color
138
182
  // A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
139
183
  const symbolOnly = leading != null && (children == null || children === "") && trailing == null && !onRemove
184
+ // An input chip's cross stands in a target of its own after the chip's press: on iOS the field's clear button
185
+ const cross = onRemove != null && !token
186
+ const clearSize = 17 * 1.2
140
187
  // The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
141
188
  // HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
142
189
  const target = android ? 48 : 44
@@ -164,7 +211,7 @@ export function Chip({
164
211
  // Android: 12 at the sides, 8 before an icon and 6 after it
165
212
  paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
166
213
  // Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
167
- paddingRight: symbolOnly ? (height - iconSize) / 2 : onRemove ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
214
+ paddingRight: symbolOnly ? (height - iconSize) / 2 : cross ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
168
215
  gap: 6,
169
216
  opacity: !android && pressed ? 0.7 : 1,
170
217
  }
@@ -182,12 +229,13 @@ export function Chip({
182
229
  // Text's own face and tracking, in a color that blends
183
230
  <Animated.Text
184
231
  numberOfLines={1}
232
+ selectable={false}
185
233
  style={[textStyle(theme, { weight: "regular" }), { fontSize: label.fontSize, lineHeight: label.lineHeight, letterSpacing: theme.tracking(label.fontSize), color: labelPaint }]}
186
234
  >
187
235
  {children}
188
236
  </Animated.Text>
189
237
  ) : (
190
- <Text color={color} weight="regular" numberOfLines={1} style={{ fontSize: label.fontSize, lineHeight: label.lineHeight }}>
238
+ <Text color={color} weight="regular" numberOfLines={1} selectable={false} style={{ fontSize: label.fontSize, lineHeight: label.lineHeight }}>
191
239
  {children}
192
240
  </Text>
193
241
  )}
@@ -200,7 +248,7 @@ export function Chip({
200
248
  ) : null}
201
249
  </>
202
250
  )
203
- const interactive = filter || !!onPress
251
+ const interactive = filter || !!onPress || token
204
252
  // Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
205
253
  const dim = android && disabled ? styles.dim : null
206
254
  const handlers = {
@@ -208,18 +256,40 @@ export function Chip({
208
256
  // A menu chip is a button that opens its menu, even when it shows a chosen filter
209
257
  accessibilityRole: filter && !menu ? ("checkbox" as const) : ("button" as const),
210
258
  accessibilityLabel,
211
- accessibilityState: { disabled, checked: filter && !menu ? selected : undefined, selected: filter && menu && Platform.OS !== "web" ? selected : undefined, expanded },
259
+ accessibilityState: {
260
+ disabled,
261
+ checked: filter && !menu ? selected : undefined,
262
+ // A chosen token says so before the next press removes it
263
+ selected: token ? armed : filter && menu && Platform.OS !== "web" ? selected : undefined,
264
+ expanded,
265
+ },
212
266
  "aria-checked": filter && !menu ? selected : undefined,
267
+ // react-native-web drops `selected` on a button: the web reads a chosen token as pressed
268
+ "aria-pressed": token && Platform.OS === "web" ? armed : undefined,
213
269
  "aria-haspopup": menu ? (menu === true ? ("menu" as const) : menu) : undefined,
214
270
  "aria-expanded": menu ? expanded : undefined,
215
271
  disabled,
216
272
  onPress: press,
273
+ // A token: VoiceOver's action and a keyboard's Delete remove it; leaving it lets the selection go
274
+ ...(token
275
+ ? {
276
+ accessibilityActions: [{ name: "delete", label: removeLabel }],
277
+ onAccessibilityAction: (event: { nativeEvent: { actionName: string } }) => {
278
+ if (event.nativeEvent.actionName === "delete" && !disabled) onRemove?.()
279
+ },
280
+ onBlur: () => armed && setArmed(false),
281
+ onKeyDown: (event: { nativeEvent: { key?: string } }) => {
282
+ if ((event.nativeEvent.key === "Backspace" || event.nativeEvent.key === "Delete") && !disabled) onRemove?.()
283
+ },
284
+ "aria-keyshortcuts": "Delete Backspace",
285
+ }
286
+ : {}),
217
287
  onPressIn: () => setPressed(true),
218
288
  onPressOut: () => setPressed(false),
219
289
  }
220
290
  // An input chip holds its cross beside the chip's own press, never a button inside a button; each takes the
221
291
  // target's full height
222
- if (onRemove) {
292
+ if (cross) {
223
293
  return (
224
294
  <View testID={testID} style={[styles.chip, { minHeight: target }, dim, style]}>
225
295
  {layer}
@@ -235,9 +305,9 @@ export function Chip({
235
305
  accessibilityLabel={removeLabel}
236
306
  disabled={disabled}
237
307
  onPress={onRemove}
238
- style={[styles.part, { paddingLeft: android ? 4 : 6, paddingRight: android ? 8 : 10 }]}
308
+ style={[styles.part, android ? { paddingLeft: 4, paddingRight: 8 } : { width: 44, justifyContent: "center" }]}
239
309
  >
240
- <CloseBold size={android ? 18 : 14} color={color} />
310
+ {android ? <CloseBold size={18} color={color} /> : <XCircleFilled size={clearSize} color={theme.color("--mobile-label-tertiary")} />}
241
311
  </Pressable>
242
312
  </View>
243
313
  )
@@ -251,21 +251,51 @@ type AndroidPanelProps = Omit<PanelProps, "title"> & {
251
251
  list?: ReactNode
252
252
  }
253
253
 
254
+ /** An iOS alert action's label inset from its capsule's ends. */
255
+ const IOS_ACTION_INSET = 16
256
+
254
257
  function IOSAlert({ theme, title, description, actions, run, ids, layout, children }: PanelProps & { layout?: "inline" | "stacked" }) {
255
258
  const { width: screen } = useWindowDimensions()
256
259
  const width = Math.min(theme.length("--dialog-alert-width", 320), screen - 32)
257
260
  const radius = theme.length("--dialog-alert-radius", 34)
258
- const inline = layout === "inline" || (layout !== "stacked" && actions.length <= 2)
261
+ const padding = theme.length("--dialog-alert-padding", 16)
262
+ const gap = theme.length("--dialog-alert-action-gap", 8)
263
+ // Two actions stand side by side while each label fits its half on one line; iOS never wraps an alert button's
264
+ // label, so a longer one stacks them at the full width (UIAlertController). Each label is measured on one line
265
+ const [labels, setLabels] = useState<number[]>([])
266
+ const half = (width - padding * 2 - gap) / 2 - IOS_ACTION_INSET * 2
267
+ const fits = actions.every((_, index) => labels[index] == null || labels[index] <= half + 0.5)
268
+ const inline = layout === "inline" || (layout !== "stacked" && actions.length <= 2 && fits)
259
269
  // The cancel action stands first of two side by side, as UIAlertController; a stack keeps the order written, as the
260
270
  // web's alert footer does. Each keeps its place in `actions` as its key, since two actions may share a label
261
271
  const indexed = actions.map((action, index) => ({ action, index }))
262
272
  const cancel = indexed.filter(({ action }) => action.variant === "cancel")
263
273
  const others = indexed.filter(({ action }) => action.variant !== "cancel")
264
- const ordered = inline ? [...cancel, ...others] : indexed
265
- const gap = theme.length("--dialog-alert-action-gap", 8)
274
+ // Two stacked because their labels do not fit: Cancel last, at the bottom, as UIAlertController stacks them
275
+ const autoStacked = !inline && layout == null && actions.length === 2
276
+ const ordered = inline ? [...cancel, ...others] : autoStacked ? [...others, ...cancel] : indexed
266
277
  const type = { fontSize: theme.length("--dialog-mobile-type-size", 17), lineHeight: theme.length("--dialog-mobile-type-leading", 22) }
267
278
  return (
268
- <Glass radius={radius} elevation="raised" fillToken="--dialog-alert-background" style={{ width, flexShrink: 1, padding: theme.length("--dialog-alert-padding", 16), gap: 10 }}>
279
+ <Glass radius={radius} elevation="raised" fillToken="--dialog-alert-background" style={{ width, flexShrink: 1, padding, gap: 10 }}>
280
+ {layout == null && actions.length === 2 ? (
281
+ // The labels on one line, unseen, to tell whether two fit side by side
282
+ <View pointerEvents="none" aria-hidden style={styles.measure}>
283
+ {actions.map((action, index) => (
284
+ <Text
285
+ key={index}
286
+ weight={action.preferred ? "semibold" : "medium"}
287
+ numberOfLines={1}
288
+ style={type}
289
+ onLayout={(event) => {
290
+ const next = event.nativeEvent.layout.width
291
+ setLabels((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next })))
292
+ }}
293
+ >
294
+ {action.label}
295
+ </Text>
296
+ ))}
297
+ </View>
298
+ ) : null}
269
299
  <ScrollView style={styles.scroll} contentContainerStyle={{ gap: 10 }} bounces={false}>
270
300
  {/* The text 31 from the sides: 16 of padding and 15 of the header's own */}
271
301
  <View style={{ paddingTop: 5, paddingHorizontal: 15, paddingBottom: 5.5, gap: 5.67 }}>
@@ -298,12 +328,11 @@ function IOSAlert({ theme, title, description, actions, run, ids, layout, childr
298
328
  }
299
329
 
300
330
  function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: DialogAction; run: (action: DialogAction) => void; type: { fontSize: number; lineHeight: number }; grow: boolean }) {
301
- // The preferred action is the accent with a white label, its sheen and edge, as a bar's prominent button
302
- // (Dialog.module.css: an alert's solid footer action takes the --toolbar-prominent tokens); disabled, the phone's
303
- // disabled fill (Button.module.css). A destructive one keeps the alert's fill and its red label
331
+ // The preferred action is the accent with a white label, one flat color with no sheen and no edge, as native draws
332
+ // a preferredAction (iOS 27.2: 0082f7 on every row); disabled, the phone's disabled fill (Button.module.css). A
333
+ // destructive one keeps the alert's fill and its red label
304
334
  const accent = action.preferred && action.variant !== "destructive"
305
335
  const height = theme.length("--dialog-alert-action-height", 48)
306
- const [measured, setMeasured] = useState(height)
307
336
  const fill = accent
308
337
  ? action.disabled
309
338
  ? theme.color("--button-mobile-disabled-background", theme.color("--color-background-disabled"))
@@ -317,15 +346,12 @@ function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: D
317
346
  ? theme.color("--toolbar-prominent-color")
318
347
  : theme.colors.text
319
348
  const lit = accent && !action.disabled
320
- const shadow = lit ? theme.token("--toolbar-prominent-shadow") : undefined
321
- const sheen = lit ? sheenOf(theme, measured) : undefined
322
349
  return (
323
350
  <Pressable
324
351
  accessibilityRole="button"
325
352
  accessibilityState={{ disabled: !!action.disabled }}
326
353
  disabled={action.disabled}
327
354
  onPress={() => run(action)}
328
- onLayout={lit ? (event) => setMeasured(event.nativeEvent.layout.height) : undefined}
329
355
  testID={action.testID}
330
356
  style={({ pressed }) => [
331
357
  styles.iosAction,
@@ -334,12 +360,10 @@ function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: D
334
360
  borderRadius: height / 2,
335
361
  backgroundColor: lit && pressed ? theme.color("--toolbar-prominent-background-active") : fill,
336
362
  opacity: pressed && !lit ? 0.7 : 1,
337
- boxShadow: typeof shadow === "string" ? shadow : undefined,
338
363
  },
339
364
  grow ? styles.grow : null,
340
365
  ]}
341
366
  >
342
- {sheen ? <View pointerEvents="none" style={[StyleSheet.absoluteFill, { borderRadius: height / 2, backgroundImage: sheen }]} /> : null}
343
367
  <Text color={text} weight={action.preferred ? "semibold" : "medium"} style={[type, styles.centered]}>
344
368
  {action.label}
345
369
  </Text>
@@ -347,16 +371,6 @@ function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: D
347
371
  )
348
372
  }
349
373
 
350
- /**
351
- * `--toolbar-prominent-sheen`, lighter along the top and the bottom edge, for a face of a known height: its
352
- * `calc(100% - 8px)` stop in pixels, since React Native's gradients take no calc().
353
- */
354
- function sheenOf(theme: Theme, height: number) {
355
- const value = theme.token("--toolbar-prominent-sheen")
356
- if (typeof value !== "string" || !value.includes("gradient")) return undefined
357
- return value.replace(/calc\(\s*100%\s*-\s*([\d.]+)px\s*\)/g, (_, px: string) => `${Math.max(0, height - Number(px))}px`)
358
- }
359
-
360
374
  function AndroidDialog({ theme, title, description, actions, run, ids, children, list }: AndroidPanelProps) {
361
375
  const m = theme.material
362
376
  const { width: screen } = useWindowDimensions()
@@ -469,7 +483,8 @@ const styles = StyleSheet.create({
469
483
  row: { flexDirection: "row" },
470
484
  grow: { flex: 1, flexBasis: 0 },
471
485
  centered: { textAlign: "center" },
472
- iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: 16, borderCurve: "continuous" },
486
+ iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: IOS_ACTION_INSET, borderCurve: "continuous" },
487
+ measure: { position: "absolute", top: 0, left: 0, width: 2000, alignItems: "flex-start", opacity: 0 },
473
488
  // Android's alert: 21dp corners (the catalog's); the text 24 in. Measured on the reference's alerts: the title's
474
489
  // baseline 40 under the top, the message's first 33 under it in lines 18.75 apart (16sp Roboto's), its last 59
475
490
  // over the buttons' (Roboto's font padding sets these 2 to 3 lower than the layout's 19, 10 and 20 would)
@@ -578,6 +578,9 @@ export function InputField({
578
578
  const required = ownRequired ?? floatLabel?.required
579
579
  const shift = ownShift ?? floatLabel?.shift
580
580
  const [focused, setFocused] = useState(false)
581
+ // A Tab to the iOS clear button blurs the field on the web: the button stays while it has focus (a press keeps the
582
+ // field's focus, below)
583
+ const [clearing, setClearing] = useState(false)
581
584
  const [own, setOwn] = useState(defaultValue ?? "")
582
585
  const text = value ?? own
583
586
  const filled = text.length > 0
@@ -662,7 +665,14 @@ export function InputField({
662
665
  // Android's label is in the hint color at rest and in the accent while the field has focus, springing between them
663
666
  const labelColor = invalid ? dangerText(theme) : focused ? focusAccent(theme) : look.placeholder
664
667
  const labelTint = useSpringColor(labelColor, FIELD_SPRING.stiffness, !floating || theme.reducedMotion)
665
- const showClear = !!onClear && filled && !disabled && !readOnly
668
+ // iOS shows a form field's clear button while it is edited (UITextField's whileEditing), a search field's while it
669
+ // has text; Android while the field has text
670
+ const searchField = rest.inputMode === "search" || barField != null
671
+ // A value at a row's end has no clear button on iOS, as Settings' and Contacts' rows: only a value that starts its
672
+ // column or stands on its own line under the label takes one
673
+ const valueRight = !startAligned && (inRow || (fillsRow && valueAtEnd))
674
+ const showClear =
675
+ !!onClear && filled && !disabled && !readOnly && (theme.isAndroid || ((focused || clearing || searchField) && !valueRight))
666
676
  // Android's search fields keep their clear button in place and show it with the text
667
677
  const androidClear = (search || barSearch) && !!onClear && !disabled && !readOnly
668
678
  // A 24dp icon stands 12 in, the text 12 past it (48 in); otherwise the text is 14 in (the outlined field), 21 in a
@@ -704,7 +714,11 @@ export function InputField({
704
714
  // round end (Input.module.css), or keeps its box beside an end adornment
705
715
  const clearMargin: ViewStyle = theme.isAndroid
706
716
  ? { marginHorizontal: -(look.clearTarget - look.clearSize) / 2 }
707
- : { marginEnd: endAdornment ? theme.length("--input-clear-target-offset", 0) : look.height / 2 - look.clearTarget / 2 - look.gutter }
717
+ : bare
718
+ ? // In a List row the target reaches over and under the row's line, so the row keeps its height, and its circle
719
+ // ends at the row's end inset, as a form row's clear button
720
+ { marginVertical: -(look.clearTarget - look.text.lineHeight) / 2, marginEnd: -(look.clearTarget - look.clearSize) / 2 }
721
+ : { marginEnd: endAdornment ? theme.length("--input-clear-target-offset", 0) : look.height / 2 - look.clearTarget / 2 - look.gutter }
708
722
  // An adornment stands in a View of its own, centered on the field: a Button in it keeps its own `alignSelf`
709
723
  // ("flex-start", for a column) to that View, not to the field's row, where it would rise to the top of a field taller
710
724
  // than itself (an IconButton's 40dp in a 50dp field)
@@ -824,7 +838,7 @@ export function InputField({
824
838
  theme.font("regular"),
825
839
  // A label floated inside the field (8 to 24) sets the text under it
826
840
  { paddingTop: padding.top, paddingBottom: padding.bottom },
827
- (inRow && !startAligned) || (fillsRow && valueAtEnd && !startAligned) ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
841
+ valueRight ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
828
842
  // A value in a row that the person cannot edit is the secondary label, as the web's phone rows (iOS's
829
843
  // values of a row that only informs)
830
844
  fillsRow && readOnly && !disabled ? { color: theme.colors.labelSecondary } : null,
@@ -852,7 +866,13 @@ export function InputField({
852
866
  <Pressable
853
867
  accessibilityRole="button"
854
868
  accessibilityLabel="Clear"
869
+ onFocus={() => setClearing(true)}
870
+ onBlur={() => setClearing(false)}
871
+ // On the web a press would blur the field before it lands and take the button away: the field keeps focus
872
+ {...(Platform.OS === "web" ? ({ onMouseDown: (event: { preventDefault: () => void }) => event.preventDefault() } as object) : null)}
855
873
  onPress={() => {
874
+ // As UIKit's clear button, the field keeps editing; first, so a caller's onClear may still move the focus
875
+ if (!theme.isAndroid && !searchField) input.current?.focus()
856
876
  if (value === undefined) setOwn("")
857
877
  onChangeText?.("")
858
878
  onClear()
@@ -201,6 +201,54 @@ function ToolbarGroup({ children, style, ...rest }: ViewProps) {
201
201
  }
202
202
  ToolbarGroup.displayName = "Toolbar.Group"
203
203
 
204
+ export type ToolbarLabelProps = ViewProps & {
205
+ /** The text: a step of a flow ("3 of 10"), a count, a status. Its digits keep one width as it changes. */
206
+ children: ReactNode
207
+ }
208
+
209
+ /**
210
+ * A text in the bar that is not a button: a step of a flow, a count, a status. On iOS it stands in a capsule of the
211
+ * bar's glass as a button would, as SwiftUI draws a Text in a toolbar (iOS 27.2 ref-app tb-status: 48pt in a bottom bar,
212
+ * 15pt Semibold, 8pt from its ends); on Android it is the bar's plain text, 14sp Medium. Read as text, not a control.
213
+ */
214
+ function ToolbarLabel({ children, style, ...rest }: ToolbarLabelProps) {
215
+ const theme = useTheme()
216
+ const item = useContext(BarItemContext)
217
+ const text = (
218
+ <Text
219
+ weight={theme.isAndroid ? "medium" : "semibold"}
220
+ tabularNums
221
+ numberOfLines={1}
222
+ style={theme.isAndroid ? { fontSize: 14, lineHeight: 20 } : { fontSize: theme.length("--toolbar-status-font-size", 15), lineHeight: theme.length("--toolbar-status-line-height", 20) }}
223
+ >
224
+ {children}
225
+ </Text>
226
+ )
227
+ if (theme.isAndroid || !item || item.inGroup) {
228
+ return (
229
+ <View {...rest} style={[styles.slot, styles.label, item ? { minHeight: item.height, paddingHorizontal: theme.isAndroid ? 8 : 0 } : null, style]}>
230
+ {text}
231
+ </View>
232
+ )
233
+ }
234
+ return (
235
+ <Glass
236
+ {...rest}
237
+ elevation={item.raised ? "raised" : "regular"}
238
+ radius={item.height / 2}
239
+ style={[
240
+ styles.slot,
241
+ styles.label,
242
+ { height: item.height, minWidth: item.height, paddingHorizontal: theme.length("--toolbar-status-padding", 8) },
243
+ style,
244
+ ]}
245
+ >
246
+ {text}
247
+ </Glass>
248
+ )
249
+ }
250
+ ToolbarLabel.displayName = "Toolbar.Label"
251
+
204
252
  export type ToolbarTitleProps = {
205
253
  /** The title's text. With `image` it may be left out. */
206
254
  children?: ReactNode
@@ -682,12 +730,14 @@ export const Toolbar = Object.assign(ToolbarRoot, {
682
730
  Group: ToolbarGroup,
683
731
  Trailing: ToolbarTrailing,
684
732
  Row: ToolbarRow,
733
+ Label: ToolbarLabel,
685
734
  })
686
735
 
687
736
  const styles = StyleSheet.create({
688
737
  titleImage: { flexDirection: "row", alignItems: "center" },
689
738
  slot: { flexDirection: "row", alignItems: "center" },
690
739
  trailing: { justifyContent: "flex-end" },
740
+ label: { justifyContent: "center" },
691
741
  content: { justifyContent: "center" },
692
742
  // A filling content stretches its control across (a search field, a block button), as a column would
693
743
  fill: { flex: 1, flexDirection: "column", alignItems: "stretch" },