@purpurds/drawer 5.15.1
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/LICENSE.txt +478 -0
- package/dist/drawer-container.d.ts +11 -0
- package/dist/drawer-container.d.ts.map +1 -0
- package/dist/drawer-content.d.ts +27 -0
- package/dist/drawer-content.d.ts.map +1 -0
- package/dist/drawer-frame.d.ts +23 -0
- package/dist/drawer-frame.d.ts.map +1 -0
- package/dist/drawer-handle.d.ts +13 -0
- package/dist/drawer-handle.d.ts.map +1 -0
- package/dist/drawer-header.d.ts +14 -0
- package/dist/drawer-header.d.ts.map +1 -0
- package/dist/drawer-scroll-area.d.ts +9 -0
- package/dist/drawer-scroll-area.d.ts.map +1 -0
- package/dist/drawer-trigger.d.ts +9 -0
- package/dist/drawer-trigger.d.ts.map +1 -0
- package/dist/drawer.cjs.js +62 -0
- package/dist/drawer.cjs.js.map +1 -0
- package/dist/drawer.context.d.ts +4 -0
- package/dist/drawer.context.d.ts.map +1 -0
- package/dist/drawer.d.ts +17 -0
- package/dist/drawer.d.ts.map +1 -0
- package/dist/drawer.es.js +2791 -0
- package/dist/drawer.es.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/use-swipe-to-dismiss.hook.d.ts +13 -0
- package/dist/use-swipe-to-dismiss.hook.d.ts.map +1 -0
- package/dist/use-swipe-tracking.hook.d.ts +15 -0
- package/dist/use-swipe-tracking.hook.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/drawer-container.module.scss +24 -0
- package/src/drawer-container.test.tsx +74 -0
- package/src/drawer-container.tsx +48 -0
- package/src/drawer-content.module.scss +101 -0
- package/src/drawer-content.test.tsx +80 -0
- package/src/drawer-content.tsx +124 -0
- package/src/drawer-frame.module.scss +44 -0
- package/src/drawer-frame.test.tsx +139 -0
- package/src/drawer-frame.tsx +140 -0
- package/src/drawer-handle.module.scss +23 -0
- package/src/drawer-handle.test.tsx +37 -0
- package/src/drawer-handle.tsx +59 -0
- package/src/drawer-header.module.scss +29 -0
- package/src/drawer-header.test.tsx +173 -0
- package/src/drawer-header.tsx +117 -0
- package/src/drawer-scroll-area.module.scss +42 -0
- package/src/drawer-scroll-area.test.tsx +28 -0
- package/src/drawer-scroll-area.tsx +45 -0
- package/src/drawer-trigger.test.tsx +33 -0
- package/src/drawer-trigger.tsx +34 -0
- package/src/drawer.context.ts +5 -0
- package/src/drawer.module.scss +3 -0
- package/src/drawer.stories.tsx +197 -0
- package/src/drawer.test.tsx +210 -0
- package/src/drawer.tsx +59 -0
- package/src/global.d.ts +4 -0
- package/src/types.ts +3 -0
- package/src/use-swipe-to-dismiss.hook.ts +60 -0
- package/src/use-swipe-tracking.hook.ts +78 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import React, { ForwardedRef, forwardRef } from "react";
|
|
2
|
+
import { Button, BUTTON_VARIANT } from "@purpurds/button";
|
|
3
|
+
import { Heading, TitleVariant } from "@purpurds/heading";
|
|
4
|
+
import { IconClose } from "@purpurds/icon";
|
|
5
|
+
import { IconArrowLeft } from "@purpurds/icon";
|
|
6
|
+
import * as RadixDialog from "@radix-ui/react-dialog";
|
|
7
|
+
import c from "classnames/bind";
|
|
8
|
+
|
|
9
|
+
import styles from "./drawer-header.module.scss";
|
|
10
|
+
const cx = c.bind(styles);
|
|
11
|
+
|
|
12
|
+
export type DrawerHeaderProps = {
|
|
13
|
+
["data-testid"]?: string;
|
|
14
|
+
backButton: boolean;
|
|
15
|
+
backButtonText?: string;
|
|
16
|
+
backButtonOnlyIcon: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
closeButtonText: string;
|
|
19
|
+
onBackButtonClick?: () => void;
|
|
20
|
+
title: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const rootClassName = "purpur-drawer-header";
|
|
24
|
+
|
|
25
|
+
export const DrawerHeader = forwardRef(
|
|
26
|
+
(
|
|
27
|
+
{
|
|
28
|
+
["data-testid"]: dataTestId = "purpur-drawer-header",
|
|
29
|
+
backButton,
|
|
30
|
+
backButtonText,
|
|
31
|
+
backButtonOnlyIcon,
|
|
32
|
+
className,
|
|
33
|
+
closeButtonText,
|
|
34
|
+
onBackButtonClick,
|
|
35
|
+
title,
|
|
36
|
+
...props
|
|
37
|
+
}: DrawerHeaderProps,
|
|
38
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
39
|
+
) => {
|
|
40
|
+
const classes = cx([className, rootClassName]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className={classes} data-testid={dataTestId} ref={ref} {...props}>
|
|
44
|
+
<div
|
|
45
|
+
className={cx([
|
|
46
|
+
`${rootClassName}__row`,
|
|
47
|
+
{
|
|
48
|
+
[`${rootClassName}__row--with-back-button`]:
|
|
49
|
+
backButton && backButtonText && onBackButtonClick,
|
|
50
|
+
},
|
|
51
|
+
])}
|
|
52
|
+
data-testid={`${dataTestId}-row`}
|
|
53
|
+
>
|
|
54
|
+
<div className={cx(`${rootClassName}__left`)}>
|
|
55
|
+
{backButton && backButtonText && onBackButtonClick ? (
|
|
56
|
+
<Button
|
|
57
|
+
aria-label={backButtonOnlyIcon ? backButtonText : ""}
|
|
58
|
+
className={cx([
|
|
59
|
+
`${rootClassName}__back-button`,
|
|
60
|
+
{
|
|
61
|
+
[`${rootClassName}__back-button--only-icon`]: backButtonOnlyIcon,
|
|
62
|
+
},
|
|
63
|
+
])}
|
|
64
|
+
data-testid={`${dataTestId}-back-button`}
|
|
65
|
+
iconOnly={backButtonOnlyIcon}
|
|
66
|
+
onClick={onBackButtonClick}
|
|
67
|
+
size="sm"
|
|
68
|
+
variant={backButtonOnlyIcon ? BUTTON_VARIANT.TERTIARY_PURPLE : BUTTON_VARIANT.TEXT}
|
|
69
|
+
>
|
|
70
|
+
<IconArrowLeft size="sm" />
|
|
71
|
+
{!backButtonOnlyIcon && backButtonText}
|
|
72
|
+
</Button>
|
|
73
|
+
) : (
|
|
74
|
+
<RadixDialog.Title asChild>
|
|
75
|
+
<Heading
|
|
76
|
+
data-testid={`${dataTestId}-title`}
|
|
77
|
+
tag="h2"
|
|
78
|
+
variant={TitleVariant.TITLE200}
|
|
79
|
+
>
|
|
80
|
+
{title}
|
|
81
|
+
</Heading>
|
|
82
|
+
</RadixDialog.Title>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div className={cx(`${rootClassName}__right`)}>
|
|
87
|
+
<RadixDialog.Close asChild>
|
|
88
|
+
<Button
|
|
89
|
+
aria-label={closeButtonText}
|
|
90
|
+
className={cx(`${rootClassName}__close-button`)}
|
|
91
|
+
iconOnly
|
|
92
|
+
size="sm"
|
|
93
|
+
variant={BUTTON_VARIANT.TERTIARY_PURPLE}
|
|
94
|
+
>
|
|
95
|
+
<IconClose size="sm" />
|
|
96
|
+
</Button>
|
|
97
|
+
</RadixDialog.Close>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
{backButton && backButtonText && onBackButtonClick && (
|
|
101
|
+
<RadixDialog.Title asChild>
|
|
102
|
+
<Heading
|
|
103
|
+
className={cx(`${rootClassName}__heading`)}
|
|
104
|
+
data-testid={`${dataTestId}-title-with-back-button`}
|
|
105
|
+
tag="h2"
|
|
106
|
+
variant={TitleVariant.TITLE200}
|
|
107
|
+
>
|
|
108
|
+
{title}
|
|
109
|
+
</Heading>
|
|
110
|
+
</RadixDialog.Title>
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
DrawerHeader.displayName = "DrawerHeader";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
$animation-settings: var(--purpur-motion-duration-200) var(--purpur-motion-easing-ease-in-out);
|
|
2
|
+
|
|
3
|
+
.purpur-drawer-scroll-area {
|
|
4
|
+
&__root {
|
|
5
|
+
height: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
&__viewport {
|
|
9
|
+
height: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
&__scrollbar {
|
|
13
|
+
display: flex;
|
|
14
|
+
/* ensures no selection */
|
|
15
|
+
user-select: none;
|
|
16
|
+
/* disable browser handling of all panning and zooming gestures on touch devices */
|
|
17
|
+
touch-action: none;
|
|
18
|
+
padding: var(--purpur-spacing-25);
|
|
19
|
+
background: var(--purpur-color-functional-white);
|
|
20
|
+
transition: background $animation-settings;
|
|
21
|
+
width: var(--purpur-spacing-100);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&__thumb {
|
|
25
|
+
background: var(--purpur-color-gray-200);
|
|
26
|
+
border-radius: var(--purpur-spacing-200);
|
|
27
|
+
flex: 1;
|
|
28
|
+
position: relative;
|
|
29
|
+
|
|
30
|
+
&::before {
|
|
31
|
+
content: "";
|
|
32
|
+
height: 100%;
|
|
33
|
+
left: 50%;
|
|
34
|
+
min-height: var(--purpur-spacing-300);
|
|
35
|
+
min-width: var(--purpur-spacing-300);
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 50%;
|
|
38
|
+
transform: translate(-50%, -50%);
|
|
39
|
+
width: 100%;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
3
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { DrawerScrollArea } from "./drawer-scroll-area";
|
|
7
|
+
|
|
8
|
+
expect.extend(matchers);
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
cleanup();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("DrawerScrollArea", () => {
|
|
15
|
+
it("should render children", async () => {
|
|
16
|
+
render(
|
|
17
|
+
<DrawerScrollArea data-testid={Selectors.DRAWER_SCROLL_AREA}>
|
|
18
|
+
This is the scrollable content
|
|
19
|
+
</DrawerScrollArea>
|
|
20
|
+
);
|
|
21
|
+
const scrollArea = screen.getByTestId(Selectors.DRAWER_SCROLL_AREA);
|
|
22
|
+
expect(scrollArea).toHaveTextContent("This is the scrollable content");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const Selectors = {
|
|
27
|
+
DRAWER_SCROLL_AREA: "purpur-drawer-scroll-area",
|
|
28
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { ForwardedRef, forwardRef, ReactNode } from "react";
|
|
2
|
+
import * as RadixScrollArea from "@radix-ui/react-scroll-area";
|
|
3
|
+
import c from "classnames/bind";
|
|
4
|
+
|
|
5
|
+
import styles from "./drawer-scroll-area.module.scss";
|
|
6
|
+
const cx = c.bind(styles);
|
|
7
|
+
|
|
8
|
+
export type DrawerScrollAreaProps = {
|
|
9
|
+
["data-testid"]?: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const rootClassName = "purpur-drawer-scroll-area";
|
|
15
|
+
|
|
16
|
+
export const DrawerScrollArea = forwardRef(
|
|
17
|
+
(
|
|
18
|
+
{
|
|
19
|
+
["data-testid"]: dataTestId = "purpur-drawer-scroll-area",
|
|
20
|
+
children,
|
|
21
|
+
className,
|
|
22
|
+
...props
|
|
23
|
+
}: DrawerScrollAreaProps,
|
|
24
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
25
|
+
) => {
|
|
26
|
+
const classes = cx([className, rootClassName]);
|
|
27
|
+
return (
|
|
28
|
+
<div className={classes} data-testid={dataTestId} ref={ref} {...props}>
|
|
29
|
+
<RadixScrollArea.Root className={cx(`${rootClassName}__root`)}>
|
|
30
|
+
<RadixScrollArea.Viewport className={cx(`${rootClassName}__viewport`)}>
|
|
31
|
+
{children}
|
|
32
|
+
</RadixScrollArea.Viewport>
|
|
33
|
+
<RadixScrollArea.Scrollbar
|
|
34
|
+
className={cx(`${rootClassName}__scrollbar`)}
|
|
35
|
+
orientation="vertical"
|
|
36
|
+
>
|
|
37
|
+
<RadixScrollArea.Thumb className={cx(`${rootClassName}__thumb`)} />
|
|
38
|
+
</RadixScrollArea.Scrollbar>
|
|
39
|
+
</RadixScrollArea.Root>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
DrawerScrollArea.displayName = "DrawerScrollArea";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as RadixDialog from "@radix-ui/react-dialog";
|
|
3
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
4
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { DrawerTrigger } from "./drawer-trigger";
|
|
8
|
+
|
|
9
|
+
expect.extend(matchers);
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
cleanup();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("DrawerTrigger", () => {
|
|
16
|
+
it("should render children", async () => {
|
|
17
|
+
render(
|
|
18
|
+
<RadixDialog.Root open={true}>
|
|
19
|
+
<DrawerTrigger>
|
|
20
|
+
<button type="button" data-testid={Selectors.DRAWER_TRIGGER}>
|
|
21
|
+
This is the trigger content
|
|
22
|
+
</button>
|
|
23
|
+
</DrawerTrigger>
|
|
24
|
+
</RadixDialog.Root>
|
|
25
|
+
);
|
|
26
|
+
const drawerTrigger = screen.getByTestId(Selectors.DRAWER_TRIGGER);
|
|
27
|
+
expect(drawerTrigger).toHaveTextContent("This is the trigger content");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const Selectors = {
|
|
32
|
+
DRAWER_TRIGGER: "purpur-drawer-trigger",
|
|
33
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { ForwardedRef, forwardRef, ReactNode } from "react";
|
|
2
|
+
import * as RadixDialog from "@radix-ui/react-dialog";
|
|
3
|
+
|
|
4
|
+
export type DrawerTriggerProps = {
|
|
5
|
+
["data-testid"]?: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const DrawerTrigger = forwardRef(
|
|
11
|
+
(
|
|
12
|
+
{
|
|
13
|
+
["data-testid"]: dataTestId = "purpur-drawer-trigger",
|
|
14
|
+
children,
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}: DrawerTriggerProps,
|
|
18
|
+
ref: ForwardedRef<HTMLButtonElement>
|
|
19
|
+
) => {
|
|
20
|
+
return (
|
|
21
|
+
<RadixDialog.Trigger
|
|
22
|
+
asChild
|
|
23
|
+
className={className}
|
|
24
|
+
data-testid={dataTestId}
|
|
25
|
+
ref={ref}
|
|
26
|
+
{...props}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</RadixDialog.Trigger>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
DrawerTrigger.displayName = "DrawerTrigger";
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Button } from "@purpurds/button";
|
|
3
|
+
import { Heading } from "@purpurds/heading";
|
|
4
|
+
import { Paragraph } from "@purpurds/paragraph";
|
|
5
|
+
import { useArgs } from "@storybook/preview-api";
|
|
6
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
7
|
+
|
|
8
|
+
import "@purpurds/heading/styles";
|
|
9
|
+
import "@purpurds/button/styles";
|
|
10
|
+
import "@purpurds/paragraph/styles";
|
|
11
|
+
import "@purpurds/icon/styles";
|
|
12
|
+
import { Drawer, DrawerProps } from "./drawer";
|
|
13
|
+
import { DrawerContent } from "./drawer-content";
|
|
14
|
+
|
|
15
|
+
const StorybookTestBodyContent = () => {
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
<Heading variant="subsection-100" tag="h3">
|
|
19
|
+
The standard Lorem Ipsum passage, used since the 1500s
|
|
20
|
+
</Heading>
|
|
21
|
+
<Paragraph variant="paragraph-100" style={{ marginBottom: "32px" }}>
|
|
22
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
|
|
23
|
+
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
|
|
24
|
+
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
|
|
25
|
+
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
|
|
26
|
+
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
|
27
|
+
</Paragraph>
|
|
28
|
+
|
|
29
|
+
<Heading variant="subsection-100" tag="h3">
|
|
30
|
+
Section 1.10.32 of de Finibus Bonorum et Malorum, written by Cicero in 45 BC
|
|
31
|
+
</Heading>
|
|
32
|
+
<Paragraph variant="paragraph-100" style={{ marginBottom: "32px" }}>
|
|
33
|
+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
|
|
34
|
+
laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
|
|
35
|
+
architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit
|
|
36
|
+
aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
|
|
37
|
+
voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet,
|
|
38
|
+
consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et
|
|
39
|
+
dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum
|
|
40
|
+
exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi
|
|
41
|
+
consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil
|
|
42
|
+
molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
|
43
|
+
</Paragraph>
|
|
44
|
+
|
|
45
|
+
<Heading variant="subsection-100" tag="h3">
|
|
46
|
+
Section 1.10.33 of de Finibus Bonorum et Malorum, written by Cicero in 45 BC
|
|
47
|
+
</Heading>
|
|
48
|
+
<Paragraph variant="paragraph-100">
|
|
49
|
+
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium
|
|
50
|
+
voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati
|
|
51
|
+
cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id
|
|
52
|
+
est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam
|
|
53
|
+
libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod
|
|
54
|
+
maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
|
|
55
|
+
Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut
|
|
56
|
+
et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a
|
|
57
|
+
sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis
|
|
58
|
+
doloribus asperiores repellat.
|
|
59
|
+
</Paragraph>
|
|
60
|
+
</>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const StorybookTestFooterContent = () => {
|
|
65
|
+
return (
|
|
66
|
+
<div style={{ textAlign: "center" }}>
|
|
67
|
+
<div
|
|
68
|
+
style={{
|
|
69
|
+
display: "flex",
|
|
70
|
+
gap: "16px",
|
|
71
|
+
width: "100%",
|
|
72
|
+
marginBottom: "16px",
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
<Button variant="secondary" style={{ flex: "1 1 50%" }}>
|
|
76
|
+
Secondary button
|
|
77
|
+
</Button>
|
|
78
|
+
<Button variant="primary" style={{ flex: "1 1 50%" }}>
|
|
79
|
+
Primary button
|
|
80
|
+
</Button>
|
|
81
|
+
</div>
|
|
82
|
+
<Button variant="tertiary-purple" style={{ minWidth: "50%" }}>
|
|
83
|
+
Tertiary button
|
|
84
|
+
</Button>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const meta = {
|
|
90
|
+
title: "Components/Drawer",
|
|
91
|
+
component: Drawer,
|
|
92
|
+
parameters: {
|
|
93
|
+
design: [
|
|
94
|
+
{
|
|
95
|
+
name: "Drawer",
|
|
96
|
+
type: "figma",
|
|
97
|
+
url: "https://www.figma.com/design/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?node-id=48315-32864",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
subcomponents: {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
"Drawer.Trigger": Drawer.Trigger,
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
"Drawer.Content": Drawer.Content,
|
|
108
|
+
},
|
|
109
|
+
args: {
|
|
110
|
+
className: "myClass",
|
|
111
|
+
open: false,
|
|
112
|
+
},
|
|
113
|
+
} satisfies Meta<typeof Drawer>;
|
|
114
|
+
|
|
115
|
+
export default meta;
|
|
116
|
+
type DrawerStory = StoryObj<typeof Drawer>;
|
|
117
|
+
|
|
118
|
+
export const ShowcaseForDrawer: DrawerStory = {
|
|
119
|
+
name: "Showcase",
|
|
120
|
+
render: (args) => {
|
|
121
|
+
const [props, updateArgs]: [
|
|
122
|
+
DrawerProps,
|
|
123
|
+
(newArgs: Partial<DrawerProps>) => void,
|
|
124
|
+
(argNames?: (keyof DrawerProps)[] | undefined) => void
|
|
125
|
+
] = useArgs(); // eslint-disable-line react-hooks/rules-of-hooks
|
|
126
|
+
const handler = (isOpen: boolean) => {
|
|
127
|
+
updateArgs({ open: isOpen });
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div>
|
|
132
|
+
<Drawer {...args} {...props} onOpenChange={handler}>
|
|
133
|
+
<Drawer.Trigger>
|
|
134
|
+
<Button variant="primary">Open drawer</Button>
|
|
135
|
+
</Drawer.Trigger>
|
|
136
|
+
<Drawer.Content
|
|
137
|
+
backButton
|
|
138
|
+
backButtonText="Back"
|
|
139
|
+
backButtonOnlyIcon={false}
|
|
140
|
+
bodyText="This is the body text"
|
|
141
|
+
closeButtonText="Close drawer"
|
|
142
|
+
onBackButtonClick={() => {
|
|
143
|
+
return undefined;
|
|
144
|
+
}}
|
|
145
|
+
footerContent={<StorybookTestFooterContent />}
|
|
146
|
+
title="Title"
|
|
147
|
+
stickyFooter
|
|
148
|
+
>
|
|
149
|
+
<StorybookTestBodyContent />
|
|
150
|
+
</Drawer.Content>
|
|
151
|
+
</Drawer>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
type DrawerContentStory = StoryObj<typeof DrawerContent>;
|
|
158
|
+
export const ShowcaseForDrawerContent: DrawerContentStory = {
|
|
159
|
+
name: "Drawer.Content",
|
|
160
|
+
args: {
|
|
161
|
+
backButton: true,
|
|
162
|
+
backButtonText: "Back",
|
|
163
|
+
backButtonOnlyIcon: false,
|
|
164
|
+
bodyText: "This is the body text",
|
|
165
|
+
closeButtonText: "Close drawer",
|
|
166
|
+
disableCloseOnClickOutside: false,
|
|
167
|
+
footerContent: <StorybookTestFooterContent />,
|
|
168
|
+
onBackButtonClick: () => {
|
|
169
|
+
return undefined;
|
|
170
|
+
},
|
|
171
|
+
title: "Title",
|
|
172
|
+
stickyFooter: true,
|
|
173
|
+
},
|
|
174
|
+
render: (args) => {
|
|
175
|
+
const [props, updateArgs]: [
|
|
176
|
+
DrawerProps,
|
|
177
|
+
(newArgs: Partial<DrawerProps>) => void,
|
|
178
|
+
(argNames?: (keyof DrawerProps)[] | undefined) => void
|
|
179
|
+
] = useArgs(); // eslint-disable-line react-hooks/rules-of-hooks
|
|
180
|
+
const handler = (isOpen: boolean) => {
|
|
181
|
+
updateArgs({ open: isOpen });
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<div>
|
|
186
|
+
<Drawer {...props} onOpenChange={handler}>
|
|
187
|
+
<Drawer.Trigger>
|
|
188
|
+
<Button variant="primary">Open drawer</Button>
|
|
189
|
+
</Drawer.Trigger>
|
|
190
|
+
<Drawer.Content {...args}>
|
|
191
|
+
<StorybookTestBodyContent />
|
|
192
|
+
</Drawer.Content>
|
|
193
|
+
</Drawer>
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
};
|