@plexui/react-native 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/ActionSheet/ActionSheet.js +1 -1
- package/dist/es/components/BottomSheet/BottomSheet.js +87 -17
- package/dist/es/components/Button/Button.js +21 -4
- package/dist/es/components/ContextMenu/ContextMenu.js +16 -16
- package/dist/es/components/Input/Input.js +3 -1
- package/dist/es/components/List/List.js +15 -1
- package/dist/es/components/Menu/Menu.js +26 -11
- package/dist/es/components/Tip/Tip.js +29 -12
- package/dist/es/internal/Glass.js +15 -8
- package/dist/types/components/BottomSheet/BottomSheet.d.ts +22 -1
- package/dist/types/components/Button/Button.d.ts +6 -2
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +17 -2
- package/dist/types/components/Menu/Menu.d.ts +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/internal/Glass.d.ts +7 -1
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +1 -0
- package/src/components/BottomSheet/BottomSheet.tsx +153 -25
- package/src/components/Button/Button.tsx +26 -6
- package/src/components/ContextMenu/ContextMenu.tsx +42 -12
- package/src/components/Input/Input.tsx +3 -1
- package/src/components/List/List.tsx +13 -1
- package/src/components/Menu/Menu.tsx +27 -12
- package/src/components/Tip/Tip.tsx +68 -12
- package/src/index.ts +2 -2
- package/src/internal/Glass.tsx +22 -8
|
@@ -99,7 +99,7 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
99
99
|
const icons = actions.some((action) => action.icon);
|
|
100
100
|
return (_jsxs(BottomSheetBase, { open: open, onOpenChange: onOpenChange, testID: testID, contentStyle: styles.androidList, "aria-label": typeof title === "string" ? title : undefined,
|
|
101
101
|
// With reduced motion the exit is at once either way
|
|
102
|
-
exit: quick && !theme.reducedMotion ? ANDROID_PICK_EXIT : undefined, onExited: runPicked, children: [title != null || message != null ? (_jsxs(View, { style: styles.androidHeader, children: [title != null ? (_jsx(Text, { nativeID: ids.title, accessibilityRole: "header", color: theme.colors.labelSecondary, style: styles.androidTitle, children: title })) : null, message != null ? (_jsx(Text, { nativeID: ids.message, color: theme.colors.labelSecondary, style: styles.androidMessage, children: message })) : null] })) : null, actions.map((action, index) => {
|
|
102
|
+
exit: quick && !theme.reducedMotion ? ANDROID_PICK_EXIT : undefined, onExited: runPicked, androidClose: false, children: [title != null || message != null ? (_jsxs(View, { style: styles.androidHeader, children: [title != null ? (_jsx(Text, { nativeID: ids.title, accessibilityRole: "header", color: theme.colors.labelSecondary, style: styles.androidTitle, children: title })) : null, message != null ? (_jsx(Text, { nativeID: ids.message, color: theme.colors.labelSecondary, style: styles.androidMessage, children: message })) : null] })) : null, actions.map((action, index) => {
|
|
103
103
|
const color = action.destructive ? dangerText(theme) : m.onSurface;
|
|
104
104
|
return (_jsxs(Pressable
|
|
105
105
|
// Two actions may share a label: each keeps its place in `actions`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { isValidElement, useId, useLayoutEffect, useMemo, useState } from "react";
|
|
2
|
+
import { Children, cloneElement, isValidElement, useId, useLayoutEffect, useMemo, useState } from "react";
|
|
3
3
|
import { InSheetContext } from "./context";
|
|
4
4
|
import { Animated, Easing, PanResponder, Platform, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
5
5
|
import { Pressable } from "../../internal/Pressable";
|
|
@@ -7,10 +7,12 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
|
7
7
|
import { childrenOfType, flattenChildren } from "../../internal/children";
|
|
8
8
|
import { useKeyboardHeight } from "../../internal/keyboard";
|
|
9
9
|
import { iosDim, Overlay, ANDROID_DIM } from "../../internal/Overlay";
|
|
10
|
+
import { BarBackdrop, SoftBottomEdge } from "../../internal/BarBackdrop";
|
|
10
11
|
import { withAlpha } from "../../theme/material";
|
|
11
12
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
12
|
-
import { BarItemContext } from "../Button/Button";
|
|
13
|
+
import { BarItemContext, Button } from "../Button/Button";
|
|
13
14
|
import { NavigationButton } from "../NavigationButton/NavigationButton";
|
|
15
|
+
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
14
16
|
import { Text } from "../Text/Text";
|
|
15
17
|
/**
|
|
16
18
|
* The actions of a sheet, pinned under its content, which scrolls above them: the web's `Dialog.Footer` (12 above,
|
|
@@ -168,8 +170,10 @@ function BottomSheetRoot(props) {
|
|
|
168
170
|
return _jsx(BottomSheetBase, { ...props });
|
|
169
171
|
}
|
|
170
172
|
/** The sheet with an exit of its own (ActionSheet's item tap); not part of the public API. */
|
|
171
|
-
export function BottomSheetBase({ open, onOpenChange, title, children, dismissible = true, "aria-label": ariaLabel, testID, contentStyle, closeLabel = "Close", detent = "content", exit, onExited, }) {
|
|
173
|
+
export function BottomSheetBase({ open, onOpenChange, title: titleProp, hero, children, dismissible = true, "aria-label": ariaLabel, testID, contentStyle, closeLabel = "Close", detent = "content", exit, onExited, androidClose = true, }) {
|
|
172
174
|
const theme = useTheme();
|
|
175
|
+
// A hero names the sheet from its content: the bar keeps Close alone
|
|
176
|
+
const title = hero ? undefined : titleProp;
|
|
173
177
|
const insets = useSafeAreaInsets();
|
|
174
178
|
const { width, height: screen } = useWindowDimensions();
|
|
175
179
|
const [height, setHeight] = useState(0);
|
|
@@ -209,7 +213,7 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
209
213
|
const web = Platform.OS === "web";
|
|
210
214
|
// The web names the dialog by its title; a phone keeps the modal view
|
|
211
215
|
const a11y = web
|
|
212
|
-
? { role: "dialog", "aria-modal": true, "aria-labelledby": title != null ? titleId : undefined, "aria-label": title != null ? undefined : ariaLabel }
|
|
216
|
+
? { role: "dialog", "aria-modal": true, "aria-labelledby": title != null || hero ? titleId : undefined, "aria-label": title != null || hero ? undefined : ariaLabel }
|
|
213
217
|
: { accessibilityViewIsModal: true, "aria-label": ariaLabel };
|
|
214
218
|
// Android's sheet stands under the status bar at most; the phone layer's 16 under the top inset
|
|
215
219
|
const maxHeight = screen - insets.top - (android ? 0 : 16);
|
|
@@ -218,28 +222,43 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
218
222
|
// Android's sheet is as wide as the screen in portrait; in landscape 80% of it and 480dp at least
|
|
219
223
|
const maxWidth = android && width > screen ? Math.max(width * 0.8, Math.min(480, width)) : undefined;
|
|
220
224
|
const closeSize = theme.length("--dialog-sheet-close-size", 44);
|
|
221
|
-
const margin = theme.length("--mobile-layout-margin", 16);
|
|
222
225
|
// Android: content scrolled under the bar fades out under it; the footer's height sets the room under the content
|
|
223
226
|
const [scrolled, setScrolled] = useState(false);
|
|
224
227
|
// The Android bar's height: 69 with a title on one line, a line more when it wraps to a second
|
|
225
228
|
const [androidBarHeight, setAndroidBarHeight] = useState(ANDROID_BAR_HEIGHT);
|
|
226
229
|
const [footerHeight, setFooterHeight] = useState(0);
|
|
230
|
+
// iOS: the bar and the footer stand over the content, which scrolls under them (iOS 26's sheets)
|
|
231
|
+
const [iosBarHeight, setIosBarHeight] = useState(0);
|
|
227
232
|
// Android's sheet has no handle: the whole sheet takes the drag. With a title its bar is the reference's sheet bar,
|
|
228
233
|
// over the content: Close in a 46dp glass circle 12 under the top edge and 12 from the side (in line with the
|
|
229
234
|
// content's cards), concentric with the sheet's corner, the title 17/22 Medium centered between the circles' places
|
|
230
235
|
// (69 in all). Content scrolled under it shows through the sheet's color at
|
|
231
236
|
// 63% over a light blur, let go over its last 32dp (12 past the bar), with no line
|
|
232
237
|
const barItem = useMemoBarItem(background);
|
|
233
|
-
|
|
238
|
+
// Android's bar stands with a title, or with Close alone where the sheet can be closed (as iOS's)
|
|
239
|
+
const androidBar = android && (title != null || (dismissible && androidClose));
|
|
240
|
+
const header = android ? (androidBar ? (_jsxs(View, { onStartShouldSetResponderCapture: gesture.chrome, onLayout: (event) => setAndroidBarHeight(Math.max(ANDROID_BAR_HEIGHT, event.nativeEvent.layout.height)), style: [styles.androidBar, { paddingHorizontal: androidInline }], children: [_jsx(SheetBarFade, { fill: background, shown: scrolled }), _jsx(View, { style: styles.androidCircle, children: dismissible ? (_jsx(BarItemContext.Provider, { value: barItem, children: _jsx(NavigationButton, { action: "close", accessibilityLabel: closeLabel, onPress: close }) })) : null }), _jsx(View, { style: styles.androidHeading, children: title == null ? null : _jsx(Text, { nativeID: titleId, accessibilityRole: "header", weight: "medium", align: "center", numberOfLines: 2, color: m.onSurface, style: { fontSize: titleType.fontSize, lineHeight: titleType.lineHeight }, children: title }) }), _jsx(View, { style: styles.androidCircle })] })) : (_jsx(View, { onStartShouldSetResponderCapture: gesture.chrome, style: styles.androidGrip }))) : dismissible || title != null ? (
|
|
234
241
|
// The web's phone Sheet bar: one 44 row 16 under the top edge, Close at the leading edge and the title alone centered
|
|
235
242
|
// The bar is the web's Toolbar: 16 above the row and --toolbar-padding-bottom under it
|
|
236
|
-
|
|
243
|
+
// It stands over the content: scrolled under it, the content goes soft (the veil of the canvas over a blur), as
|
|
244
|
+
// under a soft Toolbar
|
|
245
|
+
_jsxs(View, { ...responder.panHandlers, onLayout: (event) => setIosBarHeight(event.nativeEvent.layout.height),
|
|
246
|
+
// iOS 26's sheets set Close and Back 20 from the top and the sides (Health, Files, Apple Account)
|
|
247
|
+
style: [styles.iosBar, { paddingTop: IOS_BAR_INSET, paddingBottom: theme.length("--toolbar-padding-bottom", 10), paddingHorizontal: IOS_BAR_INSET }], children: [scrolled ? (_jsx(BarBackdrop, { fill: withAlpha(background, parseFloat(String(theme.token("--page-bar-veil-opacity") ?? "55")) / 100), blur: theme.length("--page-bar-soft-blur", 10), edge: "bottom" })) : null, _jsx(View, { style: { width: closeSize, height: closeSize }, children: dismissible ? _jsx(NavigationButton, { action: "close", accessibilityLabel: closeLabel, onPress: close }) : null }), _jsx(View, { style: [styles.iosHeading, { minHeight: closeSize }], children: title != null ? (_jsx(Text, { nativeID: titleId, accessibilityRole: "header", weight: "semibold", align: "center", style: { fontSize: titleType.fontSize, lineHeight: titleType.lineHeight }, children: title })) : null }), _jsx(View, { style: { width: closeSize } })] })) : null;
|
|
237
248
|
const footer = childrenOfType(children, BottomSheetFooter)[0];
|
|
238
249
|
const content = footer ? flattenChildren(children).filter((child) => !isFooter(child)) : children;
|
|
239
250
|
// The content starts where the bar's soft edge ends (--page-bar-soft-tail under the bar, Dialog.module.css), and
|
|
240
251
|
// ends 16 over a footer, or over the home indicator
|
|
241
252
|
const bottom = keyboard || footer ? 16 : Math.max(16, insets.bottom);
|
|
242
|
-
const
|
|
253
|
+
const hasIosBar = !android && (dismissible || title != null);
|
|
254
|
+
const iosContent = {
|
|
255
|
+
paddingTop: (hasIosBar ? iosBarHeight : 0) + theme.length("--page-bar-soft-tail", 32),
|
|
256
|
+
// iOS 26's sheets set their fields and cards 20 from the sides, in line with Close (Health's Medication Name
|
|
257
|
+
// and its lists); the action at the foot stands further in, concentric with the screen's corners
|
|
258
|
+
paddingHorizontal: IOS_BAR_INSET,
|
|
259
|
+
// Over a footer: 16 above its actions, which stand over the content's end
|
|
260
|
+
paddingBottom: footer ? Math.max(0, footerHeight - keyboard) + 16 : bottom,
|
|
261
|
+
};
|
|
243
262
|
// The sheet's way in and out, under the drag. Android's starts and ends 10 under the screen's edge, and leaves from
|
|
244
263
|
// where a drag let it go: the drag shrinks with the progress, so the sheet goes from there to its place under the edge
|
|
245
264
|
const slide = (progress) => android
|
|
@@ -264,7 +283,7 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
264
283
|
opacity: reduced ? progress : undefined,
|
|
265
284
|
transform: [{ translateY: reduced ? drag : slide(progress) }],
|
|
266
285
|
},
|
|
267
|
-
], children: [
|
|
286
|
+
], children: [androidBar ? null : header, _jsxs(ScrollView
|
|
268
287
|
// A sheet of a fixed height gives its content the room left, so a footer stays at its bottom
|
|
269
288
|
, {
|
|
270
289
|
// A sheet of a fixed height gives its content the room left, so a footer stays at its bottom
|
|
@@ -279,20 +298,27 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
279
298
|
},
|
|
280
299
|
scrollEventThrottle: 16,
|
|
281
300
|
}
|
|
282
|
-
:
|
|
301
|
+
: {
|
|
302
|
+
onScroll: (event) => {
|
|
303
|
+
const under = event.nativeEvent.contentOffset.y > 0;
|
|
304
|
+
if (under !== scrolled)
|
|
305
|
+
setScrolled(under);
|
|
306
|
+
},
|
|
307
|
+
scrollEventThrottle: 16,
|
|
308
|
+
}), contentContainerStyle: [
|
|
283
309
|
android
|
|
284
310
|
? [
|
|
285
311
|
styles.androidContent,
|
|
286
312
|
// A screen whose gutter is Material's compact 16 sets it with --bottom-sheet-android-padding-inline
|
|
287
313
|
{ paddingHorizontal: androidInline },
|
|
288
314
|
// 2 under the bar: 71 under a one-line title
|
|
289
|
-
|
|
315
|
+
androidBar ? { paddingTop: androidBarHeight + 2 } : null,
|
|
290
316
|
// Over a footer: 8 above its height, which reaches over the sheet's bottom padding
|
|
291
317
|
footer ? { paddingBottom: 8 + Math.max(0, footerHeight - insets.bottom - keyboard) } : null,
|
|
292
318
|
]
|
|
293
319
|
: iosContent,
|
|
294
320
|
contentStyle,
|
|
295
|
-
], keyboardShouldPersistTaps: "handled", bounces: false, children:
|
|
321
|
+
], keyboardShouldPersistTaps: "handled", bounces: false, children: [hero ? _jsx(SheetHero, { hero: hero, id: titleId }) : null, content] }), androidBar ? header : null, footer ? (_jsxs(View, { onStartShouldSetResponderCapture: android ? gesture.chrome : undefined, onLayout: (event) => setFooterHeight(event.nativeEvent.layout.height), style: [
|
|
296
322
|
android
|
|
297
323
|
? [
|
|
298
324
|
styles.androidFooter,
|
|
@@ -300,9 +326,53 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
300
326
|
// Over the sheet's color at 80%, faded in over its top 24dp, down over the gesture bar
|
|
301
327
|
{ paddingBottom: 12 + insets.bottom + keyboard, backgroundImage: `linear-gradient(to bottom, ${withAlpha(background, 0)}, ${withAlpha(background, 0.8)} 24px)` },
|
|
302
328
|
]
|
|
303
|
-
:
|
|
329
|
+
: // iOS 26: the sheet's bottom corners are the screen's, so its actions stand as BottomActions does,
|
|
330
|
+
// concentric with them: 36 from the sides and from the bottom (Apple Account's Add Email: 38
|
|
331
|
+
// and 39), 52 tall, at least 2 over the home indicator; 16 over the keyboard
|
|
332
|
+
// It stands over the content's end, over the keyboard while it is up
|
|
333
|
+
[styles.iosFooter, { paddingHorizontal: IOS_ACTION_SIDE, paddingBottom: keyboard ? 16 + keyboard : Math.max(IOS_ACTION_SIDE, insets.bottom + 2) }],
|
|
304
334
|
footer.props.style,
|
|
305
|
-
], children: [android ? null :
|
|
335
|
+
], children: [android ? null : _jsx(SoftBottomEdge, { fill: background, top: 12, tail: 27, blur: theme.length("--toolbar-edge-blur-small", 3) }), android ? footer.props.children : iosActions(footer.props.children)] })) : null] }), android && Platform.OS === "android" && dismissible ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: closeLabel, onPress: close, style: [styles.scrimTarget, { bottom: height }] })) : null] }) })) }));
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* A sheet's hero header. iOS: a 56pt symbol, 12 over a centered Title 1 bold (28/34, 4 more over a 17/22 secondary
|
|
339
|
+
* description), 24 over the content, as Apple's setup sheets. Android: Material's dialog hero, a 24dp icon in the
|
|
340
|
+
* secondary color 16 over a centered headline small (24/32), 16 over a 14/20 onSurfaceVariant text, 24 over the content.
|
|
341
|
+
*/
|
|
342
|
+
function SheetHero({ hero, id }) {
|
|
343
|
+
const theme = useTheme();
|
|
344
|
+
const android = theme.isAndroid;
|
|
345
|
+
const m = theme.material;
|
|
346
|
+
const tone = hero.tone ?? "accent";
|
|
347
|
+
const ink = tone === "accent"
|
|
348
|
+
? android
|
|
349
|
+
? m.secondary
|
|
350
|
+
: theme.colors.accent
|
|
351
|
+
: tone === "secondary"
|
|
352
|
+
? android
|
|
353
|
+
? m.onSurfaceVariant
|
|
354
|
+
: theme.colors.labelSecondary
|
|
355
|
+
: theme.color(`--color-text-${tone}-ghost`, theme.colors.accent);
|
|
356
|
+
const size = android ? 24 : theme.length("--bottom-sheet-hero-icon-size", 56);
|
|
357
|
+
return (_jsxs(View, { style: [styles.hero, { paddingBottom: 24 }], children: [hero.icon != null ? (_jsx(View, { style: { marginBottom: android ? 16 : 12 }, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: _jsx(IconDefaultsProvider, { size: size, color: ink, children: hero.icon }) })) : null, _jsx(Text, { nativeID: id, accessibilityRole: "header", align: "center", weight: android ? "regular" : "bold", color: android ? m.onSurface : undefined, style: android ? { fontSize: 24, lineHeight: 32 } : { fontSize: theme.length("--bottom-sheet-hero-title-font-size", 28), lineHeight: theme.length("--bottom-sheet-hero-title-line-height", 34) }, children: hero.title }), hero.description != null ? (_jsx(Text, { align: "center", color: android ? m.onSurfaceVariant : theme.colors.labelSecondary, style: android ? { fontSize: 14, lineHeight: 20, marginTop: 16 } : { fontSize: 17, lineHeight: 22, marginTop: 4 }, children: hero.description })) : null] }));
|
|
358
|
+
}
|
|
359
|
+
/** iOS 26's bottom action of a sheet: 36 from the sides, as BottomActions on a screen. */
|
|
360
|
+
const IOS_ACTION_SIDE = 36;
|
|
361
|
+
/** Close and Back in an iOS 26 sheet's bar: 20 from its top and sides. */
|
|
362
|
+
const IOS_BAR_INSET = 20;
|
|
363
|
+
const IOS_ACTION_HEIGHT = 52;
|
|
364
|
+
/** The footer's Buttons on iOS: blocks 52 tall, capsules, as BottomActions sets them; other elements stand as given. */
|
|
365
|
+
function iosActions(children) {
|
|
366
|
+
return Children.map(children, (child) => {
|
|
367
|
+
if (!isValidElement(child) || child.type !== Button)
|
|
368
|
+
return child;
|
|
369
|
+
const props = child.props;
|
|
370
|
+
return cloneElement(child, {
|
|
371
|
+
block: props.block ?? true,
|
|
372
|
+
size: props.size ?? "3xl",
|
|
373
|
+
style: [{ minHeight: IOS_ACTION_HEIGHT, borderRadius: IOS_ACTION_HEIGHT / 2 }, props.style],
|
|
374
|
+
});
|
|
375
|
+
});
|
|
306
376
|
}
|
|
307
377
|
const isFooter = (child) => isValidElement(child) && child.type === BottomSheetFooter;
|
|
308
378
|
/** The item of an Android sheet's bar: a 46dp glass circle solved against the sheet's color. */
|
|
@@ -346,7 +416,7 @@ const styles = StyleSheet.create({
|
|
|
346
416
|
sheet: { alignSelf: "stretch", overflow: "hidden", borderCurve: "continuous", marginHorizontal: "auto", width: "100%" },
|
|
347
417
|
scroll: { flexGrow: 0, flexShrink: 1 },
|
|
348
418
|
grow: { flexGrow: 1 },
|
|
349
|
-
iosBar: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
419
|
+
iosBar: { position: "absolute", top: 0, left: 0, right: 0, zIndex: 1, flexDirection: "row", alignItems: "center", gap: 8 },
|
|
350
420
|
iosHeading: { flex: 1, alignItems: "center", justifyContent: "center" },
|
|
351
421
|
scrimTarget: { position: "absolute", top: 0, left: 0, right: 0 },
|
|
352
422
|
// The bar: 46dp circles 12 under the top edge and 12 from the sides, 11 under them; with no title the top 8 of the
|
|
@@ -356,11 +426,11 @@ const styles = StyleSheet.create({
|
|
|
356
426
|
androidCircle: { width: 46, height: 46 },
|
|
357
427
|
androidHeading: { flex: 1, minWidth: 0, alignItems: "center", justifyContent: "center" },
|
|
358
428
|
androidGrip: { height: 8 },
|
|
429
|
+
hero: { alignItems: "center" },
|
|
359
430
|
// The content 12 from the sides (as a page's groups), 16 over the navigation bar; under a bar 13 under its circles
|
|
360
431
|
// (71 from the sheet's top, 2 under the bar)
|
|
361
432
|
androidContent: { paddingHorizontal: 12, paddingTop: 4, paddingBottom: 16 },
|
|
362
|
-
iosFooter: { gap:
|
|
363
|
-
iosFooterEdge: { position: "absolute", top: -15, left: 0, right: 0, bottom: 0 },
|
|
433
|
+
iosFooter: { position: "absolute", left: 0, right: 0, bottom: 0, zIndex: 1, gap: 8, paddingTop: 12 },
|
|
364
434
|
// Android's sheet actions: 48dp buttons 4 apart, 12 from the sides and above, 12 over the gesture bar, over the
|
|
365
435
|
// content that scrolls under them
|
|
366
436
|
androidFooter: { position: "absolute", left: 0, right: 0, bottom: 0, gap: 4, paddingHorizontal: 12, paddingTop: 12 },
|
|
@@ -365,22 +365,39 @@ function ButtonBody({ color = "primary", variant = "solid", size = "md", shape =
|
|
|
365
365
|
// its buttons on glass and its plain ones; the token alone gives the Regular of the plain button
|
|
366
366
|
weight: theme.isIOS && variant !== "ghost" ? "medium" : base.weight,
|
|
367
367
|
};
|
|
368
|
-
const
|
|
368
|
+
const barred = barColors(theme, buttonColors(theme, color, variant, disabled, selected), { bar, prominent: accentAction, neutral, disabled, selected, flat: mobileMaterial === "flat" });
|
|
369
|
+
// Clear glass over a photo, a video or a color: the kit's #f5f5f5 label in both themes, on iOS clear glass and on
|
|
370
|
+
// Android (no glass) its gray at 17%, a little more when pressed
|
|
371
|
+
const clear = mobileMaterial === "clear" && neutral && !bar;
|
|
372
|
+
const clearLabel = clear ? theme.color("--mobile-glass-clear-label", "#f5f5f5") : "";
|
|
373
|
+
const colors = clear
|
|
374
|
+
? {
|
|
375
|
+
...barred,
|
|
376
|
+
text: disabled ? withAlpha(clearLabel, 0.4) : clearLabel,
|
|
377
|
+
pressedText: undefined,
|
|
378
|
+
background: theme.color("--mobile-glass-clear-background", "rgba(153, 153, 153, 0.17)"),
|
|
379
|
+
pressed: theme.color("--mobile-glass-clear-background-active", "rgba(153, 153, 153, 0.28)"),
|
|
380
|
+
border: undefined,
|
|
381
|
+
}
|
|
382
|
+
: barred;
|
|
369
383
|
// In a bar every neutral soft or ghost button is glass, as on iOS 26, unless it asks to stay flat or is selected.
|
|
370
384
|
// A disabled glass button keeps its glass, as the phone CSS's
|
|
371
385
|
const wantsGlass = bar ? mobileMaterial !== "flat" && neutral && !selected && !bar.inGroup : mobileMaterial === "glass" && neutral;
|
|
372
|
-
const glass = theme.isIOS && wantsGlass;
|
|
386
|
+
const glass = theme.isIOS && (wantsGlass || clear);
|
|
373
387
|
// On Android the same button stands on a glass of its own, as the Android bar circles: a see-through card with a
|
|
374
388
|
// rim and a soft shadow (the glass of a plain bar)
|
|
375
389
|
const card = theme.isAndroid && !!bar && !bar.plain && (wantsGlass || (accentAction && disabled && !bar.inGroup));
|
|
376
390
|
const androidGlass = useAndroidGlass("bar", bar?.canvas);
|
|
377
391
|
if (glass && !bar) {
|
|
378
|
-
// The Liquid Glass text button of the iOS 27 kit: Medium (`--button-glass-font-weight`), 17/22 at md and lg
|
|
392
|
+
// The Liquid Glass text button of the iOS 27 kit: Medium (`--button-glass-font-weight`), 17/22 at md and lg, 12 a side
|
|
379
393
|
const glassWeight = theme.length("--button-glass-font-weight", 510);
|
|
380
394
|
metrics.weight = glassWeight >= 590 ? "semibold" : glassWeight >= 500 ? "medium" : "regular";
|
|
381
395
|
if (size === "md" || size === "lg") {
|
|
382
396
|
metrics.fontSize = theme.length("--button-glass-font-size", metrics.fontSize);
|
|
383
397
|
metrics.lineHeight = theme.length("--button-glass-line-height", metrics.lineHeight);
|
|
398
|
+
// 12 each side, where a bordered medium button's Subheadline label takes 14
|
|
399
|
+
if (!gutterSize)
|
|
400
|
+
metrics.gutter = theme.length("--button-glass-gutter", metrics.gutter);
|
|
384
401
|
}
|
|
385
402
|
}
|
|
386
403
|
const nativeRipple = useMaterialPress(theme);
|
|
@@ -522,7 +539,7 @@ function ButtonBody({ color = "primary", variant = "solid", size = "md", shape =
|
|
|
522
539
|
...rest,
|
|
523
540
|
};
|
|
524
541
|
if (glass) {
|
|
525
|
-
return (_jsx(Pressable, { ...pressable, style: [{ alignSelf: block ? "stretch" : "flex-start" }, style], children: _jsx(Glass, { interactive: !inert, elevation: bar?.raised ? "raised" : "regular", radius: metrics.radius, fillToken: pressed && !inert ? "--mobile-glass-background-active" : undefined, style: [body, { borderRadius: metrics.radius }], children: content }) }));
|
|
542
|
+
return (_jsx(Pressable, { ...pressable, style: [{ alignSelf: block ? "stretch" : "flex-start" }, style], children: _jsx(Glass, { interactive: !inert, clear: clear, elevation: bar?.raised ? "raised" : "regular", radius: metrics.radius, fillToken: pressed && !inert ? (clear ? "--mobile-glass-clear-background-active" : "--mobile-glass-background-active") : undefined, style: [body, { borderRadius: metrics.radius }], children: content }) }));
|
|
526
543
|
}
|
|
527
544
|
// The pressable is the body: the native ripple is drawn and clipped by the view that has the (animated) corners
|
|
528
545
|
return (_jsxs(AnimatedPressable, { ...pressable, android_ripple: nativeRipple ? { color: pressLayer, foreground: true, ...(dot ? { borderless: true, radius: dot / 2 } : null) } : undefined, style: [body, card ? androidGlass : null, { borderRadius: corners }, scales ? { transform: [{ scale }] } : null, style], children: [layer, content] }));
|
|
@@ -5,6 +5,7 @@ import { useTheme } from "../../theme/ThemeProvider";
|
|
|
5
5
|
import { Menu, MenuSurface, hasCheckedItems, measure } from "../Menu/Menu";
|
|
6
6
|
/** A touch and hold opens the menu after half a second, as the web's ContextMenu (CONTEXT_MENU_LONG_PRESS). */
|
|
7
7
|
export const CONTEXT_MENU_LONG_PRESS = 500;
|
|
8
|
+
const CARD = { shape: "card" };
|
|
8
9
|
const ContextMenuContext = createContext(null);
|
|
9
10
|
function useContextMenu(part) {
|
|
10
11
|
const context = useContext(ContextMenuContext);
|
|
@@ -23,8 +24,9 @@ function ContextMenuRoot({ children, open: openProp, onOpenChange }) {
|
|
|
23
24
|
const [own, setOwn] = useState(false);
|
|
24
25
|
const open = openProp ?? own;
|
|
25
26
|
const [anchor, setAnchor] = useState(null);
|
|
26
|
-
const target = useRef({ node: null, preview: null });
|
|
27
|
+
const target = useRef({ node: null, preview: null, look: CARD });
|
|
27
28
|
const [preview, setPreview] = useState(null);
|
|
29
|
+
const [look, setLook] = useState(CARD);
|
|
28
30
|
const apply = useCallback((next) => {
|
|
29
31
|
if (openProp === undefined)
|
|
30
32
|
setOwn(next);
|
|
@@ -46,6 +48,7 @@ function ContextMenuRoot({ children, open: openProp, onOpenChange }) {
|
|
|
46
48
|
return;
|
|
47
49
|
setAnchor(box);
|
|
48
50
|
setPreview(target.current.preview);
|
|
51
|
+
setLook(target.current.look);
|
|
49
52
|
});
|
|
50
53
|
// A turn of the screen moves the element: the menu closes, as iOS dismisses a context menu on rotation
|
|
51
54
|
const sub = Dimensions.addEventListener("change", () => applyRef.current(false));
|
|
@@ -54,18 +57,13 @@ function ContextMenuRoot({ children, open: openProp, onOpenChange }) {
|
|
|
54
57
|
sub.remove();
|
|
55
58
|
};
|
|
56
59
|
}, [open]);
|
|
57
|
-
const setTarget = useCallback((node, next) => {
|
|
58
|
-
target.current = { node, preview: next };
|
|
60
|
+
const setTarget = useCallback((node, next, nextLook) => {
|
|
61
|
+
target.current = { node, preview: next, look: nextLook };
|
|
59
62
|
}, []);
|
|
60
|
-
return _jsx(ContextMenuContext.Provider, { value: { open, setOpen, anchor, preview, setTarget }, children: children });
|
|
63
|
+
return _jsx(ContextMenuContext.Provider, { value: { open, setOpen, anchor, preview, look, setTarget }, children: children });
|
|
61
64
|
}
|
|
62
65
|
ContextMenuRoot.displayName = "ContextMenu";
|
|
63
|
-
|
|
64
|
-
* The element the menu is for: a ListItem, a Pressable, a Button, anything with `onLongPress`. Its own press still
|
|
65
|
-
* runs; a touch and hold opens the menu, and so does a right click on the web. The lifted preview on iOS is the
|
|
66
|
-
* element drawn again from its props, so state the element keeps inside itself is not in it.
|
|
67
|
-
*/
|
|
68
|
-
function ContextMenuTrigger({ children, style }) {
|
|
66
|
+
function ContextMenuTrigger({ children, style, radius, shape = "card" }) {
|
|
69
67
|
const theme = useTheme();
|
|
70
68
|
const { setOpen, setTarget, open, anchor } = useContextMenu("ContextMenu.Trigger");
|
|
71
69
|
const child = isValidElement(children) ? children : null;
|
|
@@ -91,7 +89,7 @@ function ContextMenuTrigger({ children, style }) {
|
|
|
91
89
|
// The preview is the element drawn again over the dimming, taking no presses
|
|
92
90
|
const preview = child ? cloneElement(child, { onLongPress: undefined, onPress: undefined }) : null;
|
|
93
91
|
const web = Platform.OS === "web";
|
|
94
|
-
return (_jsx(View, { ref: (next) => setTarget(next, preview), collapsable: false,
|
|
92
|
+
return (_jsx(View, { ref: (next) => setTarget(next, preview, { radius, shape }), collapsable: false,
|
|
95
93
|
// On iOS the element hides under its lifted preview while the menu is open, so it is not drawn twice; Android
|
|
96
94
|
// keeps it lit in its place
|
|
97
95
|
style: [{ opacity: open && anchor && !theme.isAndroid ? 0 : 1 }, style], ...(web
|
|
@@ -107,16 +105,18 @@ ContextMenuTrigger.displayName = "ContextMenu.Trigger";
|
|
|
107
105
|
/** The menu: Menu's items, 250 wide on iOS. */
|
|
108
106
|
function ContextMenuContent(props) {
|
|
109
107
|
const theme = useTheme();
|
|
110
|
-
const { open, setOpen, anchor, preview } = useContextMenu("ContextMenu.Content");
|
|
111
|
-
// The preview keeps a row's corners to half its height, else the kit's 30 (--context-menu-preview-radius)
|
|
108
|
+
const { open, setOpen, anchor, preview, look } = useContextMenu("ContextMenu.Content");
|
|
109
|
+
// The preview keeps a row's corners to half its height, else the kit's 30 (--context-menu-preview-radius); a
|
|
110
|
+
// Trigger's `radius` is the element's own corners
|
|
112
111
|
// Items that say `checked` make a set of options, with the checkmark's column, as in Menu
|
|
113
112
|
const check = hasCheckedItems(props.children);
|
|
114
|
-
const
|
|
113
|
+
const half = (anchor?.height ?? 60) / 2;
|
|
114
|
+
const radius = Math.min(look.radius ?? theme.length("--context-menu-preview-radius", 30), half);
|
|
115
115
|
if (theme.isAndroid) {
|
|
116
116
|
// Android: Material's popup under the element at its end, the screen dimmed around it
|
|
117
|
-
return _jsx(MenuSurface, { ...props, check: check, open: open && anchor != null, anchor: anchor, row: anchor ? { box: anchor, radius: { top: 0, bottom: 0 } } : null, cover: false, onClose: () => setOpen(false) });
|
|
117
|
+
return _jsx(MenuSurface, { ...props, check: check, open: open && anchor != null, anchor: anchor, row: anchor ? { box: anchor, radius: { top: look.radius ?? 0, bottom: look.radius ?? 0 } } : null, cover: false, onClose: () => setOpen(false) });
|
|
118
118
|
}
|
|
119
|
-
return _jsx(MenuSurface, { ...props, check: check, open: open && anchor != null, anchor: anchor, context: { preview, radius }, onClose: () => setOpen(false) });
|
|
119
|
+
return _jsx(MenuSurface, { ...props, check: check, open: open && anchor != null, anchor: anchor, context: { preview, radius, bare: look.shape === "element" }, onClose: () => setOpen(false) });
|
|
120
120
|
}
|
|
121
121
|
ContextMenuContent.displayName = "ContextMenu.Content";
|
|
122
122
|
export const ContextMenu = Object.assign(ContextMenuRoot, {
|
|
@@ -206,7 +206,9 @@ export function fieldLook(theme, { variant, size, pill, startAdornment = false,
|
|
|
206
206
|
const row = IOS_FIELD[size] ?? IOS_FIELD.md;
|
|
207
207
|
const height = theme.length(`--control-size-${row.height}`, 44);
|
|
208
208
|
const radius = pill ? height / 2 : theme.length(`--control-radius-${row.radius}`, IOS_RADIUS[row.radius]);
|
|
209
|
-
|
|
209
|
+
// A tall capsule (50 and up) sets its text 20 in, as iOS 26's own (Mail's Add Account, Apple Account's Add Email
|
|
210
|
+
// Address); a smaller field keeps 14
|
|
211
|
+
const gutter = startAdornment ? 11 : pill && height >= 48 ? 20 : 14;
|
|
210
212
|
const border = variant === "outline"
|
|
211
213
|
? state.invalid
|
|
212
214
|
? theme.color("--input-border-color-invalid")
|
|
@@ -443,6 +443,9 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
443
443
|
// A picture wider than the tile (a photo, an avatar) keeps its own size: it starts at the row's inset, where the
|
|
444
444
|
// header and the footer stand, and the text follows 14 past it, as UIKit's image to text padding
|
|
445
445
|
const [wide, setWide] = useState(false);
|
|
446
|
+
// A picture taller than the tile (a 40 photo) keeps the cell's margins over and under it, 10 as UIKit's content
|
|
447
|
+
// configuration keeps them: a 40 photo makes a 60 row
|
|
448
|
+
const [tall, setTall] = useState(false);
|
|
446
449
|
// In a List with `columns` a field's value starts at one column, 40% into the row (`--field-row-column-width`)
|
|
447
450
|
// A switch, a checkbox and a radio stay at the row's edge
|
|
448
451
|
const columns = useContext(ListOptionsContext)?.columns === true && trailing != null;
|
|
@@ -461,11 +464,15 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
461
464
|
return (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { style: [
|
|
462
465
|
styles.tile,
|
|
463
466
|
{ minWidth: tile, minHeight: tile, marginStart: wide ? 0 : theme.length("--field-row-icon-offset", -2), marginEnd: theme.length("--field-row-icon-gap", 14) },
|
|
467
|
+
tall ? { marginVertical: theme.length("--field-row-picture-margin-block", 10) } : null,
|
|
464
468
|
leadingColor ? { backgroundColor: leadingColor, borderRadius: theme.length("--field-row-icon-radius", 7) } : null,
|
|
465
469
|
], onLayout: (event) => {
|
|
466
470
|
const next = event.nativeEvent.layout.width > tile + 0.5;
|
|
467
471
|
if (next !== wide)
|
|
468
472
|
setWide(next);
|
|
473
|
+
const taller = event.nativeEvent.layout.height > tile + 0.5;
|
|
474
|
+
if (taller !== tall)
|
|
475
|
+
setTall(taller);
|
|
469
476
|
}, children: _jsx(IconDefaultsProvider, { size: leadingColor ? 20 : theme.length("--field-row-icon-symbol-size", 24), color: leadingColor ? "#ffffff" : disabled ? theme.colors.labelTertiary : theme.colors.accent, children: leading }) })) : null, _jsxs(View, { ref: ref, onLayout: onRowLayout, style: [
|
|
470
477
|
error != null ? styles.iosColumn : styles.iosMain,
|
|
471
478
|
{ minHeight: iosMinHeight(theme, description != null || error != null), paddingEnd: inset },
|
|
@@ -492,6 +499,9 @@ function AndroidContent({ handPress, valueColor, theme, label, description, desc
|
|
|
492
499
|
// A picture wider than the symbol's 24 (a photo, an avatar) keeps its own size from the rows' inset (21, where the
|
|
493
500
|
// header and the footer stand), the text 16 past it, as Material's list item with a leading avatar; 0 for a symbol
|
|
494
501
|
const [wide, setWide] = useState(0);
|
|
502
|
+
// A picture taller than the symbol's 24 (a 40 avatar) keeps 8 over and under it, Material's list item with a leading
|
|
503
|
+
// avatar: a 40 photo makes a 56 row
|
|
504
|
+
const [tall, setTall] = useState(false);
|
|
495
505
|
// The text (and the divider) 21 in, or 64 after a symbol, a tile or a choice's mark (its 20dp circle 22 in)
|
|
496
506
|
const textStart = leading == null ? ANDROID_INSET : wide > 0 && !tile && !leadingMark ? ANDROID_INSET + wide + 16 : 64;
|
|
497
507
|
// A value that ends the row stands 17 from the end (a value row), 20 in a row with a tile (a tiled row)
|
|
@@ -506,13 +516,16 @@ function AndroidContent({ handPress, valueColor, theme, label, description, desc
|
|
|
506
516
|
const columns = useContext(ListOptionsContext)?.columns === true && trailing != null;
|
|
507
517
|
const startsColumn = columns && !edgeControl;
|
|
508
518
|
const rowEnd = useMemo(() => ({ fill: setFill, press: handPress, align: startsColumn ? "start" : "end", valueColor }), [handPress, startsColumn, valueColor]);
|
|
509
|
-
const parts = (_jsxs(_Fragment, { children: [leading == null ? null : leadingMark ? (_jsx(View, { style: styles.androidMark, children: leading })) : (_jsx(View, { style: tile ? [styles.androidTile, { backgroundColor: leadingColor, opacity: disabled ? 0.5 : 1 }] : [styles.androidIcon, wide > 0 ? styles.androidWide : null], onLayout: tile
|
|
519
|
+
const parts = (_jsxs(_Fragment, { children: [leading == null ? null : leadingMark ? (_jsx(View, { style: styles.androidMark, children: leading })) : (_jsx(View, { style: tile ? [styles.androidTile, { backgroundColor: leadingColor, opacity: disabled ? 0.5 : 1 }] : [styles.androidIcon, wide > 0 ? styles.androidWide : null, tall ? styles.androidTall : null], onLayout: tile
|
|
510
520
|
? undefined
|
|
511
521
|
: (event) => {
|
|
512
522
|
const width = event.nativeEvent.layout.width;
|
|
513
523
|
const next = width > 24.5 ? width : 0;
|
|
514
524
|
if (Math.abs(next - wide) > 0.5)
|
|
515
525
|
setWide(next);
|
|
526
|
+
const taller = event.nativeEvent.layout.height > 24.5;
|
|
527
|
+
if (taller !== tall)
|
|
528
|
+
setTall(taller);
|
|
516
529
|
}, children: _jsx(IconDefaultsProvider, { size: 24, color: tile ? "#ffffff" : symbol, children: leading }) })), _jsxs(View, { style: [
|
|
517
530
|
columns ? [styles.androidTextHug, styles.column] : fill ? styles.androidTextHug : styles.androidText,
|
|
518
531
|
// One line centred in the 50dp row (54 beside a text field: a card's input row); with a second line 12 above
|
|
@@ -557,6 +570,7 @@ const styles = StyleSheet.create({
|
|
|
557
570
|
androidFooterPlain: { paddingHorizontal: ANDROID_INSET },
|
|
558
571
|
androidRow: { flexDirection: "row", alignItems: "center", minHeight: 50, paddingStart: ANDROID_INSET, paddingEnd: ANDROID_INSET },
|
|
559
572
|
// A 24dp symbol at 20, a 28dp tile at 18 with a 24dp symbol, or a choice's 20dp mark at 22: the text at 64
|
|
573
|
+
androidTall: { marginVertical: 8 },
|
|
560
574
|
androidIcon: { minWidth: 24, minHeight: 24, alignItems: "center", justifyContent: "center", marginStart: -1, marginEnd: 20 },
|
|
561
575
|
androidWide: { marginStart: 0, marginEnd: 16 },
|
|
562
576
|
androidMark: { width: 20, alignItems: "center", justifyContent: "center", marginStart: 1, marginEnd: 22 },
|
|
@@ -213,18 +213,30 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
|
|
|
213
213
|
const fitsBelow = below + height <= window.height - bottomEdge;
|
|
214
214
|
const above = over ? box.y + box.height - height : box.y - gap - height;
|
|
215
215
|
let top = size == null ? -window.height - 1000 : fitsBelow ? below : Math.max(topEdge, above);
|
|
216
|
-
|
|
216
|
+
// A preview wider than the screen less 16 a side is scaled down about its middle to fit, as iOS 27.2 shrinks a
|
|
217
|
+
// lifted cell or card, and one that would cross the 16 is moved in: `seen` is where it shows
|
|
218
|
+
const fit = 16;
|
|
219
|
+
const fitScale = context && box.width > window.width - fit * 2 ? (window.width - fit * 2) / box.width : 1;
|
|
220
|
+
const seenWidth = box.width * fitScale;
|
|
221
|
+
const seenHeight = box.height * fitScale;
|
|
222
|
+
const seen = {
|
|
223
|
+
x: context && box.width > 0 ? Math.max(fit, Math.min(box.x + (box.width - seenWidth) / 2, window.width - fit - seenWidth)) : box.x,
|
|
224
|
+
y: box.y + (box.height - seenHeight) / 2,
|
|
225
|
+
width: seenWidth,
|
|
226
|
+
height: seenHeight,
|
|
227
|
+
};
|
|
228
|
+
let previewTop = seen.y;
|
|
217
229
|
if (context) {
|
|
218
230
|
// iOS 27.2 places a context menu by where the element stands (ref-app menus-context): in the left third at its
|
|
219
231
|
// left edge, in the right third at its right edge, else at its centre; 16 under it, or over it when the element
|
|
220
232
|
// is in the lower half and the menu fits there (the web's ContextMenu, contextMenuPreview)
|
|
221
|
-
const centre =
|
|
222
|
-
left = centre < window.width / 3 ?
|
|
233
|
+
const centre = seen.x + seen.width / 2;
|
|
234
|
+
left = centre < window.width / 3 ? seen.x : centre > (window.width * 2) / 3 ? seen.x + seen.width - measured : centre - measured / 2;
|
|
223
235
|
left = Math.max(margin, Math.min(left, window.width - measured - margin));
|
|
224
236
|
const lift = 16;
|
|
225
|
-
const overIt =
|
|
226
|
-
const underIt =
|
|
227
|
-
const lower =
|
|
237
|
+
const overIt = seen.y - lift - height;
|
|
238
|
+
const underIt = seen.y + seen.height + lift;
|
|
239
|
+
const lower = seen.y + seen.height / 2 > window.height / 2;
|
|
228
240
|
if (size != null) {
|
|
229
241
|
if (lower && overIt >= topEdge)
|
|
230
242
|
top = overIt;
|
|
@@ -232,8 +244,8 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
|
|
|
232
244
|
// Where the menu does not fit under the element it lifts the element up with it, as iOS moves the preview, so
|
|
233
245
|
// the menu never covers it
|
|
234
246
|
const overflow = underIt + height - (window.height - bottomEdge);
|
|
235
|
-
previewTop = overflow > 0 ? Math.max(topEdge,
|
|
236
|
-
top = Math.max(topEdge, Math.min(previewTop +
|
|
247
|
+
previewTop = overflow > 0 ? Math.max(topEdge, seen.y - overflow) : seen.y;
|
|
248
|
+
top = Math.max(topEdge, Math.min(previewTop + seen.height + lift, window.height - bottomEdge - height));
|
|
237
249
|
}
|
|
238
250
|
}
|
|
239
251
|
}
|
|
@@ -320,13 +332,16 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
|
|
|
320
332
|
web ? { backdropFilter: "blur(30px)", WebkitBackdropFilter: "blur(30px)" } : null,
|
|
321
333
|
] }), _jsx(View, { pointerEvents: "none", style: [
|
|
322
334
|
styles.preview,
|
|
323
|
-
|
|
335
|
+
// Drawn at its own size and scaled about its middle onto where it is seen
|
|
336
|
+
swap ? { right: seen.x + (seen.width - box.width) / 2 } : { left: seen.x + (seen.width - box.width) / 2 },
|
|
324
337
|
{
|
|
325
|
-
top: previewTop,
|
|
338
|
+
top: previewTop + (seen.height - box.height) / 2,
|
|
326
339
|
width: box.width,
|
|
327
340
|
height: box.height,
|
|
341
|
+
transform: fitScale < 1 ? [{ scale: fitScale }] : undefined,
|
|
328
342
|
borderRadius: context.radius,
|
|
329
|
-
|
|
343
|
+
// An element that draws its own shape lifts as it is: no card behind it and no clip of its own
|
|
344
|
+
...(context.bare ? { overflow: "visible" } : { backgroundColor: theme.colors.groupedSurface }),
|
|
330
345
|
boxShadow: String(theme.token("--context-menu-preview-shadow") ?? "0 0 32px rgba(0, 0, 0, 0.2)"),
|
|
331
346
|
},
|
|
332
347
|
], children: context.preview })] })) : null, _jsx(Animated.View, { ref: panel, ...(web ? { tabIndex: -1 } : null), accessibilityRole: "menu", "aria-label": ariaLabel, ...keysOf(panel), onLayout: (event) => setSize({ width: event.nativeEvent.layout.width, height: event.nativeEvent.layout.height }), style: [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { cloneElement, isValidElement, useState } from "react";
|
|
3
|
-
import { StyleSheet, View, useWindowDimensions } from "react-native";
|
|
3
|
+
import { ActivityIndicator, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
5
|
import Svg, { Path } from "react-native-svg";
|
|
6
6
|
import X from "../../icons/plex/X";
|
|
@@ -8,7 +8,7 @@ import { flattenChildren, isRenderable, textOf } from "../../internal/children";
|
|
|
8
8
|
import { FloatingPanel } from "../../internal/FloatingPanel";
|
|
9
9
|
import { anchorProps } from "../../internal/floating";
|
|
10
10
|
import { Glass } from "../../internal/Glass";
|
|
11
|
-
import { accentText, barSurface, controlHighlight, dangerText, elevationShadow } from "../../theme/material";
|
|
11
|
+
import { accentText, barSurface, controlHighlight, dangerText, elevationShadow, withAlpha } from "../../theme/material";
|
|
12
12
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
13
13
|
import { Button } from "../Button/Button";
|
|
14
14
|
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
@@ -66,37 +66,50 @@ function TipBody({ title, description, icon, actions, mobileActions = "rows", on
|
|
|
66
66
|
const closable = onClose != null;
|
|
67
67
|
const descriptionColor = android ? theme.colors.textSecondary : theme.color("--tip-description-color", theme.colors.textSecondary);
|
|
68
68
|
const paddingBottom = !hasActions ? m.bottomNone : buttons ? m.bottomButtons : m.bottomRows;
|
|
69
|
+
// iOS's tip with button actions is TipKit's mini tip (its kit's Hint View): 22 over the title, 4 between the title
|
|
70
|
+
// and the message, 22 from the words to the action and 16 under it
|
|
71
|
+
const miniTip = !android && hasActions && buttons;
|
|
69
72
|
const textStart = hasIcon ? m.iconFrame + m.iconGap : 0;
|
|
70
73
|
return (_jsxs(View, { role: role, "aria-label": role ? textOf(title) || undefined : undefined, testID: testID, style: [
|
|
71
74
|
styles.tip,
|
|
72
75
|
{
|
|
73
76
|
borderRadius: m.radius,
|
|
74
|
-
paddingTop: m.top,
|
|
77
|
+
paddingTop: miniTip ? 22 : m.top,
|
|
75
78
|
paddingHorizontal: m.inline,
|
|
76
79
|
paddingBottom,
|
|
77
80
|
columnGap: m.iconGap,
|
|
78
|
-
rowGap: hasActions && buttons ? m.gapButtons : m.gap,
|
|
81
|
+
rowGap: miniTip ? 22 : hasActions && buttons ? m.gapButtons : m.gap,
|
|
79
82
|
backgroundColor: background ?? theme.colors.groupedSurface,
|
|
80
83
|
},
|
|
81
84
|
style,
|
|
82
|
-
], children: [children, hasIcon ? (_jsx(View, { style: [styles.icon, { width: m.iconFrame, height: m.iconFrame }], children: _jsx(IconDefaultsProvider, { size: m.icon, color: descriptionColor, children: icon }) })) : null, _jsxs(View, { style: [styles.message, closable ? { paddingEnd: m.messageEnd } : null], children: [_jsx(Text, { variant: "headline", children: title }), isRenderable(description) ? (_jsx(TextColorProvider, { value: descriptionColor, children: _jsx(Text, { variant: "subheadline", color: descriptionColor, style: android ? styles.androidDescription : null, children: description }) })) : null] }), hasActions ? (_jsx(View, { style: [
|
|
85
|
+
], children: [children, hasIcon ? (_jsx(View, { style: [styles.icon, { width: m.iconFrame, height: m.iconFrame }], children: _jsx(IconDefaultsProvider, { size: m.icon, color: descriptionColor, children: icon }) })) : null, _jsxs(View, { style: [styles.message, closable ? { paddingEnd: m.messageEnd } : null], children: [_jsx(Text, { variant: "headline", children: title }), isRenderable(description) ? (_jsx(TextColorProvider, { value: descriptionColor, children: _jsx(Text, { variant: "subheadline", color: descriptionColor, style: android ? styles.androidDescription : miniTip ? styles.miniDescription : null, children: description }) })) : null] }), hasActions ? (_jsx(View, { style: [
|
|
83
86
|
styles.actions,
|
|
84
87
|
buttons ? styles.buttons : android ? [styles.androidActions, { marginStart: textStart - ANDROID_TEXT_BUTTON_INSET }] : { paddingStart: textStart },
|
|
85
88
|
], children: items.map((item, index) => (buttons ? _jsx(ActionButton, { item: item }, index) : _jsx(ActionRow, { item: item }, index))) })) : null, closable ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: closeLabel, onPress: onClose, style: [styles.close, { width: m.closeTarget, height: m.closeTarget, top: m.closeTop, end: m.closeEnd, borderRadius: m.closeTarget / 2 }], children: ({ pressed }) => (_jsx(View, { style: [styles.closeGlyph, android && pressed ? { backgroundColor: controlHighlight(theme.scheme), borderRadius: m.closeTarget / 2 } : null], children: _jsx(X, { size: m.closeIcon, color: android ? theme.colors.labelSecondary : theme.colors.labelTertiary, style: !android && pressed ? styles.pressed : undefined }) })) })) : null] }));
|
|
86
89
|
}
|
|
87
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* An action as a capsule across the tip. On iOS it is TipKit's action (the kit's Hint View): 50 tall, a 17 Semibold
|
|
92
|
+
* label in the action's color (the accent for a primary one) on that color at 8% over the gray fill at 8%. On Android
|
|
93
|
+
* the Button keeps its color and variant, a 40dp capsule.
|
|
94
|
+
*/
|
|
88
95
|
function ActionButton({ item }) {
|
|
89
96
|
const theme = useTheme();
|
|
90
97
|
if (!isValidElement(item) || item.type !== Button)
|
|
91
98
|
return _jsx(_Fragment, { children: item });
|
|
92
99
|
const button = item;
|
|
93
|
-
|
|
94
|
-
size:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
if (theme.isAndroid)
|
|
101
|
+
return cloneElement(button, { size: "lg", pill: true, block: true });
|
|
102
|
+
// The Button's look props stay here; its handlers, ref and accessibility props pass on to the capsule
|
|
103
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
104
|
+
const { color = "primary", children, disabled = false, loading = false, inert: inertProp = loading, variant, size, pill, shape, mobileMaterial, uniform, block, labelLines, selected, iconSize, gutterSize, opticallyAlign, style, accessibilityState, ...pressable } = button.props;
|
|
105
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
106
|
+
// As the Button: a loading or inert action takes no presses and keeps its look; a disabled one dims
|
|
107
|
+
const inert = disabled || inertProp;
|
|
108
|
+
const ink = color === "primary" ? theme.colors.accent : theme.color(`--color-text-${color}-ghost`, theme.colors.accent);
|
|
109
|
+
return (_jsxs(Pressable, { accessibilityRole: "button", ...pressable, accessibilityState: { ...accessibilityState, disabled: inert, busy: loading }, "aria-busy": loading, disabled: inert, style: ({ pressed }) => [styles.miniAction, { backgroundColor: MINI_GRAY, opacity: disabled ? 0.4 : 1 }, pressed && !inert ? styles.pressed : null], children: [_jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, styles.miniActionTint, { backgroundColor: withAlpha(ink, 0.08) }] }), loading ? (_jsx(ActivityIndicator, { color: ink })) : (_jsx(Text, { variant: "body", weight: "semibold", numberOfLines: 2, style: styles.miniLabel, color: ink, children: children }))] }));
|
|
99
110
|
}
|
|
111
|
+
/** The gray under a TipKit action's tint: the kit's rgba(116, 116, 128, 0.08). */
|
|
112
|
+
const MINI_GRAY = "rgba(116, 116, 128, 0.08)";
|
|
100
113
|
/**
|
|
101
114
|
* An action as a row of text in its Button's color under a separator, 46 tall, as iOS tips list them; on Android a
|
|
102
115
|
* text button in the accent, as Material 3's rich tooltip sets its actions. Other elements stand as given.
|
|
@@ -182,6 +195,10 @@ const styles = StyleSheet.create({
|
|
|
182
195
|
androidDescription: { marginTop: 2 },
|
|
183
196
|
actions: { flexBasis: "100%", flexGrow: 1, flexDirection: "column" },
|
|
184
197
|
buttons: { gap: 10 },
|
|
198
|
+
miniDescription: { marginTop: 4 },
|
|
199
|
+
miniAction: { minHeight: 50, paddingHorizontal: 20, paddingVertical: 14, borderRadius: 25, borderCurve: "continuous", alignItems: "center", justifyContent: "center", overflow: "hidden" },
|
|
200
|
+
miniActionTint: { borderRadius: 25 },
|
|
201
|
+
miniLabel: { lineHeight: 18, textAlign: "center" },
|
|
185
202
|
androidActions: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
|
186
203
|
row: { minHeight: 46, paddingVertical: 12, borderTopWidth: 1, justifyContent: "center" },
|
|
187
204
|
androidRow: { alignSelf: "flex-start", minHeight: 40, paddingHorizontal: 12, borderRadius: 20, justifyContent: "center" },
|