@delacour/react-native-ui 0.1.0-alpha.20261006141045 → 0.1.0-alpha.20261006141648
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/package.json +4 -3
- package/src/components/dialog/AGENTS.md +97 -0
- package/src/components/dialog/dialog-body.tsx +21 -0
- package/src/components/dialog/dialog-close.tsx +82 -0
- package/src/components/dialog/dialog-content.tsx +153 -0
- package/src/components/dialog/dialog-description.tsx +23 -0
- package/src/components/dialog/dialog-footer.tsx +32 -0
- package/src/components/dialog/dialog-header.tsx +20 -0
- package/src/components/dialog/dialog-title.tsx +42 -0
- package/src/components/dialog/dialog-trigger.tsx +54 -0
- package/src/components/dialog/dialog.context.tsx +90 -0
- package/src/components/dialog/dialog.tsx +119 -0
- package/src/components/dialog/dialog.variants.test.ts +224 -0
- package/src/components/dialog/dialog.variants.ts +173 -0
- package/src/components/dialog/index.ts +30 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.20261006141648",
|
|
4
4
|
"description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"./checkbox": "./src/components/checkbox/index.ts",
|
|
46
46
|
"./chip": "./src/components/chip/index.ts",
|
|
47
47
|
"./collapsible": "./src/components/collapsible/index.ts",
|
|
48
|
+
"./dialog": "./src/components/dialog/index.ts",
|
|
48
49
|
"./empty-state": "./src/components/empty-state/index.ts",
|
|
49
50
|
"./field": "./src/components/field/index.ts",
|
|
50
51
|
"./icon": "./src/components/icon/index.ts",
|
|
@@ -104,8 +105,8 @@
|
|
|
104
105
|
},
|
|
105
106
|
"peerDependencies": {
|
|
106
107
|
"@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
|
|
107
|
-
"@delacour/react-native-bottom-sheet": "0.1.0-alpha.
|
|
108
|
-
"@delacour/react-native-charts": "0.1.0-alpha.
|
|
108
|
+
"@delacour/react-native-bottom-sheet": "0.1.0-alpha.20261006141648",
|
|
109
|
+
"@delacour/react-native-charts": "0.1.0-alpha.20261006141648",
|
|
109
110
|
"@legendapp/list": ">=3.3",
|
|
110
111
|
"expo-linear-gradient": ">=15",
|
|
111
112
|
"expo-router": ">=57",
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Dialog
|
|
2
|
+
|
|
3
|
+
A centred card over a dimmed app that asks for a decision or a short input before the user goes
|
|
4
|
+
on: confirm a delete, rename a file, accept terms. Compound root plus `Dialog.Trigger`,
|
|
5
|
+
`Dialog.Content`, `Dialog.Close`, `Dialog.Header`, `Dialog.Title`, `Dialog.Description`,
|
|
6
|
+
`Dialog.Body` and `Dialog.Footer`, and `useDialog()`.
|
|
7
|
+
|
|
8
|
+
`import { Dialog } from "@delacour/react-native-ui/dialog";`
|
|
9
|
+
|
|
10
|
+
It is drawn with the [overlay foundation](../overlay/AGENTS.md) — `Overlay.Portal`,
|
|
11
|
+
`Overlay.Scrim`, `useOverlayPresence`, `useOverlayBackHandler` — so the app has to mount
|
|
12
|
+
`OverlayProvider` once at its root. Without one the dialog draws inline and warns once.
|
|
13
|
+
|
|
14
|
+
## Files
|
|
15
|
+
|
|
16
|
+
| File | What it holds |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `index.ts` | → `@delacour/react-native-ui/dialog` |
|
|
19
|
+
| `dialog.tsx` | Root — the open state, the ids and the focus refs — and the `Object.assign` compound surface |
|
|
20
|
+
| `dialog.context.tsx` | **Leaf.** `DialogProvider`, `DialogSizeProvider`, `useDialog()`, `useDialogContext()`, `useDialogPart()`, `useDialogSize()` |
|
|
21
|
+
| `dialog-trigger.tsx` | `Dialog.Trigger` — donates the open with `asChild`, keeps the trigger's ref for focus return |
|
|
22
|
+
| `dialog-content.tsx` | `Dialog.Content` — presence, portal, scrim, card, motion, keyboard lift, back button, focus |
|
|
23
|
+
| `dialog-close.tsx` | `Dialog.Close` — the corner ✕, or with `asChild` any control that closes |
|
|
24
|
+
| `dialog-header.tsx` | `Dialog.Header` |
|
|
25
|
+
| `dialog-title.tsx` | `Dialog.Title` — a `Text.Header` carrying the title `nativeID` and the focus ref |
|
|
26
|
+
| `dialog-description.tsx` | `Dialog.Description` — a muted `Text.Paragraph` |
|
|
27
|
+
| `dialog-body.tsx` | `Dialog.Body` |
|
|
28
|
+
| `dialog-footer.tsx` | `Dialog.Footer` — `plain` or `panel`, row or stacked by size |
|
|
29
|
+
| `dialog.variants.ts` | The slotted `tv()`, the size classes, the motion and slop constants, and three pure resolvers — no RN imports |
|
|
30
|
+
| `dialog.variants.test.ts` | Slots per size and footer variant, tokens in both themes, the resolvers |
|
|
31
|
+
|
|
32
|
+
## Design
|
|
33
|
+
|
|
34
|
+
- **One axis on the card, one on the footer.** `size` (`sm` 320, `md` 400, `lg` 520, `full`) is a
|
|
35
|
+
`max-w-*` on a `w-full` card, so a narrow phone shrinks every size to the screen gutter and only
|
|
36
|
+
a wider screen reaches the cap. `Dialog.Footer`'s `variant` is `plain` — a right-aligned row
|
|
37
|
+
inside the card's padding — or `panel`, which bleeds out of the padding to the card's edges on a
|
|
38
|
+
`bg-muted` band under a hairline, rounding only its bottom corners.
|
|
39
|
+
- **An `sm` footer stacks.** Two labelled buttons side by side on a 320pt card leave each label a
|
|
40
|
+
few characters before it truncates. `resolveDialogFooterDirection` is the rule, and the footer
|
|
41
|
+
reads the size from `DialogSizeProvider`, which `Dialog.Content` mounts — a context of its own
|
|
42
|
+
rather than a field on the root's, because the size belongs to the content, not the dialog.
|
|
43
|
+
Stacked actions keep written order, so the primary action, written last, sits last either way.
|
|
44
|
+
- **The card is a popover surface with the card corner.** `bg-popover`, the token a layer over the
|
|
45
|
+
app paints with (as `BottomSheet` does), and `rounded-lg`, the package's card step. The scrim is
|
|
46
|
+
the foundation's `bg-overlay` at opacity 1, faded by presence.
|
|
47
|
+
- **`Dialog.Content` renders nothing until the dialog opens, and stays through the exit.**
|
|
48
|
+
`useOverlayPresence` keeps it mounted until the exit animation ends, and the portal is mounted
|
|
49
|
+
only while present, so the registry entry, the z-order and the back handler all follow presence
|
|
50
|
+
— the foundation's contract. A re-open mid-exit reverses from wherever `progress` is.
|
|
51
|
+
- **It draws in the `modal` band**, above every bottom sheet and the navigator's header. A sheet
|
|
52
|
+
opened *from* a dialog would draw under it; open a dialog from a sheet, never the reverse.
|
|
53
|
+
- **Every path to closed is one `setOpen(false)`** — the trigger, `Dialog.Close`, the scrim, the
|
|
54
|
+
back button, the escape gesture and `useDialog().close()`. The root drops a set that does not
|
|
55
|
+
change the value, so a second tap on the scrim while the card is already leaving does not report
|
|
56
|
+
`onOpenChange(false)` twice.
|
|
57
|
+
- **`isDismissible={false}` turns off the ways out the user did not choose.** The scrim still takes
|
|
58
|
+
the touch — the app under an alert dialog must not be pressable — but does nothing; the back
|
|
59
|
+
button is not subscribed; `onAccessibilityEscape` is not set; and the card announces as
|
|
60
|
+
`alertdialog`. `Dialog.Close` still closes it: it is one of the dialog's own actions.
|
|
61
|
+
- **Triggers and closes donate the press.** With `asChild` they hand `onPress` to the child,
|
|
62
|
+
chained ahead of the child's own, for `BottomSheet.Trigger`'s reason: two tap gestures in an
|
|
63
|
+
ancestor/descendant pair are not simultaneous, so a pressable wrapped around a `Button` never
|
|
64
|
+
fires. The child has to be something that handles `onPress`.
|
|
65
|
+
- **The corner ✕ presses with `fade` and 8pt of slop.** A scale on a glyph this small reads as a
|
|
66
|
+
jitter, and a bare glyph has no capsule to bring it toward 44pt. It sits out of the flow, and
|
|
67
|
+
`Dialog.Title`'s `pr-8` reserves its clearance on every dialog, so adding a close never reflows
|
|
68
|
+
the title.
|
|
69
|
+
- **The title and description carry no type of their own.** They *are* `Text.Header` and a muted
|
|
70
|
+
`Text.Paragraph`; a size in the slot would be a second definition of a preset. A test asserts
|
|
71
|
+
the `title` slot is exactly `pr-8`. There is no `description` slot: `tv` emits `undefined` for an
|
|
72
|
+
empty string, so the part merges its `className` with `cn()`, as `BottomSheet.Description` does.
|
|
73
|
+
- **Motion.** Scrim opacity is `progress`; the card fades with it and grows from
|
|
74
|
+
`DIALOG_ENTER_SCALE` (0.96) and `DIALOG_ENTER_TRANSLATE_Y` (8pt) below. Under reduce motion the
|
|
75
|
+
transforms drop and the fade stays, per the foundation. `isMotionCalm` does not still it.
|
|
76
|
+
- **The keyboard lifts the card just enough.** `resolveDialogKeyboardLift` is the smallest lift
|
|
77
|
+
that keeps the card's bottom `DIALOG_KEYBOARD_MARGIN` (16pt) above the keyboard, never negative,
|
|
78
|
+
and capped so the card's top never rises under the top safe-area inset — a card too tall for
|
|
79
|
+
both keeps its title on screen. It is a worklet read in the card's animated style against
|
|
80
|
+
`useReanimatedKeyboardAnimation`'s height, so it rides the keyboard's own frames. The card's
|
|
81
|
+
edges come from `onLayout`, which ignores transforms, so the lift never feeds back into itself.
|
|
82
|
+
The positioner fills the portal host, which fills the window, so layout `y` is window `y`.
|
|
83
|
+
- **Accessibility.** The card is `accessibilityViewIsModal` with `role="dialog"` (or
|
|
84
|
+
`"alertdialog"`, `resolveDialogRole`) and `accessibilityLabelledBy` the title's `nativeID` for
|
|
85
|
+
Android. Once the entrance finishes (`onEntered`) focus moves to the title; once the exit
|
|
86
|
+
finishes, to the trigger, if one is still mounted. `findNodeHandle` of a ref that has gone is
|
|
87
|
+
null, and focus is then left where the system puts it. `Dialog.Title` takes no `ref` for that
|
|
88
|
+
reason — the dialog holds it.
|
|
89
|
+
- **No blur backdrop.** Frosted scrims need `expo-blur`, which is not a peer; recorded as a
|
|
90
|
+
follow-up for every overlay.
|
|
91
|
+
|
|
92
|
+
## Testing
|
|
93
|
+
|
|
94
|
+
`bun test` reaches `dialogVariants`, the size classes, the footer direction, the role and the
|
|
95
|
+
keyboard lift. Opening from a trigger and controlled, every dismissal path, the alert dialog, the
|
|
96
|
+
z-order over a sheet, the exit, the keyboard, VoiceOver focus and reduce motion are verified on a
|
|
97
|
+
simulator through `/dialog` in the playground — `over-sheet` is the z-order case.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { View, type ViewProps } from "react-native";
|
|
3
|
+
import { dialogVariants } from "./dialog.variants";
|
|
4
|
+
|
|
5
|
+
export type DialogBodyProps = ViewProps & { className?: string };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Whatever the dialog asks for between the header and the footer — a field, a
|
|
9
|
+
* checkbox, a short list. Optional: a confirmation is a header and a footer.
|
|
10
|
+
*
|
|
11
|
+
* It does not scroll. Content long enough to need it belongs in a `BottomSheet`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <Dialog.Body>
|
|
15
|
+
* <Input placeholder="Project name" />
|
|
16
|
+
* </Dialog.Body>
|
|
17
|
+
*/
|
|
18
|
+
export function DialogBody({ className, ...props }: DialogBodyProps): ReactElement {
|
|
19
|
+
return <View className={dialogVariants().body({ className })} {...props} />;
|
|
20
|
+
}
|
|
21
|
+
DialogBody.displayName = "DelacourUI.Dialog.Body";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type ReactElement, useCallback } from "react";
|
|
2
|
+
import { IconCrossSmall } from "../../icons/central";
|
|
3
|
+
import { Slot } from "../../lib/slot";
|
|
4
|
+
import { Icon } from "../icon";
|
|
5
|
+
import { Pressable, type PressableProps } from "../pressable";
|
|
6
|
+
import { useDialogPart } from "./dialog.context";
|
|
7
|
+
import { DIALOG_CLOSE_HIT_SLOP, dialogVariants } from "./dialog.variants";
|
|
8
|
+
|
|
9
|
+
export type DialogCloseProps =
|
|
10
|
+
/** Donates the close to the single child — a `Button` in the footer, say. */
|
|
11
|
+
| ({ asChild: true; children: ReactElement } & Omit<PressableProps, "asChild" | "children">)
|
|
12
|
+
/** The ✕ glyph in the card's top-right corner. */
|
|
13
|
+
| ({ asChild?: false; accessibilityLabel?: string } & Omit<PressableProps, "asChild" | "children">);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Closes the dialog.
|
|
17
|
+
*
|
|
18
|
+
* Without children it is the ✕ in the card's corner: this library's
|
|
19
|
+
* `Pressable` with `fade` feedback — a scale on a glyph this small reads as a
|
|
20
|
+
* jitter — 8pt of slop because a bare glyph has no capsule to bring it toward
|
|
21
|
+
* 44pt, and `"Close"` as its label. It sits out of the flow; `Dialog.Title`
|
|
22
|
+
* reserves the clearance.
|
|
23
|
+
*
|
|
24
|
+
* With `asChild` it donates the close to its child, chained ahead of the
|
|
25
|
+
* child's own `onPress`, the way `Dialog.Trigger` donates the open. Either way
|
|
26
|
+
* the close is the same `setOpen(false)` the scrim and the back button take, so
|
|
27
|
+
* `onOpenChange` is the one thing to watch.
|
|
28
|
+
*
|
|
29
|
+
* It closes even an alert dialog: `isDismissible={false}` turns off the ways
|
|
30
|
+
* out the user did not choose, not the ones the dialog offers.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* <Dialog.Close />
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* <Dialog.Close asChild>
|
|
37
|
+
* <Button variant="secondary">Cancel</Button>
|
|
38
|
+
* </Dialog.Close>
|
|
39
|
+
*/
|
|
40
|
+
export function DialogClose(props: DialogCloseProps): ReactElement {
|
|
41
|
+
const { close } = useDialogPart("Dialog.Close");
|
|
42
|
+
const { onPress } = props;
|
|
43
|
+
|
|
44
|
+
const handlePress = useCallback(() => {
|
|
45
|
+
close();
|
|
46
|
+
onPress?.();
|
|
47
|
+
}, [close, onPress]);
|
|
48
|
+
|
|
49
|
+
if (props.asChild) {
|
|
50
|
+
const { asChild: _asChild, children, onPress: _onPress, ...rest } = props;
|
|
51
|
+
return (
|
|
52
|
+
<Slot onPress={handlePress} {...rest}>
|
|
53
|
+
{children}
|
|
54
|
+
</Slot>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const {
|
|
59
|
+
asChild: _asChild,
|
|
60
|
+
accessibilityLabel = "Close",
|
|
61
|
+
className,
|
|
62
|
+
feedback = "fade",
|
|
63
|
+
hitSlop = DIALOG_CLOSE_HIT_SLOP,
|
|
64
|
+
onPress: _onPress,
|
|
65
|
+
...rest
|
|
66
|
+
} = props;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Pressable
|
|
70
|
+
accessibilityLabel={accessibilityLabel}
|
|
71
|
+
accessibilityRole="button"
|
|
72
|
+
className={dialogVariants().close({ className })}
|
|
73
|
+
feedback={feedback}
|
|
74
|
+
hitSlop={hitSlop}
|
|
75
|
+
onPress={handlePress}
|
|
76
|
+
{...rest}
|
|
77
|
+
>
|
|
78
|
+
<Icon color="muted-foreground" icon={IconCrossSmall} />
|
|
79
|
+
</Pressable>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
DialogClose.displayName = "DelacourUI.Dialog.Close";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type ReactElement, useCallback, useId } from "react";
|
|
2
|
+
import {
|
|
3
|
+
AccessibilityInfo,
|
|
4
|
+
findNodeHandle,
|
|
5
|
+
type LayoutChangeEvent,
|
|
6
|
+
useWindowDimensions,
|
|
7
|
+
View,
|
|
8
|
+
type ViewProps,
|
|
9
|
+
} from "react-native";
|
|
10
|
+
import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller";
|
|
11
|
+
import Animated, { interpolate, useAnimatedStyle, useSharedValue } from "react-native-reanimated";
|
|
12
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
13
|
+
import { Overlay, useOverlayBackHandler, useOverlayPresence } from "../overlay";
|
|
14
|
+
import { type DialogFocusTarget, DialogSizeProvider, useDialogPart } from "./dialog.context";
|
|
15
|
+
import {
|
|
16
|
+
DIALOG_ENTER_SCALE,
|
|
17
|
+
DIALOG_ENTER_TRANSLATE_Y,
|
|
18
|
+
DIALOG_KEYBOARD_MARGIN,
|
|
19
|
+
type DialogSize,
|
|
20
|
+
dialogVariants,
|
|
21
|
+
resolveDialogKeyboardLift,
|
|
22
|
+
resolveDialogRole,
|
|
23
|
+
} from "./dialog.variants";
|
|
24
|
+
|
|
25
|
+
export type DialogContentProps = ViewProps & {
|
|
26
|
+
className?: string;
|
|
27
|
+
/** Classes for the scrim behind the card. */
|
|
28
|
+
scrimClassName?: string;
|
|
29
|
+
/** The card's width cap: `sm` 320, `md` 400, `lg` 520, `full` the gutter. Default `md`. */
|
|
30
|
+
size?: DialogSize;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Moves VoiceOver / TalkBack focus to a mounted element. A no-op when it has gone. */
|
|
34
|
+
function focus(target: DialogFocusTarget | null): void {
|
|
35
|
+
if (target === null) return;
|
|
36
|
+
const handle = findNodeHandle(target as Parameters<typeof findNodeHandle>[0]);
|
|
37
|
+
if (handle !== null) AccessibilityInfo.setAccessibilityFocus(handle);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The card, its scrim and the portal they draw through.
|
|
42
|
+
*
|
|
43
|
+
* Renders nothing until the dialog opens, and stays mounted through the exit
|
|
44
|
+
* animation (`useOverlayPresence`), so the portal, the z-order and the back
|
|
45
|
+
* button all follow presence with nothing else to keep in sync. It draws in the
|
|
46
|
+
* `modal` band, above every bottom sheet and the navigator's header.
|
|
47
|
+
*
|
|
48
|
+
* - **Motion.** The scrim's opacity is `progress`; the card fades with it and
|
|
49
|
+
* grows from 0.96 and 8pt below. Under reduce motion only the fade runs.
|
|
50
|
+
* - **Keyboard.** The card lifts by `resolveDialogKeyboardLift` — just enough
|
|
51
|
+
* to keep its bottom 16pt above the keyboard, never past the top inset — on
|
|
52
|
+
* the keyboard's own frames, and settles back when it closes.
|
|
53
|
+
* - **Dismissal.** A scrim tap, Android back and the iOS escape gesture close a
|
|
54
|
+
* dismissible dialog. With `isDismissible={false}` the scrim still takes the
|
|
55
|
+
* touch so the app under it cannot be pressed, and only the dialog's own
|
|
56
|
+
* actions close it.
|
|
57
|
+
* - **Accessibility.** The card is modal to assistive technology, announces as
|
|
58
|
+
* a `dialog` (an `alertdialog` when not dismissible), is labelled by the
|
|
59
|
+
* title, and moves focus to the title once it has entered — and back to the
|
|
60
|
+
* trigger, if one is still mounted, once it has gone.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* <Dialog.Content size="sm">
|
|
64
|
+
* <Dialog.Header>…</Dialog.Header>
|
|
65
|
+
* </Dialog.Content>
|
|
66
|
+
*/
|
|
67
|
+
export function DialogContent({
|
|
68
|
+
className,
|
|
69
|
+
scrimClassName,
|
|
70
|
+
size = "md",
|
|
71
|
+
children,
|
|
72
|
+
onLayout,
|
|
73
|
+
style,
|
|
74
|
+
...props
|
|
75
|
+
}: DialogContentProps): ReactElement | null {
|
|
76
|
+
const { isOpen, close, isDismissible, titleId, titleRef, triggerRef } = useDialogPart("Dialog.Content");
|
|
77
|
+
const id = useId();
|
|
78
|
+
|
|
79
|
+
const handleEntered = useCallback(() => focus(titleRef.current), [titleRef]);
|
|
80
|
+
const handleExited = useCallback(() => focus(triggerRef.current), [triggerRef]);
|
|
81
|
+
const { isPresent, isReduced, progress } = useOverlayPresence({
|
|
82
|
+
isOpen,
|
|
83
|
+
onEntered: handleEntered,
|
|
84
|
+
onExited: handleExited,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
useOverlayBackHandler({ id, isEnabled: isPresent && isDismissible, onBack: close });
|
|
88
|
+
|
|
89
|
+
const keyboard = useReanimatedKeyboardAnimation();
|
|
90
|
+
const { top: topInset } = useSafeAreaInsets();
|
|
91
|
+
const { height: windowHeight } = useWindowDimensions();
|
|
92
|
+
const cardTop = useSharedValue(0);
|
|
93
|
+
const cardBottom = useSharedValue(0);
|
|
94
|
+
|
|
95
|
+
const handleLayout = useCallback(
|
|
96
|
+
(event: LayoutChangeEvent) => {
|
|
97
|
+
const { y, height } = event.nativeEvent.layout;
|
|
98
|
+
cardTop.value = y;
|
|
99
|
+
cardBottom.value = y + height;
|
|
100
|
+
onLayout?.(event);
|
|
101
|
+
},
|
|
102
|
+
[cardTop, cardBottom, onLayout]
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const cardStyle = useAnimatedStyle(() => {
|
|
106
|
+
const lift = resolveDialogKeyboardLift({
|
|
107
|
+
cardBottom: cardBottom.value,
|
|
108
|
+
cardTop: cardTop.value,
|
|
109
|
+
keyboardHeight: keyboard.height.value,
|
|
110
|
+
margin: DIALOG_KEYBOARD_MARGIN,
|
|
111
|
+
topInset,
|
|
112
|
+
windowHeight,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (isReduced) {
|
|
116
|
+
return { opacity: progress.value, transform: [{ translateY: -lift }] };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
opacity: progress.value,
|
|
121
|
+
transform: [
|
|
122
|
+
{ translateY: interpolate(progress.value, [0, 1], [DIALOG_ENTER_TRANSLATE_Y, 0]) - lift },
|
|
123
|
+
{ scale: interpolate(progress.value, [0, 1], [DIALOG_ENTER_SCALE, 1]) },
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
}, [isReduced, topInset, windowHeight]);
|
|
127
|
+
|
|
128
|
+
if (!isPresent) return null;
|
|
129
|
+
|
|
130
|
+
const slots = dialogVariants({ size });
|
|
131
|
+
const onEscape = isDismissible ? close : undefined;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<Overlay.Portal id={id} layer="modal">
|
|
135
|
+
<Overlay.Scrim className={slots.scrim({ className: scrimClassName })} onDismiss={onEscape} progress={progress} />
|
|
136
|
+
<View className={slots.positioner()} pointerEvents="box-none">
|
|
137
|
+
<Animated.View
|
|
138
|
+
accessibilityLabelledBy={titleId}
|
|
139
|
+
accessibilityViewIsModal
|
|
140
|
+
className={slots.content({ className })}
|
|
141
|
+
onAccessibilityEscape={onEscape}
|
|
142
|
+
onLayout={handleLayout}
|
|
143
|
+
role={resolveDialogRole(isDismissible)}
|
|
144
|
+
style={[cardStyle, style]}
|
|
145
|
+
{...props}
|
|
146
|
+
>
|
|
147
|
+
<DialogSizeProvider value={size}>{children}</DialogSizeProvider>
|
|
148
|
+
</Animated.View>
|
|
149
|
+
</View>
|
|
150
|
+
</Overlay.Portal>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
DialogContent.displayName = "DelacourUI.Dialog.Content";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { cn } from "../../lib/cn";
|
|
3
|
+
import { Text, type TextPresetProps } from "../text";
|
|
4
|
+
import { useDialogPart } from "./dialog.context";
|
|
5
|
+
|
|
6
|
+
export type DialogDescriptionProps = TextPresetProps;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Supporting copy under the title.
|
|
10
|
+
*
|
|
11
|
+
* *Is* a `Text.Paragraph`, muted by default so the title and this read as a
|
|
12
|
+
* hierarchy rather than two equal lines. `color` is an ordinary prop. It has no
|
|
13
|
+
* slot in `dialogVariants` — see the note there.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* <Dialog.Description>This cannot be undone.</Dialog.Description>
|
|
17
|
+
*/
|
|
18
|
+
export function DialogDescription({ className, color = "muted", ...props }: DialogDescriptionProps): ReactElement {
|
|
19
|
+
const { descriptionId } = useDialogPart("Dialog.Description");
|
|
20
|
+
|
|
21
|
+
return <Text.Paragraph className={cn(className)} color={color} nativeID={descriptionId} {...props} />;
|
|
22
|
+
}
|
|
23
|
+
DialogDescription.displayName = "DelacourUI.Dialog.Description";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { View, type ViewProps } from "react-native";
|
|
3
|
+
import { useDialogSize } from "./dialog.context";
|
|
4
|
+
import { type DialogFooterVariant, dialogVariants, resolveDialogFooterDirection } from "./dialog.variants";
|
|
5
|
+
|
|
6
|
+
export type DialogFooterProps = ViewProps & {
|
|
7
|
+
className?: string;
|
|
8
|
+
/** `plain` sits inside the card's padding; `panel` bleeds to its edges on a muted band. Default `plain`. */
|
|
9
|
+
variant?: DialogFooterVariant;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The dialog's actions.
|
|
14
|
+
*
|
|
15
|
+
* A right-aligned row on every size but `sm`, where two labelled buttons side
|
|
16
|
+
* by side would truncate, so they stack full width in written order — write the
|
|
17
|
+
* primary action last and it sits last either way. The direction follows the
|
|
18
|
+
* card's size from `Dialog.Content`; `resolveDialogFooterDirection` is the rule.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <Dialog.Footer variant="panel">
|
|
22
|
+
* <Dialog.Close asChild><Button variant="secondary">Cancel</Button></Dialog.Close>
|
|
23
|
+
* <Button onPress={save}>Save</Button>
|
|
24
|
+
* </Dialog.Footer>
|
|
25
|
+
*/
|
|
26
|
+
export function DialogFooter({ className, variant = "plain", ...props }: DialogFooterProps): ReactElement {
|
|
27
|
+
const size = useDialogSize();
|
|
28
|
+
const footerDirection = resolveDialogFooterDirection(size);
|
|
29
|
+
|
|
30
|
+
return <View className={dialogVariants({ footer: variant, footerDirection }).footer({ className })} {...props} />;
|
|
31
|
+
}
|
|
32
|
+
DialogFooter.displayName = "DelacourUI.Dialog.Footer";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { View, type ViewProps } from "react-native";
|
|
3
|
+
import { dialogVariants } from "./dialog.variants";
|
|
4
|
+
|
|
5
|
+
export type DialogHeaderProps = ViewProps & { className?: string };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The column holding `Dialog.Title` and `Dialog.Description`, a tight gap apart
|
|
9
|
+
* so the two read as one block above the body.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <Dialog.Header>
|
|
13
|
+
* <Dialog.Title>Delete project?</Dialog.Title>
|
|
14
|
+
* <Dialog.Description>This cannot be undone.</Dialog.Description>
|
|
15
|
+
* </Dialog.Header>
|
|
16
|
+
*/
|
|
17
|
+
export function DialogHeader({ className, ...props }: DialogHeaderProps): ReactElement {
|
|
18
|
+
return <View className={dialogVariants().header({ className })} {...props} />;
|
|
19
|
+
}
|
|
20
|
+
DialogHeader.displayName = "DelacourUI.Dialog.Header";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ReactElement, useCallback } from "react";
|
|
2
|
+
import { Text, type TextPresetProps } from "../text";
|
|
3
|
+
import { type DialogFocusTarget, useDialogPart } from "./dialog.context";
|
|
4
|
+
import { dialogVariants } from "./dialog.variants";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A `Text.Header`'s props less `ref`: the dialog holds the title's ref itself,
|
|
8
|
+
* to move accessibility focus onto it.
|
|
9
|
+
*/
|
|
10
|
+
export type DialogTitleProps = Omit<TextPresetProps, "ref">;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The dialog's heading.
|
|
14
|
+
*
|
|
15
|
+
* *Is* a `Text.Header` — the preset supplies the type, and this adds only the
|
|
16
|
+
* clearance the corner ✕ needs. It carries the `nativeID` the card is labelled
|
|
17
|
+
* by on Android, and it is where accessibility focus lands once the card has
|
|
18
|
+
* finished entering, so a screen reader announces what the dialog is for first.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <Dialog.Title>Delete project?</Dialog.Title>
|
|
22
|
+
*/
|
|
23
|
+
export function DialogTitle({ className, ...props }: DialogTitleProps): ReactElement {
|
|
24
|
+
const { titleId, titleRef } = useDialogPart("Dialog.Title");
|
|
25
|
+
const setTitleRef = useCallback(
|
|
26
|
+
(node: DialogFocusTarget | null) => {
|
|
27
|
+
titleRef.current = node;
|
|
28
|
+
},
|
|
29
|
+
[titleRef]
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Text.Header
|
|
34
|
+
accessibilityRole="header"
|
|
35
|
+
className={dialogVariants().title({ className })}
|
|
36
|
+
nativeID={titleId}
|
|
37
|
+
ref={setTitleRef}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
DialogTitle.displayName = "DelacourUI.Dialog.Title";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ReactElement, useCallback } from "react";
|
|
2
|
+
import { composeRefs } from "../../lib/compose-refs";
|
|
3
|
+
import { Slot } from "../../lib/slot";
|
|
4
|
+
import { Pressable, type PressableProps } from "../pressable";
|
|
5
|
+
import { useDialogPart } from "./dialog.context";
|
|
6
|
+
|
|
7
|
+
export type DialogTriggerProps = PressableProps;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The control that opens the dialog.
|
|
11
|
+
*
|
|
12
|
+
* On its own it is this library's `Pressable`. **`asChild` donates the press
|
|
13
|
+
* rather than wrapping the child**, the way `BottomSheet.Trigger` does: two tap
|
|
14
|
+
* gestures in an ancestor/descendant pair are not simultaneous, so a `Button`
|
|
15
|
+
* wrapped in a pressable trigger would win the touch and the dialog would never
|
|
16
|
+
* open. With `asChild` the open is chained ahead of the child's own `onPress`,
|
|
17
|
+
* and the child keeps its gesture, feedback and haptic — so the child has to be
|
|
18
|
+
* something that handles `onPress`.
|
|
19
|
+
*
|
|
20
|
+
* The trigger's ref is kept so accessibility focus can return to it when the
|
|
21
|
+
* dialog closes.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <Dialog.Trigger asChild>
|
|
25
|
+
* <Button variant="destructive">Delete</Button>
|
|
26
|
+
* </Dialog.Trigger>
|
|
27
|
+
*/
|
|
28
|
+
export function DialogTrigger({ asChild = false, children, onPress, ref, ...props }: DialogTriggerProps): ReactElement {
|
|
29
|
+
const { setOpen, triggerRef } = useDialogPart("Dialog.Trigger");
|
|
30
|
+
|
|
31
|
+
const handlePress = useCallback(() => {
|
|
32
|
+
setOpen(true);
|
|
33
|
+
onPress?.();
|
|
34
|
+
}, [setOpen, onPress]);
|
|
35
|
+
|
|
36
|
+
const composedRef = composeRefs(ref, (node) => {
|
|
37
|
+
triggerRef.current = node;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (asChild) {
|
|
41
|
+
return (
|
|
42
|
+
<Slot onPress={handlePress} ref={composedRef} {...props}>
|
|
43
|
+
{children}
|
|
44
|
+
</Slot>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Pressable accessibilityRole="button" onPress={handlePress} ref={composedRef} {...props}>
|
|
50
|
+
{children}
|
|
51
|
+
</Pressable>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
DialogTrigger.displayName = "DelacourUI.Dialog.Trigger";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createContext, type ReactElement, type ReactNode, type RefObject, use } from "react";
|
|
2
|
+
import type { DialogSize } from "./dialog.variants";
|
|
3
|
+
|
|
4
|
+
/** Anything `AccessibilityInfo.setAccessibilityFocus` can be pointed at through `findNodeHandle`. */
|
|
5
|
+
export type DialogFocusTarget = object;
|
|
6
|
+
|
|
7
|
+
export type DialogContextValue = {
|
|
8
|
+
/** Whether the dialog is open — the owner's state, not the exit animation's. */
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
/** Opens or closes it. Reports through `onOpenChange` only when the value changes. */
|
|
11
|
+
setOpen: (isOpen: boolean) => void;
|
|
12
|
+
/** `setOpen(false)`, for an action inside the card. */
|
|
13
|
+
close: () => void;
|
|
14
|
+
/** Whether the scrim, Android back and the iOS escape gesture close it. */
|
|
15
|
+
isDismissible: boolean;
|
|
16
|
+
/** The `nativeID` `Dialog.Title` carries and the card is labelled by. */
|
|
17
|
+
titleId: string;
|
|
18
|
+
/** The `nativeID` `Dialog.Description` carries. */
|
|
19
|
+
descriptionId: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What the parts share that a caller has no use for: where focus goes on open
|
|
24
|
+
* and on close, and the card's size for the footer.
|
|
25
|
+
*/
|
|
26
|
+
export type DialogInternalValue = DialogContextValue & {
|
|
27
|
+
/** The trigger, so focus can return to it on close. */
|
|
28
|
+
triggerRef: RefObject<DialogFocusTarget | null>;
|
|
29
|
+
/** The title, so focus can land on it on open. */
|
|
30
|
+
titleRef: RefObject<DialogFocusTarget | null>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const DialogContext = createContext<DialogInternalValue | null>(null);
|
|
34
|
+
|
|
35
|
+
/** The card's size, provided by `Dialog.Content` so the footer can choose its direction. */
|
|
36
|
+
const DialogSizeContext = createContext<DialogSize>("md");
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Supplies the dialog's state to its parts.
|
|
40
|
+
*
|
|
41
|
+
* Lives in its own module, importing nothing but `dialog.variants`' types, so a
|
|
42
|
+
* part can read it without importing `./dialog` — that import would close a
|
|
43
|
+
* cycle, and Metro serves a partially initialised module for one.
|
|
44
|
+
*/
|
|
45
|
+
export function DialogProvider({ value, children }: { value: DialogInternalValue; children: ReactNode }): ReactElement {
|
|
46
|
+
return <DialogContext value={value}>{children}</DialogContext>;
|
|
47
|
+
}
|
|
48
|
+
DialogProvider.displayName = "DelacourUI.Dialog.Provider";
|
|
49
|
+
|
|
50
|
+
/** Supplies the card's size to the parts inside `Dialog.Content`. */
|
|
51
|
+
export function DialogSizeProvider({ value, children }: { value: DialogSize; children: ReactNode }): ReactElement {
|
|
52
|
+
return <DialogSizeContext value={value}>{children}</DialogSizeContext>;
|
|
53
|
+
}
|
|
54
|
+
DialogSizeProvider.displayName = "DelacourUI.Dialog.SizeProvider";
|
|
55
|
+
|
|
56
|
+
/** The enclosing dialog's context, or null outside a `<Dialog>`. */
|
|
57
|
+
export function useDialogContext(): DialogContextValue | null {
|
|
58
|
+
return use(DialogContext);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Reads the enclosing dialog's open state, its setter and its ids.
|
|
63
|
+
*
|
|
64
|
+
* Lets a custom child close the dialog — a form's submit, say — without the
|
|
65
|
+
* caller threading a setter down. Throws outside a `<Dialog>`.
|
|
66
|
+
*/
|
|
67
|
+
export function useDialog(): DialogContextValue {
|
|
68
|
+
const context = use(DialogContext);
|
|
69
|
+
if (!context) {
|
|
70
|
+
throw new Error("useDialog must be called inside a <Dialog>.");
|
|
71
|
+
}
|
|
72
|
+
return context;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The full context, for a part that cannot work without one. Internal: not
|
|
77
|
+
* re-exported from `index.ts`.
|
|
78
|
+
*/
|
|
79
|
+
export function useDialogPart(component: string): DialogInternalValue {
|
|
80
|
+
const context = use(DialogContext);
|
|
81
|
+
if (!context) {
|
|
82
|
+
throw new Error(`${component} must be rendered inside a <Dialog>.`);
|
|
83
|
+
}
|
|
84
|
+
return context;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The card's size. `md` outside `Dialog.Content`. */
|
|
88
|
+
export function useDialogSize(): DialogSize {
|
|
89
|
+
return use(DialogSizeContext);
|
|
90
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode, useCallback, useId, useMemo, useRef } from "react";
|
|
2
|
+
import { useControllableState } from "../../hooks/use-controllable-state";
|
|
3
|
+
import { type DialogFocusTarget, type DialogInternalValue, DialogProvider } from "./dialog.context";
|
|
4
|
+
import { DialogBody } from "./dialog-body";
|
|
5
|
+
import { DialogClose } from "./dialog-close";
|
|
6
|
+
import { DialogContent } from "./dialog-content";
|
|
7
|
+
import { DialogDescription } from "./dialog-description";
|
|
8
|
+
import { DialogFooter } from "./dialog-footer";
|
|
9
|
+
import { DialogHeader } from "./dialog-header";
|
|
10
|
+
import { DialogTitle } from "./dialog-title";
|
|
11
|
+
import { DialogTrigger } from "./dialog-trigger";
|
|
12
|
+
|
|
13
|
+
export type DialogProps = {
|
|
14
|
+
/** Whether the dialog is open. Pass it to control the dialog; omit it and the dialog holds its own state. */
|
|
15
|
+
isOpen?: boolean;
|
|
16
|
+
/** Whether an uncontrolled dialog starts open. Default false. */
|
|
17
|
+
defaultOpen?: boolean;
|
|
18
|
+
/** Called with the new value whenever the dialog opens or closes, from any path. */
|
|
19
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Whether a scrim tap, Android back and the iOS escape gesture close it.
|
|
22
|
+
* `false` makes an alert dialog: only its own actions close it. Default true.
|
|
23
|
+
*/
|
|
24
|
+
isDismissible?: boolean;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function DialogRoot({
|
|
29
|
+
isOpen,
|
|
30
|
+
defaultOpen = false,
|
|
31
|
+
onOpenChange,
|
|
32
|
+
isDismissible = true,
|
|
33
|
+
children,
|
|
34
|
+
}: DialogProps): ReactElement {
|
|
35
|
+
const [open, setControllableOpen] = useControllableState({
|
|
36
|
+
defaultValue: defaultOpen,
|
|
37
|
+
onChange: onOpenChange,
|
|
38
|
+
value: isOpen,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Every path — trigger, close, scrim, back, escape — lands here, and a
|
|
42
|
+
// second close while the first is still exiting would report twice.
|
|
43
|
+
const setOpen = useCallback(
|
|
44
|
+
(next: boolean) => {
|
|
45
|
+
if (next !== open) setControllableOpen(next);
|
|
46
|
+
},
|
|
47
|
+
[open, setControllableOpen]
|
|
48
|
+
);
|
|
49
|
+
const close = useCallback(() => setOpen(false), [setOpen]);
|
|
50
|
+
|
|
51
|
+
const titleId = useId();
|
|
52
|
+
const descriptionId = useId();
|
|
53
|
+
const triggerRef = useRef<DialogFocusTarget | null>(null);
|
|
54
|
+
const titleRef = useRef<DialogFocusTarget | null>(null);
|
|
55
|
+
|
|
56
|
+
const value = useMemo<DialogInternalValue>(
|
|
57
|
+
() => ({ close, descriptionId, isDismissible, isOpen: open, setOpen, titleId, titleRef, triggerRef }),
|
|
58
|
+
[close, descriptionId, isDismissible, open, setOpen, titleId]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return <DialogProvider value={value}>{children}</DialogProvider>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A centred card over a dimmed app that asks for a decision or a short input
|
|
66
|
+
* before the user goes on — confirm a delete, rename a file, accept terms.
|
|
67
|
+
*
|
|
68
|
+
* It takes the whole screen. Use a `Popover` when the surrounding context must
|
|
69
|
+
* stay visible, and a `BottomSheet` when the content is long or scrolls. With
|
|
70
|
+
* `isDismissible={false}` it is an alert dialog: only its own actions close it.
|
|
71
|
+
*
|
|
72
|
+
* Draws through `Overlay.Portal`, so the app needs `OverlayProvider` mounted
|
|
73
|
+
* once at its root.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* <Dialog>
|
|
77
|
+
* <Dialog.Trigger asChild>
|
|
78
|
+
* <Button variant="destructive">Delete</Button>
|
|
79
|
+
* </Dialog.Trigger>
|
|
80
|
+
* <Dialog.Content>
|
|
81
|
+
* <Dialog.Close />
|
|
82
|
+
* <Dialog.Header>
|
|
83
|
+
* <Dialog.Title>Delete project?</Dialog.Title>
|
|
84
|
+
* <Dialog.Description>This cannot be undone.</Dialog.Description>
|
|
85
|
+
* </Dialog.Header>
|
|
86
|
+
* <Dialog.Footer>
|
|
87
|
+
* <Dialog.Close asChild>
|
|
88
|
+
* <Button variant="secondary">Cancel</Button>
|
|
89
|
+
* </Dialog.Close>
|
|
90
|
+
* <Button variant="destructive" onPress={remove}>Delete</Button>
|
|
91
|
+
* </Dialog.Footer>
|
|
92
|
+
* </Dialog.Content>
|
|
93
|
+
* </Dialog>
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // Controlled, and an alert dialog.
|
|
97
|
+
* <Dialog isOpen={isOpen} onOpenChange={setIsOpen} isDismissible={false}>
|
|
98
|
+
* …
|
|
99
|
+
* </Dialog>
|
|
100
|
+
*/
|
|
101
|
+
export const Dialog = Object.assign(DialogRoot, {
|
|
102
|
+
/** The control that opens it. `asChild` donates the press to a `Button`. */
|
|
103
|
+
Trigger: DialogTrigger,
|
|
104
|
+
/** The portal, scrim and card. Renders nothing while closed. */
|
|
105
|
+
Content: DialogContent,
|
|
106
|
+
/** The ✕ in the corner, or — with `asChild` — any control that closes it. */
|
|
107
|
+
Close: DialogClose,
|
|
108
|
+
/** The column holding the title and description. */
|
|
109
|
+
Header: DialogHeader,
|
|
110
|
+
/** The heading — a `Text.Header` the card is labelled by. */
|
|
111
|
+
Title: DialogTitle,
|
|
112
|
+
/** Muted supporting copy — a `Text.Paragraph`. */
|
|
113
|
+
Description: DialogDescription,
|
|
114
|
+
/** What the dialog asks for, between the header and the footer. */
|
|
115
|
+
Body: DialogBody,
|
|
116
|
+
/** The actions — a row, or a stacked column on an `sm` card. */
|
|
117
|
+
Footer: DialogFooter,
|
|
118
|
+
displayName: "DelacourUI.Dialog",
|
|
119
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { declaredTokens } from "../../styles/theme-tokens.test";
|
|
3
|
+
import {
|
|
4
|
+
DIALOG_CLOSE_HIT_SLOP,
|
|
5
|
+
DIALOG_ENTER_SCALE,
|
|
6
|
+
DIALOG_ENTER_TRANSLATE_Y,
|
|
7
|
+
DIALOG_FOOTER_VARIANTS,
|
|
8
|
+
DIALOG_KEYBOARD_MARGIN,
|
|
9
|
+
DIALOG_SCRIM_TOKEN,
|
|
10
|
+
DIALOG_SIZE_CLASS,
|
|
11
|
+
DIALOG_SIZES,
|
|
12
|
+
dialogVariants,
|
|
13
|
+
resolveDialogFooterDirection,
|
|
14
|
+
resolveDialogKeyboardLift,
|
|
15
|
+
resolveDialogRole,
|
|
16
|
+
} from "./dialog.variants";
|
|
17
|
+
|
|
18
|
+
const LIGHT = declaredTokens("light");
|
|
19
|
+
const DARK = declaredTokens("dark");
|
|
20
|
+
|
|
21
|
+
/** `border-t` and friends set a width, not a colour, and name no token. */
|
|
22
|
+
const STRUCTURAL_BORDER_SUFFIXES = new Set(["t", "b", "l", "r", "x", "y", "s", "e"]);
|
|
23
|
+
|
|
24
|
+
/** Every theme token a class string paints with, with any `/alpha` suffix dropped. */
|
|
25
|
+
function colorTokens(cls: string): string[] {
|
|
26
|
+
const tokens: string[] = [];
|
|
27
|
+
|
|
28
|
+
for (const [, utility, token] of cls.matchAll(/\b(bg|border|text)-([a-z][\w-]*)(?:\/\d+)?\b/g)) {
|
|
29
|
+
if (utility === "border" && STRUCTURAL_BORDER_SUFFIXES.has(token)) continue;
|
|
30
|
+
tokens.push(token);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return tokens;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The slots this component declares, pinned rather than derived — `tv` adds a
|
|
38
|
+
* `base` slot of its own, and a new slot has to be listed here before the
|
|
39
|
+
* token sweep can miss it.
|
|
40
|
+
*/
|
|
41
|
+
const SLOT_NAMES = ["scrim", "positioner", "content", "close", "header", "title", "body", "footer"] as const;
|
|
42
|
+
|
|
43
|
+
describe("dialogVariants", () => {
|
|
44
|
+
test("the scrim paints the overlay token, which exists in both themes", () => {
|
|
45
|
+
expect(dialogVariants().scrim()).toContain(`bg-${DIALOG_SCRIM_TOKEN}`);
|
|
46
|
+
expect(LIGHT.has(DIALOG_SCRIM_TOKEN)).toBe(true);
|
|
47
|
+
expect(DARK.has(DIALOG_SCRIM_TOKEN)).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("the positioner fills the window, centres the card and keeps the screen gutter", () => {
|
|
51
|
+
const positioner = dialogVariants().positioner();
|
|
52
|
+
expect(positioner).toContain("absolute");
|
|
53
|
+
expect(positioner).toContain("inset-0");
|
|
54
|
+
expect(positioner).toContain("items-center");
|
|
55
|
+
expect(positioner).toContain("justify-center");
|
|
56
|
+
expect(positioner).toContain("px-screen-gutter");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("the card is a popover surface with the card corner and a hairline", () => {
|
|
60
|
+
const content = dialogVariants().content();
|
|
61
|
+
expect(content).toContain("bg-popover");
|
|
62
|
+
expect(content).toContain("rounded-lg");
|
|
63
|
+
expect(content).toContain("border");
|
|
64
|
+
expect(content).toContain("border-border");
|
|
65
|
+
expect(content).toContain("w-full");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("each size pins its own max width", () => {
|
|
69
|
+
expect(DIALOG_SIZE_CLASS).toEqual({
|
|
70
|
+
full: "max-w-full",
|
|
71
|
+
lg: "max-w-[520px]",
|
|
72
|
+
md: "max-w-[400px]",
|
|
73
|
+
sm: "max-w-[320px]",
|
|
74
|
+
});
|
|
75
|
+
for (const size of DIALOG_SIZES) {
|
|
76
|
+
expect(dialogVariants({ size }).content()).toContain(DIALOG_SIZE_CLASS[size]);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("defaults to md", () => {
|
|
81
|
+
expect(dialogVariants().content()).toContain(DIALOG_SIZE_CLASS.md);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("a caller's className reaches the card and wins a conflict", () => {
|
|
85
|
+
const content = dialogVariants().content({ className: "rounded-2xl" });
|
|
86
|
+
expect(content).toContain("rounded-2xl");
|
|
87
|
+
expect(content).not.toContain("rounded-lg");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("the title reserves clearance for the close glyph and carries no type of its own", () => {
|
|
91
|
+
const title = dialogVariants().title();
|
|
92
|
+
expect(title).toBe("pr-8");
|
|
93
|
+
expect(title).not.toMatch(/\btext-(xs|sm|base|lg|xl|\dxl)\b/);
|
|
94
|
+
expect(title).not.toMatch(/\bfont-/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("the close glyph sits in the card's top-right corner", () => {
|
|
98
|
+
const close = dialogVariants().close();
|
|
99
|
+
expect(close).toContain("absolute");
|
|
100
|
+
expect(close).toContain("top-");
|
|
101
|
+
expect(close).toContain("right-");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("a plain footer is a right-aligned row inside the card padding", () => {
|
|
105
|
+
const footer = dialogVariants({ footer: "plain" }).footer();
|
|
106
|
+
expect(footer).toContain("flex-row");
|
|
107
|
+
expect(footer).toContain("justify-end");
|
|
108
|
+
expect(footer).toContain("gap-2");
|
|
109
|
+
expect(footer).not.toContain("bg-muted");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a panel footer bleeds to the card's edges on a muted band under a hairline", () => {
|
|
113
|
+
const footer = dialogVariants({ footer: "panel" }).footer();
|
|
114
|
+
expect(footer).toContain("bg-muted");
|
|
115
|
+
expect(footer).toContain("border-t");
|
|
116
|
+
expect(footer).toContain("border-border");
|
|
117
|
+
expect(footer).toMatch(/-mx-\d/);
|
|
118
|
+
expect(footer).toMatch(/-mb-\d/);
|
|
119
|
+
expect(footer).toContain("rounded-b-lg");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("a column footer stacks its actions full width", () => {
|
|
123
|
+
const footer = dialogVariants({ footer: "plain", footerDirection: "column" }).footer();
|
|
124
|
+
expect(footer).toContain("flex-col");
|
|
125
|
+
expect(footer).not.toContain("flex-row");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("the footer variants are the two the spec names", () => {
|
|
129
|
+
expect([...DIALOG_FOOTER_VARIANTS]).toEqual(["plain", "panel"]);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("every token the slots name", () => {
|
|
134
|
+
test("is declared in both variants of theme.css", () => {
|
|
135
|
+
for (const size of DIALOG_SIZES) {
|
|
136
|
+
for (const footer of DIALOG_FOOTER_VARIANTS) {
|
|
137
|
+
const slots = dialogVariants({ footer, size });
|
|
138
|
+
for (const name of SLOT_NAMES) {
|
|
139
|
+
for (const token of colorTokens(slots[name]())) {
|
|
140
|
+
expect({ inLight: LIGHT.has(token), slot: name, token }).toEqual({ inLight: true, slot: name, token });
|
|
141
|
+
expect({ inDark: DARK.has(token), slot: name, token }).toEqual({ inDark: true, slot: name, token });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("the reader found tokens at all", () => {
|
|
149
|
+
expect(colorTokens(dialogVariants().content())).toEqual(expect.arrayContaining(["popover", "border"]));
|
|
150
|
+
expect(colorTokens(dialogVariants({ footer: "panel" }).footer())).toEqual(
|
|
151
|
+
expect.arrayContaining(["muted", "border"])
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("resolveDialogFooterDirection", () => {
|
|
157
|
+
test("stacks on the narrow card only", () => {
|
|
158
|
+
expect(resolveDialogFooterDirection("sm")).toBe("column");
|
|
159
|
+
expect(resolveDialogFooterDirection("md")).toBe("row");
|
|
160
|
+
expect(resolveDialogFooterDirection("lg")).toBe("row");
|
|
161
|
+
expect(resolveDialogFooterDirection("full")).toBe("row");
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("resolveDialogRole", () => {
|
|
166
|
+
test("a dismissible dialog is a dialog, a non-dismissible one an alert dialog", () => {
|
|
167
|
+
expect(resolveDialogRole(true)).toBe("dialog");
|
|
168
|
+
expect(resolveDialogRole(false)).toBe("alertdialog");
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("motion constants", () => {
|
|
173
|
+
test("the card grows into place from just under full size and just below", () => {
|
|
174
|
+
expect(DIALOG_ENTER_SCALE).toBe(0.96);
|
|
175
|
+
expect(DIALOG_ENTER_TRANSLATE_Y).toBe(8);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("DIALOG_CLOSE_HIT_SLOP", () => {
|
|
180
|
+
test("brings a bare corner glyph up toward the 44pt minimum", () => {
|
|
181
|
+
expect(DIALOG_CLOSE_HIT_SLOP).toBe(8);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("resolveDialogKeyboardLift", () => {
|
|
186
|
+
const base = { cardBottom: 500, cardTop: 300, margin: DIALOG_KEYBOARD_MARGIN, topInset: 59, windowHeight: 852 };
|
|
187
|
+
|
|
188
|
+
test("the margin is 16", () => {
|
|
189
|
+
expect(DIALOG_KEYBOARD_MARGIN).toBe(16);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("no keyboard, no lift", () => {
|
|
193
|
+
expect(resolveDialogKeyboardLift({ ...base, keyboardHeight: 0 })).toBe(0);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("a keyboard that stays below the card and its margin does not lift it", () => {
|
|
197
|
+
// The keyboard's top is at 852 - 300 = 552, clear of 500 + 16.
|
|
198
|
+
expect(resolveDialogKeyboardLift({ ...base, keyboardHeight: 300 })).toBe(0);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("a keyboard overlapping the card lifts it just clear, plus the margin", () => {
|
|
202
|
+
// The keyboard's top is at 852 - 400 = 452; the card's bottom needs to be at 436.
|
|
203
|
+
expect(resolveDialogKeyboardLift({ ...base, keyboardHeight: 400 })).toBe(64);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("accepts the keyboard controller's negative height", () => {
|
|
207
|
+
expect(resolveDialogKeyboardLift({ ...base, keyboardHeight: -400 })).toBe(64);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("never pushes the card's top under the top safe-area inset", () => {
|
|
211
|
+
// The card would need 500 + 16 - (852 - 700) = 364, but its top can rise only 300 - 59.
|
|
212
|
+
expect(resolveDialogKeyboardLift({ ...base, keyboardHeight: 700 })).toBe(241);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("never negative, even for a card already above the inset", () => {
|
|
216
|
+
expect(resolveDialogKeyboardLift({ ...base, cardTop: 20, keyboardHeight: 700 })).toBe(0);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("an unmeasured card is not lifted", () => {
|
|
220
|
+
expect(
|
|
221
|
+
resolveDialogKeyboardLift({ ...base, cardBottom: 0, cardTop: 0, keyboardHeight: 400, windowHeight: 852 })
|
|
222
|
+
).toBe(0);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { VariantProps } from "tailwind-variants";
|
|
2
|
+
import { tv } from "../../lib/tv";
|
|
3
|
+
|
|
4
|
+
/** The card's widths, narrowest first. */
|
|
5
|
+
export const DIALOG_SIZES = ["sm", "md", "lg", "full"] as const;
|
|
6
|
+
export type DialogSize = (typeof DIALOG_SIZES)[number];
|
|
7
|
+
|
|
8
|
+
/** How `Dialog.Footer` sits in the card: a row inside the padding, or a muted band bled to the edges. */
|
|
9
|
+
export const DIALOG_FOOTER_VARIANTS = ["plain", "panel"] as const;
|
|
10
|
+
export type DialogFooterVariant = (typeof DIALOG_FOOTER_VARIANTS)[number];
|
|
11
|
+
|
|
12
|
+
/** Which way `Dialog.Footer` lays out its actions. */
|
|
13
|
+
export type DialogFooterDirection = "row" | "column";
|
|
14
|
+
|
|
15
|
+
/** The accessibility role the card announces. */
|
|
16
|
+
export type DialogRole = "dialog" | "alertdialog";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Each size's cap on the card's width.
|
|
20
|
+
*
|
|
21
|
+
* Classes, not numbers: the card is `w-full` and the cap is a `max-w-*`, so a
|
|
22
|
+
* narrow phone shrinks every size to the gutter and a tablet stops it at the
|
|
23
|
+
* cap. The arbitrary values are written out in full because Tailwind's scanner
|
|
24
|
+
* is static — a width computed at runtime would compile to nothing.
|
|
25
|
+
*/
|
|
26
|
+
export const DIALOG_SIZE_CLASS = {
|
|
27
|
+
sm: "max-w-[320px]",
|
|
28
|
+
md: "max-w-[400px]",
|
|
29
|
+
lg: "max-w-[520px]",
|
|
30
|
+
full: "max-w-full",
|
|
31
|
+
} as const satisfies Record<DialogSize, string>;
|
|
32
|
+
|
|
33
|
+
/** The scrim's token — the foundation's, named here so the test can pin it. */
|
|
34
|
+
export const DIALOG_SCRIM_TOKEN = "overlay";
|
|
35
|
+
|
|
36
|
+
/** Slop around the corner ✕ — a bare glyph has no capsule to bring it toward 44pt. */
|
|
37
|
+
export const DIALOG_CLOSE_HIT_SLOP = 8;
|
|
38
|
+
|
|
39
|
+
/** The scale the card grows from on enter. */
|
|
40
|
+
export const DIALOG_ENTER_SCALE = 0.96;
|
|
41
|
+
|
|
42
|
+
/** How far below its resting place the card starts on enter, in points. */
|
|
43
|
+
export const DIALOG_ENTER_TRANSLATE_Y = 8;
|
|
44
|
+
|
|
45
|
+
/** The clearance kept between the card's bottom edge and the keyboard's top, in points. */
|
|
46
|
+
export const DIALOG_KEYBOARD_MARGIN = 16;
|
|
47
|
+
|
|
48
|
+
export const dialogVariants = tv({
|
|
49
|
+
slots: {
|
|
50
|
+
/** The foundation's scrim token. The fade is `Overlay.Scrim`'s own. */
|
|
51
|
+
scrim: "bg-overlay",
|
|
52
|
+
/**
|
|
53
|
+
* The window-sized frame the card is centred in. The gutter is the
|
|
54
|
+
* screen's, so a `full` card lines up with the content behind it.
|
|
55
|
+
*/
|
|
56
|
+
positioner: "absolute inset-0 items-center justify-center px-screen-gutter",
|
|
57
|
+
/**
|
|
58
|
+
* The card. `popover` because a dialog is a layer over the app — the
|
|
59
|
+
* token `BottomSheet` paints with too — and `rounded-lg` because that is
|
|
60
|
+
* the card corner (see the package's Sizing section).
|
|
61
|
+
*/
|
|
62
|
+
content: "w-full gap-4 rounded-lg border border-border bg-popover p-5",
|
|
63
|
+
close: "absolute top-4 right-4 z-10",
|
|
64
|
+
header: "gap-1.5",
|
|
65
|
+
/**
|
|
66
|
+
* Clearance for `Dialog.Close`, and nothing else — reserved on every
|
|
67
|
+
* dialog so adding a close never reflows the title. The type is
|
|
68
|
+
* `Text.Header`'s; a size here would be a second definition of it.
|
|
69
|
+
*/
|
|
70
|
+
title: "pr-8",
|
|
71
|
+
body: "gap-3",
|
|
72
|
+
footer: "gap-2",
|
|
73
|
+
},
|
|
74
|
+
variants: {
|
|
75
|
+
size: {
|
|
76
|
+
sm: { content: DIALOG_SIZE_CLASS.sm },
|
|
77
|
+
md: { content: DIALOG_SIZE_CLASS.md },
|
|
78
|
+
lg: { content: DIALOG_SIZE_CLASS.lg },
|
|
79
|
+
full: { content: DIALOG_SIZE_CLASS.full },
|
|
80
|
+
},
|
|
81
|
+
footer: {
|
|
82
|
+
plain: {},
|
|
83
|
+
/**
|
|
84
|
+
* Bleeds out of the card's `p-5` on three sides, then restores it as
|
|
85
|
+
* its own padding, so the band reaches the edges and the hairline runs
|
|
86
|
+
* corner to corner. Only the bottom corners round: the top edge meets
|
|
87
|
+
* the card's own fill.
|
|
88
|
+
*/
|
|
89
|
+
panel: { footer: "-mx-5 -mb-5 mt-1 rounded-b-lg border-border border-t bg-muted px-5 py-4" },
|
|
90
|
+
},
|
|
91
|
+
footerDirection: {
|
|
92
|
+
row: { footer: "flex-row items-center justify-end" },
|
|
93
|
+
/** Stacked full width, in written order — so the primary action, written last, sits last. */
|
|
94
|
+
column: { footer: "flex-col" },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
defaultVariants: {
|
|
98
|
+
size: "md",
|
|
99
|
+
footer: "plain",
|
|
100
|
+
footerDirection: "row",
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* There is no `description` slot. A description is a muted `Text.Paragraph` in
|
|
106
|
+
* the header's gap column with no layout of its own, and `tv` emits `undefined`
|
|
107
|
+
* for an empty class string — a slot no test could assert against. The part
|
|
108
|
+
* merges the caller's `className` with `cn()` instead, as `BottomSheet`'s does.
|
|
109
|
+
*/
|
|
110
|
+
export type DialogVariantProps = VariantProps<typeof dialogVariants>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Whether a footer's actions sit side by side or stack.
|
|
114
|
+
*
|
|
115
|
+
* Only the `sm` card stacks: two labelled buttons in a row on a 320pt card
|
|
116
|
+
* leave each label a few characters before it truncates. Pure so the rule is
|
|
117
|
+
* reachable from `bun test`.
|
|
118
|
+
*/
|
|
119
|
+
export function resolveDialogFooterDirection(size: DialogSize): DialogFooterDirection {
|
|
120
|
+
return size === "sm" ? "column" : "row";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The role the card announces. A dialog the user cannot dismiss is an alert
|
|
125
|
+
* dialog: assistive technology tells them only an action will close it.
|
|
126
|
+
*/
|
|
127
|
+
export function resolveDialogRole(isDismissible: boolean): DialogRole {
|
|
128
|
+
return isDismissible ? "dialog" : "alertdialog";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type DialogKeyboardLiftInput = {
|
|
132
|
+
/** The keyboard's height. Either sign — the keyboard controller reports it negative while open. */
|
|
133
|
+
keyboardHeight: number;
|
|
134
|
+
/** The card's top edge in window coordinates, before any lift. */
|
|
135
|
+
cardTop: number;
|
|
136
|
+
/** The card's bottom edge in window coordinates, before any lift. */
|
|
137
|
+
cardBottom: number;
|
|
138
|
+
windowHeight: number;
|
|
139
|
+
/** The top safe-area inset — the card's top never rises past it. */
|
|
140
|
+
topInset: number;
|
|
141
|
+
/** The clearance to keep between the card and the keyboard. */
|
|
142
|
+
margin: number;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* How far to lift the card so the keyboard does not cover it.
|
|
147
|
+
*
|
|
148
|
+
* The smallest lift that keeps the card's bottom `margin` above the keyboard's
|
|
149
|
+
* top — zero when the keyboard is closed or already clear — capped so the
|
|
150
|
+
* card's top never rises under the top safe-area inset, and never negative. A
|
|
151
|
+
* card too tall to fit both ways keeps its top on screen: the title and the
|
|
152
|
+
* field being typed into matter more than the footer.
|
|
153
|
+
*
|
|
154
|
+
* A worklet, because it runs inside the card's animated style on every frame
|
|
155
|
+
* of the keyboard's own animation.
|
|
156
|
+
*/
|
|
157
|
+
export function resolveDialogKeyboardLift({
|
|
158
|
+
keyboardHeight,
|
|
159
|
+
cardTop,
|
|
160
|
+
cardBottom,
|
|
161
|
+
windowHeight,
|
|
162
|
+
topInset,
|
|
163
|
+
margin,
|
|
164
|
+
}: DialogKeyboardLiftInput): number {
|
|
165
|
+
"worklet";
|
|
166
|
+
const keyboard = Math.abs(keyboardHeight);
|
|
167
|
+
if (keyboard === 0 || cardBottom <= 0) return 0;
|
|
168
|
+
|
|
169
|
+
const needed = cardBottom + margin - (windowHeight - keyboard);
|
|
170
|
+
const room = cardTop - topInset;
|
|
171
|
+
|
|
172
|
+
return Math.max(0, Math.min(needed, room));
|
|
173
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { Dialog, type DialogProps } from "./dialog";
|
|
2
|
+
export { type DialogContextValue, useDialog, useDialogContext } from "./dialog.context";
|
|
3
|
+
export {
|
|
4
|
+
DIALOG_CLOSE_HIT_SLOP,
|
|
5
|
+
DIALOG_ENTER_SCALE,
|
|
6
|
+
DIALOG_ENTER_TRANSLATE_Y,
|
|
7
|
+
DIALOG_FOOTER_VARIANTS,
|
|
8
|
+
DIALOG_KEYBOARD_MARGIN,
|
|
9
|
+
DIALOG_SCRIM_TOKEN,
|
|
10
|
+
DIALOG_SIZE_CLASS,
|
|
11
|
+
DIALOG_SIZES,
|
|
12
|
+
type DialogFooterDirection,
|
|
13
|
+
type DialogFooterVariant,
|
|
14
|
+
type DialogKeyboardLiftInput,
|
|
15
|
+
type DialogRole,
|
|
16
|
+
type DialogSize,
|
|
17
|
+
type DialogVariantProps,
|
|
18
|
+
dialogVariants,
|
|
19
|
+
resolveDialogFooterDirection,
|
|
20
|
+
resolveDialogKeyboardLift,
|
|
21
|
+
resolveDialogRole,
|
|
22
|
+
} from "./dialog.variants";
|
|
23
|
+
export type { DialogBodyProps } from "./dialog-body";
|
|
24
|
+
export type { DialogCloseProps } from "./dialog-close";
|
|
25
|
+
export type { DialogContentProps } from "./dialog-content";
|
|
26
|
+
export type { DialogDescriptionProps } from "./dialog-description";
|
|
27
|
+
export type { DialogFooterProps } from "./dialog-footer";
|
|
28
|
+
export type { DialogHeaderProps } from "./dialog-header";
|
|
29
|
+
export type { DialogTitleProps } from "./dialog-title";
|
|
30
|
+
export type { DialogTriggerProps } from "./dialog-trigger";
|