@purpurds/drawer 7.6.0 → 7.7.0

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.
Files changed (37) hide show
  1. package/dist/LICENSE.txt +4 -4
  2. package/dist/drawer-container.d.ts +3 -8
  3. package/dist/drawer-container.d.ts.map +1 -1
  4. package/dist/drawer-content.d.ts +35 -3
  5. package/dist/drawer-content.d.ts.map +1 -1
  6. package/dist/drawer-frame.d.ts +3 -21
  7. package/dist/drawer-frame.d.ts.map +1 -1
  8. package/dist/drawer-handle.d.ts +3 -9
  9. package/dist/drawer-handle.d.ts.map +1 -1
  10. package/dist/drawer-header.d.ts +3 -12
  11. package/dist/drawer-header.d.ts.map +1 -1
  12. package/dist/drawer-scroll-area.d.ts +3 -7
  13. package/dist/drawer-scroll-area.d.ts.map +1 -1
  14. package/dist/drawer-trigger.d.ts +3 -6
  15. package/dist/drawer-trigger.d.ts.map +1 -1
  16. package/dist/drawer.cjs.js +11 -11
  17. package/dist/drawer.cjs.js.map +1 -1
  18. package/dist/drawer.d.ts +2 -2
  19. package/dist/drawer.d.ts.map +1 -1
  20. package/dist/drawer.es.js +560 -586
  21. package/dist/drawer.es.js.map +1 -1
  22. package/dist/use-swipe-to-dismiss.hook.d.ts +3 -3
  23. package/dist/use-swipe-to-dismiss.hook.d.ts.map +1 -1
  24. package/dist/use-swipe-tracking.hook.d.ts +6 -6
  25. package/dist/use-swipe-tracking.hook.d.ts.map +1 -1
  26. package/package.json +8 -7
  27. package/src/drawer-container.tsx +7 -6
  28. package/src/drawer-content.tsx +20 -6
  29. package/src/drawer-frame.tsx +7 -6
  30. package/src/drawer-handle.tsx +7 -6
  31. package/src/drawer-header.tsx +10 -8
  32. package/src/drawer-scroll-area.tsx +7 -6
  33. package/src/drawer-trigger.tsx +6 -20
  34. package/src/drawer.stories.tsx +1 -1
  35. package/src/drawer.tsx +3 -2
  36. package/src/use-swipe-to-dismiss.hook.ts +4 -4
  37. package/src/use-swipe-tracking.hook.ts +9 -9
@@ -1,13 +1,13 @@
1
- import { default as React } from 'react';
1
+ import { AnimationEvent, RefObject } from 'react';
2
2
  import { SwipeEvent } from './types';
3
3
 
4
4
  type UseSwipeToDismiss = {
5
- onAnimationEnd(event: React.AnimationEvent<HTMLDivElement>): void;
5
+ onAnimationEnd(event: AnimationEvent<HTMLDivElement>): void;
6
6
  onSwipeStart(): void;
7
7
  onSwipeMove(event: SwipeEvent): void;
8
8
  onSwipeCancel(): void;
9
9
  onSwipeEnd(event: SwipeEvent): void;
10
10
  };
11
- export declare const useSwipeToDismiss: <T extends HTMLElement>(containerRef: React.MutableRefObject<T | null>, handleOpenChange: (open: boolean) => void) => UseSwipeToDismiss;
11
+ export declare const useSwipeToDismiss: <T extends HTMLElement>(containerRef: RefObject<T | null>, handleOpenChange: (open: boolean) => void) => UseSwipeToDismiss;
12
12
  export {};
13
13
  //# sourceMappingURL=use-swipe-to-dismiss.hook.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-swipe-to-dismiss.hook.d.ts","sourceRoot":"","sources":["../src/use-swipe-to-dismiss.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,iBAAiB,GAAG;IACvB,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAClE,YAAY,IAAI,IAAI,CAAC;IACrB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACrC,aAAa,IAAI,IAAI,CAAC;IACtB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,gBACvC,KAAK,CAAC,gBAAgB,CAAC,CAAC,GAAG,IAAI,CAAC,oBAC5B,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,KACxC,iBA4CF,CAAC"}
