@plexui/react-native 0.2.0 → 0.2.2
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.
|
@@ -63,20 +63,34 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
63
63
|
const { width: windowWidth } = useWindowDimensions();
|
|
64
64
|
const sourced = !theme.isAndroid && source != null && !unplaced;
|
|
65
65
|
useEffect(() => {
|
|
66
|
-
if (
|
|
66
|
+
if (theme.isAndroid || source == null)
|
|
67
67
|
return;
|
|
68
|
+
// Closed, the next opening tries its source again
|
|
69
|
+
if (!open) {
|
|
70
|
+
setUnplaced(false);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
68
73
|
let live = true;
|
|
69
74
|
// A new opening measures again: the panel never shows at the source's last place first
|
|
70
75
|
setAnchor(null);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// A frame at a time: a sheet open as its screen appears waits for its source's layout, up to 120 frames (2s), then
|
|
77
|
+
// stands in the middle
|
|
78
|
+
let frame = 0;
|
|
79
|
+
const attempt = (left) => {
|
|
80
|
+
frame = requestAnimationFrame(() => measure(source.current, (box) => {
|
|
81
|
+
if (!live)
|
|
82
|
+
return;
|
|
83
|
+
const placed = box.width > 0 || box.height > 0;
|
|
84
|
+
if (!placed && left > 0)
|
|
85
|
+
return attempt(left - 1);
|
|
86
|
+
setAnchor(placed ? box : null);
|
|
87
|
+
setUnplaced(!placed);
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
attempt(120);
|
|
78
91
|
return () => {
|
|
79
92
|
live = false;
|
|
93
|
+
cancelAnimationFrame(frame);
|
|
80
94
|
};
|
|
81
95
|
}, [open, theme.isAndroid, source, windowWidth, screen]);
|
|
82
96
|
if (theme.isAndroid) {
|
|
@@ -107,7 +121,7 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
107
121
|
backgroundColor: theme.color("--dialog-alert-fill"),
|
|
108
122
|
opacity: pressed ? 0.7 : 1,
|
|
109
123
|
},
|
|
110
|
-
], children: _jsx(Text, { weight: "
|
|
124
|
+
], children: _jsx(Text, { weight: "medium", color: item.disabled ? theme.color("--mobile-label-tertiary") : item.destructive ? theme.color("--color-background-danger-solid") : theme.colors.text, style: styles.iosLabel, children: item.label }) }, key));
|
|
111
125
|
const header = title != null || message != null ? (_jsxs(View, { style: styles.iosHeader, children: [title != null ? (_jsx(Text, { nativeID: ids.title, weight: "semibold", accessibilityRole: "header", style: styles.iosHeaderText, children: title })) : null, message != null ? (_jsx(Text, { nativeID: ids.message, style: styles.iosHeaderText, children: message })) : null] })) : null;
|
|
112
126
|
if (sourced) {
|
|
113
127
|
// At its source: the phone popover's glass and corners (the web's Popover "Confirmation"), no Cancel
|
|
@@ -3,7 +3,9 @@ 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";
|
|
8
|
+
import { Glass } from "../../internal/Glass";
|
|
7
9
|
import { withAlpha } from "../../theme/material";
|
|
8
10
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
9
11
|
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
@@ -11,18 +13,51 @@ import { MaterialArrowDropDown } from "../Icon/material";
|
|
|
11
13
|
import { Text, textStyle } from "../Text/Text";
|
|
12
14
|
/**
|
|
13
15
|
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
14
|
-
* selected one in the Plex primary
|
|
15
|
-
*
|
|
16
|
+
* selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
|
|
17
|
+
* an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
|
|
18
|
+
* one in the app's accent (its tint) with a white label. The web has
|
|
16
19
|
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
17
20
|
*/
|
|
18
|
-
|
|
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, }) {
|
|
19
24
|
const theme = useTheme();
|
|
20
25
|
const [own, setOwn] = useState(defaultSelected ?? false);
|
|
21
|
-
|
|
22
|
-
|
|
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;
|
|
23
50
|
const press = () => {
|
|
24
51
|
if (disabled)
|
|
25
52
|
return;
|
|
53
|
+
if (token) {
|
|
54
|
+
if (armed) {
|
|
55
|
+
setArmed(false);
|
|
56
|
+
onRemove?.();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setArmed(true);
|
|
60
|
+
}
|
|
26
61
|
if (filter) {
|
|
27
62
|
if (selectedProp === undefined)
|
|
28
63
|
setOwn(!selected);
|
|
@@ -31,6 +66,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
31
66
|
onPress?.();
|
|
32
67
|
};
|
|
33
68
|
const android = theme.isAndroid;
|
|
69
|
+
const glass = !android && appearance === "glass";
|
|
34
70
|
const m = theme.material;
|
|
35
71
|
// Android: the label and the fill of either state, which a selection blends between
|
|
36
72
|
const androidColor = { off: m.onSurface, on: theme.color("--color-text-primary-solid") };
|
|
@@ -41,7 +77,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
41
77
|
? androidColor.on
|
|
42
78
|
: androidColor.off
|
|
43
79
|
: selected
|
|
44
|
-
? theme.color("--color-text-
|
|
80
|
+
? theme.color("--color-text-accent-solid", "#FFFFFF")
|
|
45
81
|
: disabled
|
|
46
82
|
? theme.colors.textDisabled
|
|
47
83
|
: theme.colors.text;
|
|
@@ -50,9 +86,12 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
50
86
|
? androidFill.on
|
|
51
87
|
: androidFill.off
|
|
52
88
|
: selected
|
|
53
|
-
? //
|
|
54
|
-
|
|
55
|
-
|
|
89
|
+
? // The app's accent, as iOS tints a chosen filter; a disabled selected chip fades to 40%, so it still stands
|
|
90
|
+
// apart from an off one
|
|
91
|
+
withAlpha(theme.colors.accent, disabled ? 0.4 : 1)
|
|
92
|
+
: glass
|
|
93
|
+
? "transparent"
|
|
94
|
+
: theme.color("--color-background-secondary-soft-alpha");
|
|
56
95
|
// Android blends the fill and the label from one state to the other in 120ms, linear; iOS changes at once
|
|
57
96
|
const [blend] = useState(() => new Animated.Value(selected ? 1 : 0));
|
|
58
97
|
const blends = android && !theme.reducedMotion;
|
|
@@ -69,13 +108,19 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
69
108
|
}, [blend, blends, selected]);
|
|
70
109
|
const fillPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidFill.off, androidFill.on] }) : fill;
|
|
71
110
|
const labelPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidColor.off, androidColor.on] }) : color;
|
|
72
|
-
const height = android ? 32 :
|
|
73
|
-
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize:
|
|
111
|
+
const height = android ? 32 : glass ? 44 : 40;
|
|
112
|
+
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize: 17, lineHeight: 22 };
|
|
74
113
|
const leading = icon;
|
|
75
|
-
|
|
114
|
+
// iOS: a 17pt symbol draws about 20 (the label's size)
|
|
115
|
+
const iconSize = android ? 18 : 20;
|
|
76
116
|
// A menu chip's chevron: Material's 18dp arrow_drop_down, iOS's small chevron.down at the label's weight
|
|
77
|
-
const trailing = trailingIcon ?? (menu ? android ? _jsx(MaterialArrowDropDown, { size: 18 }) : _jsx(ChevronDownSm, { size:
|
|
117
|
+
const trailing = trailingIcon ?? (menu ? android ? _jsx(MaterialArrowDropDown, { size: 18 }) : _jsx(ChevronDownSm, { size: 16 }) : null);
|
|
78
118
|
const leadingColor = color;
|
|
119
|
+
// A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
|
|
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;
|
|
79
124
|
// The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
|
|
80
125
|
// HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
|
|
81
126
|
const target = android ? 48 : 44;
|
|
@@ -83,23 +128,25 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
83
128
|
// A capsule, which stays one when a large text size makes it taller
|
|
84
129
|
const radius = 999;
|
|
85
130
|
const [pressed, setPressed] = useState(false);
|
|
86
|
-
|
|
131
|
+
// iOS's glass filter: a glass capsule (its rim and sheen), filled with the accent once chosen
|
|
132
|
+
const glassLayer = glass && !selected ? _jsx(Glass, { pointerEvents: "none", radius: radius, style: [StyleSheet.absoluteFill, { top: inset, bottom: inset }] }) : null;
|
|
133
|
+
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 }));
|
|
87
134
|
const box = {
|
|
88
135
|
// The label's own air inside the chip, then the target's outside it: 48 (44) at the regular size, and taller
|
|
89
136
|
// with the text at a large font scale instead of cutting it (Compose's chips have a minimum height, not a height)
|
|
90
137
|
minHeight: target,
|
|
91
138
|
paddingVertical: inset + (height - label.lineHeight) / 2,
|
|
92
139
|
// Android: 12 at the sides, 8 before an icon and 6 after it
|
|
93
|
-
paddingLeft: leading != null ? (android ? 8 : 12) : android ? 12 :
|
|
94
|
-
// Android: 8 after a trailing icon (Compose's FilterChip), iOS
|
|
95
|
-
paddingRight:
|
|
140
|
+
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
141
|
+
// Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
|
|
142
|
+
paddingRight: symbolOnly ? (height - iconSize) / 2 : cross ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
96
143
|
gap: 6,
|
|
97
144
|
opacity: !android && pressed ? 0.7 : 1,
|
|
98
145
|
};
|
|
99
|
-
const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, android ? (
|
|
146
|
+
const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, symbolOnly ? null : android ? (
|
|
100
147
|
// Text's own face and tracking, in a color that blends
|
|
101
|
-
_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: "
|
|
102
|
-
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;
|
|
103
150
|
// Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
|
|
104
151
|
const dim = android && disabled ? styles.dim : null;
|
|
105
152
|
const handlers = {
|
|
@@ -107,19 +154,43 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
107
154
|
// A menu chip is a button that opens its menu, even when it shows a chosen filter
|
|
108
155
|
accessibilityRole: filter && !menu ? "checkbox" : "button",
|
|
109
156
|
accessibilityLabel,
|
|
110
|
-
accessibilityState: {
|
|
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
|
+
},
|
|
111
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,
|
|
112
167
|
"aria-haspopup": menu ? (menu === true ? "menu" : menu) : undefined,
|
|
113
168
|
"aria-expanded": menu ? expanded : undefined,
|
|
114
169
|
disabled,
|
|
115
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
|
+
: {}),
|
|
116
187
|
onPressIn: () => setPressed(true),
|
|
117
188
|
onPressOut: () => setPressed(false),
|
|
118
189
|
};
|
|
119
190
|
// An input chip holds its cross beside the chip's own press, never a button inside a button; each takes the
|
|
120
191
|
// target's full height
|
|
121
|
-
if (
|
|
122
|
-
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,
|
|
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") }) })] }));
|
|
123
194
|
}
|
|
124
195
|
if (!interactive) {
|
|
125
196
|
return (_jsxs(View, { testID: testID, style: [styles.chip, styles.part, box, dim, style], children: [layer, body] }));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
3
3
|
export type ChipProps = {
|
|
4
|
-
|
|
4
|
+
/** The label. Leave it out with an `icon` for a chip of the symbol alone, a circle named by `accessibilityLabel`. */
|
|
5
|
+
children?: ReactNode;
|
|
5
6
|
/** A filter chip: chosen or not. Leave it out for an action chip. */
|
|
6
7
|
selected?: boolean;
|
|
7
8
|
defaultSelected?: boolean;
|
|
@@ -21,18 +22,27 @@ export type ChipProps = {
|
|
|
21
22
|
/** Whether the chip's menu is open (`aria-expanded`). */
|
|
22
23
|
expanded?: boolean;
|
|
23
24
|
accessibilityLabel?: string;
|
|
24
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* iOS: `tag`, a capsule of the gray fill 40pt tall (a tag cloud in a sheet, as Maps' Filters), or `glass`, a glass
|
|
27
|
+
* capsule 44pt tall (a filter in a row over content, as Maps' filters under its search). Android draws its chip with
|
|
28
|
+
* either. @default "tag"
|
|
29
|
+
*/
|
|
30
|
+
appearance?: "tag" | "glass";
|
|
31
|
+
/** An input chip: called when the reader takes the value back (a cross on Android; see `removeStyle` on iOS). */
|
|
25
32
|
onRemove?: () => void;
|
|
26
|
-
/** @default "Remove" */
|
|
33
|
+
/** The remove action's name, for screen readers. @default "Remove" */
|
|
27
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";
|
|
28
44
|
disabled?: boolean;
|
|
29
45
|
testID?: string;
|
|
30
46
|
style?: StyleProp<ViewStyle>;
|
|
31
47
|
};
|
|
32
|
-
|
|
33
|
-
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
34
|
-
* selected one in the Plex primary, as on iOS). iOS has no chip control: the filter capsules of iOS apps (a 34pt
|
|
35
|
-
* capsule, 15/20 medium, the soft gray fill, the Plex primary when selected, as a selected Plex Button). The web has
|
|
36
|
-
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
37
|
-
*/
|
|
38
|
-
export declare function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, 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;
|
package/package.json
CHANGED
|
@@ -86,18 +86,33 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
86
86
|
const { width: windowWidth } = useWindowDimensions()
|
|
87
87
|
const sourced = !theme.isAndroid && source != null && !unplaced
|
|
88
88
|
useEffect(() => {
|
|
89
|
-
if (
|
|
89
|
+
if (theme.isAndroid || source == null) return
|
|
90
|
+
// Closed, the next opening tries its source again
|
|
91
|
+
if (!open) {
|
|
92
|
+
setUnplaced(false)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
90
95
|
let live = true
|
|
91
96
|
// A new opening measures again: the panel never shows at the source's last place first
|
|
92
97
|
setAnchor(null)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
// A frame at a time: a sheet open as its screen appears waits for its source's layout, up to 120 frames (2s), then
|
|
99
|
+
// stands in the middle
|
|
100
|
+
let frame = 0
|
|
101
|
+
const attempt = (left: number) => {
|
|
102
|
+
frame = requestAnimationFrame(() =>
|
|
103
|
+
measure(source.current as Measurable | null, (box) => {
|
|
104
|
+
if (!live) return
|
|
105
|
+
const placed = box.width > 0 || box.height > 0
|
|
106
|
+
if (!placed && left > 0) return attempt(left - 1)
|
|
107
|
+
setAnchor(placed ? box : null)
|
|
108
|
+
setUnplaced(!placed)
|
|
109
|
+
}),
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
attempt(120)
|
|
99
113
|
return () => {
|
|
100
114
|
live = false
|
|
115
|
+
cancelAnimationFrame(frame)
|
|
101
116
|
}
|
|
102
117
|
}, [open, theme.isAndroid, source, windowWidth, screen])
|
|
103
118
|
if (theme.isAndroid) {
|
|
@@ -186,9 +201,10 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
186
201
|
},
|
|
187
202
|
]}
|
|
188
203
|
>
|
|
189
|
-
{/* iOS 27's action sheet: every action
|
|
204
|
+
{/* iOS 27's action sheet: every action one weight, 17/22, a destructive one in the native red (the danger
|
|
205
|
+
solid). The kit's SF Semibold draws as heavy as Inter's Medium, so Medium, Cancel too */}
|
|
190
206
|
<Text
|
|
191
|
-
weight="
|
|
207
|
+
weight="medium"
|
|
192
208
|
color={item.disabled ? theme.color("--mobile-label-tertiary") : item.destructive ? theme.color("--color-background-danger-solid") : theme.colors.text}
|
|
193
209
|
style={styles.iosLabel}
|
|
194
210
|
>
|
|
@@ -2,7 +2,9 @@ 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"
|
|
7
|
+
import { Glass } from "../../internal/Glass"
|
|
6
8
|
import { withAlpha } from "../../theme/material"
|
|
7
9
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
8
10
|
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
@@ -10,7 +12,8 @@ import { MaterialArrowDropDown } from "../Icon/material"
|
|
|
10
12
|
import { Text, textStyle } from "../Text/Text"
|
|
11
13
|
|
|
12
14
|
export type ChipProps = {
|
|
13
|
-
|
|
15
|
+
/** The label. Leave it out with an `icon` for a chip of the symbol alone, a circle named by `accessibilityLabel`. */
|
|
16
|
+
children?: ReactNode
|
|
14
17
|
/** A filter chip: chosen or not. Leave it out for an action chip. */
|
|
15
18
|
selected?: boolean
|
|
16
19
|
defaultSelected?: boolean
|
|
@@ -30,10 +33,25 @@ export type ChipProps = {
|
|
|
30
33
|
/** Whether the chip's menu is open (`aria-expanded`). */
|
|
31
34
|
expanded?: boolean
|
|
32
35
|
accessibilityLabel?: string
|
|
33
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* iOS: `tag`, a capsule of the gray fill 40pt tall (a tag cloud in a sheet, as Maps' Filters), or `glass`, a glass
|
|
38
|
+
* capsule 44pt tall (a filter in a row over content, as Maps' filters under its search). Android draws its chip with
|
|
39
|
+
* either. @default "tag"
|
|
40
|
+
*/
|
|
41
|
+
appearance?: "tag" | "glass"
|
|
42
|
+
/** An input chip: called when the reader takes the value back (a cross on Android; see `removeStyle` on iOS). */
|
|
34
43
|
onRemove?: () => void
|
|
35
|
-
/** @default "Remove" */
|
|
44
|
+
/** The remove action's name, for screen readers. @default "Remove" */
|
|
36
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"
|
|
37
55
|
disabled?: boolean
|
|
38
56
|
testID?: string
|
|
39
57
|
style?: StyleProp<ViewStyle>
|
|
@@ -41,10 +59,14 @@ export type ChipProps = {
|
|
|
41
59
|
|
|
42
60
|
/**
|
|
43
61
|
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
44
|
-
* selected one in the Plex primary
|
|
45
|
-
*
|
|
62
|
+
* selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
|
|
63
|
+
* an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
|
|
64
|
+
* one in the app's accent (its tint) with a white label. The web has
|
|
46
65
|
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
47
66
|
*/
|
|
67
|
+
/** The chosen token's way to let go, so that choosing another lets it go */
|
|
68
|
+
let disarmToken: (() => void) | null = null
|
|
69
|
+
|
|
48
70
|
export function Chip({
|
|
49
71
|
children,
|
|
50
72
|
selected: selectedProp,
|
|
@@ -56,18 +78,50 @@ export function Chip({
|
|
|
56
78
|
menu,
|
|
57
79
|
expanded,
|
|
58
80
|
accessibilityLabel,
|
|
81
|
+
appearance = "tag",
|
|
59
82
|
onRemove,
|
|
60
83
|
removeLabel = "Remove",
|
|
84
|
+
removeStyle = "token",
|
|
61
85
|
disabled = false,
|
|
62
86
|
testID,
|
|
63
87
|
style,
|
|
64
88
|
}: ChipProps) {
|
|
65
89
|
const theme = useTheme()
|
|
66
90
|
const [own, setOwn] = useState(defaultSelected ?? false)
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
69
115
|
const press = () => {
|
|
70
116
|
if (disabled) return
|
|
117
|
+
if (token) {
|
|
118
|
+
if (armed) {
|
|
119
|
+
setArmed(false)
|
|
120
|
+
onRemove?.()
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
setArmed(true)
|
|
124
|
+
}
|
|
71
125
|
if (filter) {
|
|
72
126
|
if (selectedProp === undefined) setOwn(!selected)
|
|
73
127
|
onSelectedChange?.(!selected)
|
|
@@ -75,6 +129,7 @@ export function Chip({
|
|
|
75
129
|
onPress?.()
|
|
76
130
|
}
|
|
77
131
|
const android = theme.isAndroid
|
|
132
|
+
const glass = !android && appearance === "glass"
|
|
78
133
|
const m = theme.material
|
|
79
134
|
// Android: the label and the fill of either state, which a selection blends between
|
|
80
135
|
const androidColor = { off: m.onSurface, on: theme.color("--color-text-primary-solid") }
|
|
@@ -85,7 +140,7 @@ export function Chip({
|
|
|
85
140
|
? androidColor.on
|
|
86
141
|
: androidColor.off
|
|
87
142
|
: selected
|
|
88
|
-
? theme.color("--color-text-
|
|
143
|
+
? theme.color("--color-text-accent-solid", "#FFFFFF")
|
|
89
144
|
: disabled
|
|
90
145
|
? theme.colors.textDisabled
|
|
91
146
|
: theme.colors.text
|
|
@@ -94,9 +149,12 @@ export function Chip({
|
|
|
94
149
|
? androidFill.on
|
|
95
150
|
: androidFill.off
|
|
96
151
|
: selected
|
|
97
|
-
? //
|
|
98
|
-
|
|
99
|
-
|
|
152
|
+
? // The app's accent, as iOS tints a chosen filter; a disabled selected chip fades to 40%, so it still stands
|
|
153
|
+
// apart from an off one
|
|
154
|
+
withAlpha(theme.colors.accent, disabled ? 0.4 : 1)
|
|
155
|
+
: glass
|
|
156
|
+
? "transparent"
|
|
157
|
+
: theme.color("--color-background-secondary-soft-alpha")
|
|
100
158
|
// Android blends the fill and the label from one state to the other in 120ms, linear; iOS changes at once
|
|
101
159
|
const [blend] = useState(() => new Animated.Value(selected ? 1 : 0))
|
|
102
160
|
const blends = android && !theme.reducedMotion
|
|
@@ -113,13 +171,19 @@ export function Chip({
|
|
|
113
171
|
}, [blend, blends, selected])
|
|
114
172
|
const fillPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidFill.off, androidFill.on] }) : fill
|
|
115
173
|
const labelPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidColor.off, androidColor.on] }) : color
|
|
116
|
-
const height = android ? 32 :
|
|
117
|
-
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize:
|
|
174
|
+
const height = android ? 32 : glass ? 44 : 40
|
|
175
|
+
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize: 17, lineHeight: 22 }
|
|
118
176
|
const leading = icon
|
|
119
|
-
|
|
177
|
+
// iOS: a 17pt symbol draws about 20 (the label's size)
|
|
178
|
+
const iconSize = android ? 18 : 20
|
|
120
179
|
// A menu chip's chevron: Material's 18dp arrow_drop_down, iOS's small chevron.down at the label's weight
|
|
121
|
-
const trailing = trailingIcon ?? (menu ? android ? <MaterialArrowDropDown size={18} /> : <ChevronDownSm size={
|
|
180
|
+
const trailing = trailingIcon ?? (menu ? android ? <MaterialArrowDropDown size={18} /> : <ChevronDownSm size={16} /> : null)
|
|
122
181
|
const leadingColor = color
|
|
182
|
+
// A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
|
|
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
|
|
123
187
|
// The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
|
|
124
188
|
// HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
|
|
125
189
|
const target = android ? 48 : 44
|
|
@@ -127,7 +191,10 @@ export function Chip({
|
|
|
127
191
|
// A capsule, which stays one when a large text size makes it taller
|
|
128
192
|
const radius = 999
|
|
129
193
|
const [pressed, setPressed] = useState(false)
|
|
130
|
-
|
|
194
|
+
// iOS's glass filter: a glass capsule (its rim and sheen), filled with the accent once chosen
|
|
195
|
+
const glassLayer =
|
|
196
|
+
glass && !selected ? <Glass pointerEvents="none" radius={radius} style={[StyleSheet.absoluteFill, { top: inset, bottom: inset }]} /> : null
|
|
197
|
+
const layer = glassLayer ?? (
|
|
131
198
|
<Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: radius, backgroundColor: fillPaint, borderCurve: "continuous" }]}>
|
|
132
199
|
{/* Android's press: the list selector over the chip, 6% black and 5% white at night (the dark theme's); over a
|
|
133
200
|
selected chip's solid fill its label's color at 12%, which shows on either scheme */}
|
|
@@ -142,9 +209,9 @@ export function Chip({
|
|
|
142
209
|
minHeight: target,
|
|
143
210
|
paddingVertical: inset + (height - label.lineHeight) / 2,
|
|
144
211
|
// Android: 12 at the sides, 8 before an icon and 6 after it
|
|
145
|
-
paddingLeft: leading != null ? (android ? 8 : 12) : android ? 12 :
|
|
146
|
-
// Android: 8 after a trailing icon (Compose's FilterChip), iOS
|
|
147
|
-
paddingRight:
|
|
212
|
+
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
213
|
+
// Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
|
|
214
|
+
paddingRight: symbolOnly ? (height - iconSize) / 2 : cross ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
148
215
|
gap: 6,
|
|
149
216
|
opacity: !android && pressed ? 0.7 : 1,
|
|
150
217
|
}
|
|
@@ -158,16 +225,17 @@ export function Chip({
|
|
|
158
225
|
</IconDefaultsProvider>
|
|
159
226
|
</View>
|
|
160
227
|
) : null}
|
|
161
|
-
{android ? (
|
|
228
|
+
{symbolOnly ? null : android ? (
|
|
162
229
|
// Text's own face and tracking, in a color that blends
|
|
163
230
|
<Animated.Text
|
|
164
231
|
numberOfLines={1}
|
|
232
|
+
selectable={false}
|
|
165
233
|
style={[textStyle(theme, { weight: "regular" }), { fontSize: label.fontSize, lineHeight: label.lineHeight, letterSpacing: theme.tracking(label.fontSize), color: labelPaint }]}
|
|
166
234
|
>
|
|
167
235
|
{children}
|
|
168
236
|
</Animated.Text>
|
|
169
237
|
) : (
|
|
170
|
-
<Text color={color} weight="
|
|
238
|
+
<Text color={color} weight="regular" numberOfLines={1} selectable={false} style={{ fontSize: label.fontSize, lineHeight: label.lineHeight }}>
|
|
171
239
|
{children}
|
|
172
240
|
</Text>
|
|
173
241
|
)}
|
|
@@ -180,7 +248,7 @@ export function Chip({
|
|
|
180
248
|
) : null}
|
|
181
249
|
</>
|
|
182
250
|
)
|
|
183
|
-
const interactive = filter || !!onPress
|
|
251
|
+
const interactive = filter || !!onPress || token
|
|
184
252
|
// Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
|
|
185
253
|
const dim = android && disabled ? styles.dim : null
|
|
186
254
|
const handlers = {
|
|
@@ -188,18 +256,40 @@ export function Chip({
|
|
|
188
256
|
// A menu chip is a button that opens its menu, even when it shows a chosen filter
|
|
189
257
|
accessibilityRole: filter && !menu ? ("checkbox" as const) : ("button" as const),
|
|
190
258
|
accessibilityLabel,
|
|
191
|
-
accessibilityState: {
|
|
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
|
+
},
|
|
192
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,
|
|
193
269
|
"aria-haspopup": menu ? (menu === true ? ("menu" as const) : menu) : undefined,
|
|
194
270
|
"aria-expanded": menu ? expanded : undefined,
|
|
195
271
|
disabled,
|
|
196
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
|
+
: {}),
|
|
197
287
|
onPressIn: () => setPressed(true),
|
|
198
288
|
onPressOut: () => setPressed(false),
|
|
199
289
|
}
|
|
200
290
|
// An input chip holds its cross beside the chip's own press, never a button inside a button; each takes the
|
|
201
291
|
// target's full height
|
|
202
|
-
if (
|
|
292
|
+
if (cross) {
|
|
203
293
|
return (
|
|
204
294
|
<View testID={testID} style={[styles.chip, { minHeight: target }, dim, style]}>
|
|
205
295
|
{layer}
|
|
@@ -215,9 +305,9 @@ export function Chip({
|
|
|
215
305
|
accessibilityLabel={removeLabel}
|
|
216
306
|
disabled={disabled}
|
|
217
307
|
onPress={onRemove}
|
|
218
|
-
style={[styles.part,
|
|
308
|
+
style={[styles.part, android ? { paddingLeft: 4, paddingRight: 8 } : { width: 44, justifyContent: "center" }]}
|
|
219
309
|
>
|
|
220
|
-
<CloseBold size={
|
|
310
|
+
{android ? <CloseBold size={18} color={color} /> : <XCircleFilled size={clearSize} color={theme.color("--mobile-label-tertiary")} />}
|
|
221
311
|
</Pressable>
|
|
222
312
|
</View>
|
|
223
313
|
)
|