@kopexa/drawer 0.0.0-canary-20250718183330

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/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @kopexa/drawer
2
+
3
+ A Quick description of the component
4
+
5
+ > This is an internal utility, not intended for public usage.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ yarn add @kopexa/drawer
11
+ # or
12
+ npm i @kopexa/drawer
13
+ ```
14
+
15
+ ## Contribution
16
+
17
+ Yes please! See the
18
+ [contributing guidelines](https://github.com/kopexa-grc/sight/blob/master/CONTRIBUTING.md)
19
+ for details.
20
+
21
+ ## License
22
+
23
+ This project is licensed under the terms of the
24
+ [MIT license](https://github.com/kopexa-grc/sight/blob/master/LICENSE).
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import {
3
+ DrawerBody,
4
+ DrawerClose,
5
+ DrawerCloseTrigger,
6
+ DrawerContent,
7
+ DrawerDescription,
8
+ DrawerFooter,
9
+ DrawerHeader,
10
+ DrawerOverlay,
11
+ DrawerPortal,
12
+ DrawerRoot,
13
+ DrawerTitle,
14
+ DrawerTrigger,
15
+ __export
16
+ } from "./chunk-P5E6W3AQ.mjs";
17
+
18
+ // src/namespace.ts
19
+ var namespace_exports = {};
20
+ __export(namespace_exports, {
21
+ Body: () => DrawerBody,
22
+ Close: () => DrawerClose,
23
+ CloseTrigger: () => DrawerCloseTrigger,
24
+ Content: () => DrawerContent,
25
+ Description: () => DrawerDescription,
26
+ Footer: () => DrawerFooter,
27
+ Header: () => DrawerHeader,
28
+ Overlay: () => DrawerOverlay,
29
+ Portal: () => DrawerPortal,
30
+ Root: () => DrawerRoot,
31
+ Title: () => DrawerTitle,
32
+ Trigger: () => DrawerTrigger
33
+ });
34
+
35
+ export {
36
+ namespace_exports
37
+ };
@@ -0,0 +1,281 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+
8
+ // src/drawer.tsx
9
+ import { CloseIcon } from "@kopexa/icons";
10
+ import { TRANSITION_EASINGS, TRANSITION_VARIANTS } from "@kopexa/motion-utils";
11
+ import { createContext } from "@kopexa/react-utils";
12
+ import { drawer } from "@kopexa/theme";
13
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
14
+ import {
15
+ AnimatePresence,
16
+ domAnimation,
17
+ LazyMotion,
18
+ motion
19
+ } from "motion/react";
20
+ import { useMemo as useMemo2 } from "react";
21
+
22
+ // ../../hooks/use-callback-ref/src/index.ts
23
+ import { useCallback, useInsertionEffect, useRef } from "react";
24
+ function useCallbackRef(callback, deps = []) {
25
+ const callbackRef = useRef(() => {
26
+ throw new Error("Cannot call an event handler while rendering.");
27
+ });
28
+ useInsertionEffect(() => {
29
+ callbackRef.current = callback;
30
+ });
31
+ return useCallback((...args) => {
32
+ var _a;
33
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
34
+ }, deps);
35
+ }
36
+
37
+ // ../../hooks/use-controllable-state/src/index.ts
38
+ import { useMemo, useState } from "react";
39
+ function useControllableState(props) {
40
+ const {
41
+ value: valueProp,
42
+ defaultValue,
43
+ onChange,
44
+ shouldUpdate = (prev, next) => prev !== next
45
+ } = props;
46
+ const onChangeProp = useCallbackRef(onChange);
47
+ const shouldUpdateProp = useCallbackRef(shouldUpdate);
48
+ const [uncontrolledState, setUncontrolledState] = useState(defaultValue);
49
+ const controlled = valueProp !== void 0;
50
+ const value = controlled ? valueProp : uncontrolledState;
51
+ const setValue = useCallbackRef(
52
+ (next) => {
53
+ const setter = next;
54
+ const nextValue = typeof next === "function" ? setter(value) : next;
55
+ if (!shouldUpdateProp(value, nextValue)) {
56
+ return;
57
+ }
58
+ if (!controlled) {
59
+ setUncontrolledState(nextValue);
60
+ }
61
+ onChangeProp(nextValue);
62
+ },
63
+ [controlled, onChangeProp, value, shouldUpdateProp]
64
+ );
65
+ return [value, setValue];
66
+ }
67
+
68
+ // src/drawer.tsx
69
+ import { jsx, jsxs } from "react/jsx-runtime";
70
+ var [DrawerProvider, useDrawerContext] = createContext();
71
+ var DrawerRoot = (props) => {
72
+ const {
73
+ open: openProp,
74
+ onOpenChange,
75
+ size,
76
+ radius,
77
+ placement = "right",
78
+ ...restProps
79
+ } = props;
80
+ const [open, setOpen] = useControllableState({
81
+ value: openProp,
82
+ onChange: onOpenChange,
83
+ defaultValue: false
84
+ });
85
+ const styles = drawer({ size, radius, placement });
86
+ return /* @__PURE__ */ jsx(DrawerProvider, { value: { styles, open, placement }, children: /* @__PURE__ */ jsx(
87
+ DialogPrimitive.Root,
88
+ {
89
+ "data-slot": "dialog",
90
+ open,
91
+ onOpenChange: setOpen,
92
+ ...restProps
93
+ }
94
+ ) });
95
+ };
96
+ function DrawerTrigger({ ...props }) {
97
+ return /* @__PURE__ */ jsx(DialogPrimitive.Trigger, { "data-slot": "drawer-trigger", ...props });
98
+ }
99
+ function DrawerPortal({ ...props }) {
100
+ return /* @__PURE__ */ jsx(DialogPrimitive.Portal, { "data-slot": "drawer-portal", ...props });
101
+ }
102
+ function DrawerClose({ ...props }) {
103
+ return /* @__PURE__ */ jsx(DialogPrimitive.Close, { "data-slot": "drawer-close", ...props });
104
+ }
105
+ function DrawerOverlay({ className, ...props }) {
106
+ const { styles } = useDrawerContext();
107
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(
108
+ DialogPrimitive.Overlay,
109
+ {
110
+ "data-slot": "drawer-overlay",
111
+ className: styles.overlay({
112
+ className
113
+ }),
114
+ ...props,
115
+ asChild: true,
116
+ children: /* @__PURE__ */ jsx(
117
+ motion.div,
118
+ {
119
+ animate: "enter",
120
+ exit: "exit",
121
+ initial: "exit",
122
+ variants: TRANSITION_VARIANTS.fade
123
+ }
124
+ )
125
+ }
126
+ ) });
127
+ }
128
+ var DrawerContent = (props) => {
129
+ const { className, children, showCloseButton, ...rest } = props;
130
+ const { open, styles, placement } = useDrawerContext();
131
+ const motionProps = useMemo2(() => {
132
+ const key = placement === "left" || placement === "right" ? "x" : "y";
133
+ return {
134
+ variants: {
135
+ enter: {
136
+ [key]: 0,
137
+ transition: {
138
+ [key]: {
139
+ duration: 0.2,
140
+ ease: TRANSITION_EASINGS.easeOut
141
+ }
142
+ }
143
+ },
144
+ exit: {
145
+ [key]: placement === "top" || placement === "left" ? "-100%" : "100%",
146
+ transition: {
147
+ [key]: {
148
+ duration: 0.1,
149
+ ease: TRANSITION_EASINGS.easeIn
150
+ }
151
+ }
152
+ }
153
+ }
154
+ };
155
+ }, [placement]);
156
+ return /* @__PURE__ */ jsx(AnimatePresence, { children: open ? /* @__PURE__ */ jsxs(DrawerPortal, { "data-slot": "drawer-portal", forceMount: true, children: [
157
+ /* @__PURE__ */ jsx(DrawerOverlay, {}),
158
+ /* @__PURE__ */ jsx(
159
+ DialogPrimitive.Content,
160
+ {
161
+ "data-slot": "drawer-content",
162
+ className: styles.content({ className }),
163
+ asChild: true,
164
+ ...rest,
165
+ children: /* @__PURE__ */ jsxs(
166
+ motion.div,
167
+ {
168
+ animate: "enter",
169
+ exit: "exit",
170
+ initial: "exit",
171
+ ...motionProps,
172
+ children: [
173
+ children,
174
+ showCloseButton && /* @__PURE__ */ jsxs(
175
+ DialogPrimitive.Close,
176
+ {
177
+ "data-slot": "dialog-close",
178
+ className: styles.close(),
179
+ children: [
180
+ /* @__PURE__ */ jsx(CloseIcon, {}),
181
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
182
+ ]
183
+ }
184
+ )
185
+ ]
186
+ }
187
+ )
188
+ }
189
+ )
190
+ ] }) : null });
191
+ };
192
+ function DrawerHeader({ className, ...props }) {
193
+ const { styles } = useDrawerContext();
194
+ return /* @__PURE__ */ jsx(
195
+ "div",
196
+ {
197
+ "data-slot": "drawer-header",
198
+ className: styles.header({ className }),
199
+ ...props
200
+ }
201
+ );
202
+ }
203
+ function DrawerFooter({ className, ...props }) {
204
+ const { styles } = useDrawerContext();
205
+ return /* @__PURE__ */ jsx(
206
+ "div",
207
+ {
208
+ "data-slot": "drawer-footer",
209
+ className: styles.footer({ className }),
210
+ ...props
211
+ }
212
+ );
213
+ }
214
+ function DrawerBody({ className, ...props }) {
215
+ const { styles } = useDrawerContext();
216
+ return /* @__PURE__ */ jsx(
217
+ "div",
218
+ {
219
+ "data-slot": "drawer-body",
220
+ className: styles.body({ className }),
221
+ ...props
222
+ }
223
+ );
224
+ }
225
+ function DrawerTitle({ className, ...props }) {
226
+ const { styles } = useDrawerContext();
227
+ return /* @__PURE__ */ jsx(
228
+ DialogPrimitive.Title,
229
+ {
230
+ "data-slot": "drawer-title",
231
+ className: styles.title({ className }),
232
+ ...props
233
+ }
234
+ );
235
+ }
236
+ function DrawerDescription({
237
+ className,
238
+ ...props
239
+ }) {
240
+ const { styles } = useDrawerContext();
241
+ return /* @__PURE__ */ jsx(
242
+ DialogPrimitive.Description,
243
+ {
244
+ "data-slot": "drawer-description",
245
+ className: styles.description({ className }),
246
+ ...props
247
+ }
248
+ );
249
+ }
250
+ function DrawerCloseTrigger({
251
+ className,
252
+ ...props
253
+ }) {
254
+ const { styles } = useDrawerContext();
255
+ return /* @__PURE__ */ jsx(
256
+ DialogPrimitive.Close,
257
+ {
258
+ "data-slot": "drawer-close-trigger",
259
+ className: styles.closeTrigger({ className }),
260
+ ...props
261
+ }
262
+ );
263
+ }
264
+
265
+ export {
266
+ __export,
267
+ DrawerProvider,
268
+ useDrawerContext,
269
+ DrawerRoot,
270
+ DrawerTrigger,
271
+ DrawerPortal,
272
+ DrawerClose,
273
+ DrawerOverlay,
274
+ DrawerContent,
275
+ DrawerHeader,
276
+ DrawerFooter,
277
+ DrawerBody,
278
+ DrawerTitle,
279
+ DrawerDescription,
280
+ DrawerCloseTrigger
281
+ };
@@ -0,0 +1,42 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ComponentProps } from 'react';
4
+ import { drawer, DrawerVariantProps } from '@kopexa/theme';
5
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
6
+
7
+ type DrawerContextValue = {
8
+ styles: ReturnType<typeof drawer>;
9
+ open: boolean;
10
+ placement: "top" | "bottom" | "left" | "right";
11
+ };
12
+ declare const DrawerProvider: react.Provider<DrawerContextValue>;
13
+ declare const useDrawerContext: () => DrawerContextValue;
14
+
15
+ type DrawerRootProps = ComponentProps<typeof DialogPrimitive.Root> & DrawerVariantProps;
16
+ declare const DrawerRoot: (props: DrawerRootProps) => react_jsx_runtime.JSX.Element;
17
+ type DrawerTriggerProps = ComponentProps<typeof DialogPrimitive.Trigger>;
18
+ declare function DrawerTrigger({ ...props }: DrawerTriggerProps): react_jsx_runtime.JSX.Element;
19
+ type DrawerPortalProps = ComponentProps<typeof DialogPrimitive.Portal>;
20
+ declare function DrawerPortal({ ...props }: DrawerPortalProps): react_jsx_runtime.JSX.Element;
21
+ type DrawerCloseProps = ComponentProps<typeof DialogPrimitive.Close>;
22
+ declare function DrawerClose({ ...props }: DrawerCloseProps): react_jsx_runtime.JSX.Element;
23
+ type DrawerOverlayProps = ComponentProps<typeof DialogPrimitive.Overlay>;
24
+ declare function DrawerOverlay({ className, ...props }: DrawerOverlayProps): react_jsx_runtime.JSX.Element;
25
+ type DrawerContentProps = ComponentProps<typeof DialogPrimitive.Content> & {
26
+ showCloseButton?: boolean;
27
+ };
28
+ declare const DrawerContent: (props: DrawerContentProps) => react_jsx_runtime.JSX.Element;
29
+ type DrawerHeaderProps = ComponentProps<"div">;
30
+ declare function DrawerHeader({ className, ...props }: DrawerHeaderProps): react_jsx_runtime.JSX.Element;
31
+ type DrawerFooterProps = ComponentProps<"div">;
32
+ declare function DrawerFooter({ className, ...props }: DrawerFooterProps): react_jsx_runtime.JSX.Element;
33
+ type DrawerBodyProps = ComponentProps<"div">;
34
+ declare function DrawerBody({ className, ...props }: DrawerBodyProps): react_jsx_runtime.JSX.Element;
35
+ type DrawerTitleProps = ComponentProps<typeof DialogPrimitive.Title>;
36
+ declare function DrawerTitle({ className, ...props }: DrawerTitleProps): react_jsx_runtime.JSX.Element;
37
+ type DrawerDescriptionProps = ComponentProps<typeof DialogPrimitive.Description>;
38
+ declare function DrawerDescription({ className, ...props }: DrawerDescriptionProps): react_jsx_runtime.JSX.Element;
39
+ type DrawerCloseTriggerProps = ComponentProps<typeof DialogPrimitive.Close>;
40
+ declare function DrawerCloseTrigger({ className, ...props }: DrawerCloseTriggerProps): react_jsx_runtime.JSX.Element;
41
+
42
+ export { DrawerBody, type DrawerBodyProps, DrawerClose, type DrawerCloseProps, DrawerCloseTrigger, type DrawerCloseTriggerProps, DrawerContent, type DrawerContentProps, DrawerDescription, type DrawerDescriptionProps, DrawerFooter, type DrawerFooterProps, DrawerHeader, type DrawerHeaderProps, DrawerOverlay, type DrawerOverlayProps, DrawerPortal, type DrawerPortalProps, DrawerProvider, DrawerRoot, type DrawerRootProps, DrawerTitle, type DrawerTitleProps, DrawerTrigger, type DrawerTriggerProps, useDrawerContext };
@@ -0,0 +1,42 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ComponentProps } from 'react';
4
+ import { drawer, DrawerVariantProps } from '@kopexa/theme';
5
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
6
+
7
+ type DrawerContextValue = {
8
+ styles: ReturnType<typeof drawer>;
9
+ open: boolean;
10
+ placement: "top" | "bottom" | "left" | "right";
11
+ };
12
+ declare const DrawerProvider: react.Provider<DrawerContextValue>;
13
+ declare const useDrawerContext: () => DrawerContextValue;
14
+
15
+ type DrawerRootProps = ComponentProps<typeof DialogPrimitive.Root> & DrawerVariantProps;
16
+ declare const DrawerRoot: (props: DrawerRootProps) => react_jsx_runtime.JSX.Element;
17
+ type DrawerTriggerProps = ComponentProps<typeof DialogPrimitive.Trigger>;
18
+ declare function DrawerTrigger({ ...props }: DrawerTriggerProps): react_jsx_runtime.JSX.Element;
19
+ type DrawerPortalProps = ComponentProps<typeof DialogPrimitive.Portal>;
20
+ declare function DrawerPortal({ ...props }: DrawerPortalProps): react_jsx_runtime.JSX.Element;
21
+ type DrawerCloseProps = ComponentProps<typeof DialogPrimitive.Close>;
22
+ declare function DrawerClose({ ...props }: DrawerCloseProps): react_jsx_runtime.JSX.Element;
23
+ type DrawerOverlayProps = ComponentProps<typeof DialogPrimitive.Overlay>;
24
+ declare function DrawerOverlay({ className, ...props }: DrawerOverlayProps): react_jsx_runtime.JSX.Element;
25
+ type DrawerContentProps = ComponentProps<typeof DialogPrimitive.Content> & {
26
+ showCloseButton?: boolean;
27
+ };
28
+ declare const DrawerContent: (props: DrawerContentProps) => react_jsx_runtime.JSX.Element;
29
+ type DrawerHeaderProps = ComponentProps<"div">;
30
+ declare function DrawerHeader({ className, ...props }: DrawerHeaderProps): react_jsx_runtime.JSX.Element;
31
+ type DrawerFooterProps = ComponentProps<"div">;
32
+ declare function DrawerFooter({ className, ...props }: DrawerFooterProps): react_jsx_runtime.JSX.Element;
33
+ type DrawerBodyProps = ComponentProps<"div">;
34
+ declare function DrawerBody({ className, ...props }: DrawerBodyProps): react_jsx_runtime.JSX.Element;
35
+ type DrawerTitleProps = ComponentProps<typeof DialogPrimitive.Title>;
36
+ declare function DrawerTitle({ className, ...props }: DrawerTitleProps): react_jsx_runtime.JSX.Element;
37
+ type DrawerDescriptionProps = ComponentProps<typeof DialogPrimitive.Description>;
38
+ declare function DrawerDescription({ className, ...props }: DrawerDescriptionProps): react_jsx_runtime.JSX.Element;
39
+ type DrawerCloseTriggerProps = ComponentProps<typeof DialogPrimitive.Close>;
40
+ declare function DrawerCloseTrigger({ className, ...props }: DrawerCloseTriggerProps): react_jsx_runtime.JSX.Element;
41
+
42
+ export { DrawerBody, type DrawerBodyProps, DrawerClose, type DrawerCloseProps, DrawerCloseTrigger, type DrawerCloseTriggerProps, DrawerContent, type DrawerContentProps, DrawerDescription, type DrawerDescriptionProps, DrawerFooter, type DrawerFooterProps, DrawerHeader, type DrawerHeaderProps, DrawerOverlay, type DrawerOverlayProps, DrawerPortal, type DrawerPortalProps, DrawerProvider, DrawerRoot, type DrawerRootProps, DrawerTitle, type DrawerTitleProps, DrawerTrigger, type DrawerTriggerProps, useDrawerContext };