@funstack/ui 0.1.0-alpha.20 → 0.1.0-alpha.22
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/alert-dialog/alert-dialog-root.mjs +2 -1
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -1
- package/dist/avatar/avatar-context.mjs +24 -0
- package/dist/avatar/avatar-context.mjs.map +1 -0
- package/dist/avatar/avatar-fallback.d.mts +32 -0
- package/dist/avatar/avatar-fallback.d.mts.map +1 -0
- package/dist/avatar/avatar-fallback.mjs +31 -0
- package/dist/avatar/avatar-fallback.mjs.map +1 -0
- package/dist/avatar/avatar-image.d.mts +37 -0
- package/dist/avatar/avatar-image.d.mts.map +1 -0
- package/dist/avatar/avatar-image.mjs +91 -0
- package/dist/avatar/avatar-image.mjs.map +1 -0
- package/dist/avatar/avatar-root.d.mts +48 -0
- package/dist/avatar/avatar-root.d.mts.map +1 -0
- package/dist/avatar/avatar-root.mjs +81 -0
- package/dist/avatar/avatar-root.mjs.map +1 -0
- package/dist/avatar/index.d.mts +24 -0
- package/dist/avatar/index.d.mts.map +1 -0
- package/dist/avatar/index.mjs +24 -0
- package/dist/avatar/index.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +14 -3
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs +7 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +1 -0
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +20 -2
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.mjs +6 -4
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/docs/components/avatar.md +354 -0
- package/dist/docs/components/drawer.md +622 -0
- package/dist/docs/components/menu.md +1 -1
- package/dist/docs/components/menubar.md +309 -0
- package/dist/docs/components/meter.md +1 -1
- package/dist/docs/components/navigation-menu.md +501 -0
- package/dist/docs/components/number-field.md +2 -2
- package/dist/docs/components/otp-field.md +508 -0
- package/dist/docs/components/progress.md +1 -1
- package/dist/docs/components/radio-group.md +1 -1
- package/dist/docs/components/scroll-area.md +294 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/concepts/direction-and-locales.md +106 -0
- package/dist/docs/index.md +8 -1
- package/dist/docs/roadmap.md +13 -0
- package/dist/drawer/drawer-close.d.mts +26 -0
- package/dist/drawer/drawer-close.d.mts.map +1 -0
- package/dist/drawer/drawer-close.mjs +19 -0
- package/dist/drawer/drawer-close.mjs.map +1 -0
- package/dist/drawer/drawer-description.d.mts +23 -0
- package/dist/drawer/drawer-description.d.mts.map +1 -0
- package/dist/drawer/drawer-description.mjs +18 -0
- package/dist/drawer/drawer-description.mjs.map +1 -0
- package/dist/drawer/drawer-form.d.mts +24 -0
- package/dist/drawer/drawer-form.d.mts.map +1 -0
- package/dist/drawer/drawer-form.mjs +19 -0
- package/dist/drawer/drawer-form.mjs.map +1 -0
- package/dist/drawer/drawer-popup.d.mts +77 -0
- package/dist/drawer/drawer-popup.d.mts.map +1 -0
- package/dist/drawer/drawer-popup.mjs +124 -0
- package/dist/drawer/drawer-popup.mjs.map +1 -0
- package/dist/drawer/drawer-root.d.mts +31 -0
- package/dist/drawer/drawer-root.d.mts.map +1 -0
- package/dist/drawer/drawer-root.mjs +23 -0
- package/dist/drawer/drawer-root.mjs.map +1 -0
- package/dist/drawer/drawer-swipe.d.mts +5 -0
- package/dist/drawer/drawer-swipe.d.mts.map +1 -0
- package/dist/drawer/drawer-swipe.mjs +193 -0
- package/dist/drawer/drawer-swipe.mjs.map +1 -0
- package/dist/drawer/drawer-title.d.mts +23 -0
- package/dist/drawer/drawer-title.d.mts.map +1 -0
- package/dist/drawer/drawer-title.mjs +18 -0
- package/dist/drawer/drawer-title.mjs.map +1 -0
- package/dist/drawer/drawer-trigger.d.mts +23 -0
- package/dist/drawer/drawer-trigger.d.mts.map +1 -0
- package/dist/drawer/drawer-trigger.mjs +18 -0
- package/dist/drawer/drawer-trigger.mjs.map +1 -0
- package/dist/drawer/index.d.mts +34 -0
- package/dist/drawer/index.d.mts.map +1 -0
- package/dist/drawer/index.mjs +33 -0
- package/dist/drawer/index.mjs.map +1 -0
- package/dist/index.d.mts +29 -2
- package/dist/index.mjs +6 -1
- package/dist/internal/menubar-context.mjs +12 -0
- package/dist/internal/menubar-context.mjs.map +1 -0
- package/dist/internal/overlay/trigger-ref.mjs +1 -1
- package/dist/internal/overlay/trigger-ref.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +3 -2
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.mjs +2 -2
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/range-value.mjs +5 -3
- package/dist/internal/range-value.mjs.map +1 -1
- package/dist/internal/swipe-arithmetic.mjs +75 -0
- package/dist/internal/swipe-arithmetic.mjs.map +1 -0
- package/dist/internal/swipe.mjs +169 -0
- package/dist/internal/swipe.mjs.map +1 -0
- package/dist/menu/menu-context-trigger.mjs +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +34 -7
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +10 -3
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +53 -5
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menubar/index.d.mts +3 -0
- package/dist/menubar/index.mjs +1 -0
- package/dist/menubar/menubar.d.mts +49 -0
- package/dist/menubar/menubar.d.mts.map +1 -0
- package/dist/menubar/menubar.mjs +147 -0
- package/dist/menubar/menubar.mjs.map +1 -0
- package/dist/meter/meter-root.d.mts +3 -2
- package/dist/meter/meter-root.d.mts.map +1 -1
- package/dist/meter/meter-root.mjs.map +1 -1
- package/dist/multi-select/multi-select-root.mjs +1 -1
- package/dist/multi-select/multi-select-trigger.mjs +1 -1
- package/dist/navigation-menu/index.d.mts +32 -0
- package/dist/navigation-menu/index.d.mts.map +1 -0
- package/dist/navigation-menu/index.mjs +32 -0
- package/dist/navigation-menu/index.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-context.mjs +19 -0
- package/dist/navigation-menu/navigation-menu-context.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts +79 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.mjs +80 -0
- package/dist/navigation-menu/navigation-menu-item.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts +48 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.mjs +66 -0
- package/dist/navigation-menu/navigation-menu-link.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.mjs +30 -0
- package/dist/navigation-menu/navigation-menu-list.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts +102 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs +93 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.mjs +27 -0
- package/dist/navigation-menu/navigation-menu-root.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts +32 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs +42 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs.map +1 -0
- package/dist/otp-field/index.d.mts +23 -0
- package/dist/otp-field/index.d.mts.map +1 -0
- package/dist/otp-field/index.mjs +23 -0
- package/dist/otp-field/index.mjs.map +1 -0
- package/dist/otp-field/otp-field-context.mjs +13 -0
- package/dist/otp-field/otp-field-context.mjs.map +1 -0
- package/dist/otp-field/otp-field-filter.d.mts +5 -0
- package/dist/otp-field/otp-field-filter.d.mts.map +1 -0
- package/dist/otp-field/otp-field-filter.mjs +135 -0
- package/dist/otp-field/otp-field-filter.mjs.map +1 -0
- package/dist/otp-field/otp-field-input.d.mts +41 -0
- package/dist/otp-field/otp-field-input.d.mts.map +1 -0
- package/dist/otp-field/otp-field-input.mjs +177 -0
- package/dist/otp-field/otp-field-input.mjs.map +1 -0
- package/dist/otp-field/otp-field-root.d.mts +152 -0
- package/dist/otp-field/otp-field-root.d.mts.map +1 -0
- package/dist/otp-field/otp-field-root.mjs +400 -0
- package/dist/otp-field/otp-field-root.mjs.map +1 -0
- package/dist/otp-field/otp-field-slot.d.mts +52 -0
- package/dist/otp-field/otp-field-slot.d.mts.map +1 -0
- package/dist/otp-field/otp-field-slot.mjs +67 -0
- package/dist/otp-field/otp-field-slot.mjs.map +1 -0
- package/dist/popover/index.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/progress/progress-root.d.mts +3 -2
- package/dist/progress/progress-root.d.mts.map +1 -1
- package/dist/progress/progress-root.mjs.map +1 -1
- package/package.json +7 -1
- package/skills/funstack-ui-knowledge/SKILL.md +8 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-form.d.mts","names":[],"sources":["../../src/drawer/drawer-form.tsx"],"mappings":";;;YAKY,kBAAkB;;;;;;YAOlB,kBAAkB;;;;;;;;;wBAUd,WAAW,OAAO,kCAAe;yBAAjC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDialogForm } from "../dialog/dialog-form.mjs";
|
|
3
|
+
//#region src/drawer/drawer-form.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A form whose submission closes the drawer: exactly `Dialog.Form` (`method="dialog"` without
|
|
6
|
+
* `action`; with a function `action`, the drawer closes when its transition settles).
|
|
7
|
+
*
|
|
8
|
+
* Owned keys (conventions 1.2): `method` (except with a string `action`), `action`.
|
|
9
|
+
*
|
|
10
|
+
* @see https://ui.funstack.work/components/drawer
|
|
11
|
+
*/
|
|
12
|
+
function DrawerForm(props) {
|
|
13
|
+
return useDialogForm(props, "Drawer");
|
|
14
|
+
}
|
|
15
|
+
DrawerForm.displayName = "DrawerForm";
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DrawerForm };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=drawer-form.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-form.mjs","names":[],"sources":["../../src/drawer/drawer-form.tsx"],"sourcesContent":["\"use client\";\nimport { useDialogForm } from \"../dialog/dialog-form.js\";\nimport type { DialogFormProps, DialogFormState } from \"../dialog/dialog-form.js\";\n\n/** State of `Drawer.Form`: Dialog's (`useFormStatus().pending` of this form). */\nexport type DrawerFormState = DialogFormState;\n\n/**\n * Props of `Drawer.Form`: `Dialog.Form`'s.\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport type DrawerFormProps = DialogFormProps;\n\n/**\n * A form whose submission closes the drawer: exactly `Dialog.Form` (`method=\"dialog\"` without\n * `action`; with a function `action`, the drawer closes when its transition settles).\n *\n * Owned keys (conventions 1.2): `method` (except with a string `action`), `action`.\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport function DrawerForm(props: DrawerFormProps) {\n return useDialogForm(props, \"Drawer\");\n}\n\nDrawerForm.displayName = \"DrawerForm\";\n"],"mappings":";;;;;;;;;;;AAsBA,SAAgB,WAAW,OAAwB;CACjD,OAAO,cAAc,OAAO,QAAQ;AACtC;AAEA,WAAW,cAAc"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { DialogPopupProps, DialogPopupState } from "../dialog/dialog-popup.mjs";
|
|
3
|
+
import { DrawerSide } from "./drawer-swipe.mjs";
|
|
4
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
5
|
+
//#region src/drawer/drawer-popup.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* State of `Drawer.Popup`, passed to the function forms of `className`, `style`, `children` and
|
|
8
|
+
* `render`: Dialog's, with the `side`. A drag is not in the state: it is `data-swiping` and the
|
|
9
|
+
* `--drawer-swipe-*` properties, written to the DOM.
|
|
10
|
+
*/
|
|
11
|
+
export interface DrawerPopupState extends DialogPopupState {
|
|
12
|
+
/** The `side` prop. */
|
|
13
|
+
readonly side: DrawerSide;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Props of `Drawer.Popup`: `Dialog.Popup`'s, with `side` and `swipeDismiss`, and `lightDismiss`
|
|
17
|
+
* defaulting to the Root's `modal`.
|
|
18
|
+
*
|
|
19
|
+
* @see https://ui.funstack.work/components/drawer
|
|
20
|
+
*/
|
|
21
|
+
export interface DrawerPopupProps extends Omit<DialogPopupProps, "className" | "style" | "children" | "render"> {
|
|
22
|
+
/**
|
|
23
|
+
* The edge the drawer is attached to. Rendered as `data-side` (also in the server HTML); the
|
|
24
|
+
* swipe goes toward it. `inline-start` / `inline-end` follow the drawer's own `direction`.
|
|
25
|
+
* The library places nothing: style `[data-side]`.
|
|
26
|
+
*
|
|
27
|
+
* @defaultValue `"bottom"`
|
|
28
|
+
*/
|
|
29
|
+
side?: DrawerSide;
|
|
30
|
+
/**
|
|
31
|
+
* Let the user drag the drawer toward its edge to close it (mouse, pen, touch; after
|
|
32
|
+
* hydration). The close is a dismissal: reported to `onOpenChange`, never to
|
|
33
|
+
* `openChangeAction`. While dragging the drawer has `data-swiping`, `--drawer-swipe-x`,
|
|
34
|
+
* `--drawer-swipe-y` and `--drawer-swipe-progress`; your CSS moves it. Also renders an inline
|
|
35
|
+
* `touch-action`. Always give another way to close (`Drawer.Close`).
|
|
36
|
+
*
|
|
37
|
+
* @defaultValue `true`
|
|
38
|
+
*/
|
|
39
|
+
swipeDismiss?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* As `Dialog.Popup`'s: close on a press outside the drawer (on the backdrop of a modal one).
|
|
42
|
+
*
|
|
43
|
+
* @defaultValue the Root's `modal`
|
|
44
|
+
*/
|
|
45
|
+
lightDismiss?: boolean;
|
|
46
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
47
|
+
className?: StateValue<string | undefined, DrawerPopupState>;
|
|
48
|
+
/** Inline style, or a function of the part's state that returns one. Merged over the `touch-action`. */
|
|
49
|
+
style?: StateValue<CSSProperties | undefined, DrawerPopupState>;
|
|
50
|
+
/** Content, or a function of the part's state. */
|
|
51
|
+
children?: StateValue<ReactNode, DrawerPopupState>;
|
|
52
|
+
/** Must render a `<dialog>`. */
|
|
53
|
+
render?: RenderProp<ComponentPropsWithRef<"dialog">, DrawerPopupState>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The drawer: `Dialog.Popup` (a `<dialog>`, with everything a dialog does) attached to an edge.
|
|
57
|
+
* `side` is rendered as `data-side`; the library writes no inset, size or transform. With
|
|
58
|
+
* `swipeDismiss` (default), a drag toward that edge (mouse, pen or touch, after hydration)
|
|
59
|
+
* follows the pointer through `--drawer-swipe-x` / `-y` / `-progress` and, released past a
|
|
60
|
+
* quarter of the drawer or with a flick, finishes the slide with your CSS transition and then
|
|
61
|
+
* closes the dialog with `requestClose()`: a fact, reported to `onOpenChange(false, { reason:
|
|
62
|
+
* "dismiss", event: <the pointerup> })`. A press inside a scroll container along the drawer's
|
|
63
|
+
* axis scrolls it and never drags.
|
|
64
|
+
*
|
|
65
|
+
* Owned keys (conventions 1.2): Dialog.Popup's (`id`, `open`, `closedby`, `aria-labelledby` and
|
|
66
|
+
* `aria-describedby` token-merged, `data-modal`, `suppressHydrationWarning`), `data-side`,
|
|
67
|
+
* `data-swiping`; the inline `touch-action` is merged under your `style`.
|
|
68
|
+
*
|
|
69
|
+
* @see https://ui.funstack.work/components/drawer
|
|
70
|
+
*/
|
|
71
|
+
export declare function DrawerPopup({ side, swipeDismiss, lightDismiss, className, style, children, render, ...rest }: DrawerPopupProps): ReactNode;
|
|
72
|
+
export declare namespace DrawerPopup {
|
|
73
|
+
var displayName: string;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export type { DrawerSide };
|
|
77
|
+
//# sourceMappingURL=drawer-popup.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-popup.d.mts","names":[],"sources":["../../src/drawer/drawer-popup.tsx"],"mappings":";;;;;;;;;;iBAqBiB,yBAAyB;;WAE/B,MAAM;;;;;;;;iBASA,yBAAyB,KACxC;;;;;;;;EAUA,OAAO;;;;;;;;;;EAUP;;;;;;EAMA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;wBAmBvC,cACd,MACA,cACA,cACA,WACA,OACA,UACA,WACG,QACF,mBAAgB;yBATH"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
3
|
+
import { DialogCloseRegistry, useDialogContext } from "../dialog/dialog-context.mjs";
|
|
4
|
+
import { useDialogPopup } from "../dialog/dialog-popup.mjs";
|
|
5
|
+
import { isVerticalSide, listenDrawerSwipe, swipeTouchAction } from "./drawer-swipe.mjs";
|
|
6
|
+
import { useCallback, useRef } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
//#region src/drawer/drawer-popup.tsx
|
|
9
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
10
|
+
/**
|
|
11
|
+
* The drawer: `Dialog.Popup` (a `<dialog>`, with everything a dialog does) attached to an edge.
|
|
12
|
+
* `side` is rendered as `data-side`; the library writes no inset, size or transform. With
|
|
13
|
+
* `swipeDismiss` (default), a drag toward that edge (mouse, pen or touch, after hydration)
|
|
14
|
+
* follows the pointer through `--drawer-swipe-x` / `-y` / `-progress` and, released past a
|
|
15
|
+
* quarter of the drawer or with a flick, finishes the slide with your CSS transition and then
|
|
16
|
+
* closes the dialog with `requestClose()`: a fact, reported to `onOpenChange(false, { reason:
|
|
17
|
+
* "dismiss", event: <the pointerup> })`. A press inside a scroll container along the drawer's
|
|
18
|
+
* axis scrolls it and never drags.
|
|
19
|
+
*
|
|
20
|
+
* Owned keys (conventions 1.2): Dialog.Popup's (`id`, `open`, `closedby`, `aria-labelledby` and
|
|
21
|
+
* `aria-describedby` token-merged, `data-modal`, `suppressHydrationWarning`), `data-side`,
|
|
22
|
+
* `data-swiping`; the inline `touch-action` is merged under your `style`.
|
|
23
|
+
*
|
|
24
|
+
* @see https://ui.funstack.work/components/drawer
|
|
25
|
+
*/
|
|
26
|
+
function DrawerPopup({ side = "bottom", swipeDismiss = true, lightDismiss, className, style, children, render, ...rest }) {
|
|
27
|
+
const ctx = useDialogContext("Drawer.Popup");
|
|
28
|
+
const { popupRef } = ctx;
|
|
29
|
+
const extend = (state) => ({
|
|
30
|
+
...state,
|
|
31
|
+
side
|
|
32
|
+
});
|
|
33
|
+
const checks = useRef({
|
|
34
|
+
closeSeen: false,
|
|
35
|
+
closeWarned: false,
|
|
36
|
+
scrollWarned: false,
|
|
37
|
+
listWarned: false
|
|
38
|
+
});
|
|
39
|
+
const registerClose = useCallback((element) => {
|
|
40
|
+
const dialog = popupRef.current;
|
|
41
|
+
if (dialog === null || element.closest("dialog") === dialog) checks.current.closeSeen = true;
|
|
42
|
+
}, [popupRef]);
|
|
43
|
+
const attachDismiss = useCallback((dialog, dismiss) => {
|
|
44
|
+
const stopSwipe = listenDrawerSwipe(dialog, side, dismiss, isDev && !isVerticalSide(side) ? (scroller) => warnVerticalListInSideDrawer(scroller, checks.current) : void 0);
|
|
45
|
+
const stopChecks = isDev ? watchDevChecks(dialog, side, checks.current) : void 0;
|
|
46
|
+
return () => {
|
|
47
|
+
stopSwipe();
|
|
48
|
+
stopChecks?.();
|
|
49
|
+
};
|
|
50
|
+
}, [side]);
|
|
51
|
+
const touchAction = swipeDismiss ? { touchAction: swipeTouchAction(side) } : void 0;
|
|
52
|
+
const ownProps = {
|
|
53
|
+
"data-side": side,
|
|
54
|
+
"data-swiping": void 0
|
|
55
|
+
};
|
|
56
|
+
return useDialogPopup({
|
|
57
|
+
...rest,
|
|
58
|
+
lightDismiss: lightDismiss ?? ctx.modal,
|
|
59
|
+
className: typeof className === "function" ? (s) => className(extend(s)) : className,
|
|
60
|
+
style: (s) => touchAction === void 0 ? resolveStateValue(style, extend(s)) : {
|
|
61
|
+
...touchAction,
|
|
62
|
+
...resolveStateValue(style, extend(s))
|
|
63
|
+
},
|
|
64
|
+
children: typeof children === "function" ? (s) => children(extend(s)) : children,
|
|
65
|
+
render: typeof render === "function" ? (props, s) => render(props, extend(s)) : render
|
|
66
|
+
}, {
|
|
67
|
+
namespace: "Drawer",
|
|
68
|
+
ownProps,
|
|
69
|
+
attachDismiss: swipeDismiss ? attachDismiss : void 0,
|
|
70
|
+
wrapChildren: !isDev ? void 0 : (content) => /* @__PURE__ */ jsx(DialogCloseRegistry, {
|
|
71
|
+
value: registerClose,
|
|
72
|
+
children: content
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
DrawerPopup.displayName = "DrawerPopup";
|
|
77
|
+
/**
|
|
78
|
+
* Development check (design 5.1): a press in a side drawer refused by a scroll container that
|
|
79
|
+
* scrolls only vertically. Computed `overflow` pairs the axes (`overflow-y: auto` makes
|
|
80
|
+
* `overflow-x` compute to `auto`), so a vertical list is also a horizontal scroll container by
|
|
81
|
+
* the rule, and a swipe never starts in it. Warns once per instance when the refusing element has
|
|
82
|
+
* `overflow-x: auto`, a non-`visible` `overflow-y`, and nothing to scroll horizontally.
|
|
83
|
+
*/
|
|
84
|
+
function warnVerticalListInSideDrawer(scroller, checks) {
|
|
85
|
+
if (checks.listWarned) return;
|
|
86
|
+
const style = getComputedStyle(scroller);
|
|
87
|
+
if (style.overflowX !== "auto" || style.overflowY === "visible") return;
|
|
88
|
+
if (scroller.scrollWidth > scroller.clientWidth) return;
|
|
89
|
+
checks.listWarned = true;
|
|
90
|
+
console.error("Drawer.Popup: a press in a vertically scrolling element of this side drawer did not start a swipe. `overflow-y: auto` makes `overflow-x` compute to `auto`, so the element is a horizontal scroll container, which keeps its presses (also for touch). To let the drawer be swiped from it, give it `overflow-x: hidden; touch-action: pan-y pinch-zoom`.", scroller);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Development checks of a drawer with the swipe, installed with it:
|
|
94
|
+
* - design 7: another way to close it. Warns at the `close` of a showing during which no Close
|
|
95
|
+
* part of this drawer was mounted.
|
|
96
|
+
* - design 5.1: a `top` / `bottom` drawer whose dialog is itself the scroller cannot be scrolled
|
|
97
|
+
* by touch (`touch-action: pan-x`). Checked when it has opened.
|
|
98
|
+
*/
|
|
99
|
+
function watchDevChecks(dialog, side, checks) {
|
|
100
|
+
const onToggle = (event) => {
|
|
101
|
+
if (event.target !== dialog || checks.scrollWarned || !dialog.open) return;
|
|
102
|
+
if (!isVerticalSide(side)) return;
|
|
103
|
+
const overflow = getComputedStyle(dialog).overflowY;
|
|
104
|
+
if (overflow !== "auto" && overflow !== "scroll") return;
|
|
105
|
+
if (dialog.scrollHeight <= dialog.clientHeight) return;
|
|
106
|
+
checks.scrollWarned = true;
|
|
107
|
+
console.error(`Drawer.Popup: this ${side} drawer scrolls its own content, which touch cannot scroll while the swipe owns the vertical axis (\`touch-action: pan-x\`). Scroll in a child (\`overflow-y: auto\` on a body element) and give the dialog \`overflow: hidden\`.`);
|
|
108
|
+
};
|
|
109
|
+
const onClose = (event) => {
|
|
110
|
+
if (event.target !== dialog || checks.closeWarned || checks.closeSeen) return;
|
|
111
|
+
checks.closeWarned = true;
|
|
112
|
+
console.error("Drawer.Popup: the drawer has no Drawer.Close. A swipe is a path-based gesture: give another way to close the drawer (WCAG 2.5.1), which is also the only one before hydration on a phone.");
|
|
113
|
+
};
|
|
114
|
+
dialog.addEventListener("toggle", onToggle);
|
|
115
|
+
dialog.addEventListener("close", onClose);
|
|
116
|
+
return () => {
|
|
117
|
+
dialog.removeEventListener("toggle", onToggle);
|
|
118
|
+
dialog.removeEventListener("close", onClose);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
export { DrawerPopup };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=drawer-popup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-popup.mjs","names":[],"sources":["../../src/drawer/drawer-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { DialogCloseRegistry, useDialogContext } from \"../dialog/dialog-context.js\";\nimport { useDialogPopup } from \"../dialog/dialog-popup.js\";\nimport type { DialogPopupProps, DialogPopupState } from \"../dialog/dialog-popup.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { isVerticalSide, listenDrawerSwipe, swipeTouchAction } from \"./drawer-swipe.js\";\nimport type { DrawerSide } from \"./drawer-swipe.js\";\n\nexport type { DrawerSide } from \"./drawer-swipe.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Drawer.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`: Dialog's, with the `side`. A drag is not in the state: it is `data-swiping` and the\n * `--drawer-swipe-*` properties, written to the DOM.\n */\nexport interface DrawerPopupState extends DialogPopupState {\n /** The `side` prop. */\n readonly side: DrawerSide;\n}\n\n/**\n * Props of `Drawer.Popup`: `Dialog.Popup`'s, with `side` and `swipeDismiss`, and `lightDismiss`\n * defaulting to the Root's `modal`.\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport interface DrawerPopupProps extends Omit<\n DialogPopupProps,\n \"className\" | \"style\" | \"children\" | \"render\"\n> {\n /**\n * The edge the drawer is attached to. Rendered as `data-side` (also in the server HTML); the\n * swipe goes toward it. `inline-start` / `inline-end` follow the drawer's own `direction`.\n * The library places nothing: style `[data-side]`.\n *\n * @defaultValue `\"bottom\"`\n */\n side?: DrawerSide;\n /**\n * Let the user drag the drawer toward its edge to close it (mouse, pen, touch; after\n * hydration). The close is a dismissal: reported to `onOpenChange`, never to\n * `openChangeAction`. While dragging the drawer has `data-swiping`, `--drawer-swipe-x`,\n * `--drawer-swipe-y` and `--drawer-swipe-progress`; your CSS moves it. Also renders an inline\n * `touch-action`. Always give another way to close (`Drawer.Close`).\n *\n * @defaultValue `true`\n */\n swipeDismiss?: boolean;\n /**\n * As `Dialog.Popup`'s: close on a press outside the drawer (on the backdrop of a modal one).\n *\n * @defaultValue the Root's `modal`\n */\n lightDismiss?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DrawerPopupState>;\n /** Inline style, or a function of the part's state that returns one. Merged over the `touch-action`. */\n style?: StateValue<CSSProperties | undefined, DrawerPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DrawerPopupState>;\n /** Must render a `<dialog>`. */\n render?: RenderProp<ComponentPropsWithRef<\"dialog\">, DrawerPopupState>;\n}\n\n/**\n * The drawer: `Dialog.Popup` (a `<dialog>`, with everything a dialog does) attached to an edge.\n * `side` is rendered as `data-side`; the library writes no inset, size or transform. With\n * `swipeDismiss` (default), a drag toward that edge (mouse, pen or touch, after hydration)\n * follows the pointer through `--drawer-swipe-x` / `-y` / `-progress` and, released past a\n * quarter of the drawer or with a flick, finishes the slide with your CSS transition and then\n * closes the dialog with `requestClose()`: a fact, reported to `onOpenChange(false, { reason:\n * \"dismiss\", event: <the pointerup> })`. A press inside a scroll container along the drawer's\n * axis scrolls it and never drags.\n *\n * Owned keys (conventions 1.2): Dialog.Popup's (`id`, `open`, `closedby`, `aria-labelledby` and\n * `aria-describedby` token-merged, `data-modal`, `suppressHydrationWarning`), `data-side`,\n * `data-swiping`; the inline `touch-action` is merged under your `style`.\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport function DrawerPopup({\n side = \"bottom\",\n swipeDismiss = true,\n lightDismiss,\n className,\n style,\n children,\n render,\n ...rest\n}: DrawerPopupProps) {\n const ctx = useDialogContext(\"Drawer.Popup\");\n const { popupRef } = ctx;\n const extend = (state: DialogPopupState): DrawerPopupState => ({ ...state, side });\n\n // Development checks (design 5.1, 7), once per instance.\n const checks = useRef<DevChecks>({\n closeSeen: false,\n closeWarned: false,\n scrollWarned: false,\n listWarned: false,\n });\n const registerClose = useCallback(\n (element: Element) => {\n const dialog = popupRef.current;\n if (dialog === null || element.closest(\"dialog\") === dialog) {\n checks.current.closeSeen = true;\n }\n },\n [popupRef],\n );\n\n const attachDismiss = useCallback(\n (dialog: HTMLDialogElement, dismiss: (event: Event) => void) => {\n const stopSwipe = listenDrawerSwipe(\n dialog,\n side,\n dismiss,\n isDev && !isVerticalSide(side)\n ? (scroller) => warnVerticalListInSideDrawer(scroller, checks.current)\n : undefined,\n );\n const stopChecks = isDev ? watchDevChecks(dialog, side, checks.current) : undefined;\n return () => {\n stopSwipe();\n stopChecks?.();\n };\n },\n [side],\n );\n\n const touchAction: CSSProperties | undefined = swipeDismiss\n ? { touchAction: swipeTouchAction(side) }\n : undefined;\n\n const ownProps: ComponentPropsWithRef<\"dialog\"> & DataAttributes = {\n \"data-side\": side,\n // Written through the DOM while a pointer drags (design 4.3); owned so a prop cannot set it.\n \"data-swiping\": undefined,\n };\n\n return useDialogPopup(\n {\n ...rest,\n lightDismiss: lightDismiss ?? ctx.modal,\n className: typeof className === \"function\" ? (s) => className(extend(s)) : className,\n style: (s) =>\n touchAction === undefined\n ? resolveStateValue(style, extend(s))\n : { ...touchAction, ...resolveStateValue(style, extend(s)) },\n children: typeof children === \"function\" ? (s) => children(extend(s)) : children,\n render: typeof render === \"function\" ? (props, s) => render(props, extend(s)) : render,\n },\n {\n namespace: \"Drawer\",\n ownProps,\n attachDismiss: swipeDismiss ? attachDismiss : undefined,\n wrapChildren: !isDev\n ? undefined\n : (content: ReactNode) => (\n <DialogCloseRegistry value={registerClose}>{content}</DialogCloseRegistry>\n ),\n },\n );\n}\n\nDrawerPopup.displayName = \"DrawerPopup\";\n\n/** Once-per-instance flags of the development checks (design 5.1, 7). */\ninterface DevChecks {\n /** A Close part of this drawer has mounted. */\n closeSeen: boolean;\n closeWarned: boolean;\n scrollWarned: boolean;\n /** The side-drawer list warning (design 5.1) has been logged. */\n listWarned: boolean;\n}\n\n/**\n * Development check (design 5.1): a press in a side drawer refused by a scroll container that\n * scrolls only vertically. Computed `overflow` pairs the axes (`overflow-y: auto` makes\n * `overflow-x` compute to `auto`), so a vertical list is also a horizontal scroll container by\n * the rule, and a swipe never starts in it. Warns once per instance when the refusing element has\n * `overflow-x: auto`, a non-`visible` `overflow-y`, and nothing to scroll horizontally.\n */\nfunction warnVerticalListInSideDrawer(scroller: Element, checks: DevChecks): void {\n if (checks.listWarned) return;\n const style = getComputedStyle(scroller);\n if (style.overflowX !== \"auto\" || style.overflowY === \"visible\") return;\n if (scroller.scrollWidth > scroller.clientWidth) return;\n checks.listWarned = true;\n console.error(\n \"Drawer.Popup: a press in a vertically scrolling element of this side drawer did not start \" +\n \"a swipe. `overflow-y: auto` makes `overflow-x` compute to `auto`, so the element is a \" +\n \"horizontal scroll container, which keeps its presses (also for touch). To let the drawer \" +\n \"be swiped from it, give it `overflow-x: hidden; touch-action: pan-y pinch-zoom`.\",\n scroller,\n );\n}\n\n/**\n * Development checks of a drawer with the swipe, installed with it:\n * - design 7: another way to close it. Warns at the `close` of a showing during which no Close\n * part of this drawer was mounted.\n * - design 5.1: a `top` / `bottom` drawer whose dialog is itself the scroller cannot be scrolled\n * by touch (`touch-action: pan-x`). Checked when it has opened.\n */\nfunction watchDevChecks(\n dialog: HTMLDialogElement,\n side: DrawerSide,\n checks: DevChecks,\n): () => void {\n const onToggle = (event: Event) => {\n if (event.target !== dialog || checks.scrollWarned || !dialog.open) return;\n if (!isVerticalSide(side)) return;\n const overflow = getComputedStyle(dialog).overflowY;\n if (overflow !== \"auto\" && overflow !== \"scroll\") return;\n if (dialog.scrollHeight <= dialog.clientHeight) return;\n checks.scrollWarned = true;\n console.error(\n `Drawer.Popup: this ${side} drawer scrolls its own content, which touch cannot scroll ` +\n \"while the swipe owns the vertical axis (`touch-action: pan-x`). Scroll in a child \" +\n \"(`overflow-y: auto` on a body element) and give the dialog `overflow: hidden`.\",\n );\n };\n const onClose = (event: Event) => {\n if (event.target !== dialog || checks.closeWarned || checks.closeSeen) return;\n checks.closeWarned = true;\n console.error(\n \"Drawer.Popup: the drawer has no Drawer.Close. A swipe is a path-based gesture: give \" +\n \"another way to close the drawer (WCAG 2.5.1), which is also the only one before \" +\n \"hydration on a phone.\",\n );\n };\n dialog.addEventListener(\"toggle\", onToggle);\n dialog.addEventListener(\"close\", onClose);\n return () => {\n dialog.removeEventListener(\"toggle\", onToggle);\n dialog.removeEventListener(\"close\", onClose);\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DialogOpenChangeDetails, DialogRootProps, DialogRootState } from "../dialog/dialog-root.mjs";
|
|
2
|
+
//#region src/drawer/drawer-root.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Details passed as the second argument of `openChangeAction` and `onOpenChange`: Dialog's.
|
|
5
|
+
* `reason` is `"activate"` for the Trigger, a Close or a Form; `"dismiss"` for Escape, a press
|
|
6
|
+
* on the backdrop and a swipe (a swipe's `details.event` is its `pointerup`).
|
|
7
|
+
*/
|
|
8
|
+
export type DrawerOpenChangeDetails = DialogOpenChangeDetails;
|
|
9
|
+
/** State of `Drawer.Root`, passed to the function form of `children`: Dialog's. */
|
|
10
|
+
export type DrawerRootState = DialogRootState;
|
|
11
|
+
/**
|
|
12
|
+
* Props of `Drawer.Root`: `Dialog.Root`'s. Without `open`, `defaultOpen`, `openChangeAction` and
|
|
13
|
+
* `onOpenChange` it is JS-free.
|
|
14
|
+
*
|
|
15
|
+
* @see https://ui.funstack.work/components/drawer
|
|
16
|
+
*/
|
|
17
|
+
export type DrawerRootProps = DialogRootProps;
|
|
18
|
+
/**
|
|
19
|
+
* `Dialog.Root` with the Drawer's transition types (`fsui-drawer`, `fsui-drawer-open`,
|
|
20
|
+
* `fsui-drawer-close`). Owns the ids, the mode and the open state; renders no DOM. Opening and
|
|
21
|
+
* the closes a part asks for are requests (`openChangeAction`); Escape, a press on the backdrop
|
|
22
|
+
* and a swipe are the browser's facts (`onOpenChange`).
|
|
23
|
+
*
|
|
24
|
+
* @see https://ui.funstack.work/components/drawer
|
|
25
|
+
*/
|
|
26
|
+
export declare function DrawerRoot({ modal, ...props }: DrawerRootProps): import("react").ReactNode;
|
|
27
|
+
export declare namespace DrawerRoot {
|
|
28
|
+
var displayName: string;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//# sourceMappingURL=drawer-root.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-root.d.mts","names":[],"sources":["../../src/drawer/drawer-root.tsx"],"mappings":";;;;;;;YAaY,0BAA0B;;YAG1B,kBAAkB;;;;;;;YAQlB,kBAAkB;;;;;;;;;wBAUd,aAAa,UAAiB,SAAS,kCAAe;yBAAtD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDialogRoot } from "../dialog/dialog-root.mjs";
|
|
3
|
+
//#region src/drawer/drawer-root.tsx
|
|
4
|
+
/**
|
|
5
|
+
* `Dialog.Root` with the Drawer's transition types (`fsui-drawer`, `fsui-drawer-open`,
|
|
6
|
+
* `fsui-drawer-close`). Owns the ids, the mode and the open state; renders no DOM. Opening and
|
|
7
|
+
* the closes a part asks for are requests (`openChangeAction`); Escape, a press on the backdrop
|
|
8
|
+
* and a swipe are the browser's facts (`onOpenChange`).
|
|
9
|
+
*
|
|
10
|
+
* @see https://ui.funstack.work/components/drawer
|
|
11
|
+
*/
|
|
12
|
+
function DrawerRoot({ modal = true, ...props }) {
|
|
13
|
+
return useDialogRoot(props, {
|
|
14
|
+
namespace: "Drawer",
|
|
15
|
+
modal,
|
|
16
|
+
component: "drawer"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
DrawerRoot.displayName = "DrawerRoot";
|
|
20
|
+
//#endregion
|
|
21
|
+
export { DrawerRoot };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=drawer-root.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-root.mjs","names":[],"sources":["../../src/drawer/drawer-root.tsx"],"sourcesContent":["\"use client\";\nimport { useDialogRoot } from \"../dialog/dialog-root.js\";\nimport type {\n DialogOpenChangeDetails,\n DialogRootProps,\n DialogRootState,\n} from \"../dialog/dialog-root.js\";\n\n/**\n * Details passed as the second argument of `openChangeAction` and `onOpenChange`: Dialog's.\n * `reason` is `\"activate\"` for the Trigger, a Close or a Form; `\"dismiss\"` for Escape, a press\n * on the backdrop and a swipe (a swipe's `details.event` is its `pointerup`).\n */\nexport type DrawerOpenChangeDetails = DialogOpenChangeDetails;\n\n/** State of `Drawer.Root`, passed to the function form of `children`: Dialog's. */\nexport type DrawerRootState = DialogRootState;\n\n/**\n * Props of `Drawer.Root`: `Dialog.Root`'s. Without `open`, `defaultOpen`, `openChangeAction` and\n * `onOpenChange` it is JS-free.\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport type DrawerRootProps = DialogRootProps;\n\n/**\n * `Dialog.Root` with the Drawer's transition types (`fsui-drawer`, `fsui-drawer-open`,\n * `fsui-drawer-close`). Owns the ids, the mode and the open state; renders no DOM. Opening and\n * the closes a part asks for are requests (`openChangeAction`); Escape, a press on the backdrop\n * and a swipe are the browser's facts (`onOpenChange`).\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport function DrawerRoot({ modal = true, ...props }: DrawerRootProps) {\n return useDialogRoot(props, { namespace: \"Drawer\", modal, component: \"drawer\" });\n}\n\nDrawerRoot.displayName = \"DrawerRoot\";\n"],"mappings":";;;;;;;;;;;AAkCA,SAAgB,WAAW,EAAE,QAAQ,MAAM,GAAG,SAA0B;CACtE,OAAO,cAAc,OAAO;EAAE,WAAW;EAAU;EAAO,WAAW;CAAS,CAAC;AACjF;AAEA,WAAW,cAAc"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//#region src/drawer/drawer-swipe.d.ts
|
|
2
|
+
/** The edge a drawer is attached to (conventions 13.1's `AnchorSide` vocabulary). */
|
|
3
|
+
export type DrawerSide = "top" | "bottom" | "left" | "right" | "inline-start" | "inline-end";
|
|
4
|
+
//#endregion
|
|
5
|
+
//# sourceMappingURL=drawer-swipe.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-swipe.d.mts","names":[],"sources":["../../src/drawer/drawer-swipe.ts"],"mappings":";;YAYY"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
2
|
+
import { animationBaseline, exitAnimations } from "../internal/overlay/use-exit-animation.mjs";
|
|
3
|
+
import { swipeTranslation } from "../internal/swipe-arithmetic.mjs";
|
|
4
|
+
import { trackSwipe } from "../internal/swipe.mjs";
|
|
5
|
+
//#region src/drawer/drawer-swipe.ts
|
|
6
|
+
/** The custom properties the drag writes (design 4.3). */
|
|
7
|
+
const SWIPE_X = "--drawer-swipe-x";
|
|
8
|
+
const SWIPE_Y = "--drawer-swipe-y";
|
|
9
|
+
const SWIPE_PROGRESS = "--drawer-swipe-progress";
|
|
10
|
+
/** Present on the Popup while a pointer drags it (design 4.3). */
|
|
11
|
+
const SWIPING = "data-swiping";
|
|
12
|
+
/** Whether the drawer's axis is vertical (`top` / `bottom`). */
|
|
13
|
+
function isVerticalSide(side) {
|
|
14
|
+
return side === "top" || side === "bottom";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The inline `touch-action` of a drawer with the swipe on (design 5.1): the browser keeps the
|
|
18
|
+
* cross axis and pinch zoom, the drawer's axis is the page's.
|
|
19
|
+
*/
|
|
20
|
+
function swipeTouchAction(side) {
|
|
21
|
+
return isVerticalSide(side) ? "pan-x pinch-zoom" : "pan-y pinch-zoom";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The direction a swipe dismisses toward: toward the side. An inline side reads the dialog's
|
|
25
|
+
* computed `direction`, at the press (design 2): a gesture-time read, not placement.
|
|
26
|
+
*/
|
|
27
|
+
function swipeDirectionOf(side, dialog) {
|
|
28
|
+
switch (side) {
|
|
29
|
+
case "top": return "up";
|
|
30
|
+
case "bottom": return "down";
|
|
31
|
+
case "left": return "left";
|
|
32
|
+
case "right": return "right";
|
|
33
|
+
case "inline-start":
|
|
34
|
+
case "inline-end": {
|
|
35
|
+
const rtl = getComputedStyle(dialog).direction === "rtl";
|
|
36
|
+
return side === "inline-end" !== rtl ? "right" : "left";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The distance that takes the dialog fully off its edge (design 4.1), from its box now (the
|
|
42
|
+
* offset is still 0 when the drag starts): for `down`, the viewport's height minus its top.
|
|
43
|
+
*/
|
|
44
|
+
function swipeExtent(dialog, direction) {
|
|
45
|
+
const rect = dialog.getBoundingClientRect();
|
|
46
|
+
const view = dialog.ownerDocument.defaultView;
|
|
47
|
+
const width = view?.innerWidth ?? 0;
|
|
48
|
+
const height = view?.innerHeight ?? 0;
|
|
49
|
+
switch (direction) {
|
|
50
|
+
case "down": return Math.max(0, height - rect.top);
|
|
51
|
+
case "up": return Math.max(0, rect.bottom);
|
|
52
|
+
case "right": return Math.max(0, width - rect.left);
|
|
53
|
+
case "left": return Math.max(0, rect.right);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Whether a pointer event on the dialog itself lies outside its border box (the `::backdrop`). */
|
|
57
|
+
function onBackdrop(dialog, event) {
|
|
58
|
+
const rect = dialog.getBoundingClientRect();
|
|
59
|
+
const { clientX: x, clientY: y } = event;
|
|
60
|
+
return !(rect.left <= x && x <= rect.right && rect.top <= y && y <= rect.bottom);
|
|
61
|
+
}
|
|
62
|
+
function isTextEntry(element) {
|
|
63
|
+
if (element.matches("input, textarea, select")) return true;
|
|
64
|
+
if (element.isContentEditable === true) return true;
|
|
65
|
+
const editable = element.getAttribute("contenteditable");
|
|
66
|
+
return editable !== null && editable.toLowerCase() !== "false";
|
|
67
|
+
}
|
|
68
|
+
/** Computed `overflow` on the axis makes a scroll container there (design 5.1). */
|
|
69
|
+
function scrollsOn(element, vertical) {
|
|
70
|
+
const style = getComputedStyle(element);
|
|
71
|
+
const overflow = vertical ? style.overflowY : style.overflowX;
|
|
72
|
+
return overflow === "auto" || overflow === "scroll";
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether a press can become a swipe of `dialog` (design 4.1 "Not a candidate", 5.1, 8.1): not
|
|
76
|
+
* on the `::backdrop`; its nearest `<dialog>` is this one (not a nested one); not inside an open
|
|
77
|
+
* popover, a text-entry or range control, or a scroll container along the drawer's axis between
|
|
78
|
+
* the target and the dialog (by computed `overflow`, whatever the overflow amount).
|
|
79
|
+
* `onScrollerRefusal` hears the scroll container that refused a press (a development check).
|
|
80
|
+
*/
|
|
81
|
+
function isSwipeCandidate(dialog, event, vertical, onScrollerRefusal) {
|
|
82
|
+
const target = event.target;
|
|
83
|
+
if (!(target instanceof Element)) return false;
|
|
84
|
+
if (target === dialog) return !onBackdrop(dialog, event);
|
|
85
|
+
if (target.closest("dialog") !== dialog) return false;
|
|
86
|
+
for (let node = target; node !== null && node !== dialog;) {
|
|
87
|
+
if (isTextEntry(node)) return false;
|
|
88
|
+
if (node.hasAttribute("popover") && isPopoverOpen(node)) return false;
|
|
89
|
+
if (scrollsOn(node, vertical)) {
|
|
90
|
+
onScrollerRefusal?.(node);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
node = node.parentElement;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
function clearOffset(dialog) {
|
|
98
|
+
dialog.style.removeProperty(SWIPE_X);
|
|
99
|
+
dialog.style.removeProperty(SWIPE_Y);
|
|
100
|
+
dialog.style.removeProperty(SWIPE_PROGRESS);
|
|
101
|
+
}
|
|
102
|
+
function writeOffset(dialog, offset, progress, direction) {
|
|
103
|
+
const [x, y] = swipeTranslation(offset, direction);
|
|
104
|
+
dialog.style.setProperty(SWIPE_X, `${x}px`);
|
|
105
|
+
dialog.style.setProperty(SWIPE_Y, `${y}px`);
|
|
106
|
+
dialog.style.setProperty(SWIPE_PROGRESS, String(progress));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Installs the swipe on a drawer's `<dialog>` and returns its cleanup (design 4.1, 4.2).
|
|
110
|
+
* `dismiss(event)` records the close intent and calls `requestClose()`. `onScrollerRefusal`
|
|
111
|
+
* hears a scroll container that refused a press (the development check of design 5.1).
|
|
112
|
+
*/
|
|
113
|
+
function listenDrawerSwipe(dialog, side, dismiss, onScrollerRefusal) {
|
|
114
|
+
const vertical = isVerticalSide(side);
|
|
115
|
+
let direction = "down";
|
|
116
|
+
/** A dismissal waits for its slide: presses start nothing meanwhile. */
|
|
117
|
+
let closing = false;
|
|
118
|
+
let disposed = false;
|
|
119
|
+
/**
|
|
120
|
+
* The showing a release belongs to: bumped by every open, so a slide that outlives its
|
|
121
|
+
* showing (closed by Escape and opened again before the slide settled) closes nothing.
|
|
122
|
+
*/
|
|
123
|
+
let generation = 0;
|
|
124
|
+
const tracker = trackSwipe(dialog, {
|
|
125
|
+
press: (event) => {
|
|
126
|
+
if (closing || !dialog.open) return null;
|
|
127
|
+
if (!isSwipeCandidate(dialog, event, vertical, onScrollerRefusal)) return null;
|
|
128
|
+
direction = swipeDirectionOf(side, dialog);
|
|
129
|
+
return direction;
|
|
130
|
+
},
|
|
131
|
+
extent: () => swipeExtent(dialog, direction),
|
|
132
|
+
start: () => {
|
|
133
|
+
dialog.setAttribute(SWIPING, "");
|
|
134
|
+
},
|
|
135
|
+
move: (offset, progress) => {
|
|
136
|
+
writeOffset(dialog, offset, progress, direction);
|
|
137
|
+
},
|
|
138
|
+
end: ({ outcome, event, extent }) => {
|
|
139
|
+
const baseline = animationBaseline(dialog);
|
|
140
|
+
dialog.removeAttribute(SWIPING);
|
|
141
|
+
if (outcome !== "dismiss") {
|
|
142
|
+
clearOffset(dialog);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
writeOffset(dialog, extent, 1, direction);
|
|
146
|
+
closing = true;
|
|
147
|
+
const showing = generation;
|
|
148
|
+
const close = () => {
|
|
149
|
+
if (disposed || showing !== generation) return;
|
|
150
|
+
closing = false;
|
|
151
|
+
if (!dialog.open) return;
|
|
152
|
+
dismiss(event);
|
|
153
|
+
if (dialog.open) clearOffset(dialog);
|
|
154
|
+
};
|
|
155
|
+
const animations = exitAnimations(dialog, baseline);
|
|
156
|
+
if (animations.length === 0) close();
|
|
157
|
+
else Promise.allSettled(animations.map((animation) => animation.finished)).then(close);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
const onBeforeToggle = (event) => {
|
|
161
|
+
if (event.target !== dialog) return;
|
|
162
|
+
if (event.newState === "open") {
|
|
163
|
+
generation++;
|
|
164
|
+
closing = false;
|
|
165
|
+
clearOffset(dialog);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (tracker.dragging()) {
|
|
169
|
+
tracker.cancel();
|
|
170
|
+
dialog.removeAttribute(SWIPING);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const onClose = (event) => {
|
|
174
|
+
if (event.target !== dialog) return;
|
|
175
|
+
tracker.cancel();
|
|
176
|
+
dialog.removeAttribute(SWIPING);
|
|
177
|
+
clearOffset(dialog);
|
|
178
|
+
};
|
|
179
|
+
dialog.addEventListener("beforetoggle", onBeforeToggle);
|
|
180
|
+
dialog.addEventListener("close", onClose);
|
|
181
|
+
return () => {
|
|
182
|
+
disposed = true;
|
|
183
|
+
tracker.dispose();
|
|
184
|
+
dialog.removeEventListener("beforetoggle", onBeforeToggle);
|
|
185
|
+
dialog.removeEventListener("close", onClose);
|
|
186
|
+
dialog.removeAttribute(SWIPING);
|
|
187
|
+
clearOffset(dialog);
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
export { SWIPE_PROGRESS, SWIPE_X, SWIPE_Y, SWIPING, isSwipeCandidate, isVerticalSide, listenDrawerSwipe, swipeDirectionOf, swipeExtent, swipeTouchAction };
|
|
192
|
+
|
|
193
|
+
//# sourceMappingURL=drawer-swipe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-swipe.mjs","names":[],"sources":["../../src/drawer/drawer-swipe.ts"],"sourcesContent":["// The Drawer's swipe to dismiss (design/components/drawer.md 4, 5): the glue between the\n// dialog-agnostic tracker (`internal/swipe.ts`) and a `<dialog>`: which presses are candidates,\n// which way the edge is, how far it is, the custom properties, and the release that finishes\n// the slide before the browser closes the dialog. No directive: DOM listeners only\n// (conventions 7.1); only `drawer-popup.tsx` imports it.\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { animationBaseline, exitAnimations } from \"../internal/overlay/use-exit-animation.js\";\nimport { swipeTranslation } from \"../internal/swipe-arithmetic.js\";\nimport type { SwipeDirection } from \"../internal/swipe-arithmetic.js\";\nimport { trackSwipe } from \"../internal/swipe.js\";\n\n/** The edge a drawer is attached to (conventions 13.1's `AnchorSide` vocabulary). */\nexport type DrawerSide = \"top\" | \"bottom\" | \"left\" | \"right\" | \"inline-start\" | \"inline-end\";\n\n/** The custom properties the drag writes (design 4.3). */\nexport const SWIPE_X = \"--drawer-swipe-x\";\nexport const SWIPE_Y = \"--drawer-swipe-y\";\nexport const SWIPE_PROGRESS = \"--drawer-swipe-progress\";\n/** Present on the Popup while a pointer drags it (design 4.3). */\nexport const SWIPING = \"data-swiping\";\n\n/** Whether the drawer's axis is vertical (`top` / `bottom`). */\nexport function isVerticalSide(side: DrawerSide): boolean {\n return side === \"top\" || side === \"bottom\";\n}\n\n/**\n * The inline `touch-action` of a drawer with the swipe on (design 5.1): the browser keeps the\n * cross axis and pinch zoom, the drawer's axis is the page's.\n */\nexport function swipeTouchAction(side: DrawerSide): string {\n return isVerticalSide(side) ? \"pan-x pinch-zoom\" : \"pan-y pinch-zoom\";\n}\n\n/**\n * The direction a swipe dismisses toward: toward the side. An inline side reads the dialog's\n * computed `direction`, at the press (design 2): a gesture-time read, not placement.\n */\nexport function swipeDirectionOf(side: DrawerSide, dialog: Element): SwipeDirection {\n switch (side) {\n case \"top\":\n return \"up\";\n case \"bottom\":\n return \"down\";\n case \"left\":\n return \"left\";\n case \"right\":\n return \"right\";\n case \"inline-start\":\n case \"inline-end\": {\n const rtl = getComputedStyle(dialog).direction === \"rtl\";\n return (side === \"inline-end\") !== rtl ? \"right\" : \"left\";\n }\n }\n}\n\n/**\n * The distance that takes the dialog fully off its edge (design 4.1), from its box now (the\n * offset is still 0 when the drag starts): for `down`, the viewport's height minus its top.\n */\nexport function swipeExtent(dialog: Element, direction: SwipeDirection): number {\n const rect = dialog.getBoundingClientRect();\n const view = dialog.ownerDocument.defaultView;\n const width = view?.innerWidth ?? 0;\n const height = view?.innerHeight ?? 0;\n switch (direction) {\n case \"down\":\n return Math.max(0, height - rect.top);\n case \"up\":\n return Math.max(0, rect.bottom);\n case \"right\":\n return Math.max(0, width - rect.left);\n case \"left\":\n return Math.max(0, rect.right);\n }\n}\n\n/** Whether a pointer event on the dialog itself lies outside its border box (the `::backdrop`). */\nfunction onBackdrop(dialog: Element, event: PointerEvent): boolean {\n const rect = dialog.getBoundingClientRect();\n const { clientX: x, clientY: y } = event;\n return !(rect.left <= x && x <= rect.right && rect.top <= y && y <= rect.bottom);\n}\n\nfunction isTextEntry(element: Element): boolean {\n if (element.matches(\"input, textarea, select\")) return true;\n if ((element as HTMLElement).isContentEditable === true) return true;\n // jsdom has no `isContentEditable`.\n const editable = element.getAttribute(\"contenteditable\");\n return editable !== null && editable.toLowerCase() !== \"false\";\n}\n\n/** Computed `overflow` on the axis makes a scroll container there (design 5.1). */\nfunction scrollsOn(element: Element, vertical: boolean): boolean {\n const style = getComputedStyle(element);\n const overflow = vertical ? style.overflowY : style.overflowX;\n return overflow === \"auto\" || overflow === \"scroll\";\n}\n\n/**\n * Whether a press can become a swipe of `dialog` (design 4.1 \"Not a candidate\", 5.1, 8.1): not\n * on the `::backdrop`; its nearest `<dialog>` is this one (not a nested one); not inside an open\n * popover, a text-entry or range control, or a scroll container along the drawer's axis between\n * the target and the dialog (by computed `overflow`, whatever the overflow amount).\n * `onScrollerRefusal` hears the scroll container that refused a press (a development check).\n */\nexport function isSwipeCandidate(\n dialog: HTMLDialogElement,\n event: PointerEvent,\n vertical: boolean,\n onScrollerRefusal?: (scroller: Element) => void,\n): boolean {\n const target = event.target;\n if (!(target instanceof Element)) return false;\n if (target === dialog) return !onBackdrop(dialog, event);\n if (target.closest(\"dialog\") !== dialog) return false;\n for (let node: Element | null = target; node !== null && node !== dialog;) {\n if (isTextEntry(node)) return false;\n if (node.hasAttribute(\"popover\") && isPopoverOpen(node)) return false;\n if (scrollsOn(node, vertical)) {\n onScrollerRefusal?.(node);\n return false;\n }\n node = node.parentElement;\n }\n return true;\n}\n\nfunction clearOffset(dialog: HTMLElement): void {\n dialog.style.removeProperty(SWIPE_X);\n dialog.style.removeProperty(SWIPE_Y);\n dialog.style.removeProperty(SWIPE_PROGRESS);\n}\n\nfunction writeOffset(\n dialog: HTMLElement,\n offset: number,\n progress: number,\n direction: SwipeDirection,\n): void {\n const [x, y] = swipeTranslation(offset, direction);\n dialog.style.setProperty(SWIPE_X, `${x}px`);\n dialog.style.setProperty(SWIPE_Y, `${y}px`);\n dialog.style.setProperty(SWIPE_PROGRESS, String(progress));\n}\n\n/**\n * Installs the swipe on a drawer's `<dialog>` and returns its cleanup (design 4.1, 4.2).\n * `dismiss(event)` records the close intent and calls `requestClose()`. `onScrollerRefusal`\n * hears a scroll container that refused a press (the development check of design 5.1).\n */\nexport function listenDrawerSwipe(\n dialog: HTMLDialogElement,\n side: DrawerSide,\n dismiss: (event: Event) => void,\n onScrollerRefusal?: (scroller: Element) => void,\n): () => void {\n const vertical = isVerticalSide(side);\n let direction: SwipeDirection = \"down\";\n /** A dismissal waits for its slide: presses start nothing meanwhile. */\n let closing = false;\n let disposed = false;\n /**\n * The showing a release belongs to: bumped by every open, so a slide that outlives its\n * showing (closed by Escape and opened again before the slide settled) closes nothing.\n */\n let generation = 0;\n\n const tracker = trackSwipe(dialog, {\n press: (event) => {\n if (closing || !dialog.open) return null;\n if (!isSwipeCandidate(dialog, event, vertical, onScrollerRefusal)) return null;\n direction = swipeDirectionOf(side, dialog);\n return direction;\n },\n extent: () => swipeExtent(dialog, direction),\n start: () => {\n dialog.setAttribute(SWIPING, \"\");\n },\n move: (offset, progress) => {\n writeOffset(dialog, offset, progress, direction);\n },\n end: ({ outcome, event, extent }) => {\n // What already runs (an entry still sliding in, a spinner inside) is not the release.\n const baseline = animationBaseline(dialog);\n dialog.removeAttribute(SWIPING);\n if (outcome !== \"dismiss\") {\n // The consumer's transition on `translate` brings the drawer back.\n clearOffset(dialog);\n return;\n }\n // Finish the motion first (design 4.2): the same transition carries the drawer off its\n // edge while the dialog is still open, which every engine animates.\n writeOffset(dialog, extent, 1, direction);\n closing = true;\n const showing = generation;\n const close = (): void => {\n if (disposed || showing !== generation) return;\n closing = false;\n if (!dialog.open) return;\n dismiss(event);\n // A consumer's `cancel` listener kept it open: slide back.\n if (dialog.open) clearOffset(dialog);\n };\n const animations = exitAnimations(dialog, baseline);\n if (animations.length === 0) close();\n else void Promise.allSettled(animations.map((animation) => animation.finished)).then(close);\n },\n });\n\n // The dialog closing for any other reason (Escape, a Close, a Form settling) aborts a drag;\n // the custom properties go with the `close` event, not before (the closing frame keeps them).\n const onBeforeToggle = (event: Event): void => {\n if (event.target !== dialog) return;\n if ((event as ToggleEvent).newState === \"open\") {\n // A new showing: a release still waiting for its slide belongs to the previous one.\n generation++;\n closing = false;\n clearOffset(dialog);\n return;\n }\n if (tracker.dragging()) {\n tracker.cancel();\n dialog.removeAttribute(SWIPING);\n }\n };\n const onClose = (event: Event): void => {\n if (event.target !== dialog) return;\n tracker.cancel();\n dialog.removeAttribute(SWIPING);\n clearOffset(dialog);\n };\n dialog.addEventListener(\"beforetoggle\", onBeforeToggle);\n dialog.addEventListener(\"close\", onClose);\n\n return () => {\n disposed = true;\n tracker.dispose();\n dialog.removeEventListener(\"beforetoggle\", onBeforeToggle);\n dialog.removeEventListener(\"close\", onClose);\n dialog.removeAttribute(SWIPING);\n clearOffset(dialog);\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DialogTitleProps, DialogTitleState } from "../dialog/dialog-title.mjs";
|
|
2
|
+
//#region src/drawer/drawer-title.d.ts
|
|
3
|
+
/** State of `Drawer.Title`: Dialog's (the Popup's `open` and `modal`). */
|
|
4
|
+
export type DrawerTitleState = DialogTitleState;
|
|
5
|
+
/**
|
|
6
|
+
* Props of `Drawer.Title`: `Dialog.Title`'s.
|
|
7
|
+
*
|
|
8
|
+
* @see https://ui.funstack.work/components/drawer
|
|
9
|
+
*/
|
|
10
|
+
export type DrawerTitleProps = DialogTitleProps;
|
|
11
|
+
/**
|
|
12
|
+
* The drawer's name: an `<h2>` whose id the Popup references with `aria-labelledby`.
|
|
13
|
+
*
|
|
14
|
+
* Owned key (conventions 1.2): `id`.
|
|
15
|
+
*
|
|
16
|
+
* @see https://ui.funstack.work/components/drawer
|
|
17
|
+
*/
|
|
18
|
+
export declare function DrawerTitle(props: DrawerTitleProps): import("react").ReactNode;
|
|
19
|
+
export declare namespace DrawerTitle {
|
|
20
|
+
var displayName: string;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//# sourceMappingURL=drawer-title.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-title.d.mts","names":[],"sources":["../../src/drawer/drawer-title.tsx"],"mappings":";;;YAKY,mBAAmB;;;;;;YAOnB,mBAAmB;;;;;;;;wBASf,YAAY,OAAO,mCAAgB;yBAAnC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDialogTitle } from "../dialog/dialog-title.mjs";
|
|
3
|
+
//#region src/drawer/drawer-title.tsx
|
|
4
|
+
/**
|
|
5
|
+
* The drawer's name: an `<h2>` whose id the Popup references with `aria-labelledby`.
|
|
6
|
+
*
|
|
7
|
+
* Owned key (conventions 1.2): `id`.
|
|
8
|
+
*
|
|
9
|
+
* @see https://ui.funstack.work/components/drawer
|
|
10
|
+
*/
|
|
11
|
+
function DrawerTitle(props) {
|
|
12
|
+
return useDialogTitle(props, "Drawer");
|
|
13
|
+
}
|
|
14
|
+
DrawerTitle.displayName = "DrawerTitle";
|
|
15
|
+
//#endregion
|
|
16
|
+
export { DrawerTitle };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=drawer-title.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer-title.mjs","names":[],"sources":["../../src/drawer/drawer-title.tsx"],"sourcesContent":["\"use client\";\nimport { useDialogTitle } from \"../dialog/dialog-title.js\";\nimport type { DialogTitleProps, DialogTitleState } from \"../dialog/dialog-title.js\";\n\n/** State of `Drawer.Title`: Dialog's (the Popup's `open` and `modal`). */\nexport type DrawerTitleState = DialogTitleState;\n\n/**\n * Props of `Drawer.Title`: `Dialog.Title`'s.\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport type DrawerTitleProps = DialogTitleProps;\n\n/**\n * The drawer's name: an `<h2>` whose id the Popup references with `aria-labelledby`.\n *\n * Owned key (conventions 1.2): `id`.\n *\n * @see https://ui.funstack.work/components/drawer\n */\nexport function DrawerTitle(props: DrawerTitleProps) {\n return useDialogTitle(props, \"Drawer\");\n}\n\nDrawerTitle.displayName = \"DrawerTitle\";\n"],"mappings":";;;;;;;;;;AAqBA,SAAgB,YAAY,OAAyB;CACnD,OAAO,eAAe,OAAO,QAAQ;AACvC;AAEA,YAAY,cAAc"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DialogTriggerProps, DialogTriggerState } from "../dialog/dialog-trigger.mjs";
|
|
2
|
+
//#region src/drawer/drawer-trigger.d.ts
|
|
3
|
+
/** State of `Drawer.Trigger`: Dialog's. */
|
|
4
|
+
export type DrawerTriggerState = DialogTriggerState;
|
|
5
|
+
/**
|
|
6
|
+
* Props of `Drawer.Trigger`: `Dialog.Trigger`'s.
|
|
7
|
+
*
|
|
8
|
+
* @see https://ui.funstack.work/components/drawer
|
|
9
|
+
*/
|
|
10
|
+
export type DrawerTriggerProps = DialogTriggerProps;
|
|
11
|
+
/**
|
|
12
|
+
* The opener: exactly `Dialog.Trigger` (`<button type="button" commandfor command="show-modal">`
|
|
13
|
+
* for a modal drawer). JS-free mode: the browser runs the command. Library mode: the click is a
|
|
14
|
+
* request through the Root (`data-pending` until the drawer has opened).
|
|
15
|
+
*
|
|
16
|
+
* @see https://ui.funstack.work/components/drawer
|
|
17
|
+
*/
|
|
18
|
+
export declare function DrawerTrigger(props: DrawerTriggerProps): import("react").ReactNode;
|
|
19
|
+
export declare namespace DrawerTrigger {
|
|
20
|
+
var displayName: string;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//# sourceMappingURL=drawer-trigger.d.mts.map
|