-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawer.stories.tsx
More file actions
270 lines (258 loc) · 7.25 KB
/
Copy pathDrawer.stories.tsx
File metadata and controls
270 lines (258 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import type { Meta, StoryObj } from "@storybook/react-vite";
import { Button } from "@/components/ui/Button";
import type { DrawerWidth } from "./Drawer";
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerMain,
DrawerTitle,
DrawerTrigger,
} from "./Drawer";
interface DrawerStoryProps {
modal?: boolean;
width?: DrawerWidth;
open?: boolean;
defaultOpen?: boolean;
dismissible?: boolean;
handleOnly?: boolean;
repositionInputs?: boolean;
closeThreshold?: number;
noBodyStyles?: boolean;
scrollLockTimeout?: number;
fixed?: boolean;
snapToSequentialPoint?: boolean;
disablePreventScroll?: boolean;
preventScrollRestoration?: boolean;
autoFocus?: boolean;
nested?: boolean;
hideBackButton?: boolean;
onOpenChange?: (open: boolean) => void;
onAnimationEnd?: (open: boolean) => void;
onClose?: () => void;
}
function DrawerStory({
width = "default",
modal = true,
open,
defaultOpen = false,
dismissible = true,
handleOnly = true,
repositionInputs = true,
closeThreshold,
noBodyStyles = false,
scrollLockTimeout,
fixed = false,
snapToSequentialPoint = false,
disablePreventScroll = false,
preventScrollRestoration = false,
autoFocus,
nested = false,
hideBackButton = false,
onOpenChange,
onAnimationEnd,
onClose,
...rest
}: DrawerStoryProps) {
return (
<Drawer
autoFocus={autoFocus}
closeThreshold={closeThreshold}
defaultOpen={defaultOpen}
disablePreventScroll={disablePreventScroll}
dismissible={dismissible}
fixed={fixed}
handleOnly={handleOnly}
modal={modal}
nested={nested}
noBodyStyles={noBodyStyles}
onAnimationEnd={onAnimationEnd}
onClose={onClose}
onOpenChange={onOpenChange}
open={open}
preventScrollRestoration={preventScrollRestoration}
repositionInputs={repositionInputs}
scrollLockTimeout={scrollLockTimeout}
snapToSequentialPoint={snapToSequentialPoint}
width={width}
{...rest}
>
<DrawerTrigger asChild>
<Button variant="outlined">Open Drawer</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader hideBackButton={hideBackButton}>
<DrawerTitle>Drawer Title</DrawerTitle>
<DrawerDescription>
This is a description of the drawer content.
</DrawerDescription>
</DrawerHeader>
<DrawerMain>main content</DrawerMain>
<DrawerFooter>
<DrawerClose asChild>
<Button variant="outlined">Cancel</Button>
</DrawerClose>
<Button>Save changes</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
);
}
DrawerStory.displayName = "Drawer";
const meta: Meta<typeof DrawerStory> = {
title: "Components/Drawer",
component: DrawerStory,
parameters: {
jest: "Drawer.test.tsx",
layout: "centered",
},
tags: ["autodocs"],
argTypes: {
modal: {
control: "boolean",
description:
"When false, allows interacting with elements outside the drawer without closing it",
},
width: {
control: "select",
options: ["default", "sm", "md", "lg", "xl", "full"],
description: "Width of the drawer",
},
open: {
control: "boolean",
description: "Controlled open state",
},
defaultOpen: {
control: "boolean",
description: "Open by default, skips initial enter animation",
},
dismissible: {
control: "boolean",
description:
"When false, dragging, clicking outside, pressing esc will not close the drawer",
},
handleOnly: {
control: "boolean",
description: "When true, only allows dragging by the Handle component",
},
repositionInputs: {
control: "boolean",
description:
"When true, repositions inputs when keyboard is in the way instead of scrolling",
},
closeThreshold: {
control: { type: "number", min: 0, max: 1, step: 0.05 },
description:
"Number between 0 and 1 that determines when the drawer should close on swipe (e.g. 0.5 = 50% of height)",
},
noBodyStyles: {
control: "boolean",
description: "When true, body does not get any styles from Vaul",
},
scrollLockTimeout: {
control: { type: "number", min: 0, step: 100 },
description:
"Duration (ms) for which the drawer is not draggable after scrolling content",
},
fixed: {
control: "boolean",
description:
"When true, only change height when keyboard is open instead of moving drawer up",
},
snapToSequentialPoint: {
control: "boolean",
description: "When true, disables velocity-based skipping of snap points",
},
disablePreventScroll: {
control: "boolean",
description: "When true, prevents scroll lock on body on mount",
},
preventScrollRestoration: {
control: "boolean",
description: "When true, prevents scroll restoration behavior",
},
autoFocus: {
control: "boolean",
description: "Whether to auto focus when drawer opens",
},
nested: {
control: "boolean",
description: "Use when drawer is nested inside another drawer",
},
hideBackButton: {
control: "boolean",
description: "When true, hides the DrawerHeader back button",
},
onOpenChange: {
description: "Called when the open state changes",
},
onAnimationEnd: {
description: "Called after open/close animation ends",
},
onClose: {
description: "Called when the drawer is closed",
},
},
};
export default meta;
type Story = StoryObj<typeof DrawerStory>;
export const Default: Story = {
args: {
modal: true,
width: "default",
defaultOpen: false,
dismissible: true,
handleOnly: true,
repositionInputs: true,
noBodyStyles: false,
fixed: false,
snapToSequentialPoint: false,
disablePreventScroll: false,
preventScrollRestoration: false,
nested: false,
hideBackButton: false,
},
};
export const WithLongContent: Story = {
args: {
modal: true,
width: "default",
},
render: (args) => (
<Drawer {...args}>
<DrawerTrigger asChild>
<Button variant="outlined">Open Drawer</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Notifications</DrawerTitle>
<DrawerDescription>
You have 3 unread notifications.
</DrawerDescription>
</DrawerHeader>
<DrawerMain>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
<p>You have 3 unread notifications.</p>
</DrawerMain>
<DrawerFooter>
<DrawerClose asChild>
<Button variant="outlined">Cancel</Button>
</DrawerClose>
<Button>Send</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
),
};