@launchpad-ui/drawer 0.4.4 → 0.4.6
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/Drawer.d.ts +1 -1
- package/dist/Drawer.d.ts.map +1 -1
- package/dist/DrawerHeader.d.ts +1 -1
- package/dist/DrawerHeader.d.ts.map +1 -1
- package/dist/index.es.js +62 -94
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +89 -115
- package/dist/index.js.map +1 -1
- package/dist/style.css +12 -12
- package/package.json +5 -5
package/dist/Drawer.d.ts
CHANGED
@@ -8,7 +8,7 @@ type DrawerProps = {
|
|
8
8
|
theme?: 'dark' | 'default';
|
9
9
|
hideCancel?: boolean;
|
10
10
|
};
|
11
|
-
declare const Drawer: (props: DrawerProps) => JSX.Element;
|
11
|
+
declare const Drawer: (props: DrawerProps) => import("react/jsx-runtime").JSX.Element;
|
12
12
|
export { Drawer };
|
13
13
|
export type { DrawerProps };
|
14
14
|
//# sourceMappingURL=Drawer.d.ts.map
|
package/dist/Drawer.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../src/Drawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,OAAO,CAAC;AAqCnD,KAAK,WAAW,GAAG;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,IAAI,IAAI,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,QAAA,MAAM,MAAM,UAAW,WAAW,
|
1
|
+
{"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../src/Drawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,OAAO,CAAC;AAqCnD,KAAK,WAAW,GAAG;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,IAAI,IAAI,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,QAAA,MAAM,MAAM,UAAW,WAAW,4CAIjC,CAAC;AA8GF,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/DrawerHeader.d.ts
CHANGED
@@ -6,7 +6,7 @@ type DrawerHeaderProps = ComponentProps<'div'> & {
|
|
6
6
|
onClose?(): void;
|
7
7
|
'data-test-id'?: string;
|
8
8
|
};
|
9
|
-
declare const DrawerHeader: ({ className, children, titleID, titleClassName, "data-test-id": testId, ...rest }: DrawerHeaderProps) => JSX.Element;
|
9
|
+
declare const DrawerHeader: ({ className, children, titleID, titleClassName, "data-test-id": testId, ...rest }: DrawerHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
10
10
|
export { DrawerHeader };
|
11
11
|
export type { DrawerHeaderProps };
|
12
12
|
//# sourceMappingURL=DrawerHeader.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"DrawerHeader.d.ts","sourceRoot":"","sources":["../src/DrawerHeader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAI5C,KAAK,iBAAiB,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,QAAA,MAAM,YAAY,sFAOf,iBAAiB,
|
1
|
+
{"version":3,"file":"DrawerHeader.d.ts","sourceRoot":"","sources":["../src/DrawerHeader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAI5C,KAAK,iBAAiB,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,QAAA,MAAM,YAAY,sFAOf,iBAAiB,4CAQnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,YAAY,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/index.es.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import './style.css';
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
2
3
|
import { IconButton } from "@launchpad-ui/button";
|
3
4
|
import { FocusTrap } from "@launchpad-ui/focus-trap";
|
4
5
|
import { Close } from "@launchpad-ui/icons";
|
@@ -9,17 +10,16 @@ import { usePreventScroll } from "@react-aria/overlays";
|
|
9
10
|
import { cx } from "classix";
|
10
11
|
import { LazyMotion, m } from "framer-motion";
|
11
12
|
import { useRef, useState, useEffect, Suspense } from "react";
|
12
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
13
13
|
const DRAWER_LABELLED_BY = "drawer-title";
|
14
|
-
const drawer = "
|
15
|
-
const overlay$1 = "
|
16
|
-
const content = "
|
17
|
-
const small = "
|
18
|
-
const medium = "
|
19
|
-
const large = "
|
20
|
-
const xLarge = "
|
21
|
-
const full = "
|
22
|
-
const closeButton = "
|
14
|
+
const drawer = "_drawer_1bcak_12";
|
15
|
+
const overlay$1 = "_overlay_1bcak_31";
|
16
|
+
const content = "_content_1bcak_37";
|
17
|
+
const small = "_small_1bcak_51";
|
18
|
+
const medium = "_medium_1bcak_55";
|
19
|
+
const large = "_large_1bcak_59";
|
20
|
+
const xLarge = "_xLarge_1bcak_63";
|
21
|
+
const full = "_full_1bcak_67";
|
22
|
+
const closeButton = "_closeButton_1bcak_81";
|
23
23
|
const styles = {
|
24
24
|
drawer,
|
25
25
|
overlay: overlay$1,
|
@@ -32,30 +32,15 @@ const styles = {
|
|
32
32
|
closeButton
|
33
33
|
};
|
34
34
|
const overlay = {
|
35
|
-
visible: {
|
36
|
-
|
37
|
-
transition: {
|
38
|
-
duration: 0.15
|
39
|
-
}
|
40
|
-
},
|
41
|
-
hidden: {
|
42
|
-
opacity: 0
|
43
|
-
}
|
35
|
+
visible: { opacity: 1, transition: { duration: 0.15 } },
|
36
|
+
hidden: { opacity: 0 }
|
44
37
|
};
|
45
38
|
const slideRight = {
|
46
|
-
hidden: {
|
47
|
-
opacity: 0,
|
48
|
-
x: "25%"
|
49
|
-
},
|
39
|
+
hidden: { opacity: 0, x: "25%" },
|
50
40
|
visible: {
|
51
41
|
opacity: 1,
|
52
42
|
x: "0%",
|
53
|
-
transition: {
|
54
|
-
type: "spring",
|
55
|
-
delay: 0.15,
|
56
|
-
duration: 0.2,
|
57
|
-
bounce: 0
|
58
|
-
}
|
43
|
+
transition: { type: "spring", delay: 0.15, duration: 0.2, bounce: 0 }
|
59
44
|
}
|
60
45
|
};
|
61
46
|
const loadFeatures = () => import(
|
@@ -63,11 +48,7 @@ const loadFeatures = () => import(
|
|
63
48
|
/* webpackExports: "domAnimation" */
|
64
49
|
"framer-motion"
|
65
50
|
).then((res) => res.domAnimation);
|
66
|
-
const Drawer = (props) => /* @__PURE__ */ jsx(Portal, {
|
67
|
-
children: /* @__PURE__ */ jsx(DrawerContainer, {
|
68
|
-
...props
|
69
|
-
})
|
70
|
-
});
|
51
|
+
const Drawer = (props) => /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(DrawerContainer, { ...props }) });
|
71
52
|
const DrawerContainer = ({
|
72
53
|
className,
|
73
54
|
children,
|
@@ -79,9 +60,7 @@ const DrawerContainer = ({
|
|
79
60
|
}) => {
|
80
61
|
const ref = useRef(null);
|
81
62
|
const [isFocusWithin, setIsFocusWithin] = useState(false);
|
82
|
-
const {
|
83
|
-
focusWithinProps
|
84
|
-
} = useFocusWithin({
|
63
|
+
const { focusWithinProps } = useFocusWithin({
|
85
64
|
onFocusWithinChange: (isFocusWithin2) => setIsFocusWithin(isFocusWithin2)
|
86
65
|
});
|
87
66
|
usePreventScroll();
|
@@ -119,58 +98,56 @@ const DrawerContainer = ({
|
|
119
98
|
onCancel && onCancel();
|
120
99
|
}
|
121
100
|
};
|
122
|
-
return /* @__PURE__ */ jsx(LazyMotion, {
|
123
|
-
|
124
|
-
|
125
|
-
children: /* @__PURE__ */ jsx("div", {
|
101
|
+
return /* @__PURE__ */ jsx(LazyMotion, { strict: true, features: loadFeatures, children: /* @__PURE__ */ jsx(
|
102
|
+
"div",
|
103
|
+
{
|
126
104
|
...focusWithinProps,
|
127
105
|
className: cx(styles.drawer, styles[size], className),
|
128
106
|
"data-drawer": true,
|
129
107
|
"data-test-id": testId,
|
130
108
|
ref,
|
131
|
-
children: /* @__PURE__ */ jsx(
|
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
|
-
});
|
109
|
+
children: /* @__PURE__ */ jsx(
|
110
|
+
m.div,
|
111
|
+
{
|
112
|
+
initial: "hidden",
|
113
|
+
animate: "visible",
|
114
|
+
variants: overlay,
|
115
|
+
transition: { duration: 0.15 },
|
116
|
+
role: "presentation",
|
117
|
+
className: styles.overlay,
|
118
|
+
onMouseDown: handleOverlayClick,
|
119
|
+
children: /* @__PURE__ */ jsx(FocusTrap, { autoFocus: true, restoreFocus: true, children: /* @__PURE__ */ jsxs(
|
120
|
+
m.div,
|
121
|
+
{
|
122
|
+
initial: "hidden",
|
123
|
+
animate: "visible",
|
124
|
+
variants: slideRight,
|
125
|
+
role: "dialog",
|
126
|
+
"aria-labelledby": DRAWER_LABELLED_BY,
|
127
|
+
"aria-describedby": DRAWER_LABELLED_BY,
|
128
|
+
"aria-modal": true,
|
129
|
+
className: styles.content,
|
130
|
+
tabIndex: -1,
|
131
|
+
...theme ? { "data-theme": theme } : {},
|
132
|
+
children: [
|
133
|
+
!hideCancel && /* @__PURE__ */ jsx(
|
134
|
+
IconButton,
|
135
|
+
{
|
136
|
+
"aria-label": "close",
|
137
|
+
icon: /* @__PURE__ */ jsx(Close, { size: "medium" }),
|
138
|
+
className: styles.closeButton,
|
139
|
+
onClick: onCancel,
|
140
|
+
"data-test-id": "drawer-close-button"
|
141
|
+
}
|
142
|
+
),
|
143
|
+
/* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Progress, {}), children })
|
144
|
+
]
|
145
|
+
}
|
146
|
+
) })
|
147
|
+
}
|
148
|
+
)
|
149
|
+
}
|
150
|
+
) });
|
174
151
|
};
|
175
152
|
const DrawerHeader = ({
|
176
153
|
className,
|
@@ -180,16 +157,7 @@ const DrawerHeader = ({
|
|
180
157
|
"data-test-id": testId = "drawer-header",
|
181
158
|
...rest
|
182
159
|
}) => {
|
183
|
-
return /* @__PURE__ */ jsx("div", {
|
184
|
-
"data-test-id": testId,
|
185
|
-
className,
|
186
|
-
...rest,
|
187
|
-
children: /* @__PURE__ */ jsx("h2", {
|
188
|
-
id: DRAWER_LABELLED_BY,
|
189
|
-
className: titleClassName,
|
190
|
-
children
|
191
|
-
})
|
192
|
-
});
|
160
|
+
return /* @__PURE__ */ jsx("div", { "data-test-id": testId, className, ...rest, children: /* @__PURE__ */ jsx("h2", { id: DRAWER_LABELLED_BY, className: titleClassName, children }) });
|
193
161
|
};
|
194
162
|
export {
|
195
163
|
Drawer,
|
package/dist/index.es.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/constants.ts","../src/Drawer.tsx","../src/DrawerHeader.tsx"],"sourcesContent":["export const DRAWER_LABELLED_BY = 'drawer-title';\n","import type { Variants } from 'framer-motion';\nimport type { MouseEvent, ReactNode } from 'react';\n\nimport { IconButton } from '@launchpad-ui/button';\nimport { FocusTrap } from '@launchpad-ui/focus-trap';\nimport { Close } from '@launchpad-ui/icons';\nimport { Portal } from '@launchpad-ui/portal';\nimport { Progress } from '@launchpad-ui/progress';\nimport { useFocusWithin } from '@react-aria/interactions';\nimport { usePreventScroll } from '@react-aria/overlays';\nimport { cx } from 'classix';\nimport { LazyMotion, m } from 'framer-motion';\nimport { useState, Suspense, useEffect, useRef } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\nimport styles from './styles/Drawer.module.css';\n\nconst overlay: Variants = {\n visible: { opacity: 1, transition: { duration: 0.15 } },\n hidden: { opacity: 0 },\n};\n\nconst slideRight: Variants = {\n hidden: { opacity: 0, x: '25%' },\n visible: {\n opacity: 1,\n x: '0%',\n transition: { type: 'spring', delay: 0.15, duration: 0.2, bounce: 0 },\n },\n};\n\nconst loadFeatures = () =>\n import(\n /* webpackChunkName: \"lp-drawer-framer-features\" */\n /* webpackExports: \"domAnimation\" */\n 'framer-motion'\n ).then((res) => res.domAnimation);\n\ntype DrawerProps = {\n children?: ReactNode;\n className?: string;\n onCancel?(): void;\n 'data-test-id'?: string;\n size?: 'small' | 'medium' | 'large' | 'xLarge' | 'full';\n theme?: 'dark' | 'default';\n hideCancel?: boolean;\n};\n\nconst Drawer = (props: DrawerProps) => (\n <Portal>\n <DrawerContainer {...props} />\n </Portal>\n);\n\nconst DrawerContainer = ({\n className,\n children,\n onCancel,\n size = 'small',\n 'data-test-id': testId = 'drawer',\n theme,\n hideCancel = false,\n}: DrawerProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const [isFocusWithin, setIsFocusWithin] = useState(false);\n const { focusWithinProps } = useFocusWithin({\n onFocusWithinChange: (isFocusWithin) => setIsFocusWithin(isFocusWithin),\n });\n\n usePreventScroll();\n\n useEffect(() => {\n const handleEscape = (event: KeyboardEvent) => {\n event.stopImmediatePropagation();\n const latest = [...document.querySelectorAll('[data-drawer]')].pop();\n if (event.key === 'Escape' && latest === ref.current && isFocusWithin) {\n close();\n }\n };\n\n const addOverlayAndEventHandler = () => {\n document.body.classList.add('has-overlay');\n document.addEventListener('keydown', handleEscape);\n };\n\n const removeOverlayAndEventHandler = () => {\n document.body.classList.remove('has-overlay');\n document.removeEventListener('keydown', handleEscape);\n };\n\n const close = () => {\n onCancel?.();\n };\n\n if (isFocusWithin) {\n addOverlayAndEventHandler();\n }\n\n if (!isFocusWithin) {\n removeOverlayAndEventHandler();\n }\n\n return () => {\n removeOverlayAndEventHandler();\n };\n }, [onCancel, testId, isFocusWithin]);\n\n const handleOverlayClick = (event: MouseEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget) {\n onCancel && onCancel();\n }\n };\n\n return (\n <LazyMotion strict features={loadFeatures}>\n <div\n {...focusWithinProps}\n className={cx(styles.drawer, styles[size], className)}\n data-drawer\n data-test-id={testId}\n ref={ref}\n >\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={overlay}\n transition={{ duration: 0.15 }}\n role=\"presentation\"\n className={styles.overlay}\n onMouseDown={handleOverlayClick}\n >\n <FocusTrap autoFocus restoreFocus>\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={slideRight}\n role=\"dialog\"\n aria-labelledby={DRAWER_LABELLED_BY}\n aria-describedby={DRAWER_LABELLED_BY}\n aria-modal\n className={styles.content}\n tabIndex={-1}\n {...(theme ? { 'data-theme': theme } : {})}\n >\n {!hideCancel && (\n <IconButton\n aria-label=\"close\"\n icon={<Close size=\"medium\" />}\n className={styles.closeButton}\n onClick={onCancel}\n data-test-id=\"drawer-close-button\"\n />\n )}\n <Suspense fallback={<Progress />}>{children}</Suspense>\n </m.div>\n </FocusTrap>\n </m.div>\n </div>\n </LazyMotion>\n );\n};\n\nexport { Drawer };\nexport type { DrawerProps };\n","import type { ComponentProps } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\n\ntype DrawerHeaderProps = ComponentProps<'div'> & {\n closeable?: boolean;\n titleID?: string;\n titleClassName?: string;\n onClose?(): void;\n 'data-test-id'?: string;\n};\n\nconst DrawerHeader = ({\n className,\n children,\n titleID,\n titleClassName,\n 'data-test-id': testId = 'drawer-header',\n ...rest\n}: DrawerHeaderProps) => {\n return (\n <div data-test-id={testId} className={className} {...rest}>\n <h2 id={DRAWER_LABELLED_BY} className={titleClassName}>\n {children}\n </h2>\n </div>\n );\n};\n\nexport { DrawerHeader };\nexport type { DrawerHeaderProps };\n"],"names":["
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/constants.ts","../src/Drawer.tsx","../src/DrawerHeader.tsx"],"sourcesContent":["export const DRAWER_LABELLED_BY = 'drawer-title';\n","import type { Variants } from 'framer-motion';\nimport type { MouseEvent, ReactNode } from 'react';\n\nimport { IconButton } from '@launchpad-ui/button';\nimport { FocusTrap } from '@launchpad-ui/focus-trap';\nimport { Close } from '@launchpad-ui/icons';\nimport { Portal } from '@launchpad-ui/portal';\nimport { Progress } from '@launchpad-ui/progress';\nimport { useFocusWithin } from '@react-aria/interactions';\nimport { usePreventScroll } from '@react-aria/overlays';\nimport { cx } from 'classix';\nimport { LazyMotion, m } from 'framer-motion';\nimport { useState, Suspense, useEffect, useRef } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\nimport styles from './styles/Drawer.module.css';\n\nconst overlay: Variants = {\n visible: { opacity: 1, transition: { duration: 0.15 } },\n hidden: { opacity: 0 },\n};\n\nconst slideRight: Variants = {\n hidden: { opacity: 0, x: '25%' },\n visible: {\n opacity: 1,\n x: '0%',\n transition: { type: 'spring', delay: 0.15, duration: 0.2, bounce: 0 },\n },\n};\n\nconst loadFeatures = () =>\n import(\n /* webpackChunkName: \"lp-drawer-framer-features\" */\n /* webpackExports: \"domAnimation\" */\n 'framer-motion'\n ).then((res) => res.domAnimation);\n\ntype DrawerProps = {\n children?: ReactNode;\n className?: string;\n onCancel?(): void;\n 'data-test-id'?: string;\n size?: 'small' | 'medium' | 'large' | 'xLarge' | 'full';\n theme?: 'dark' | 'default';\n hideCancel?: boolean;\n};\n\nconst Drawer = (props: DrawerProps) => (\n <Portal>\n <DrawerContainer {...props} />\n </Portal>\n);\n\nconst DrawerContainer = ({\n className,\n children,\n onCancel,\n size = 'small',\n 'data-test-id': testId = 'drawer',\n theme,\n hideCancel = false,\n}: DrawerProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const [isFocusWithin, setIsFocusWithin] = useState(false);\n const { focusWithinProps } = useFocusWithin({\n onFocusWithinChange: (isFocusWithin) => setIsFocusWithin(isFocusWithin),\n });\n\n usePreventScroll();\n\n useEffect(() => {\n const handleEscape = (event: KeyboardEvent) => {\n event.stopImmediatePropagation();\n const latest = [...document.querySelectorAll('[data-drawer]')].pop();\n if (event.key === 'Escape' && latest === ref.current && isFocusWithin) {\n close();\n }\n };\n\n const addOverlayAndEventHandler = () => {\n document.body.classList.add('has-overlay');\n document.addEventListener('keydown', handleEscape);\n };\n\n const removeOverlayAndEventHandler = () => {\n document.body.classList.remove('has-overlay');\n document.removeEventListener('keydown', handleEscape);\n };\n\n const close = () => {\n onCancel?.();\n };\n\n if (isFocusWithin) {\n addOverlayAndEventHandler();\n }\n\n if (!isFocusWithin) {\n removeOverlayAndEventHandler();\n }\n\n return () => {\n removeOverlayAndEventHandler();\n };\n }, [onCancel, testId, isFocusWithin]);\n\n const handleOverlayClick = (event: MouseEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget) {\n onCancel && onCancel();\n }\n };\n\n return (\n <LazyMotion strict features={loadFeatures}>\n <div\n {...focusWithinProps}\n className={cx(styles.drawer, styles[size], className)}\n data-drawer\n data-test-id={testId}\n ref={ref}\n >\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={overlay}\n transition={{ duration: 0.15 }}\n role=\"presentation\"\n className={styles.overlay}\n onMouseDown={handleOverlayClick}\n >\n <FocusTrap autoFocus restoreFocus>\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={slideRight}\n role=\"dialog\"\n aria-labelledby={DRAWER_LABELLED_BY}\n aria-describedby={DRAWER_LABELLED_BY}\n aria-modal\n className={styles.content}\n tabIndex={-1}\n {...(theme ? { 'data-theme': theme } : {})}\n >\n {!hideCancel && (\n <IconButton\n aria-label=\"close\"\n icon={<Close size=\"medium\" />}\n className={styles.closeButton}\n onClick={onCancel}\n data-test-id=\"drawer-close-button\"\n />\n )}\n <Suspense fallback={<Progress />}>{children}</Suspense>\n </m.div>\n </FocusTrap>\n </m.div>\n </div>\n </LazyMotion>\n );\n};\n\nexport { Drawer };\nexport type { DrawerProps };\n","import type { ComponentProps } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\n\ntype DrawerHeaderProps = ComponentProps<'div'> & {\n closeable?: boolean;\n titleID?: string;\n titleClassName?: string;\n onClose?(): void;\n 'data-test-id'?: string;\n};\n\nconst DrawerHeader = ({\n className,\n children,\n titleID,\n titleClassName,\n 'data-test-id': testId = 'drawer-header',\n ...rest\n}: DrawerHeaderProps) => {\n return (\n <div data-test-id={testId} className={className} {...rest}>\n <h2 id={DRAWER_LABELLED_BY} className={titleClassName}>\n {children}\n </h2>\n </div>\n );\n};\n\nexport { DrawerHeader };\nexport type { DrawerHeaderProps };\n"],"names":["isFocusWithin"],"mappings":";;;;;;;;;;;AAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;ACiBlC,MAAM,UAAoB;AAAA,EACxB,SAAS,EAAE,SAAS,GAAG,YAAY,EAAE,UAAU,OAAO;AAAA,EACtD,QAAQ,EAAE,SAAS,EAAE;AACvB;AAEA,MAAM,aAAuB;AAAA,EAC3B,QAAQ,EAAE,SAAS,GAAG,GAAG,MAAM;AAAA,EAC/B,SAAS;AAAA,IACP,SAAS;AAAA,IACT,GAAG;AAAA,IACH,YAAY,EAAE,MAAM,UAAU,OAAO,MAAM,UAAU,KAAK,QAAQ,EAAE;AAAA,EACtE;AACF;AAEA,MAAM,eAAe,MACnB;AAAA;AAAA;AAAA,EAGE;AACF,EAAE,KAAK,CAAC,QAAQ,IAAI,YAAY;AAY5B,MAAA,SAAS,CAAC,UACd,oBAAC,UACC,UAAC,oBAAA,iBAAA,EAAiB,GAAG,MAAA,CAAO,EAC9B,CAAA;AAGF,MAAM,kBAAkB,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,gBAAgB,SAAS;AAAA,EACzB;AAAA,EACA,aAAa;AACf,MAAmB;AACX,QAAA,MAAM,OAAuB,IAAI;AACvC,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,KAAK;AAClD,QAAA,EAAE,iBAAiB,IAAI,eAAe;AAAA,IAC1C,qBAAqB,CAACA,mBAAkB,iBAAiBA,cAAa;AAAA,EAAA,CACvE;AAEgB;AAEjB,YAAU,MAAM;AACR,UAAA,eAAe,CAAC,UAAyB;AAC7C,YAAM,yBAAyB;AACzB,YAAA,SAAS,CAAC,GAAG,SAAS,iBAAiB,eAAe,CAAC,EAAE;A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U;AAAA,cACV,WAAW,OAAO;AAAA,cAClB,UAAU;AAAA,cACT,GAAI,QAAQ,EAAE,cAAc,UAAU,CAAC;AAAA,cAEvC,UAAA;AAAA,gBAAA,CAAC,cACA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,cAAW;AAAA,oBACX,MAAM,oBAAC,OAAM,EAAA,MAAK,SAAS,CAAA;AAAA,oBAC3B,WAAW,OAAO;AAAA,oBAClB,SAAS;AAAA,oBACT,gBAAa;AAAA,kBAAA;AAAA,gBACf;AAAA,oCAED,UAAS,EAAA,UAAW,oBAAA,UAAA,CAAS,CAAA,GAAK,UAAS;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA,GAEhD;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;ACpJA,MAAM,eAAe,CAAC;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB,SAAS;AAAA,EACzB,GAAG;AACL,MAAyB;AACvB,SACG,oBAAA,OAAA,EAAI,gBAAc,QAAQ,WAAuB,GAAG,MACnD,UAAC,oBAAA,MAAA,EAAG,IAAI,oBAAoB,WAAW,gBACpC,UACH,EACF,CAAA;AAEJ;"}
|
package/dist/index.js
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
require('./style.css');
|
2
2
|
"use strict";
|
3
|
-
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
23
|
+
mod
|
24
|
+
));
|
25
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
26
|
+
const jsxRuntime = require("react/jsx-runtime");
|
4
27
|
const button = require("@launchpad-ui/button");
|
5
28
|
const focusTrap = require("@launchpad-ui/focus-trap");
|
6
29
|
const icons = require("@launchpad-ui/icons");
|
@@ -11,35 +34,16 @@ const overlays = require("@react-aria/overlays");
|
|
11
34
|
const classix = require("classix");
|
12
35
|
const framerMotion = require("framer-motion");
|
13
36
|
const react = require("react");
|
14
|
-
const jsxRuntime = require("react/jsx-runtime");
|
15
|
-
function _interopNamespace(e) {
|
16
|
-
if (e && e.__esModule)
|
17
|
-
return e;
|
18
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
19
|
-
if (e) {
|
20
|
-
for (const k in e) {
|
21
|
-
if (k !== "default") {
|
22
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
23
|
-
Object.defineProperty(n, k, d.get ? d : {
|
24
|
-
enumerable: true,
|
25
|
-
get: () => e[k]
|
26
|
-
});
|
27
|
-
}
|
28
|
-
}
|
29
|
-
}
|
30
|
-
n.default = e;
|
31
|
-
return Object.freeze(n);
|
32
|
-
}
|
33
37
|
const DRAWER_LABELLED_BY = "drawer-title";
|
34
|
-
const drawer = "
|
35
|
-
const overlay$1 = "
|
36
|
-
const content = "
|
37
|
-
const small = "
|
38
|
-
const medium = "
|
39
|
-
const large = "
|
40
|
-
const xLarge = "
|
41
|
-
const full = "
|
42
|
-
const closeButton = "
|
38
|
+
const drawer = "_drawer_1bcak_12";
|
39
|
+
const overlay$1 = "_overlay_1bcak_31";
|
40
|
+
const content = "_content_1bcak_37";
|
41
|
+
const small = "_small_1bcak_51";
|
42
|
+
const medium = "_medium_1bcak_55";
|
43
|
+
const large = "_large_1bcak_59";
|
44
|
+
const xLarge = "_xLarge_1bcak_63";
|
45
|
+
const full = "_full_1bcak_67";
|
46
|
+
const closeButton = "_closeButton_1bcak_81";
|
43
47
|
const styles = {
|
44
48
|
drawer,
|
45
49
|
overlay: overlay$1,
|
@@ -52,40 +56,23 @@ const styles = {
|
|
52
56
|
closeButton
|
53
57
|
};
|
54
58
|
const overlay = {
|
55
|
-
visible: {
|
56
|
-
|
57
|
-
transition: {
|
58
|
-
duration: 0.15
|
59
|
-
}
|
60
|
-
},
|
61
|
-
hidden: {
|
62
|
-
opacity: 0
|
63
|
-
}
|
59
|
+
visible: { opacity: 1, transition: { duration: 0.15 } },
|
60
|
+
hidden: { opacity: 0 }
|
64
61
|
};
|
65
62
|
const slideRight = {
|
66
|
-
hidden: {
|
67
|
-
opacity: 0,
|
68
|
-
x: "25%"
|
69
|
-
},
|
63
|
+
hidden: { opacity: 0, x: "25%" },
|
70
64
|
visible: {
|
71
65
|
opacity: 1,
|
72
66
|
x: "0%",
|
73
|
-
transition: {
|
74
|
-
type: "spring",
|
75
|
-
delay: 0.15,
|
76
|
-
duration: 0.2,
|
77
|
-
bounce: 0
|
78
|
-
}
|
67
|
+
transition: { type: "spring", delay: 0.15, duration: 0.2, bounce: 0 }
|
79
68
|
}
|
80
69
|
};
|
81
|
-
const loadFeatures = () =>
|
70
|
+
const loadFeatures = () => import(
|
71
|
+
/* webpackChunkName: "lp-drawer-framer-features" */
|
72
|
+
/* webpackExports: "domAnimation" */
|
82
73
|
"framer-motion"
|
83
|
-
)
|
84
|
-
const Drawer = (props) => /* @__PURE__ */ jsxRuntime.jsx(portal.Portal, {
|
85
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(DrawerContainer, {
|
86
|
-
...props
|
87
|
-
})
|
88
|
-
});
|
74
|
+
).then((res) => res.domAnimation);
|
75
|
+
const Drawer = (props) => /* @__PURE__ */ jsxRuntime.jsx(portal.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(DrawerContainer, { ...props }) });
|
89
76
|
const DrawerContainer = ({
|
90
77
|
className,
|
91
78
|
children,
|
@@ -97,9 +84,7 @@ const DrawerContainer = ({
|
|
97
84
|
}) => {
|
98
85
|
const ref = react.useRef(null);
|
99
86
|
const [isFocusWithin, setIsFocusWithin] = react.useState(false);
|
100
|
-
const {
|
101
|
-
focusWithinProps
|
102
|
-
} = interactions.useFocusWithin({
|
87
|
+
const { focusWithinProps } = interactions.useFocusWithin({
|
103
88
|
onFocusWithinChange: (isFocusWithin2) => setIsFocusWithin(isFocusWithin2)
|
104
89
|
});
|
105
90
|
overlays.usePreventScroll();
|
@@ -137,58 +122,56 @@ const DrawerContainer = ({
|
|
137
122
|
onCancel && onCancel();
|
138
123
|
}
|
139
124
|
};
|
140
|
-
return /* @__PURE__ */ jsxRuntime.jsx(framerMotion.LazyMotion, {
|
141
|
-
|
142
|
-
|
143
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", {
|
125
|
+
return /* @__PURE__ */ jsxRuntime.jsx(framerMotion.LazyMotion, { strict: true, features: loadFeatures, children: /* @__PURE__ */ jsxRuntime.jsx(
|
126
|
+
"div",
|
127
|
+
{
|
144
128
|
...focusWithinProps,
|
145
129
|
className: classix.cx(styles.drawer, styles[size], className),
|
146
130
|
"data-drawer": true,
|
147
131
|
"data-test-id": testId,
|
148
132
|
ref,
|
149
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
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
|
-
});
|
133
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
134
|
+
framerMotion.m.div,
|
135
|
+
{
|
136
|
+
initial: "hidden",
|
137
|
+
animate: "visible",
|
138
|
+
variants: overlay,
|
139
|
+
transition: { duration: 0.15 },
|
140
|
+
role: "presentation",
|
141
|
+
className: styles.overlay,
|
142
|
+
onMouseDown: handleOverlayClick,
|
143
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(focusTrap.FocusTrap, { autoFocus: true, restoreFocus: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
144
|
+
framerMotion.m.div,
|
145
|
+
{
|
146
|
+
initial: "hidden",
|
147
|
+
animate: "visible",
|
148
|
+
variants: slideRight,
|
149
|
+
role: "dialog",
|
150
|
+
"aria-labelledby": DRAWER_LABELLED_BY,
|
151
|
+
"aria-describedby": DRAWER_LABELLED_BY,
|
152
|
+
"aria-modal": true,
|
153
|
+
className: styles.content,
|
154
|
+
tabIndex: -1,
|
155
|
+
...theme ? { "data-theme": theme } : {},
|
156
|
+
children: [
|
157
|
+
!hideCancel && /* @__PURE__ */ jsxRuntime.jsx(
|
158
|
+
button.IconButton,
|
159
|
+
{
|
160
|
+
"aria-label": "close",
|
161
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Close, { size: "medium" }),
|
162
|
+
className: styles.closeButton,
|
163
|
+
onClick: onCancel,
|
164
|
+
"data-test-id": "drawer-close-button"
|
165
|
+
}
|
166
|
+
),
|
167
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(progress.Progress, {}), children })
|
168
|
+
]
|
169
|
+
}
|
170
|
+
) })
|
171
|
+
}
|
172
|
+
)
|
173
|
+
}
|
174
|
+
) });
|
192
175
|
};
|
193
176
|
const DrawerHeader = ({
|
194
177
|
className,
|
@@ -198,16 +181,7 @@ const DrawerHeader = ({
|
|
198
181
|
"data-test-id": testId = "drawer-header",
|
199
182
|
...rest
|
200
183
|
}) => {
|
201
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
202
|
-
"data-test-id": testId,
|
203
|
-
className,
|
204
|
-
...rest,
|
205
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("h2", {
|
206
|
-
id: DRAWER_LABELLED_BY,
|
207
|
-
className: titleClassName,
|
208
|
-
children
|
209
|
-
})
|
210
|
-
});
|
184
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-test-id": testId, className, ...rest, children: /* @__PURE__ */ jsxRuntime.jsx("h2", { id: DRAWER_LABELLED_BY, className: titleClassName, children }) });
|
211
185
|
};
|
212
186
|
exports.Drawer = Drawer;
|
213
187
|
exports.DrawerHeader = DrawerHeader;
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/constants.ts","../src/Drawer.tsx","../src/DrawerHeader.tsx"],"sourcesContent":["export const DRAWER_LABELLED_BY = 'drawer-title';\n","import type { Variants } from 'framer-motion';\nimport type { MouseEvent, ReactNode } from 'react';\n\nimport { IconButton } from '@launchpad-ui/button';\nimport { FocusTrap } from '@launchpad-ui/focus-trap';\nimport { Close } from '@launchpad-ui/icons';\nimport { Portal } from '@launchpad-ui/portal';\nimport { Progress } from '@launchpad-ui/progress';\nimport { useFocusWithin } from '@react-aria/interactions';\nimport { usePreventScroll } from '@react-aria/overlays';\nimport { cx } from 'classix';\nimport { LazyMotion, m } from 'framer-motion';\nimport { useState, Suspense, useEffect, useRef } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\nimport styles from './styles/Drawer.module.css';\n\nconst overlay: Variants = {\n visible: { opacity: 1, transition: { duration: 0.15 } },\n hidden: { opacity: 0 },\n};\n\nconst slideRight: Variants = {\n hidden: { opacity: 0, x: '25%' },\n visible: {\n opacity: 1,\n x: '0%',\n transition: { type: 'spring', delay: 0.15, duration: 0.2, bounce: 0 },\n },\n};\n\nconst loadFeatures = () =>\n import(\n /* webpackChunkName: \"lp-drawer-framer-features\" */\n /* webpackExports: \"domAnimation\" */\n 'framer-motion'\n ).then((res) => res.domAnimation);\n\ntype DrawerProps = {\n children?: ReactNode;\n className?: string;\n onCancel?(): void;\n 'data-test-id'?: string;\n size?: 'small' | 'medium' | 'large' | 'xLarge' | 'full';\n theme?: 'dark' | 'default';\n hideCancel?: boolean;\n};\n\nconst Drawer = (props: DrawerProps) => (\n <Portal>\n <DrawerContainer {...props} />\n </Portal>\n);\n\nconst DrawerContainer = ({\n className,\n children,\n onCancel,\n size = 'small',\n 'data-test-id': testId = 'drawer',\n theme,\n hideCancel = false,\n}: DrawerProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const [isFocusWithin, setIsFocusWithin] = useState(false);\n const { focusWithinProps } = useFocusWithin({\n onFocusWithinChange: (isFocusWithin) => setIsFocusWithin(isFocusWithin),\n });\n\n usePreventScroll();\n\n useEffect(() => {\n const handleEscape = (event: KeyboardEvent) => {\n event.stopImmediatePropagation();\n const latest = [...document.querySelectorAll('[data-drawer]')].pop();\n if (event.key === 'Escape' && latest === ref.current && isFocusWithin) {\n close();\n }\n };\n\n const addOverlayAndEventHandler = () => {\n document.body.classList.add('has-overlay');\n document.addEventListener('keydown', handleEscape);\n };\n\n const removeOverlayAndEventHandler = () => {\n document.body.classList.remove('has-overlay');\n document.removeEventListener('keydown', handleEscape);\n };\n\n const close = () => {\n onCancel?.();\n };\n\n if (isFocusWithin) {\n addOverlayAndEventHandler();\n }\n\n if (!isFocusWithin) {\n removeOverlayAndEventHandler();\n }\n\n return () => {\n removeOverlayAndEventHandler();\n };\n }, [onCancel, testId, isFocusWithin]);\n\n const handleOverlayClick = (event: MouseEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget) {\n onCancel && onCancel();\n }\n };\n\n return (\n <LazyMotion strict features={loadFeatures}>\n <div\n {...focusWithinProps}\n className={cx(styles.drawer, styles[size], className)}\n data-drawer\n data-test-id={testId}\n ref={ref}\n >\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={overlay}\n transition={{ duration: 0.15 }}\n role=\"presentation\"\n className={styles.overlay}\n onMouseDown={handleOverlayClick}\n >\n <FocusTrap autoFocus restoreFocus>\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={slideRight}\n role=\"dialog\"\n aria-labelledby={DRAWER_LABELLED_BY}\n aria-describedby={DRAWER_LABELLED_BY}\n aria-modal\n className={styles.content}\n tabIndex={-1}\n {...(theme ? { 'data-theme': theme } : {})}\n >\n {!hideCancel && (\n <IconButton\n aria-label=\"close\"\n icon={<Close size=\"medium\" />}\n className={styles.closeButton}\n onClick={onCancel}\n data-test-id=\"drawer-close-button\"\n />\n )}\n <Suspense fallback={<Progress />}>{children}</Suspense>\n </m.div>\n </FocusTrap>\n </m.div>\n </div>\n </LazyMotion>\n );\n};\n\nexport { Drawer };\nexport type { DrawerProps };\n","import type { ComponentProps } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\n\ntype DrawerHeaderProps = ComponentProps<'div'> & {\n closeable?: boolean;\n titleID?: string;\n titleClassName?: string;\n onClose?(): void;\n 'data-test-id'?: string;\n};\n\nconst DrawerHeader = ({\n className,\n children,\n titleID,\n titleClassName,\n 'data-test-id': testId = 'drawer-header',\n ...rest\n}: DrawerHeaderProps) => {\n return (\n <div data-test-id={testId} className={className} {...rest}>\n <h2 id={DRAWER_LABELLED_BY} className={titleClassName}>\n {children}\n </h2>\n </div>\n );\n};\n\nexport { DrawerHeader };\nexport type { DrawerHeaderProps };\n"],"names":["
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/constants.ts","../src/Drawer.tsx","../src/DrawerHeader.tsx"],"sourcesContent":["export const DRAWER_LABELLED_BY = 'drawer-title';\n","import type { Variants } from 'framer-motion';\nimport type { MouseEvent, ReactNode } from 'react';\n\nimport { IconButton } from '@launchpad-ui/button';\nimport { FocusTrap } from '@launchpad-ui/focus-trap';\nimport { Close } from '@launchpad-ui/icons';\nimport { Portal } from '@launchpad-ui/portal';\nimport { Progress } from '@launchpad-ui/progress';\nimport { useFocusWithin } from '@react-aria/interactions';\nimport { usePreventScroll } from '@react-aria/overlays';\nimport { cx } from 'classix';\nimport { LazyMotion, m } from 'framer-motion';\nimport { useState, Suspense, useEffect, useRef } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\nimport styles from './styles/Drawer.module.css';\n\nconst overlay: Variants = {\n visible: { opacity: 1, transition: { duration: 0.15 } },\n hidden: { opacity: 0 },\n};\n\nconst slideRight: Variants = {\n hidden: { opacity: 0, x: '25%' },\n visible: {\n opacity: 1,\n x: '0%',\n transition: { type: 'spring', delay: 0.15, duration: 0.2, bounce: 0 },\n },\n};\n\nconst loadFeatures = () =>\n import(\n /* webpackChunkName: \"lp-drawer-framer-features\" */\n /* webpackExports: \"domAnimation\" */\n 'framer-motion'\n ).then((res) => res.domAnimation);\n\ntype DrawerProps = {\n children?: ReactNode;\n className?: string;\n onCancel?(): void;\n 'data-test-id'?: string;\n size?: 'small' | 'medium' | 'large' | 'xLarge' | 'full';\n theme?: 'dark' | 'default';\n hideCancel?: boolean;\n};\n\nconst Drawer = (props: DrawerProps) => (\n <Portal>\n <DrawerContainer {...props} />\n </Portal>\n);\n\nconst DrawerContainer = ({\n className,\n children,\n onCancel,\n size = 'small',\n 'data-test-id': testId = 'drawer',\n theme,\n hideCancel = false,\n}: DrawerProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const [isFocusWithin, setIsFocusWithin] = useState(false);\n const { focusWithinProps } = useFocusWithin({\n onFocusWithinChange: (isFocusWithin) => setIsFocusWithin(isFocusWithin),\n });\n\n usePreventScroll();\n\n useEffect(() => {\n const handleEscape = (event: KeyboardEvent) => {\n event.stopImmediatePropagation();\n const latest = [...document.querySelectorAll('[data-drawer]')].pop();\n if (event.key === 'Escape' && latest === ref.current && isFocusWithin) {\n close();\n }\n };\n\n const addOverlayAndEventHandler = () => {\n document.body.classList.add('has-overlay');\n document.addEventListener('keydown', handleEscape);\n };\n\n const removeOverlayAndEventHandler = () => {\n document.body.classList.remove('has-overlay');\n document.removeEventListener('keydown', handleEscape);\n };\n\n const close = () => {\n onCancel?.();\n };\n\n if (isFocusWithin) {\n addOverlayAndEventHandler();\n }\n\n if (!isFocusWithin) {\n removeOverlayAndEventHandler();\n }\n\n return () => {\n removeOverlayAndEventHandler();\n };\n }, [onCancel, testId, isFocusWithin]);\n\n const handleOverlayClick = (event: MouseEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget) {\n onCancel && onCancel();\n }\n };\n\n return (\n <LazyMotion strict features={loadFeatures}>\n <div\n {...focusWithinProps}\n className={cx(styles.drawer, styles[size], className)}\n data-drawer\n data-test-id={testId}\n ref={ref}\n >\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={overlay}\n transition={{ duration: 0.15 }}\n role=\"presentation\"\n className={styles.overlay}\n onMouseDown={handleOverlayClick}\n >\n <FocusTrap autoFocus restoreFocus>\n <m.div\n initial=\"hidden\"\n animate=\"visible\"\n variants={slideRight}\n role=\"dialog\"\n aria-labelledby={DRAWER_LABELLED_BY}\n aria-describedby={DRAWER_LABELLED_BY}\n aria-modal\n className={styles.content}\n tabIndex={-1}\n {...(theme ? { 'data-theme': theme } : {})}\n >\n {!hideCancel && (\n <IconButton\n aria-label=\"close\"\n icon={<Close size=\"medium\" />}\n className={styles.closeButton}\n onClick={onCancel}\n data-test-id=\"drawer-close-button\"\n />\n )}\n <Suspense fallback={<Progress />}>{children}</Suspense>\n </m.div>\n </FocusTrap>\n </m.div>\n </div>\n </LazyMotion>\n );\n};\n\nexport { Drawer };\nexport type { DrawerProps };\n","import type { ComponentProps } from 'react';\n\nimport { DRAWER_LABELLED_BY } from './constants';\n\ntype DrawerHeaderProps = ComponentProps<'div'> & {\n closeable?: boolean;\n titleID?: string;\n titleClassName?: string;\n onClose?(): void;\n 'data-test-id'?: string;\n};\n\nconst DrawerHeader = ({\n className,\n children,\n titleID,\n titleClassName,\n 'data-test-id': testId = 'drawer-header',\n ...rest\n}: DrawerHeaderProps) => {\n return (\n <div data-test-id={testId} className={className} {...rest}>\n <h2 id={DRAWER_LABELLED_BY} className={titleClassName}>\n {children}\n </h2>\n </div>\n );\n};\n\nexport { DrawerHeader };\nexport type { DrawerHeaderProps };\n"],"names":["jsx","Portal","useRef","useState","useFocusWithin","isFocusWithin","usePreventScroll","useEffect","LazyMotion","cx","m","FocusTrap","jsxs","IconButton","Close","Suspense","Progress"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;ACiBlC,MAAM,UAAoB;AAAA,EACxB,SAAS,EAAE,SAAS,GAAG,YAAY,EAAE,UAAU,OAAO;AAAA,EACtD,QAAQ,EAAE,SAAS,EAAE;AACvB;AAEA,MAAM,aAAuB;AAAA,EAC3B,QAAQ,EAAE,SAAS,GAAG,GAAG,MAAM;AAAA,EAC/B,SAAS;AAAA,IACP,SAAS;AAAA,IACT,GAAG;AAAA,IACH,YAAY,EAAE,MAAM,UAAU,OAAO,MAAM,UAAU,KAAK,QAAQ,EAAE;AAAA,EACtE;AACF;AAEA,MAAM,eAAe,MACnB;AAAA;AAAA;AAAA,EAGE;AACF,EAAE,KAAK,CAAC,QAAQ,IAAI,YAAY;AAY5B,MAAA,SAAS,CAAC,UACdA,2BAAA,IAACC,iBACC,UAACD,2BAAA,IAAA,iBAAA,EAAiB,GAAG,MAAA,CAAO,EAC9B,CAAA;AAGF,MAAM,kBAAk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,MAAyB;AACvB,SACGhB,2BAAAA,IAAA,OAAA,EAAI,gBAAc,QAAQ,WAAuB,GAAG,MACnD,UAACA,2BAAA,IAAA,MAAA,EAAG,IAAI,oBAAoB,WAAW,gBACpC,UACH,EACF,CAAA;AAEJ;;;"}
|
package/dist/style.css
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[data-theme='dark'] {
|
6
6
|
--lp-component-drawer-color-bg-overlay: rgba(25, 25, 25, 0.75);
|
7
7
|
}
|
8
|
-
.
|
8
|
+
._drawer_1bcak_12 {
|
9
9
|
--page-gutter-width: 1rem;
|
10
10
|
|
11
11
|
z-index: var(--lp-z-index-400);
|
@@ -17,14 +17,14 @@
|
|
17
17
|
transform: translateZ(0);
|
18
18
|
}
|
19
19
|
@media screen and (min-width: 740px) {
|
20
|
-
.
|
20
|
+
._drawer_1bcak_12 {
|
21
21
|
--page-gutter-width: 4rem;
|
22
22
|
}
|
23
23
|
}
|
24
24
|
.has-overlay {
|
25
25
|
overflow: hidden;
|
26
26
|
}
|
27
|
-
.
|
27
|
+
._overlay_1bcak_31 {
|
28
28
|
position: fixed;
|
29
29
|
top: 0;
|
30
30
|
right: 0;
|
@@ -33,7 +33,7 @@
|
|
33
33
|
background-color: rgba(40, 40, 40, 0.5);
|
34
34
|
background-color: var(--lp-component-drawer-color-bg-overlay);
|
35
35
|
}
|
36
|
-
.
|
36
|
+
._content_1bcak_37 {
|
37
37
|
background-color: var(--lp-color-bg-ui-primary);
|
38
38
|
position: absolute;
|
39
39
|
top: 0;
|
@@ -46,35 +46,35 @@
|
|
46
46
|
box-shadow: -1px 0 4px var(--lp-color-shadow-ui-primary);
|
47
47
|
}
|
48
48
|
@media screen and (min-width: 740px) {
|
49
|
-
.
|
49
|
+
._small_1bcak_51 ._content_1bcak_37 {
|
50
50
|
width: 45rem;
|
51
51
|
}
|
52
52
|
|
53
|
-
.
|
53
|
+
._medium_1bcak_55 ._content_1bcak_37 {
|
54
54
|
width: 65rem;
|
55
55
|
}
|
56
56
|
|
57
|
-
.
|
57
|
+
._large_1bcak_59 ._content_1bcak_37 {
|
58
58
|
width: 80rem;
|
59
59
|
}
|
60
60
|
|
61
|
-
.
|
61
|
+
._xLarge_1bcak_63 ._content_1bcak_37 {
|
62
62
|
width: 120rem;
|
63
63
|
}
|
64
64
|
|
65
|
-
.
|
65
|
+
._full_1bcak_67 ._content_1bcak_37 {
|
66
66
|
width: 100%;
|
67
67
|
max-width: none;
|
68
68
|
max-width: initial;
|
69
69
|
}
|
70
70
|
}
|
71
|
-
.
|
71
|
+
._content_1bcak_37 section {
|
72
72
|
padding: 3.2rem var(--page-gutter-width);
|
73
73
|
}
|
74
|
-
.
|
74
|
+
._content_1bcak_37 section + section {
|
75
75
|
border-top: 1px dotted var(--lp-color-gray-100);
|
76
76
|
}
|
77
|
-
.
|
77
|
+
._closeButton_1bcak_81 {
|
78
78
|
position: absolute;
|
79
79
|
right: 1rem;
|
80
80
|
top: 1rem;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@launchpad-ui/drawer",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.6",
|
4
4
|
"status": "alpha",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -26,12 +26,12 @@
|
|
26
26
|
},
|
27
27
|
"source": "src/index.ts",
|
28
28
|
"dependencies": {
|
29
|
-
"@react-aria/interactions": "3.
|
30
|
-
"@react-aria/overlays": "3.
|
29
|
+
"@react-aria/interactions": "3.15.1",
|
30
|
+
"@react-aria/overlays": "3.14.1",
|
31
31
|
"classix": "2.1.17",
|
32
|
-
"framer-motion": "
|
32
|
+
"framer-motion": "10.12.16",
|
33
33
|
"@launchpad-ui/button": "~0.8.13",
|
34
|
-
"@launchpad-ui/focus-trap": "~0.1.
|
34
|
+
"@launchpad-ui/focus-trap": "~0.1.7",
|
35
35
|
"@launchpad-ui/icons": "~0.8.6",
|
36
36
|
"@launchpad-ui/portal": "~0.1.3",
|
37
37
|
"@launchpad-ui/progress": "~0.5.25",
|