@plexui/react-native 0.2.11 → 0.2.13
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.
|
@@ -41,7 +41,7 @@ export function Dialog({ open, onOpenChange, title, description, actions = [], c
|
|
|
41
41
|
? { role: "alertdialog", "aria-modal": true, "aria-labelledby": ids.title, "aria-describedby": description != null ? ids.description : undefined }
|
|
42
42
|
: { accessibilityRole: "alert", accessibilityViewIsModal: true };
|
|
43
43
|
if (theme.isAndroid) {
|
|
44
|
-
return (_jsx(AndroidFrame, { open: open, onClose: close, dismissible: dismissible ?? true, a11y: a11y, testID: testID, children: _jsx(AndroidDialog, { theme: theme, title: title, description: description, actions: actions, run: run, ids: ids, children: children }) }));
|
|
44
|
+
return (_jsx(AndroidFrame, { open: open, onClose: close, dismissible: dismissible ?? true, a11y: a11y, testID: testID, children: _jsx(AndroidDialog, { theme: theme, title: title, description: description, actions: actions, run: run, ids: ids, layout: mobileLayout, children: children }) }));
|
|
45
45
|
}
|
|
46
46
|
// With reduced motion it fades in place (Dialog.module.css): no scale
|
|
47
47
|
const scale = !theme.reducedMotion && canTransformGlass;
|
|
@@ -151,8 +151,10 @@ function IOSAlert({ theme, title, description, actions, run, ids, layout, childr
|
|
|
151
151
|
// Two stacked because their labels do not fit: Cancel last, at the bottom, as UIAlertController stacks them
|
|
152
152
|
const autoStacked = !inline && layout == null && actions.length === 2;
|
|
153
153
|
const ordered = inline ? [...cancel, ...others] : autoStacked ? [...others, ...cancel] : indexed;
|
|
154
|
+
// Until both labels are measured the alert is unseen: its first frame shows the actions as they stay
|
|
155
|
+
const ready = !(layout == null && actions.length === 2) || actions.every((_, index) => labels[index] != null);
|
|
154
156
|
const type = { fontSize: theme.length("--dialog-mobile-type-size", 17), lineHeight: theme.length("--dialog-mobile-type-leading", 22) };
|
|
155
|
-
return (_jsxs(Glass, { radius: radius, elevation: "raised", fillToken: "--dialog-alert-background", style: { width, flexShrink: 1, padding, gap: 10 }, children: [layout == null && actions.length === 2 ? (
|
|
157
|
+
return (_jsxs(Glass, { radius: radius, elevation: "raised", fillToken: "--dialog-alert-background", style: { width, flexShrink: 1, padding, gap: 10, opacity: ready ? 1 : 0 }, children: [layout == null && actions.length === 2 ? (
|
|
156
158
|
// The labels on one line, unseen, to tell whether two fit side by side
|
|
157
159
|
_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) => {
|
|
158
160
|
const next = event.nativeEvent.layout.width;
|
|
@@ -192,7 +194,7 @@ function IOSAction({ theme, action, run, type, grow }) {
|
|
|
192
194
|
grow ? styles.grow : null,
|
|
193
195
|
], children: _jsx(Text, { color: text, weight: action.preferred ? "semibold" : "medium", style: [type, styles.centered], children: action.label }) }));
|
|
194
196
|
}
|
|
195
|
-
function AndroidDialog({ theme, title, description, actions, run, ids, children, list }) {
|
|
197
|
+
function AndroidDialog({ theme, title, description, actions, run, ids, children, list, layout }) {
|
|
196
198
|
const m = theme.material;
|
|
197
199
|
const { width: screen } = useWindowDimensions();
|
|
198
200
|
// Android's alert: 48 from the screen's sides, at most 356 wide
|
|
@@ -206,16 +208,22 @@ function AndroidDialog({ theme, title, description, actions, run, ids, children,
|
|
|
206
208
|
// Each button's own width, measured in either layout (their content's, never stretched), and the row's: they stack
|
|
207
209
|
// when they do not fit side by side
|
|
208
210
|
const [room, setRoom] = useState(0);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
const
|
|
211
|
+
// Kept by each button's key (its place in `actions`), which stays with it when the row reorders: a button that moves
|
|
212
|
+
// in the row keeps its element and is not measured again
|
|
213
|
+
const [widths, setWidths] = useState({});
|
|
214
|
+
const keys = bar.map((action) => actions.indexOf(action));
|
|
215
|
+
const measured = keys.every((key) => widths[key] != null);
|
|
216
|
+
const needed = keys.reduce((sum, key) => sum + (widths[key] ?? 0), 0) + GAP * Math.max(0, bar.length - 1);
|
|
217
|
+
// Until the buttons and the row are measured the panel is unseen: its first frame shows them as they stay
|
|
218
|
+
const ready = layout != null || bar.length === 0 || (room > 0 && measured);
|
|
219
|
+
const stacked = layout === "stacked" || (layout !== "inline" && room > 0 && measured && needed > room + 0.5);
|
|
213
220
|
const order = stacked ? [...bar.keys()].reverse() : [...bar.keys()];
|
|
214
221
|
const button = (index) => {
|
|
215
222
|
const action = bar[index];
|
|
216
|
-
|
|
223
|
+
const key = keys[index];
|
|
224
|
+
return (_jsx(AndroidDialogButton, { theme: theme, action: action, run: run, onWidth: (next) => setWidths((current) => (current[key] === next ? current : { ...current, [key]: next })) }, key));
|
|
217
225
|
};
|
|
218
|
-
return (_jsxs(View, { style: [styles.android, { width, backgroundColor: androidDialogBackground(theme) }], children: [list != null ? (
|
|
226
|
+
return (_jsxs(View, { style: [styles.android, { width, backgroundColor: androidDialogBackground(theme), opacity: ready ? 1 : 0 }], children: [list != null ? (
|
|
219
227
|
// A list: the title stays, 14 over the rows, and the rows scroll under it (AlertDialog with a custom view)
|
|
220
228
|
_jsxs(_Fragment, { children: [title != null ? (_jsx(Text, { nativeID: ids.title, color: m.onSurface, accessibilityRole: "header", style: [styles.androidTitle, styles.androidListTitle, theme.font("medium")], children: title })) : null, _jsx(ScrollView, { style: styles.scroll, contentContainerStyle: title != null ? null : styles.androidListTop, bounces: false, children: list })] })) : (_jsxs(ScrollView, { style: styles.scroll, contentContainerStyle: styles.androidText, bounces: false, children: [_jsx(Text, { nativeID: ids.title, color: m.onSurface, accessibilityRole: "header", style: [styles.androidTitle, theme.font("medium")], children: title }), description != null ? (_jsx(Text, { nativeID: ids.description, color: m.onSurface, style: styles.androidMessage, children: description })) : null, children != null ? _jsx(View, { style: styles.androidContent, children: children }) : null] })), bar.length ? (_jsx(View, { onLayout: (event) => setRoom(event.nativeEvent.layout.width - 16), style: stacked ? styles.androidStack : styles.androidActions, children: order.map((index) =>
|
|
221
229
|
// The neutral actions at the start, a space, then the negative and the positive
|
|
@@ -22,7 +22,10 @@ export type DialogProps = {
|
|
|
22
22
|
actions?: DialogAction[];
|
|
23
23
|
/** Content between the text and the actions, as a text field. */
|
|
24
24
|
children?: ReactNode;
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* `stacked` stacks the actions, `inline` keeps them in a row, on iOS and Android. @default iOS: two side by side
|
|
27
|
+
* while their labels fit on one line, three or more stacked; Android: in a row while they fit, else stacked
|
|
28
|
+
*/
|
|
26
29
|
mobileLayout?: "inline" | "stacked";
|
|
27
30
|
/** A tap outside, Android's back and Escape close it: Android's dialogs do, an iOS alert does not. @default Android true, iOS false */
|
|
28
31
|
dismissible?: boolean;
|
package/package.json
CHANGED
|
@@ -34,7 +34,10 @@ export type DialogProps = {
|
|
|
34
34
|
actions?: DialogAction[]
|
|
35
35
|
/** Content between the text and the actions, as a text field. */
|
|
36
36
|
children?: ReactNode
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* `stacked` stacks the actions, `inline` keeps them in a row, on iOS and Android. @default iOS: two side by side
|
|
39
|
+
* while their labels fit on one line, three or more stacked; Android: in a row while they fit, else stacked
|
|
40
|
+
*/
|
|
38
41
|
mobileLayout?: "inline" | "stacked"
|
|
39
42
|
/** A tap outside, Android's back and Escape close it: Android's dialogs do, an iOS alert does not. @default Android true, iOS false */
|
|
40
43
|
dismissible?: boolean
|
|
@@ -73,7 +76,7 @@ export function Dialog({ open, onOpenChange, title, description, actions = [], c
|
|
|
73
76
|
if (theme.isAndroid) {
|
|
74
77
|
return (
|
|
75
78
|
<AndroidFrame open={open} onClose={close} dismissible={dismissible ?? true} a11y={a11y} testID={testID}>
|
|
76
|
-
<AndroidDialog theme={theme} title={title} description={description} actions={actions} run={run} ids={ids}>
|
|
79
|
+
<AndroidDialog theme={theme} title={title} description={description} actions={actions} run={run} ids={ids} layout={mobileLayout}>
|
|
77
80
|
{children}
|
|
78
81
|
</AndroidDialog>
|
|
79
82
|
</AndroidFrame>
|
|
@@ -296,6 +299,8 @@ type AndroidPanelProps = Omit<PanelProps, "title"> & {
|
|
|
296
299
|
title?: ReactNode
|
|
297
300
|
/** Rows across the panel's width under the title, in place of the text (an Android dialog with a list of rows). */
|
|
298
301
|
list?: ReactNode
|
|
302
|
+
/** The buttons in a row or stacked; by default in a row while they fit. */
|
|
303
|
+
layout?: "inline" | "stacked"
|
|
299
304
|
}
|
|
300
305
|
|
|
301
306
|
/** An iOS alert action's label inset from its capsule's ends. */
|
|
@@ -321,9 +326,11 @@ function IOSAlert({ theme, title, description, actions, run, ids, layout, childr
|
|
|
321
326
|
// Two stacked because their labels do not fit: Cancel last, at the bottom, as UIAlertController stacks them
|
|
322
327
|
const autoStacked = !inline && layout == null && actions.length === 2
|
|
323
328
|
const ordered = inline ? [...cancel, ...others] : autoStacked ? [...others, ...cancel] : indexed
|
|
329
|
+
// Until both labels are measured the alert is unseen: its first frame shows the actions as they stay
|
|
330
|
+
const ready = !(layout == null && actions.length === 2) || actions.every((_, index) => labels[index] != null)
|
|
324
331
|
const type = { fontSize: theme.length("--dialog-mobile-type-size", 17), lineHeight: theme.length("--dialog-mobile-type-leading", 22) }
|
|
325
332
|
return (
|
|
326
|
-
<Glass radius={radius} elevation="raised" fillToken="--dialog-alert-background" style={{ width, flexShrink: 1, padding, gap: 10 }}>
|
|
333
|
+
<Glass radius={radius} elevation="raised" fillToken="--dialog-alert-background" style={{ width, flexShrink: 1, padding, gap: 10, opacity: ready ? 1 : 0 }}>
|
|
327
334
|
{layout == null && actions.length === 2 ? (
|
|
328
335
|
// The labels on one line, unseen, to tell whether two fit side by side
|
|
329
336
|
<View pointerEvents="none" aria-hidden style={styles.measure}>
|
|
@@ -418,7 +425,7 @@ function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: D
|
|
|
418
425
|
)
|
|
419
426
|
}
|
|
420
427
|
|
|
421
|
-
function AndroidDialog({ theme, title, description, actions, run, ids, children, list }: AndroidPanelProps) {
|
|
428
|
+
function AndroidDialog({ theme, title, description, actions, run, ids, children, list, layout }: AndroidPanelProps) {
|
|
422
429
|
const m = theme.material
|
|
423
430
|
const { width: screen } = useWindowDimensions()
|
|
424
431
|
// Android's alert: 48 from the screen's sides, at most 356 wide
|
|
@@ -432,25 +439,31 @@ function AndroidDialog({ theme, title, description, actions, run, ids, children,
|
|
|
432
439
|
// Each button's own width, measured in either layout (their content's, never stretched), and the row's: they stack
|
|
433
440
|
// when they do not fit side by side
|
|
434
441
|
const [room, setRoom] = useState(0)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const
|
|
438
|
-
const
|
|
442
|
+
// Kept by each button's key (its place in `actions`), which stays with it when the row reorders: a button that moves
|
|
443
|
+
// in the row keeps its element and is not measured again
|
|
444
|
+
const [widths, setWidths] = useState<Record<number, number>>({})
|
|
445
|
+
const keys = bar.map((action) => actions.indexOf(action))
|
|
446
|
+
const measured = keys.every((key) => widths[key] != null)
|
|
447
|
+
const needed = keys.reduce((sum, key) => sum + (widths[key] ?? 0), 0) + GAP * Math.max(0, bar.length - 1)
|
|
448
|
+
// Until the buttons and the row are measured the panel is unseen: its first frame shows them as they stay
|
|
449
|
+
const ready = layout != null || bar.length === 0 || (room > 0 && measured)
|
|
450
|
+
const stacked = layout === "stacked" || (layout !== "inline" && room > 0 && measured && needed > room + 0.5)
|
|
439
451
|
const order = stacked ? [...bar.keys()].reverse() : [...bar.keys()]
|
|
440
452
|
const button = (index: number) => {
|
|
441
453
|
const action = bar[index]
|
|
454
|
+
const key = keys[index]
|
|
442
455
|
return (
|
|
443
456
|
<AndroidDialogButton
|
|
444
|
-
key={
|
|
457
|
+
key={key}
|
|
445
458
|
theme={theme}
|
|
446
459
|
action={action}
|
|
447
460
|
run={run}
|
|
448
|
-
onWidth={(next) => setWidths((current) => (current[
|
|
461
|
+
onWidth={(next) => setWidths((current) => (current[key] === next ? current : { ...current, [key]: next }))}
|
|
449
462
|
/>
|
|
450
463
|
)
|
|
451
464
|
}
|
|
452
465
|
return (
|
|
453
|
-
<View style={[styles.android, { width, backgroundColor: androidDialogBackground(theme) }]}>
|
|
466
|
+
<View style={[styles.android, { width, backgroundColor: androidDialogBackground(theme), opacity: ready ? 1 : 0 }]}>
|
|
454
467
|
{list != null ? (
|
|
455
468
|
// A list: the title stays, 14 over the rows, and the rows scroll under it (AlertDialog with a custom view)
|
|
456
469
|
<>
|