1
+ {"version":3,"file":"use-swipe-to-dismiss.hook.d.ts","sourceRoot":"","sources":["../src/use-swipe-to-dismiss.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,iBAAiB,GAAG;IACvB,cAAc,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAC5D,YAAY,IAAI,IAAI,CAAC;IACrB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACrC,aAAa,IAAI,IAAI,CAAC;IACtB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,gBACvC,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,oBACf,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,KACxC,iBA4CF,CAAC"}
@@ -1,14 +1,14 @@
1
- import { default as React } from 'react';
1
+ import { PointerEvent, RefObject } from 'react';
2
2
  import { SwipeEvent } from './types';
3
3
 
4
4
  type UseSwipeTracking = {
5
- onPointerDown(event: React.PointerEvent): void;
6
- onPointerMove(event: React.PointerEvent): void;
7
- onPointerUp(event: React.PointerEvent): void;
5
+ onPointerDown(event: PointerEvent): void;
6
+ onPointerMove(event: PointerEvent): void;
7
+ onPointerUp(event: PointerEvent): void;
8
8
  };
9
- export declare const useSwipeTracking: (pointerStartRef: React.MutableRefObject<{
9
+ export declare const useSwipeTracking: (pointerStartRef: RefObject<{
10
10
  y: number;
11
- } | null>, swipeDeltaRef: React.MutableRefObject<{
11
+ } | null>, swipeDeltaRef: RefObject<{
12
12
  y: number;
13
13
  } | null>, onSwipeStart: () => void, onSwipeMove: (event: SwipeEvent) => void, onSwipeCancel: () => void, onSwipeEnd: (event: SwipeEvent) => void) => UseSwipeTracking;
14
14
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"use-swipe-tracking.hook.d.ts","sourceRoot":"","sources":["../src/use-swipe-tracking.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,gBAAgB,GAAG;IACtB,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;IAC/C,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;IAC/C,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,gBAAgB,oBACV,KAAK,CAAC,gBAAgB,CAAC;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,iBAC9C,KAAK,CAAC,gBAAgB,CAAC;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,gBAC7C,MAAM,IAAI,eACX,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,iBACzB,MAAM,IAAI,cACb,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,KACtC,gBAuDF,CAAC"}
1
+ {"version":3,"file":"use-swipe-tracking.hook.d.ts","sourceRoot":"","sources":["../src/use-swipe-tracking.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,gBAAgB,GAAG;IACtB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACzC,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACzC,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,eAAO,MAAM,gBAAgB,oBACV,SAAS,CAAC;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,iBACjC,SAAS,CAAC;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,gBAChC,MAAM,IAAI,eACX,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,iBACzB,MAAM,IAAI,cACb,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,KACtC,gBAuDF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/drawer",
3
- "version": "7.6.0",
3
+ "version": "7.7.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "./dist/drawer.cjs.js",
6
6
  "types": "./dist/drawer.d.ts",
@@ -18,12 +18,13 @@
18
18
  "@radix-ui/react-dialog": "~1.1.6",
19
19
  "@radix-ui/react-scroll-area": "~1.2.3",
20
20
  "classnames": "~2.5.0",
21
- "@purpurds/button": "7.6.0",
22
- "@purpurds/visually-hidden": "7.6.0",
23
- "@purpurds/icon": "7.6.0",
24
- "@purpurds/tokens": "7.6.0",
25
- "@purpurds/heading": "7.6.0",
26
- "@purpurds/paragraph": "7.6.0"
21
+ "@purpurds/button": "7.7.0",
22
+ "@purpurds/icon": "7.7.0",
23
+ "@purpurds/paragraph": "7.7.0",
24
+ "@purpurds/visually-hidden": "7.7.0",
25
+ "@purpurds/tokens": "7.7.0",
26
+ "@purpurds/common-types": "7.7.0",
27
+ "@purpurds/heading": "7.7.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "eslint": "9.24.0",
@@ -1,11 +1,12 @@
1
- import React, { type ForwardedRef, forwardRef, type ReactNode } from "react";
1
+ import React, { forwardRef, type ReactNode } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
2
3
  import c from "classnames/bind";
3
4
 
4
5
  import styles from "./drawer-container.module.scss";
6
+
5
7
  const cx = c.bind(styles);
6
8
 
7
- export type DrawerContainerProps = React.HTMLAttributes<HTMLDivElement> & {
8
- ["data-testid"]?: string;
9
+ export type DrawerContainerProps = Omit<BaseProps, "children"> & {
9
10
  children: ReactNode;
10
11
  stickyFooter: boolean;
11
12
  variant?: "header" | "body" | "footer";
@@ -13,7 +14,7 @@ export type DrawerContainerProps = React.HTMLAttributes<HTMLDivElement> & {
13
14
 
14
15
  const rootClassName = "purpur-drawer-container";
15
16
 
16
- export const DrawerContainer = forwardRef(
17
+ export const DrawerContainer = forwardRef<HTMLDivElement, DrawerContainerProps>(
17
18
  (
18
19
  {
19
20
  ["data-testid"]: dataTestId = "purpur-drawer-container",
@@ -22,8 +23,8 @@ export const DrawerContainer = forwardRef(
22
23
  variant = "body",
23
24
  stickyFooter,
24
25
  ...props
25
- }: DrawerContainerProps,
26
- ref: ForwardedRef<HTMLDivElement>
26
+ },
27
+ ref
27
28
  ) => {
28
29
  const classes = cx([
29
30
  className,
@@ -1,4 +1,5 @@
1
- import React, { type ForwardedRef, forwardRef, type ReactNode, useContext, useRef } from "react";
1
+ import React, { forwardRef, type ReactNode, useContext, useRef } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
2
3
  import * as RadixDialog from "@radix-ui/react-dialog";
3
4
  import c from "classnames/bind";
4
5
 
@@ -7,6 +8,7 @@ import styles from "./drawer-content.module.scss";
7
8
  import { DrawerFrame } from "./drawer-frame";
8
9
  import { type OpenHandlerFunction } from "./types";
9
10
  import { useSwipeToDismiss } from "./use-swipe-to-dismiss.hook";
11
+
10
12
  const cx = c.bind(styles);
11
13
 
12
14
  export type WithBackButton = {
@@ -23,8 +25,7 @@ export type WithoutBackButton = {
23
25
  onBackButtonClick?: never;
24
26
  };
25
27
 
26
- export type DrawerContentProps = React.HTMLAttributes<HTMLElement> & {
27
- ["data-testid"]?: string;
28
+ export type DrawerContentProps = Omit<BaseProps, "children"> & {
28
29
  bodyText?: string;
29
30
  children: ReactNode;
30
31
  closeButtonAriaLabel: string;
@@ -42,7 +43,7 @@ export type DrawerContentProps = React.HTMLAttributes<HTMLElement> & {
42
43
 
43
44
  const rootClassName = "purpur-drawer-content";
44
45
 
45
- export const DrawerContent = forwardRef(
46
+ export const DrawerContent = forwardRef<HTMLDivElement, DrawerContentProps>(
46
47
  (
47
48
  {
48
49
  ["data-testid"]: dataTestId = "purpur-drawer-content",
@@ -62,8 +63,8 @@ export const DrawerContent = forwardRef(
62
63
  title,
63
64
  zIndex,
64
65
  ...props
65
- }: DrawerContentProps,
66
- ref: ForwardedRef<HTMLDivElement>
66
+ },
67
+ ref
67
68
  ) => {
68
69
  const classes = cx([
69
70
  className,
@@ -82,6 +83,18 @@ export const DrawerContent = forwardRef(
82
83
  }
83
84
  };
84
85
 
86
+ const handleInitialFocus = () => {
87
+ const frame = drawerFrameRef.current;
88
+ if (frame) {
89
+ const heading = frame.querySelector("h2");
90
+
91
+ heading &&
92
+ setTimeout(() => {
93
+ heading.focus();
94
+ });
95
+ }
96
+ };
97
+
85
98
  return (
86
99
  <RadixDialog.Portal>
87
100
  <RadixDialog.Overlay
@@ -91,6 +104,7 @@ export const DrawerContent = forwardRef(
91
104
  >
92
105
  <RadixDialog.Content
93
106
  onPointerDownOutside={handlePointerDownOutside}
107
+ onOpenAutoFocus={handleInitialFocus}
94
108
  className={classes}
95
109
  data-testid={dataTestId}
96
110
  ref={ref}
@@ -1,4 +1,5 @@
1
- import React, { type ForwardedRef, forwardRef, type ReactNode } from "react";
1
+ import React, { forwardRef, type ReactNode } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
2
3
  import c from "classnames/bind";
3
4
 
4
5
  import { DrawerContainer } from "./drawer-container";
@@ -7,10 +8,10 @@ import { DrawerHandle } from "./drawer-handle";
7
8
  import { DrawerHeader } from "./drawer-header";
8
9
  import { DrawerScrollArea } from "./drawer-scroll-area";
9
10
  import { type SwipeEvent } from "./types";
11
+
10
12
  const cx = c.bind(styles);
11
13
 
12
- export type DrawerFrameProps = React.HTMLAttributes<HTMLDivElement> & {
13
- ["data-testid"]?: string;
14
+ export type DrawerFrameProps = Omit<BaseProps, "children"> & {
14
15
  backButton: boolean;
15
16
  backButtonText?: string;
16
17
  backButtonOnlyIcon: boolean;
@@ -31,7 +32,7 @@ export type DrawerFrameProps = React.HTMLAttributes<HTMLDivElement> & {
31
32
 
32
33
  const rootClassName = "purpur-drawer-frame";
33
34
 
34
- export const DrawerFrame = forwardRef(
35
+ export const DrawerFrame = forwardRef<HTMLDivElement, DrawerFrameProps>(
35
36
  (
36
37
  {
37
38
  ["data-testid"]: dataTestId = "purpur-drawer-frame",
@@ -53,8 +54,8 @@ export const DrawerFrame = forwardRef(
53
54
  title,
54
55
  stickyFooter,
55
56
  ...props
56
- }: DrawerFrameProps,
57
- ref: ForwardedRef<HTMLDivElement>
57
+ },
58
+ ref
58
59
  ) => {
59
60
  const classes = cx([
60
61
  className,
@@ -1,13 +1,14 @@
1
- import React, { type ForwardedRef, forwardRef } from "react";
1
+ import React, { forwardRef } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
2
3
  import c from "classnames/bind";
3
4
 
4
5
  import styles from "./drawer-handle.module.scss";
5
6
  import { type SwipeEvent } from "./types";
6
7
  import { useSwipeTracking } from "./use-swipe-tracking.hook";
8
+
7
9
  const cx = c.bind(styles);
8
10
 
9
- export type DrawerHandleProps = React.HTMLAttributes<HTMLDivElement> & {
10
- ["data-testid"]?: string;
11
+ export type DrawerHandleProps = Omit<BaseProps, "children"> & {
11
12
  onSwipeStart(): void;
12
13
  onSwipeMove(event: SwipeEvent): void;
13
14
  onSwipeCancel(): void;
@@ -16,7 +17,7 @@ export type DrawerHandleProps = React.HTMLAttributes<HTMLDivElement> & {
16
17
 
17
18
  const rootClassName = "purpur-drawer-handle";
18
19
 
19
- export const DrawerHandle = forwardRef(
20
+ export const DrawerHandle = forwardRef<HTMLDivElement, DrawerHandleProps>(
20
21
  (
21
22
  {
22
23
  ["data-testid"]: dataTestId = "purpur-drawer-handle",
@@ -26,8 +27,8 @@ export const DrawerHandle = forwardRef(
26
27
  onSwipeCancel,
27
28
  onSwipeEnd,
28
29
  ...props
29
- }: DrawerHandleProps,
30
- ref: ForwardedRef<HTMLDivElement>
30
+ },
31
+ ref
31
32
  ) => {
32
33
  const classes = cx([className, rootClassName]);
33
34
  const pointerStartRef = React.useRef<{ y: number } | null>(null);
@@ -1,5 +1,6 @@
1
- import React, { type ForwardedRef, forwardRef } from "react";
1
+ import React, { forwardRef } from "react";
2
2
  import { Button, BUTTON_VARIANT } from "@purpurds/button";
3
+ import type { BaseProps } from "@purpurds/common-types";
3
4
  import { Heading, TitleVariant } from "@purpurds/heading";
4
5
  import { IconArrowLeft } from "@purpurds/icon/arrow-left";
5
6
  import { IconClose } from "@purpurds/icon/close";
@@ -11,8 +12,7 @@ import styles from "./drawer-header.module.scss";
11
12
 
12
13
  const cx = c.bind(styles);
13
14
 
14
- export type DrawerHeaderProps = React.HTMLAttributes<HTMLDivElement> & {
15
- ["data-testid"]?: string;
15
+ export type DrawerHeaderProps = Omit<BaseProps, "children"> & {
16
16
  backButton: boolean;
17
17
  backButtonText?: string;
18
18
  backButtonOnlyIcon: boolean;
@@ -24,7 +24,7 @@ export type DrawerHeaderProps = React.HTMLAttributes<HTMLDivElement> & {
24
24
 
25
25
  const rootClassName = "purpur-drawer-header";
26
26
 
27
- export const DrawerHeader = forwardRef(
27
+ export const DrawerHeader = forwardRef<HTMLDivElement, DrawerHeaderProps>(
28
28
  (
29
29
  {
30
30
  ["data-testid"]: dataTestId = "purpur-drawer-header",
@@ -37,8 +37,8 @@ export const DrawerHeader = forwardRef(
37
37
  onBackButtonClick,
38
38
  title,
39
39
  ...props
40
- }: DrawerHeaderProps,
41
- ref: ForwardedRef<HTMLDivElement>
40
+ },
41
+ ref
42
42
  ) => {
43
43
  const classes = cx([className, rootClassName]);
44
44
 
@@ -77,7 +77,7 @@ export const DrawerHeader = forwardRef(
77
77
  <>
78
78
  {headerContent}
79
79
  <VisuallyHidden asChild>
80
- <RadixDialog.Title asChild>{title}</RadixDialog.Title>
80
+ <RadixDialog.Title>{title}</RadixDialog.Title>
81
81
  </VisuallyHidden>
82
82
  </>
83
83
  ) : (
@@ -86,6 +86,7 @@ export const DrawerHeader = forwardRef(
86
86
  data-testid={`${dataTestId}-title`}
87
87
  tag="h2"
88
88
  variant={TitleVariant.TITLE200}
89
+ tabIndex={-1}
89
90
  >
90
91
  {title}
91
92
  </Heading>
@@ -114,7 +115,7 @@ export const DrawerHeader = forwardRef(
114
115
  <>
115
116
  {headerContent}
116
117
  <VisuallyHidden asChild>
117
- <RadixDialog.Title asChild>{title}</RadixDialog.Title>
118
+ <RadixDialog.Title>{title}</RadixDialog.Title>
118
119
  </VisuallyHidden>
119
120
  </>
120
121
  ) : (
@@ -122,6 +123,7 @@ export const DrawerHeader = forwardRef(
122
123
  <Heading
123
124
  data-testid={`${dataTestId}-title-with-back-button`}
124
125
  tag="h2"
126
+ tabIndex={-1}
125
127
  variant={TitleVariant.TITLE200}
126
128
  >
127
129
  {title}
@@ -1,19 +1,20 @@
1
- import React, { type ForwardedRef, forwardRef, type ReactNode } from "react";
1
+ import React, { forwardRef, type ReactNode } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
2
3
  import * as RadixScrollArea from "@radix-ui/react-scroll-area";
3
4
  import c from "classnames/bind";
4
5
 
5
6
  import styles from "./drawer-scroll-area.module.scss";
7
+
6
8
  const cx = c.bind(styles);
7
9
 
8
- export type DrawerScrollAreaProps = React.HTMLAttributes<HTMLDivElement> & {
9
- ["data-testid"]?: string;
10
+ export type DrawerScrollAreaProps = Omit<BaseProps, "children"> & {
10
11
  children: ReactNode;
11
12
  fitToContent?: boolean;
12
13
  };
13
14
 
14
15
  const rootClassName = "purpur-drawer-scroll-area";
15
16
 
16
- export const DrawerScrollArea = forwardRef(
17
+ export const DrawerScrollArea = forwardRef<HTMLDivElement, DrawerScrollAreaProps>(
17
18
  (
18
19
  {
19
20
  ["data-testid"]: dataTestId = "purpur-drawer-scroll-area",
@@ -21,8 +22,8 @@ export const DrawerScrollArea = forwardRef(
21
22
  className,
22
23
  fitToContent = false,
23
24
  ...props
24
- }: DrawerScrollAreaProps,
25
- ref: ForwardedRef<HTMLDivElement>
25
+ },
26
+ ref
26
27
  ) => {
27
28
  const classes = cx([className, rootClassName]);
28
29
  return (
@@ -1,29 +1,15 @@
1
- import React, { type ForwardedRef, forwardRef, type ReactNode } from "react";
1
+ import React, { forwardRef, type ReactNode } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
2
3
  import * as RadixDialog from "@radix-ui/react-dialog";
3
4
 
4
- export type DrawerTriggerProps = React.HTMLAttributes<HTMLElement> & {
5
- ["data-testid"]?: string;
5
+ export type DrawerTriggerProps = Omit<BaseProps<"button">, "children"> & {
6
6
  children: ReactNode;
7
7
  };
8
8
 
9
- export const DrawerTrigger = forwardRef(
10
- (
11
- {
12
- ["data-testid"]: dataTestId = "purpur-drawer-trigger",
13
- children,
14
- className,
15
- ...props
16
- }: DrawerTriggerProps,
17
- ref: ForwardedRef<HTMLButtonElement>
18
- ) => {
9
+ export const DrawerTrigger = forwardRef<HTMLButtonElement, DrawerTriggerProps>(
10
+ ({ ["data-testid"]: dataTestId = "purpur-drawer-trigger", children, ...props }, ref) => {
19
11
  return (
20
- <RadixDialog.Trigger
21
- asChild
22
- className={className}
23
- data-testid={dataTestId}
24
- ref={ref}
25
- {...props}
26
- >
12
+ <RadixDialog.Trigger asChild data-testid={dataTestId} ref={ref} {...props}>
27
13
  {children}
28
14
  </RadixDialog.Trigger>
29
15
  );
@@ -257,7 +257,7 @@ export const ShowcaseForDrawerContent: DrawerContentStory = {
257
257
 
258
258
  return (
259
259
  <div>
260
- <Drawer {...props} onOpenChange={handler}>
260
+ <Drawer open={props.open} onOpenChange={handler}>
261
261
  <Drawer.Trigger>
262
262
  <Button variant="primary">Open drawer</Button>
263
263
  </Drawer.Trigger>
package/src/drawer.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import React, { type ReactNode, useEffect } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
2
3
  import * as RadixDialog from "@radix-ui/react-dialog";
3
4
  import c from "classnames/bind";
4
5
 
@@ -6,10 +7,10 @@ import { DrawerContext } from "./drawer.context";
6
7
  import styles from "./drawer.module.scss";
7
8
  import { DrawerContent } from "./drawer-content";
8
9
  import { DrawerTrigger } from "./drawer-trigger";
10
+
9
11
  const cx = c.bind(styles);
10
12
 
11
- export type DrawerProps = React.HTMLAttributes<HTMLDivElement> & {
12
- ["data-testid"]?: string;
13
+ export type DrawerProps = Omit<BaseProps, "children"> & {
13
14
  children: ReactNode;
14
15
  onOpenChange?: (open: boolean) => void;
15
16
  open: boolean;
@@ -1,9 +1,9 @@
1
- import type React from "react";
1
+ import type { AnimationEvent, RefObject } from "react";
2
2
 
3
3
  import { type SwipeEvent } from "./types";
4
4
 
5
5
  type UseSwipeToDismiss = {
6
- onAnimationEnd(event: React.AnimationEvent<HTMLDivElement>): void;
6
+ onAnimationEnd(event: AnimationEvent<HTMLDivElement>): void;
7
7
  onSwipeStart(): void;
8
8
  onSwipeMove(event: SwipeEvent): void;
9
9
  onSwipeCancel(): void;
@@ -11,7 +11,7 @@ type UseSwipeToDismiss = {
11
11
  };
12
12
 
13
13
  export const useSwipeToDismiss = <T extends HTMLElement>(
14
- containerRef: React.MutableRefObject<T | null>,
14
+ containerRef: RefObject<T | null>,
15
15
  handleOpenChange: (open: boolean) => void
16
16
  ): UseSwipeToDismiss => {
17
17
  const onSwipeStart = () => {
@@ -45,7 +45,7 @@ export const useSwipeToDismiss = <T extends HTMLElement>(
45
45
  containerRef.current.style.removeProperty("--purpur-drawer-swipe-move-y");
46
46
  containerRef.current.style.setProperty("--purpur-drawer-swipe-end-y", `${y}px`);
47
47
  };
48
- const onAnimationEnd = (event: React.AnimationEvent<HTMLDivElement>) => {
48
+ const onAnimationEnd = (event: AnimationEvent<HTMLDivElement>) => {
49
49
  if (event.currentTarget.getAttribute("data-swipe") === "end") {
50
50
  handleOpenChange(false);
51
51
  }
@@ -1,25 +1,25 @@
1
- import type React from "react";
1
+ import type { PointerEvent, RefObject } from "react";
2
2
 
3
3
  import { type SwipeEvent } from "./types";
4
4
 
5
5
  type UseSwipeTracking = {
6
- onPointerDown(event: React.PointerEvent): void;
7
- onPointerMove(event: React.PointerEvent): void;
8
- onPointerUp(event: React.PointerEvent): void;
6
+ onPointerDown(event: PointerEvent): void;
7
+ onPointerMove(event: PointerEvent): void;
8
+ onPointerUp(event: PointerEvent): void;
9
9
  };
10
10
 
11
11
  export const useSwipeTracking = (
12
- pointerStartRef: React.MutableRefObject<{ y: number } | null>,
13
- swipeDeltaRef: React.MutableRefObject<{ y: number } | null>,
12
+ pointerStartRef: RefObject<{ y: number } | null>,
13
+ swipeDeltaRef: RefObject<{ y: number } | null>,
14
14
  onSwipeStart: () => void,
15
15
  onSwipeMove: (event: SwipeEvent) => void,
16
16
  onSwipeCancel: () => void,
17
17
  onSwipeEnd: (event: SwipeEvent) => void
18
18
  ): UseSwipeTracking => {
19
- const onPointerDown = (event: React.PointerEvent) => {
19
+ const onPointerDown = (event: PointerEvent) => {
20
20
  pointerStartRef.current = { y: event.clientY };
21
21
  };
22
- const onPointerMove = (event: React.PointerEvent) => {
22
+ const onPointerMove = (event: PointerEvent) => {
23
23
  if (!pointerStartRef.current) {
24
24
  return;
25
25
  }
@@ -42,7 +42,7 @@ export const useSwipeTracking = (
42
42
  pointerStartRef.current = null;
43
43
  }
44
44
  };
45
- const onPointerUp = (event: React.PointerEvent) => {
45
+ const onPointerUp = (event: PointerEvent) => {
46
46
  const delta = swipeDeltaRef.current;
47
47
  const target = event.target as HTMLElement;
48
48
  if (target.hasPointerCapture(event.pointerId)) {