@sproutsocial/seeds-react-drawer 1.0.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.
- package/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +12 -0
- package/dist/esm/index.js +291 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +69 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +328 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +50 -0
- package/src/Drawer.stories.tsx +378 -0
- package/src/Drawer.tsx +308 -0
- package/src/DrawerTypes.ts +80 -0
- package/src/__tests__/Drawer.test.tsx +188 -0
- package/src/__tests__/Drawer.typetest.tsx +39 -0
- package/src/index.ts +5 -0
- package/src/styles.ts +35 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +12 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
yarn run v1.22.22
|
|
2
|
+
$ tsup --dts
|
|
3
|
+
CLI Building entry: src/index.ts
|
|
4
|
+
CLI Using tsconfig: tsconfig.json
|
|
5
|
+
CLI tsup v8.0.2
|
|
6
|
+
CLI Using tsup config: /home/runner/work/seeds/seeds/seeds-react/seeds-react-drawer/tsup.config.ts
|
|
7
|
+
CLI Target: es2022
|
|
8
|
+
CLI Cleaning output folder
|
|
9
|
+
CJS Build start
|
|
10
|
+
ESM Build start
|
|
11
|
+
ESM dist/esm/index.js 6.89 KB
|
|
12
|
+
ESM dist/esm/index.js.map 15.15 KB
|
|
13
|
+
ESM ⚡️ Build success in 120ms
|
|
14
|
+
CJS dist/index.js 9.39 KB
|
|
15
|
+
CJS dist/index.js.map 15.31 KB
|
|
16
|
+
CJS ⚡️ Build success in 141ms
|
|
17
|
+
DTS Build start
|
|
18
|
+
DTS ⚡️ Build success in 22363ms
|
|
19
|
+
DTS dist/index.d.ts 3.35 KB
|
|
20
|
+
DTS dist/index.d.mts 3.35 KB
|
|
21
|
+
Done in 26.56s.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// src/Drawer.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useContext, useEffect, useRef } from "react";
|
|
4
|
+
import FocusLock from "react-focus-lock";
|
|
5
|
+
import { animated, useTransition } from "@react-spring/web";
|
|
6
|
+
import { MOTION_DURATION_MEDIUM } from "@sproutsocial/seeds-motion/unitless";
|
|
7
|
+
import Box2 from "@sproutsocial/seeds-react-box";
|
|
8
|
+
import Button from "@sproutsocial/seeds-react-button";
|
|
9
|
+
import Icon from "@sproutsocial/seeds-react-icon";
|
|
10
|
+
import Text from "@sproutsocial/seeds-react-text";
|
|
11
|
+
import Portal from "@sproutsocial/seeds-react-portal";
|
|
12
|
+
|
|
13
|
+
// src/styles.ts
|
|
14
|
+
import styled, { css } from "styled-components";
|
|
15
|
+
import { COMMON } from "@sproutsocial/seeds-react-system-props";
|
|
16
|
+
import Box from "@sproutsocial/seeds-react-box";
|
|
17
|
+
var Content = styled(Box)`
|
|
18
|
+
overflow-y: auto;
|
|
19
|
+
`;
|
|
20
|
+
var Container = styled.div`
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
position: fixed;
|
|
24
|
+
top: 0;
|
|
25
|
+
height: 100%;
|
|
26
|
+
width: ${(props) => props.width}px;
|
|
27
|
+
background-color: ${(props) => props.theme.colors.container.background.base};
|
|
28
|
+
box-shadow: ${(props) => props.theme.shadows.high};
|
|
29
|
+
filter: blur(0);
|
|
30
|
+
|
|
31
|
+
${(props) => css`
|
|
32
|
+
${props.direction}: ${props.offset}px;
|
|
33
|
+
`}
|
|
34
|
+
|
|
35
|
+
${COMMON}
|
|
36
|
+
`;
|
|
37
|
+
var styles_default = Container;
|
|
38
|
+
|
|
39
|
+
// src/Drawer.tsx
|
|
40
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
41
|
+
var useSlideTransition = ({
|
|
42
|
+
isVisible,
|
|
43
|
+
width,
|
|
44
|
+
direction
|
|
45
|
+
}) => {
|
|
46
|
+
const offset = width * (direction === "left" ? -1 : 1);
|
|
47
|
+
return useTransition(isVisible, {
|
|
48
|
+
from: {
|
|
49
|
+
opacity: 0,
|
|
50
|
+
x: offset
|
|
51
|
+
},
|
|
52
|
+
enter: {
|
|
53
|
+
opacity: 1,
|
|
54
|
+
x: 0
|
|
55
|
+
},
|
|
56
|
+
leave: {
|
|
57
|
+
opacity: 0,
|
|
58
|
+
x: offset
|
|
59
|
+
},
|
|
60
|
+
config: {
|
|
61
|
+
duration: MOTION_DURATION_MEDIUM * 1e3
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
var AnimatedDrawer = animated(styles_default);
|
|
66
|
+
var doesRefContainEventTarget = (ref, event) => {
|
|
67
|
+
return ref.current && event.target instanceof Node && ref.current.contains(event.target);
|
|
68
|
+
};
|
|
69
|
+
var DrawerContext = React.createContext({});
|
|
70
|
+
var DrawerCloseButton = (props) => {
|
|
71
|
+
const { onClose, closeButtonLabel } = useContext(DrawerContext);
|
|
72
|
+
if (props.render) {
|
|
73
|
+
return props.render({
|
|
74
|
+
onClose,
|
|
75
|
+
closeButtonLabel
|
|
76
|
+
}) ?? null;
|
|
77
|
+
}
|
|
78
|
+
return /* @__PURE__ */ jsx(
|
|
79
|
+
Button,
|
|
80
|
+
{
|
|
81
|
+
appearance: "pill",
|
|
82
|
+
"aria-label": closeButtonLabel,
|
|
83
|
+
onClick: onClose,
|
|
84
|
+
...props,
|
|
85
|
+
children: props.children || /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, name: "x-outline" })
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
var DrawerHeader = ({
|
|
90
|
+
title = "",
|
|
91
|
+
id = void 0,
|
|
92
|
+
children,
|
|
93
|
+
render,
|
|
94
|
+
...rest
|
|
95
|
+
}) => {
|
|
96
|
+
const drawerContext = useContext(DrawerContext);
|
|
97
|
+
if (render) {
|
|
98
|
+
return render(drawerContext);
|
|
99
|
+
}
|
|
100
|
+
return /* @__PURE__ */ jsx(
|
|
101
|
+
Box2,
|
|
102
|
+
{
|
|
103
|
+
display: "flex",
|
|
104
|
+
flex: "0 0 auto",
|
|
105
|
+
justifyContent: "space-between",
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
pt: 400,
|
|
108
|
+
px: 450,
|
|
109
|
+
...rest,
|
|
110
|
+
children: children || /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
111
|
+
/* @__PURE__ */ jsx(
|
|
112
|
+
Text,
|
|
113
|
+
{
|
|
114
|
+
as: "h2",
|
|
115
|
+
fontSize: 400,
|
|
116
|
+
fontWeight: "semibold",
|
|
117
|
+
color: "text.headline",
|
|
118
|
+
id,
|
|
119
|
+
children: title
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ jsx(DrawerCloseButton, {})
|
|
123
|
+
] })
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
var DrawerContent = ({ children, ...rest }) => /* @__PURE__ */ jsx(Content, { height: "100%", p: 450, color: "text.body", ...rest, children });
|
|
128
|
+
var useCloseOnBodyClick = ({
|
|
129
|
+
ref,
|
|
130
|
+
disableCloseOnClickOutside,
|
|
131
|
+
onClose,
|
|
132
|
+
closeTargets
|
|
133
|
+
}) => {
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const documentBody = document.body;
|
|
136
|
+
if (!documentBody) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const onEsc = (event) => {
|
|
140
|
+
if (event.key === "Escape") {
|
|
141
|
+
onClose();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const bodyClick = (event) => {
|
|
145
|
+
if (
|
|
146
|
+
// @ts-ignore I'm not sure how to type this ref properly
|
|
147
|
+
!doesRefContainEventTarget(ref, event) && !disableCloseOnClickOutside
|
|
148
|
+
) {
|
|
149
|
+
onClose();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
documentBody?.addEventListener("keydown", onEsc, { capture: true });
|
|
153
|
+
if (closeTargets) {
|
|
154
|
+
closeTargets.forEach(
|
|
155
|
+
(targetElement) => targetElement?.addEventListener("click", bodyClick, { capture: true })
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
documentBody.firstElementChild?.addEventListener("click", bodyClick, {
|
|
159
|
+
capture: true
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return () => {
|
|
163
|
+
documentBody?.removeEventListener("keydown", onEsc, { capture: true });
|
|
164
|
+
if (closeTargets) {
|
|
165
|
+
closeTargets.forEach(
|
|
166
|
+
(targetElement) => targetElement?.removeEventListener("click", bodyClick, {
|
|
167
|
+
capture: true
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
} else {
|
|
171
|
+
documentBody.firstElementChild?.removeEventListener(
|
|
172
|
+
"click",
|
|
173
|
+
bodyClick,
|
|
174
|
+
{ capture: true }
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}, [onClose, disableCloseOnClickOutside, closeTargets, ref]);
|
|
179
|
+
};
|
|
180
|
+
var Drawer = ({
|
|
181
|
+
id,
|
|
182
|
+
offset,
|
|
183
|
+
direction,
|
|
184
|
+
children,
|
|
185
|
+
disableCloseOnClickOutside,
|
|
186
|
+
onClose,
|
|
187
|
+
zIndex,
|
|
188
|
+
closeTargets,
|
|
189
|
+
width,
|
|
190
|
+
focusLockExemptCheck,
|
|
191
|
+
isOpen,
|
|
192
|
+
...rest
|
|
193
|
+
}) => {
|
|
194
|
+
const ref = useRef(null);
|
|
195
|
+
useCloseOnBodyClick({
|
|
196
|
+
ref,
|
|
197
|
+
disableCloseOnClickOutside,
|
|
198
|
+
onClose,
|
|
199
|
+
closeTargets
|
|
200
|
+
});
|
|
201
|
+
const transition = useSlideTransition({
|
|
202
|
+
isVisible: isOpen,
|
|
203
|
+
width,
|
|
204
|
+
direction
|
|
205
|
+
});
|
|
206
|
+
return /* @__PURE__ */ jsx(
|
|
207
|
+
FocusLock,
|
|
208
|
+
{
|
|
209
|
+
autoFocus: true,
|
|
210
|
+
returnFocus: true,
|
|
211
|
+
whiteList: focusLockExemptCheck ? (e) => !focusLockExemptCheck(e) : void 0,
|
|
212
|
+
children: transition(
|
|
213
|
+
(style, isVisible) => isVisible ? /* @__PURE__ */ jsx(
|
|
214
|
+
AnimatedDrawer,
|
|
215
|
+
{
|
|
216
|
+
ref,
|
|
217
|
+
style: { ...style, zIndex },
|
|
218
|
+
width,
|
|
219
|
+
offset,
|
|
220
|
+
direction,
|
|
221
|
+
"data-qa-drawer": id,
|
|
222
|
+
role: "dialog",
|
|
223
|
+
...rest,
|
|
224
|
+
children
|
|
225
|
+
}
|
|
226
|
+
) : null
|
|
227
|
+
)
|
|
228
|
+
},
|
|
229
|
+
id
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
var DrawerContainer = ({
|
|
233
|
+
children,
|
|
234
|
+
closeButtonLabel,
|
|
235
|
+
direction = "right",
|
|
236
|
+
disableCloseOnClickOutside = false,
|
|
237
|
+
id,
|
|
238
|
+
isOpen,
|
|
239
|
+
offset = 0,
|
|
240
|
+
onClose,
|
|
241
|
+
zIndex = 7,
|
|
242
|
+
closeTargets = [],
|
|
243
|
+
width = 600,
|
|
244
|
+
...rest
|
|
245
|
+
}) => {
|
|
246
|
+
return /* @__PURE__ */ jsx(Portal, { id, children: /* @__PURE__ */ jsx(
|
|
247
|
+
DrawerContext.Provider,
|
|
248
|
+
{
|
|
249
|
+
value: {
|
|
250
|
+
onClose,
|
|
251
|
+
closeButtonLabel
|
|
252
|
+
},
|
|
253
|
+
children: /* @__PURE__ */ jsx(
|
|
254
|
+
Drawer,
|
|
255
|
+
{
|
|
256
|
+
isOpen,
|
|
257
|
+
id,
|
|
258
|
+
offset,
|
|
259
|
+
direction,
|
|
260
|
+
disableCloseOnClickOutside,
|
|
261
|
+
onClose,
|
|
262
|
+
zIndex,
|
|
263
|
+
closeTargets,
|
|
264
|
+
width,
|
|
265
|
+
"data-qa-drawer": id || "",
|
|
266
|
+
"data-qa-drawer-isopen": isOpen,
|
|
267
|
+
...rest,
|
|
268
|
+
children
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
) });
|
|
273
|
+
};
|
|
274
|
+
DrawerHeader.displayName = "Drawer.Header";
|
|
275
|
+
DrawerContent.displayName = "Drawer.Content";
|
|
276
|
+
DrawerCloseButton.displayName = "Drawer.CloseButton";
|
|
277
|
+
DrawerContainer.Header = DrawerHeader;
|
|
278
|
+
DrawerContainer.Content = DrawerContent;
|
|
279
|
+
DrawerContainer.CloseButton = DrawerCloseButton;
|
|
280
|
+
var Drawer_default = DrawerContainer;
|
|
281
|
+
|
|
282
|
+
// src/DrawerTypes.ts
|
|
283
|
+
import "react";
|
|
284
|
+
|
|
285
|
+
// src/index.ts
|
|
286
|
+
var src_default = Drawer_default;
|
|
287
|
+
export {
|
|
288
|
+
Drawer_default as Drawer,
|
|
289
|
+
src_default as default
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Drawer.tsx","../../src/styles.ts","../../src/DrawerTypes.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useContext, useEffect, useRef } from \"react\";\nimport FocusLock from \"react-focus-lock\";\nimport { animated, useTransition } from \"@react-spring/web\";\nimport { MOTION_DURATION_MEDIUM } from \"@sproutsocial/seeds-motion/unitless\";\nimport Box from \"@sproutsocial/seeds-react-box\";\nimport Button from \"@sproutsocial/seeds-react-button\";\nimport Icon from \"@sproutsocial/seeds-react-icon\";\n// eslint-disable-next-line import/no-deprecated\nimport Text from \"@sproutsocial/seeds-react-text\";\nimport Portal from \"@sproutsocial/seeds-react-portal\";\nimport Container, { Content } from \"./styles\";\nimport type {\n TypeDrawerContext,\n TypeDrawerCloseButtonProps,\n TypeDrawerHeaderProps,\n TypeDrawerProps,\n TypeInnerDrawerProps,\n TypeDrawerContentProps,\n TypeUseCloseOnBodyClickProps,\n} from \"./DrawerTypes\";\n\nconst useSlideTransition = ({\n isVisible,\n width,\n direction,\n}: {\n isVisible: boolean;\n width: number;\n direction: \"left\" | \"right\";\n}) => {\n const offset = width * (direction === \"left\" ? -1 : 1);\n\n return useTransition(isVisible, {\n from: {\n opacity: 0,\n x: offset,\n },\n enter: {\n opacity: 1,\n x: 0,\n },\n leave: {\n opacity: 0,\n x: offset,\n },\n config: {\n duration: MOTION_DURATION_MEDIUM * 1000,\n },\n });\n};\n\nconst AnimatedDrawer = animated(Container);\n\nconst doesRefContainEventTarget = (\n ref: { current: { contains: (arg0: any) => any } },\n event: Event\n) => {\n return (\n ref.current &&\n event.target instanceof Node &&\n ref.current.contains(event.target)\n );\n};\n\nconst DrawerContext = React.createContext<TypeDrawerContext>({});\n\nconst DrawerCloseButton = (props: TypeDrawerCloseButtonProps) => {\n const { onClose, closeButtonLabel } = useContext(DrawerContext);\n\n if (props.render) {\n return (\n props.render({\n onClose,\n closeButtonLabel,\n }) ?? null\n );\n }\n\n return (\n <Button\n appearance=\"pill\"\n aria-label={closeButtonLabel}\n onClick={onClose}\n {...props}\n >\n {props.children || <Icon aria-hidden name=\"x-outline\" />}\n </Button>\n );\n};\n\nconst DrawerHeader = ({\n title = \"\",\n id = undefined,\n children,\n render,\n ...rest\n}: TypeDrawerHeaderProps) => {\n const drawerContext = useContext(DrawerContext);\n\n if (render) {\n return render(drawerContext);\n }\n\n return (\n <Box\n display=\"flex\"\n flex=\"0 0 auto\"\n justifyContent=\"space-between\"\n alignItems=\"center\"\n pt={400}\n px={450}\n {...rest}\n >\n {children || (\n <React.Fragment>\n <Text\n as=\"h2\"\n fontSize={400}\n fontWeight=\"semibold\"\n color=\"text.headline\"\n id={id}\n >\n {title}\n </Text>\n <DrawerCloseButton />\n </React.Fragment>\n )}\n </Box>\n );\n};\n\nconst DrawerContent = ({ children, ...rest }: TypeDrawerContentProps) => (\n <Content height=\"100%\" p={450} color=\"text.body\" {...rest}>\n {children}\n </Content>\n);\n\nconst useCloseOnBodyClick = ({\n ref,\n disableCloseOnClickOutside,\n onClose,\n closeTargets,\n}: TypeUseCloseOnBodyClickProps) => {\n useEffect(() => {\n const documentBody = document.body;\n\n if (!documentBody) {\n return;\n }\n\n const onEsc = (event: KeyboardEvent): void => {\n if (event.key === \"Escape\") {\n onClose();\n }\n };\n\n const bodyClick = (event: Event): void => {\n if (\n // @ts-ignore I'm not sure how to type this ref properly\n !doesRefContainEventTarget(ref, event) &&\n !disableCloseOnClickOutside\n ) {\n onClose();\n }\n };\n\n documentBody?.addEventListener(\"keydown\", onEsc, { capture: true });\n\n if (closeTargets) {\n closeTargets.forEach((targetElement) =>\n targetElement?.addEventListener(\"click\", bodyClick, { capture: true })\n );\n } else {\n documentBody.firstElementChild?.addEventListener(\"click\", bodyClick, {\n capture: true,\n });\n }\n\n return () => {\n documentBody?.removeEventListener(\"keydown\", onEsc, { capture: true });\n\n if (closeTargets) {\n closeTargets.forEach((targetElement) =>\n targetElement?.removeEventListener(\"click\", bodyClick, {\n capture: true,\n })\n );\n } else {\n documentBody.firstElementChild?.removeEventListener(\n \"click\",\n bodyClick,\n { capture: true }\n );\n }\n };\n }, [onClose, disableCloseOnClickOutside, closeTargets, ref]);\n};\n\nconst Drawer = ({\n id,\n offset,\n direction,\n children,\n disableCloseOnClickOutside,\n onClose,\n zIndex,\n closeTargets,\n width,\n focusLockExemptCheck,\n isOpen,\n ...rest\n}: TypeInnerDrawerProps) => {\n const ref = useRef(null);\n useCloseOnBodyClick({\n ref,\n disableCloseOnClickOutside,\n onClose,\n closeTargets,\n });\n\n const transition = useSlideTransition({\n isVisible: isOpen,\n width,\n direction,\n });\n\n return (\n <FocusLock\n key={id}\n autoFocus={true}\n returnFocus\n whiteList={\n focusLockExemptCheck ? (e) => !focusLockExemptCheck(e) : undefined\n }\n >\n {transition((style, isVisible) =>\n isVisible ? (\n <AnimatedDrawer\n ref={ref}\n style={{ ...style, zIndex }}\n width={width}\n offset={offset}\n direction={direction}\n data-qa-drawer={id}\n role=\"dialog\"\n {...rest}\n >\n {children}\n </AnimatedDrawer>\n ) : null\n )}\n </FocusLock>\n );\n};\n\nconst DrawerContainer = ({\n children,\n closeButtonLabel,\n direction = \"right\",\n disableCloseOnClickOutside = false,\n id,\n isOpen,\n offset = 0,\n onClose,\n zIndex = 7,\n closeTargets = [],\n width = 600,\n ...rest\n}: TypeDrawerProps) => {\n return (\n <Portal id={id}>\n <DrawerContext.Provider\n value={{\n onClose,\n closeButtonLabel,\n }}\n >\n <Drawer\n isOpen={isOpen}\n id={id}\n offset={offset}\n direction={direction}\n disableCloseOnClickOutside={disableCloseOnClickOutside}\n onClose={onClose}\n zIndex={zIndex}\n closeTargets={closeTargets}\n width={width}\n data-qa-drawer={id || \"\"}\n data-qa-drawer-isopen={isOpen}\n {...rest}\n >\n {children}\n </Drawer>\n </DrawerContext.Provider>\n </Portal>\n );\n};\n\nDrawerHeader.displayName = \"Drawer.Header\";\nDrawerContent.displayName = \"Drawer.Content\";\nDrawerCloseButton.displayName = \"Drawer.CloseButton\";\n\nDrawerContainer.Header = DrawerHeader;\nDrawerContainer.Content = DrawerContent;\nDrawerContainer.CloseButton = DrawerCloseButton;\n\nexport default DrawerContainer;\n","import type { TypeDrawerProps } from \"./DrawerTypes\";\nimport styled, { css } from \"styled-components\";\nimport { COMMON } from \"@sproutsocial/seeds-react-system-props\";\nimport type { TypeSystemCommonProps } from \"@sproutsocial/seeds-react-system-props\";\n\nimport Box from \"@sproutsocial/seeds-react-box\";\n\nexport const Content = styled(Box)`\n overflow-y: auto;\n`;\n\ninterface ContainerType\n extends Pick<TypeDrawerProps, \"offset\" | \"direction\">,\n TypeSystemCommonProps {\n width: number;\n}\n\nconst Container = styled.div<ContainerType>`\n display: flex;\n flex-direction: column;\n position: fixed;\n top: 0;\n height: 100%;\n width: ${(props) => props.width}px;\n background-color: ${(props) => props.theme.colors.container.background.base};\n box-shadow: ${(props) => props.theme.shadows.high};\n filter: blur(0);\n\n ${(props) => css`\n ${props.direction}: ${props.offset}px;\n `}\n\n ${COMMON}\n`;\nexport default Container;\n","import * as React from \"react\";\nimport type {\n TypeSystemCommonProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { TypeBoxProps } from \"@sproutsocial/seeds-react-box\";\nimport type { TypeButtonProps } from \"@sproutsocial/seeds-react-button\";\n\ntype DrawerAnimationDirection = \"left\" | \"right\";\n\nexport interface TypeDrawerContext {\n /** Callback for close button */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onClose?: () => any;\n\n /** aria-label for drawer close button */\n closeButtonLabel?: string;\n}\n// TODO: Should the render prop be a React.FC?\nexport interface TypeDrawerCloseButtonProps\n extends Omit<TypeButtonProps, \"children\"> {\n /** An optional function that receives the context of the parent drawer as an argument. Can be used to customize the on-close behavior. */\n render?: React.FC<TypeDrawerContext>;\n children?: React.ReactNode;\n}\n\nexport interface TypeDrawerHeaderProps extends TypeBoxProps {\n title?: string;\n children?: React.ReactNode;\n\n /** An optional function that receives the context of the parent drawer as an argument. Can be used to customize the appearance of the header. */\n render?: React.FC<TypeDrawerContext>;\n}\n\nexport interface TypeInnerDrawerProps\n extends Omit<TypeDrawerProps, \"closeButtonLabel\"> {\n width: number;\n direction: DrawerAnimationDirection;\n}\n\ntype useBodyClicksProps = Pick<\n TypeDrawerProps,\n \"closeTargets\" | \"onClose\" | \"disableCloseOnClickOutside\"\n>;\n\nexport interface TypeUseCloseOnBodyClickProps\n extends Pick<\n TypeDrawerProps,\n \"closeTargets\" | \"onClose\" | \"disableCloseOnClickOutside\"\n > {\n ref?: React.RefObject<HTMLElement | null>;\n}\n\nexport interface TypeDrawerProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n Omit<React.ComponentPropsWithoutRef<\"nav\">, \"color\"> {\n children: React.ReactNode;\n\n /** Label for the close button. Usually this should be \"Close\" */\n closeButtonLabel: string;\n\n /** Whether the drawer slides in from the left or right side of the screen */\n direction?: DrawerAnimationDirection;\n\n /** In some cases, you may not want the user to be able to click outside of the drawer to close it. You can disable that with this prop. */\n disableCloseOnClickOutside?: boolean;\n id: string;\n isOpen: boolean;\n offset?: number;\n onClose: () => void;\n zIndex?: number;\n closeTargets?: Array<Element>;\n width?: number;\n focusLockExemptCheck?: (element: HTMLElement) => boolean;\n}\n\nexport interface TypeDrawerContentProps extends TypeBoxProps {\n children?: React.ReactNode;\n}\n","import Drawer from \"./Drawer\";\n\nexport default Drawer;\nexport { Drawer };\nexport * from \"./DrawerTypes\";\n"],"mappings":";AAAA,YAAY,WAAW;AACvB,SAAS,YAAY,WAAW,cAAc;AAC9C,OAAO,eAAe;AACtB,SAAS,UAAU,qBAAqB;AACxC,SAAS,8BAA8B;AACvC,OAAOA,UAAS;AAChB,OAAO,YAAY;AACnB,OAAO,UAAU;AAEjB,OAAO,UAAU;AACjB,OAAO,YAAY;;;ACTnB,OAAO,UAAU,WAAW;AAC5B,SAAS,cAAc;AAGvB,OAAO,SAAS;AAET,IAAM,UAAU,OAAO,GAAG;AAAA;AAAA;AAUjC,IAAM,YAAY,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAMd,CAAC,UAAU,MAAM,KAAK;AAAA,sBACX,CAAC,UAAU,MAAM,MAAM,OAAO,UAAU,WAAW,IAAI;AAAA,gBAC7D,CAAC,UAAU,MAAM,MAAM,QAAQ,IAAI;AAAA;AAAA;AAAA,IAG/C,CAAC,UAAU;AAAA,MACT,MAAM,SAAS,KAAK,MAAM,MAAM;AAAA,GACnC;AAAA;AAAA,IAEC,MAAM;AAAA;AAEV,IAAO,iBAAQ;;;ADoDU,cA6BjB,YA7BiB;AAhEzB,IAAM,qBAAqB,CAAC;AAAA,EAC1B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B,QAAQ;AAAA,EACR,GAAG;AACL,MAAuB;AACrB,SACE,oBAAC,UAAO,IACN;AAAA,IAAC,cAAc;AAAA,IAAd;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,kBAAgB,MAAM;AAAA,UACtB,yBAAuB;AAAA,UACtB,GAAG;AAAA,UAEH;AAAA;AAAA,MACH;AAAA;AAAA,EACF,GACF;AAEJ;AAEA,aAAa,cAAc;AAC3B,cAAc,cAAc;AAC5B,kBAAkB,cAAc;AAEhC,gBAAgB,SAAS;AACzB,gBAAgB,UAAU;AAC1B,gBAAgB,cAAc;AAE9B,IAAO,iBAAQ;;;AEnTf,OAAuB;;;ACEvB,IAAO,cAAQ;","names":["Box","Box"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { TypeStyledComponentsCommonProps, TypeSystemCommonProps } from '@sproutsocial/seeds-react-system-props';
|
|
4
|
+
import { TypeBoxProps } from '@sproutsocial/seeds-react-box';
|
|
5
|
+
import { TypeButtonProps } from '@sproutsocial/seeds-react-button';
|
|
6
|
+
|
|
7
|
+
type DrawerAnimationDirection = "left" | "right";
|
|
8
|
+
interface TypeDrawerContext {
|
|
9
|
+
/** Callback for close button */
|
|
10
|
+
onClose?: () => any;
|
|
11
|
+
/** aria-label for drawer close button */
|
|
12
|
+
closeButtonLabel?: string;
|
|
13
|
+
}
|
|
14
|
+
interface TypeDrawerCloseButtonProps extends Omit<TypeButtonProps, "children"> {
|
|
15
|
+
/** An optional function that receives the context of the parent drawer as an argument. Can be used to customize the on-close behavior. */
|
|
16
|
+
render?: React.FC<TypeDrawerContext>;
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
interface TypeDrawerHeaderProps extends TypeBoxProps {
|
|
20
|
+
title?: string;
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
/** An optional function that receives the context of the parent drawer as an argument. Can be used to customize the appearance of the header. */
|
|
23
|
+
render?: React.FC<TypeDrawerContext>;
|
|
24
|
+
}
|
|
25
|
+
interface TypeInnerDrawerProps extends Omit<TypeDrawerProps, "closeButtonLabel"> {
|
|
26
|
+
width: number;
|
|
27
|
+
direction: DrawerAnimationDirection;
|
|
28
|
+
}
|
|
29
|
+
interface TypeUseCloseOnBodyClickProps extends Pick<TypeDrawerProps, "closeTargets" | "onClose" | "disableCloseOnClickOutside"> {
|
|
30
|
+
ref?: React.RefObject<HTMLElement | null>;
|
|
31
|
+
}
|
|
32
|
+
interface TypeDrawerProps extends TypeStyledComponentsCommonProps, TypeSystemCommonProps, Omit<React.ComponentPropsWithoutRef<"nav">, "color"> {
|
|
33
|
+
children: React.ReactNode;
|
|
34
|
+
/** Label for the close button. Usually this should be "Close" */
|
|
35
|
+
closeButtonLabel: string;
|
|
36
|
+
/** Whether the drawer slides in from the left or right side of the screen */
|
|
37
|
+
direction?: DrawerAnimationDirection;
|
|
38
|
+
/** In some cases, you may not want the user to be able to click outside of the drawer to close it. You can disable that with this prop. */
|
|
39
|
+
disableCloseOnClickOutside?: boolean;
|
|
40
|
+
id: string;
|
|
41
|
+
isOpen: boolean;
|
|
42
|
+
offset?: number;
|
|
43
|
+
onClose: () => void;
|
|
44
|
+
zIndex?: number;
|
|
45
|
+
closeTargets?: Array<Element>;
|
|
46
|
+
width?: number;
|
|
47
|
+
focusLockExemptCheck?: (element: HTMLElement) => boolean;
|
|
48
|
+
}
|
|
49
|
+
interface TypeDrawerContentProps extends TypeBoxProps {
|
|
50
|
+
children?: React.ReactNode;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const DrawerContainer: {
|
|
54
|
+
({ children, closeButtonLabel, direction, disableCloseOnClickOutside, id, isOpen, offset, onClose, zIndex, closeTargets, width, ...rest }: TypeDrawerProps): react_jsx_runtime.JSX.Element;
|
|
55
|
+
Header: {
|
|
56
|
+
({ title, id, children, render, ...rest }: TypeDrawerHeaderProps): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
|
|
57
|
+
displayName: string;
|
|
58
|
+
};
|
|
59
|
+
Content: {
|
|
60
|
+
({ children, ...rest }: TypeDrawerContentProps): react_jsx_runtime.JSX.Element;
|
|
61
|
+
displayName: string;
|
|
62
|
+
};
|
|
63
|
+
CloseButton: {
|
|
64
|
+
(props: TypeDrawerCloseButtonProps): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
|
|
65
|
+
displayName: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { DrawerContainer as Drawer, type TypeDrawerCloseButtonProps, type TypeDrawerContentProps, type TypeDrawerContext, type TypeDrawerHeaderProps, type TypeDrawerProps, type TypeInnerDrawerProps, type TypeUseCloseOnBodyClickProps, DrawerContainer as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { TypeStyledComponentsCommonProps, TypeSystemCommonProps } from '@sproutsocial/seeds-react-system-props';
|
|
4
|
+
import { TypeBoxProps } from '@sproutsocial/seeds-react-box';
|
|
5
|
+
import { TypeButtonProps } from '@sproutsocial/seeds-react-button';
|
|
6
|
+
|
|
7
|
+
type DrawerAnimationDirection = "left" | "right";
|
|
8
|
+
interface TypeDrawerContext {
|
|
9
|
+
/** Callback for close button */
|
|
10
|
+
onClose?: () => any;
|
|
11
|
+
/** aria-label for drawer close button */
|
|
12
|
+
closeButtonLabel?: string;
|
|
13
|
+
}
|
|
14
|
+
interface TypeDrawerCloseButtonProps extends Omit<TypeButtonProps, "children"> {
|
|
15
|
+
/** An optional function that receives the context of the parent drawer as an argument. Can be used to customize the on-close behavior. */
|
|
16
|
+
render?: React.FC<TypeDrawerContext>;
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
interface TypeDrawerHeaderProps extends TypeBoxProps {
|
|
20
|
+
title?: string;
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
/** An optional function that receives the context of the parent drawer as an argument. Can be used to customize the appearance of the header. */
|
|
23
|
+
render?: React.FC<TypeDrawerContext>;
|
|
24
|
+
}
|
|
25
|
+
interface TypeInnerDrawerProps extends Omit<TypeDrawerProps, "closeButtonLabel"> {
|
|
26
|
+
width: number;
|
|
27
|
+
direction: DrawerAnimationDirection;
|
|
28
|
+
}
|
|
29
|
+
interface TypeUseCloseOnBodyClickProps extends Pick<TypeDrawerProps, "closeTargets" | "onClose" | "disableCloseOnClickOutside"> {
|
|
30
|
+
ref?: React.RefObject<HTMLElement | null>;
|
|
31
|
+
}
|
|
32
|
+
interface TypeDrawerProps extends TypeStyledComponentsCommonProps, TypeSystemCommonProps, Omit<React.ComponentPropsWithoutRef<"nav">, "color"> {
|
|
33
|
+
children: React.ReactNode;
|
|
34
|
+
/** Label for the close button. Usually this should be "Close" */
|
|
35
|
+
closeButtonLabel: string;
|
|
36
|
+
/** Whether the drawer slides in from the left or right side of the screen */
|
|
37
|
+
direction?: DrawerAnimationDirection;
|
|
38
|
+
/** In some cases, you may not want the user to be able to click outside of the drawer to close it. You can disable that with this prop. */
|
|
39
|
+
disableCloseOnClickOutside?: boolean;
|
|
40
|
+
id: string;
|
|
41
|
+
isOpen: boolean;
|
|
42
|
+
offset?: number;
|
|
43
|
+
onClose: () => void;
|
|
44
|
+
zIndex?: number;
|
|
45
|
+
closeTargets?: Array<Element>;
|
|
46
|
+
width?: number;
|
|
47
|
+
focusLockExemptCheck?: (element: HTMLElement) => boolean;
|
|
48
|
+
}
|
|
49
|
+
interface TypeDrawerContentProps extends TypeBoxProps {
|
|
50
|
+
children?: React.ReactNode;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const DrawerContainer: {
|
|
54
|
+
({ children, closeButtonLabel, direction, disableCloseOnClickOutside, id, isOpen, offset, onClose, zIndex, closeTargets, width, ...rest }: TypeDrawerProps): react_jsx_runtime.JSX.Element;
|
|
55
|
+
Header: {
|
|
56
|
+
({ title, id, children, render, ...rest }: TypeDrawerHeaderProps): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
|
|
57
|
+
displayName: string;
|
|
58
|
+
};
|
|
59
|
+
Content: {
|
|
60
|
+
({ children, ...rest }: TypeDrawerContentProps): react_jsx_runtime.JSX.Element;
|
|
61
|
+
displayName: string;
|
|
62
|
+
};
|
|
63
|
+
CloseButton: {
|
|
64
|
+
(props: TypeDrawerCloseButtonProps): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
|
|
65
|
+
displayName: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { DrawerContainer as Drawer, type TypeDrawerCloseButtonProps, type TypeDrawerContentProps, type TypeDrawerContext, type TypeDrawerHeaderProps, type TypeDrawerProps, type TypeInnerDrawerProps, type TypeUseCloseOnBodyClickProps, DrawerContainer as default };
|