@trackunit/react-drawer 2.6.6 → 2.6.9
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/index.cjs.js +422 -211
- package/index.esm.js +424 -213
- package/package.json +6 -5
- package/src/components/Drawer/Drawer.d.ts +56 -70
- package/src/components/Drawer/Drawer.variants.d.ts +13 -3
- package/src/components/Drawer/drawer-animation-reducer.d.ts +27 -0
- package/src/components/Drawer/drawer-motion-style.d.ts +24 -0
- package/src/components/Drawer/useDrawer.d.ts +121 -0
- package/src/components/DrawerHeader/DrawerHeader.d.ts +67 -0
- package/src/components/Overlay/Overlay.d.ts +8 -4
- package/src/index.d.ts +3 -1
- package/src/translation.d.ts +2 -2
- package/src/types.d.ts +1 -1
- package/src/components/DrawerToggle/DrawerToggle.d.ts +0 -23
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-drawer",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.9",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/react-components": "2.10.
|
|
11
|
-
"@trackunit/css-class-variance-utilities": "1.14.
|
|
12
|
-
"@trackunit/
|
|
13
|
-
"@
|
|
10
|
+
"@trackunit/react-components": "2.10.4",
|
|
11
|
+
"@trackunit/css-class-variance-utilities": "1.14.17",
|
|
12
|
+
"@trackunit/i18n-library-translation": "2.4.13",
|
|
13
|
+
"@floating-ui/react": "^0.26.25",
|
|
14
|
+
"tailwind-merge": "^2.0.0"
|
|
14
15
|
},
|
|
15
16
|
"peerDependencies": {
|
|
16
17
|
"@tanstack/react-router": "^1.114.29",
|
|
@@ -1,43 +1,17 @@
|
|
|
1
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export interface DrawerProps extends CommonProps {
|
|
10
|
-
/**
|
|
11
|
-
* Specifies whether the sidebar drawer is open or not.
|
|
12
|
-
*/
|
|
13
|
-
open?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* The handler for closing the drawer. If not provided, the drawer will dock when closed.=
|
|
16
|
-
*/
|
|
17
|
-
onClose?: () => void;
|
|
18
|
-
/**
|
|
19
|
-
* The handler for opening the drawer. Called when the drawer transitions to open state.
|
|
20
|
-
*/
|
|
21
|
-
onOpen?: () => void;
|
|
22
|
-
/**
|
|
23
|
-
* Whether the drawer needs an overlay or not. Without the overlay, user will have to handle mechanism for closing the drawer.
|
|
24
|
-
* Default is true.
|
|
25
|
-
*/
|
|
26
|
-
hasOverlay?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* The position of the drawer.
|
|
29
|
-
*/
|
|
30
|
-
position?: DrawerPosition;
|
|
2
|
+
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import type { UseDrawerReturnValue } from "./useDrawer";
|
|
4
|
+
/**
|
|
5
|
+
* Presentational props for `Drawer`. State, dismiss wiring, variant, focus-trap
|
|
6
|
+
* opt-in, and position all flow in via {@link UseDrawerReturnValue} — call
|
|
7
|
+
* `useDrawer()` and spread its return onto `<Drawer>`.
|
|
8
|
+
*/
|
|
9
|
+
export interface DrawerProps extends CommonProps, UseDrawerReturnValue {
|
|
31
10
|
/**
|
|
32
|
-
*
|
|
11
|
+
* Content rendered inside the drawer panel. Compose layout parts explicitly — typically
|
|
12
|
+
* `<DrawerHeader />` (or a custom header such as `CardHeader`) followed by the body.
|
|
33
13
|
*/
|
|
34
14
|
children?: ReactNode;
|
|
35
|
-
/**
|
|
36
|
-
* Determines whether the drawer component should remain mounted in the DOM when it is closed.
|
|
37
|
-
* If set to true, the drawer will not be unmounted when closed
|
|
38
|
-
* Default is false.
|
|
39
|
-
*/
|
|
40
|
-
keepMountedWhenClosed?: boolean;
|
|
41
15
|
/**
|
|
42
16
|
* Whether to render the drawer in a portal or not.
|
|
43
17
|
* Default is false.
|
|
@@ -51,68 +25,80 @@ export interface DrawerProps extends CommonProps {
|
|
|
51
25
|
*/
|
|
52
26
|
containerClassName?: string;
|
|
53
27
|
/**
|
|
54
|
-
*
|
|
28
|
+
* Accessible name for the drawer's panel, forwarded as `aria-label`. Strongly recommended:
|
|
29
|
+
* without either this or `ariaLabelledBy`, assistive technology has no name for the panel and
|
|
30
|
+
* will announce it as an unnamed dialog / region. Mutually exclusive in intent with
|
|
31
|
+
* `ariaLabelledBy` — set one or the other, not both.
|
|
55
32
|
*/
|
|
56
|
-
|
|
33
|
+
ariaLabel?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Id of an existing element (typically a heading rendered inside the drawer body) whose text
|
|
36
|
+
* names the drawer's panel, forwarded as `aria-labelledby`. Prefer this over `ariaLabel` when
|
|
37
|
+
* the drawer body renders a visible heading so the two stay in sync.
|
|
38
|
+
*/
|
|
39
|
+
ariaLabelledBy?: string;
|
|
57
40
|
}
|
|
58
41
|
/**
|
|
59
|
-
* Drawers
|
|
60
|
-
*
|
|
61
|
-
* To close the drawer, users can either click outside of it or press the Esc key.
|
|
42
|
+
* Drawers slide in from the left or right edge of the viewport as either a modal
|
|
43
|
+
* dialog or a docked inspector panel.
|
|
62
44
|
*
|
|
63
45
|
* ### When to use
|
|
64
|
-
* - For secondary content
|
|
65
|
-
* - For
|
|
46
|
+
* - For secondary content that doesn't need to be always visible
|
|
47
|
+
* - For inspector panels or item detail views that slide in from the side
|
|
66
48
|
* - When you need to preserve context of the underlying page
|
|
67
49
|
*
|
|
68
50
|
* ### When not to use
|
|
69
51
|
* - For critical actions requiring user confirmation (use Modal instead)
|
|
70
52
|
* - For simple tooltips or small contextual information (use Popover)
|
|
53
|
+
* - To show a table selection and bulk actions (use ActionSheet instead)
|
|
54
|
+
*
|
|
55
|
+
* ### API
|
|
56
|
+
* `Drawer` is a presentation component. Call `useDrawer()` to own the drawer's
|
|
57
|
+
* open state, dismiss handling, and (optional) `onBeforeClose` guard, then spread
|
|
58
|
+
* its return value onto `<Drawer>`.
|
|
71
59
|
*
|
|
72
|
-
* @example Basic drawer with
|
|
60
|
+
* @example Basic modal drawer with the standard toolbar
|
|
73
61
|
* ```tsx
|
|
74
|
-
* import { Drawer } from "@trackunit/react-drawer";
|
|
62
|
+
* import { Drawer, DrawerHeader, useDrawer } from "@trackunit/react-drawer";
|
|
75
63
|
* import { Button } from "@trackunit/react-components";
|
|
76
|
-
* import { useState } from "react";
|
|
77
64
|
*
|
|
78
65
|
* const FilterDrawer = () => {
|
|
79
|
-
* const
|
|
66
|
+
* const drawer = useDrawer({ position: "right", variant: "modal" });
|
|
80
67
|
*
|
|
81
68
|
* return (
|
|
82
69
|
* <>
|
|
83
|
-
* <Button onClick={
|
|
84
|
-
* <Drawer
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* position="right"
|
|
88
|
-
* >
|
|
89
|
-
* <div className="p-4">
|
|
90
|
-
* <h2>Filter Options</h2>
|
|
91
|
-
* <p>Filter controls go here</p>
|
|
92
|
-
* </div>
|
|
70
|
+
* <Button onClick={drawer.open}>Open Filters</Button>
|
|
71
|
+
* <Drawer {...drawer} ariaLabel="Filters">
|
|
72
|
+
* <DrawerHeader onClickClose={drawer.close} />
|
|
73
|
+
* <div className="p-4">Filter controls go here</div>
|
|
93
74
|
* </Drawer>
|
|
94
75
|
* </>
|
|
95
76
|
* );
|
|
96
77
|
* };
|
|
97
78
|
* ```
|
|
98
|
-
* @example
|
|
79
|
+
* @example Guard dismissal with `onBeforeClose`
|
|
80
|
+
* ```tsx
|
|
81
|
+
* const drawer = useDrawer({
|
|
82
|
+
* variant: "modal",
|
|
83
|
+
* onBeforeClose: async () => (await confirmDiscard()) === "discard",
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
* @example Non-modal inspector — background stays interactive
|
|
99
87
|
* ```tsx
|
|
100
|
-
*
|
|
88
|
+
* const drawer = useDrawer({
|
|
89
|
+
* isOpen: Boolean(selectedAssetId),
|
|
90
|
+
* onClose: () => setSelectedAssetId(null),
|
|
91
|
+
* position: "right",
|
|
92
|
+
* variant: "default",
|
|
93
|
+
* });
|
|
101
94
|
*
|
|
102
|
-
*
|
|
103
|
-
* <
|
|
104
|
-
*
|
|
105
|
-
* hasOverlay={false}
|
|
106
|
-
* position="left"
|
|
107
|
-
* keepMountedWhenClosed={true}
|
|
108
|
-
* >
|
|
109
|
-
* {content}
|
|
110
|
-
* </Drawer>
|
|
111
|
-
* );
|
|
95
|
+
* <Drawer {...drawer} ariaLabelledBy="asset-inspector-title">
|
|
96
|
+
* <h2 id="asset-inspector-title">{selectedAsset?.name}</h2>
|
|
97
|
+
* </Drawer>
|
|
112
98
|
* ```
|
|
113
99
|
* @param {DrawerProps} props - The props for the Drawer component
|
|
114
100
|
*/
|
|
115
101
|
export declare const Drawer: {
|
|
116
|
-
({
|
|
102
|
+
({ isOpen, variant, trapFocus, position, floatingUi, open: _open, close: _close, toggle: _toggle, requestClose: _requestClose, children, "data-testid": dataTestId, className, renderInPortal, containerClassName, ariaLabel, ariaLabelledBy, ...others }: DrawerProps): ReactElement | null;
|
|
117
103
|
displayName: string;
|
|
118
104
|
};
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clip layer for the slide. Right-side enter uses `translateX(100%)`, which would
|
|
3
|
+
* otherwise extend past the edge and expand scroll width — shifting the page.
|
|
4
|
+
*
|
|
5
|
+
* - `portaled` → `fixed` (viewport-relative; escapes parent layout)
|
|
6
|
+
* - in-tree → `absolute` (parent must establish a containing block, e.g. `relative`)
|
|
7
|
+
*/
|
|
8
|
+
export declare const cvaDrawerViewport: (props?: ({
|
|
9
|
+
portaled?: boolean | null | undefined;
|
|
10
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
1
11
|
export declare const cvaDrawer: (props?: ({
|
|
2
|
-
position?: "left" | "right" |
|
|
3
|
-
mode?: "
|
|
12
|
+
position?: "left" | "right" | null | undefined;
|
|
13
|
+
mode?: "open" | "closed" | null | undefined;
|
|
4
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
5
15
|
export declare const cvaDrawerContent: (props?: ({
|
|
6
|
-
position?: "left" | "right" |
|
|
16
|
+
position?: "left" | "right" | null | undefined;
|
|
7
17
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DrawerMode } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Animation lifecycle for Drawer mount / unmount.
|
|
4
|
+
*
|
|
5
|
+
* Open always mounts (or re-opens) in `mode: "closed"` so the panel starts off-screen
|
|
6
|
+
* for its `position`. A follow-up `openVisual` after layout reflow flips to `"open"`
|
|
7
|
+
* and the CSS transform transition plays the slide-in. `enterSettled` flips true only
|
|
8
|
+
* after that enter transition ends — focus must wait until then, otherwise
|
|
9
|
+
* `scrollIntoView` on an off-screen panel shoves the layout (gap + bounce on the right).
|
|
10
|
+
*/
|
|
11
|
+
export type DrawerAnimationState = {
|
|
12
|
+
readonly shouldRender: boolean;
|
|
13
|
+
readonly mode: DrawerMode;
|
|
14
|
+
readonly enterSettled: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type DrawerAnimationAction = {
|
|
17
|
+
readonly type: "open";
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: "openVisual";
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "close";
|
|
22
|
+
} | {
|
|
23
|
+
readonly type: "transitionEnd";
|
|
24
|
+
};
|
|
25
|
+
export declare const INITIAL_DRAWER_ANIMATION_STATE: DrawerAnimationState;
|
|
26
|
+
/** Reducer managing the Drawer panel's mount / enter / exit animation lifecycle. */
|
|
27
|
+
export declare const drawerAnimationReducer: (state: DrawerAnimationState, action: DrawerAnimationAction) => DrawerAnimationState;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import type { DrawerMode, DrawerPosition } from "../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Side drawers travel farther than sheets (often 400px+). Use a standard
|
|
5
|
+
* decelerate curve with no overshoot (y-values stay in 0–1) so the panel does
|
|
6
|
+
* not slide past flush and bounce back — that looked like a gap on the right.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DRAWER_TRANSITION_DURATION_MS: 400;
|
|
9
|
+
export declare const DRAWER_TRANSITION_EASING: "cubic-bezier(0.4, 0, 0.2, 1)";
|
|
10
|
+
/**
|
|
11
|
+
* Inline transform/transition for the drawer panel.
|
|
12
|
+
*
|
|
13
|
+
* Kept as inline styles (same approach as Sheet) so enter/exit motion does not
|
|
14
|
+
* depend on Tailwind emitting arbitrary `transition-[…]` utilities into the
|
|
15
|
+
* host app's CSS bundle — missing those utilities makes the panel appear/disappear
|
|
16
|
+
* with no slide.
|
|
17
|
+
*
|
|
18
|
+
* Only `transform` is transitioned — animating `box-shadow` alongside a wide
|
|
19
|
+
* slide makes the stop feel abrupt when the shadow pops in.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getDrawerMotionStyle: ({ mode, position, }: {
|
|
22
|
+
readonly mode: DrawerMode;
|
|
23
|
+
readonly position: DrawerPosition;
|
|
24
|
+
}) => CSSProperties;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type UseFloatingReturn } from "@floating-ui/react";
|
|
2
|
+
import { type CloseReason, type DismissOptions, type UseOverlayDismissibleProps } from "@trackunit/react-components";
|
|
3
|
+
import type { DrawerPosition } from "../../types";
|
|
4
|
+
/**
|
|
5
|
+
* Semantic variant controlling the drawer's dismiss behavior, backdrop, and dialog ARIA.
|
|
6
|
+
* - `"default"` — non-overlay, non-focus-trapping panel; the surrounding page stays
|
|
7
|
+
* interactive. Panel gets `role="complementary"` so it participates in the page's
|
|
8
|
+
* landmark tree. ESC still calls `onClose` when provided.
|
|
9
|
+
* - `"modal"` — dimming backdrop, `role="dialog"` + `aria-modal`, focus trap (via
|
|
10
|
+
* `FloatingFocusManager`) that returns focus to the trigger on close, and
|
|
11
|
+
* outside-press dismiss.
|
|
12
|
+
*/
|
|
13
|
+
export type DrawerVariant = "default" | "modal";
|
|
14
|
+
/**
|
|
15
|
+
* Dismiss options honored by Drawer. Reuses the shared {@link DismissOptions} shape
|
|
16
|
+
* for API parity with `useSheet` / `useModal`; the `gesture` option has no effect
|
|
17
|
+
* on Drawer (which has no swipe gesture) and is ignored.
|
|
18
|
+
*/
|
|
19
|
+
export type DrawerDismissOptions = Pick<DismissOptions, "escapeKey" | "outsidePress">;
|
|
20
|
+
/**
|
|
21
|
+
* Floating UI wiring produced by `useDrawer` and consumed by `Drawer` for its
|
|
22
|
+
* focus manager and dismiss interaction bindings. Mirrors `useSheet`'s
|
|
23
|
+
* `floatingUi` shape.
|
|
24
|
+
*/
|
|
25
|
+
export type DrawerFloatingUiProps = {
|
|
26
|
+
readonly context: UseFloatingReturn["context"];
|
|
27
|
+
readonly refs: UseFloatingReturn["refs"];
|
|
28
|
+
readonly getFloatingProps: (userProps?: Record<string, unknown>) => Record<string, unknown>;
|
|
29
|
+
};
|
|
30
|
+
/** Props for the {@link useDrawer} hook. */
|
|
31
|
+
export type UseDrawerProps = UseOverlayDismissibleProps & {
|
|
32
|
+
/**
|
|
33
|
+
* Semantic variant controlling backdrop, focus trap, and dismiss behavior.
|
|
34
|
+
*
|
|
35
|
+
* - `"default"` — no backdrop, no focus trap, `role="complementary"`. The
|
|
36
|
+
* surrounding page stays interactive. ESC still calls `onClose` when
|
|
37
|
+
* provided; outside-press does not close the drawer.
|
|
38
|
+
* - `"modal"` — dimming backdrop, `role="dialog"` + `aria-modal`, focus trap
|
|
39
|
+
* that returns focus to the trigger on close, and outside-press dismiss.
|
|
40
|
+
*
|
|
41
|
+
* @default "modal"
|
|
42
|
+
*/
|
|
43
|
+
readonly variant?: DrawerVariant;
|
|
44
|
+
/**
|
|
45
|
+
* Opt out of the focus trap when `variant="modal"`. Use this only when a
|
|
46
|
+
* parent component already manages focus for the drawer's subtree. Ignored
|
|
47
|
+
* when `variant="default"` — the default variant never traps focus.
|
|
48
|
+
*
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
readonly trapFocus?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The position of the drawer.
|
|
54
|
+
*
|
|
55
|
+
* @default "left"
|
|
56
|
+
*/
|
|
57
|
+
readonly position?: DrawerPosition;
|
|
58
|
+
};
|
|
59
|
+
/** Return value of the {@link useDrawer} hook. */
|
|
60
|
+
export type UseDrawerReturnValue = {
|
|
61
|
+
readonly isOpen: boolean;
|
|
62
|
+
readonly open: () => void;
|
|
63
|
+
readonly close: () => void;
|
|
64
|
+
readonly toggle: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Close the drawer with a specific reason. Runs `onBeforeClose` first
|
|
67
|
+
* (when provided) and only fires `onClose` / flips state if the guard
|
|
68
|
+
* resolves to `true`.
|
|
69
|
+
*/
|
|
70
|
+
readonly requestClose: (event: Event | undefined, reason: CloseReason) => void;
|
|
71
|
+
/** Resolved variant, spread onto `Drawer`. */
|
|
72
|
+
readonly variant: DrawerVariant;
|
|
73
|
+
/** Resolved focus-trap opt-in, spread onto `Drawer`. */
|
|
74
|
+
readonly trapFocus: boolean;
|
|
75
|
+
/** Resolved position, spread onto `Drawer`. */
|
|
76
|
+
readonly position: DrawerPosition;
|
|
77
|
+
/**
|
|
78
|
+
* Floating UI wiring for the drawer's focus manager and dismiss bindings.
|
|
79
|
+
* `Drawer` merges `refs.setFloating` onto the panel and uses `context` for
|
|
80
|
+
* its `FloatingFocusManager`.
|
|
81
|
+
*/
|
|
82
|
+
readonly floatingUi: DrawerFloatingUiProps;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Hook for managing Drawer open/close state, dismiss handling, and floating UI wiring.
|
|
86
|
+
*
|
|
87
|
+
* Aligns with `useSheet` and `useModal`: consumers use `useDrawer()` to own the
|
|
88
|
+
* drawer's state and callbacks, then spread the return value onto `Drawer`.
|
|
89
|
+
*
|
|
90
|
+
* Supports controlled (`isOpen`) and uncontrolled (`defaultOpen`) modes, stable
|
|
91
|
+
* `open` / `close` / `toggle` identities (latest-ref pattern for callbacks), and
|
|
92
|
+
* an `onBeforeClose` guard that can be sync or async — return `false` (or a
|
|
93
|
+
* `Promise<false>`) to keep the drawer open in response to a close attempt.
|
|
94
|
+
*
|
|
95
|
+
* Owns ESC and outside-press dismiss via Floating UI's `useDismiss`. Outside-press
|
|
96
|
+
* is only active when `variant === "modal"` (the only variant with a backdrop).
|
|
97
|
+
* The `gesture` field of `DismissOptions` is accepted for API parity with Sheet
|
|
98
|
+
* but has no effect — Drawer has no swipe gesture.
|
|
99
|
+
*
|
|
100
|
+
* @example Controlled
|
|
101
|
+
* ```tsx
|
|
102
|
+
* const drawer = useDrawer({ isOpen, onClose: () => setOpen(false), position: "right" });
|
|
103
|
+
* return <Drawer {...drawer}>...</Drawer>;
|
|
104
|
+
* ```
|
|
105
|
+
* @example Uncontrolled with a beforeClose guard
|
|
106
|
+
* ```tsx
|
|
107
|
+
* const drawer = useDrawer({
|
|
108
|
+
* variant: "modal",
|
|
109
|
+
* onBeforeClose: async () => (await confirmDiscard()) === "discard",
|
|
110
|
+
* });
|
|
111
|
+
* return (
|
|
112
|
+
* <>
|
|
113
|
+
* <Button onClick={drawer.open}>Open</Button>
|
|
114
|
+
* <Drawer {...drawer}>
|
|
115
|
+
* <DrawerHeader onClickClose={drawer.close} />
|
|
116
|
+
* </Drawer>
|
|
117
|
+
* </>
|
|
118
|
+
* );
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare const useDrawer: (props?: UseDrawerProps) => UseDrawerReturnValue;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CommonProps, PopoverContentChildren, Refable, Styleable } from "@trackunit/react-components";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
export interface DrawerHeaderProps extends CommonProps, Styleable, Refable<HTMLDivElement> {
|
|
4
|
+
/**
|
|
5
|
+
* Renders the toolbar close (X) button and is invoked when it is clicked. Omit this prop
|
|
6
|
+
* (or set `hideCloseButton`) to hide the X.
|
|
7
|
+
*
|
|
8
|
+
* Pass `useDrawer`'s `close` so the X routes through the same dismiss pipeline
|
|
9
|
+
* (including any `onBeforeClose` guard) as Escape and outside-press.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const drawer = useDrawer({ position: "right" });
|
|
13
|
+
*
|
|
14
|
+
* <Drawer {...drawer}>
|
|
15
|
+
* <DrawerHeader onClickClose={drawer.close} />
|
|
16
|
+
* {\/* body *\/}
|
|
17
|
+
* </Drawer>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
onClickClose?: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Called when the user clicks the back-navigation arrow. When omitted, the back arrow is not
|
|
23
|
+
* rendered.
|
|
24
|
+
*/
|
|
25
|
+
onClickBack?: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Called when the user clicks the forward-navigation arrow. When omitted, the forward arrow is
|
|
28
|
+
* not rendered.
|
|
29
|
+
*/
|
|
30
|
+
onClickForward?: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Overflow-menu content, rendered inside a kebab (three-dot) popover placed before the close
|
|
33
|
+
* button. Typically a `<MenuContent>` with `<MenuItem>` children. Accepts either a static node or a
|
|
34
|
+
* render prop that receives a `close` callback, matching `<MoreMenu />`. When omitted, the
|
|
35
|
+
* kebab menu is not rendered.
|
|
36
|
+
*/
|
|
37
|
+
menuContent?: PopoverContentChildren;
|
|
38
|
+
/**
|
|
39
|
+
* Hide the built-in close button. Use for read-only drawers, or drawers whose parent already
|
|
40
|
+
* provides an equivalent affordance elsewhere.
|
|
41
|
+
*
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
hideCloseButton?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Standard drawer toolbar header. Compose it as a child of `<Drawer />`:
|
|
48
|
+
*
|
|
49
|
+
* ```tsx
|
|
50
|
+
* const drawer = useDrawer({ position: "right" });
|
|
51
|
+
*
|
|
52
|
+
* <Drawer {...drawer}>
|
|
53
|
+
* <DrawerHeader menuContent={…} onClickBack={goBack} onClickClose={drawer.close} />
|
|
54
|
+
* {\/* body *\/}
|
|
55
|
+
* </Drawer>
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* Wire the X button to `useDrawer`'s `close` so it shares the same dismiss pipeline
|
|
59
|
+
* (Escape, outside-press, `onBeforeClose` guard) as the rest of the drawer.
|
|
60
|
+
*
|
|
61
|
+
* Button labels come from this library's translation namespace and cannot be overridden — the
|
|
62
|
+
* affordances are universal ("Close", "Back", "Forward", "More actions").
|
|
63
|
+
*/
|
|
64
|
+
export declare const DrawerHeader: {
|
|
65
|
+
({ onClickClose, onClickBack, onClickForward, menuContent, hideCloseButton, "data-testid": dataTestId, className, style, ref, }: DrawerHeaderProps): ReactElement;
|
|
66
|
+
displayName: string;
|
|
67
|
+
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { ReactElement } from "react";
|
|
2
2
|
interface OverlayProps {
|
|
3
3
|
open: boolean;
|
|
4
|
-
onClose?: () => void;
|
|
5
4
|
}
|
|
6
5
|
/**
|
|
7
6
|
* Overlay Component
|
|
8
7
|
*
|
|
8
|
+
* Purely visual dimming backdrop rendered behind an open modal `<Drawer />`. Dismiss
|
|
9
|
+
* handling (Escape, outside-press) is owned by `<Drawer />`'s Floating UI wiring —
|
|
10
|
+
* clicking the overlay dispatches `onClose` via `useDismiss`'s `outsidePress`
|
|
11
|
+
* detection, not via a click handler on this component. Rendered only when the parent
|
|
12
|
+
* drawer resolves to `variant="modal"`.
|
|
13
|
+
*
|
|
9
14
|
* @param {object} props - The Overlay component properties
|
|
10
15
|
* @param {boolean} props.open - Open status of the Overlay
|
|
11
|
-
* @
|
|
12
|
-
* @returns {ReactElement|null} The Overlay component
|
|
16
|
+
* @returns {ReactElement} The Overlay component
|
|
13
17
|
*/
|
|
14
|
-
export declare const Overlay: ({ open
|
|
18
|
+
export declare const Overlay: ({ open }: OverlayProps) => ReactElement;
|
|
15
19
|
export {};
|
package/src/index.d.ts
CHANGED
package/src/translation.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare const translations: TranslationResource<TranslationKeys>;
|
|
|
14
14
|
/**
|
|
15
15
|
* Local useTranslation for this specific library
|
|
16
16
|
*/
|
|
17
|
-
export declare const useTranslation: () => [TransForLibs<
|
|
18
|
-
t: TransForLibs<
|
|
17
|
+
export declare const useTranslation: () => [TransForLibs<"drawer.header.back" | "drawer.header.close" | "drawer.header.forward" | "drawer.header.moreMenu">, import("i18next").i18n, boolean] & {
|
|
18
|
+
t: TransForLibs<"drawer.header.back" | "drawer.header.close" | "drawer.header.forward" | "drawer.header.moreMenu">;
|
|
19
19
|
i18n: import("i18next").i18n;
|
|
20
20
|
ready: boolean;
|
|
21
21
|
};
|
package/src/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type DrawerPosition = "left" | "right"
|
|
1
|
+
export type DrawerPosition = "left" | "right";
|
|
2
2
|
export type DrawerMode = "closed" | "open";
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Refable, type Styleable } from "@trackunit/react-components";
|
|
2
|
-
import { MouseEvent } from "react";
|
|
3
|
-
import { type DrawerPosition } from "../../types";
|
|
4
|
-
interface DrawerToggleProps extends Refable<HTMLDivElement>, Styleable {
|
|
5
|
-
open: boolean;
|
|
6
|
-
onClick?: (event: MouseEvent) => void;
|
|
7
|
-
position: DrawerPosition;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* DrawerToggle is a React functional component that returns a button with a chevron icon.
|
|
11
|
-
* The direction of the chevron changes depending on the state of the 'open' prop and
|
|
12
|
-
* the side the button is positioned ('position' prop).
|
|
13
|
-
* The button might be disabled based on the 'disableButton' prop.
|
|
14
|
-
*
|
|
15
|
-
* @param {object} props - The properties passed to the component
|
|
16
|
-
* @param {Function} [props.onClick] - Optional callback function for when the button is clicked
|
|
17
|
-
* @param {boolean} props.open - Indicates if the button is in "open" state
|
|
18
|
-
* @param {DrawerPosition} props.position - The position of the button relative to its container
|
|
19
|
-
* @param props.ref - Ref forwarded to the root DOM element
|
|
20
|
-
* @param props.style - Inline styles applied to the root DOM element
|
|
21
|
-
*/
|
|
22
|
-
export declare const DrawerToggle: ({ open, position, onClick, ref, style }: DrawerToggleProps) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
export {};
|