@corvu-next/drawer 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2025 Jasmin Noetzli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,207 @@
1
+ import * as _solidjs_web from '@solidjs/web';
2
+ import { ValidComponent, JSX } from '@solidjs/web';
3
+ import * as solid_js from 'solid-js';
4
+ import { Accessor } from 'solid-js';
5
+ import { CloseCorvuProps, CloseSharedElementProps, CloseElementProps, ContentCorvuProps, ContentSharedElementProps, ContentElementProps, DescriptionCorvuProps, DescriptionSharedElementProps, DescriptionElementProps, LabelCorvuProps, LabelSharedElementProps, LabelElementProps, OverlayCorvuProps, OverlaySharedElementProps, OverlayElementProps, RootChildrenProps, RootProps, TriggerCorvuProps, TriggerSharedElementProps, TriggerElementProps, PortalProps, ContextValue } from '@corvu-next/dialog';
6
+ export { ContextValue as DialogContextValue, PortalProps } from '@corvu-next/dialog';
7
+ import { Side, Size } from '@corvu-next/utils';
8
+ export { Side, Size } from '@corvu-next/utils';
9
+ import { DynamicProps } from '@corvu-next/utils/dynamic';
10
+ export { DynamicProps } from '@corvu-next/utils/dynamic';
11
+
12
+ type DrawerCloseCorvuProps = CloseCorvuProps;
13
+ type DrawerCloseSharedElementProps<T extends ValidComponent = 'button'> = CloseSharedElementProps<T>;
14
+ type DrawerCloseElementProps = DrawerCloseSharedElementProps & {
15
+ 'data-corvu-drawer-close': '';
16
+ } & CloseElementProps;
17
+ type DrawerCloseProps<T extends ValidComponent = 'button'> = DrawerCloseCorvuProps & Partial<DrawerCloseSharedElementProps<T>>;
18
+
19
+ type DrawerContentCorvuProps = ContentCorvuProps;
20
+ type DrawerContentSharedElementProps<T extends ValidComponent = 'div'> = ContentSharedElementProps<T>;
21
+ type DrawerContentElementProps = DrawerContentSharedElementProps & {
22
+ onPointerDown: JSX.EventHandlerUnion<HTMLElement, PointerEvent>;
23
+ onTouchStart: JSX.EventHandlerUnion<HTMLElement, TouchEvent>;
24
+ onTransitionEnd: JSX.EventHandlerUnion<HTMLElement, TransitionEvent>;
25
+ 'data-side': Side;
26
+ 'data-opening': '' | undefined;
27
+ 'data-closing': '' | undefined;
28
+ 'data-snapping': '' | undefined;
29
+ 'data-transitioning': '' | undefined;
30
+ 'data-resizing': '' | undefined;
31
+ 'data-corvu-drawer-content': '';
32
+ } & ContentElementProps;
33
+ type DrawerContentProps<T extends ValidComponent = 'div'> = DrawerContentCorvuProps & Partial<DrawerContentSharedElementProps<T>>;
34
+
35
+ type DrawerDescriptionCorvuProps = DescriptionCorvuProps;
36
+ type DrawerDescriptionSharedElementProps<T extends ValidComponent = 'p'> = DescriptionSharedElementProps<T>;
37
+ type DrawerDescriptionElementProps = DrawerDescriptionSharedElementProps & {
38
+ 'data-corvu-drawer-description': '';
39
+ } & DescriptionElementProps;
40
+ type DrawerDescriptionProps<T extends ValidComponent = 'p'> = DrawerDescriptionCorvuProps & Partial<DrawerDescriptionSharedElementProps<T>>;
41
+
42
+ type DrawerContextValue = {
43
+ /** An array of points to snap to. Can be either percentages of the total drawer height or CSS pixel values. */
44
+ snapPoints: Accessor<Size[]>;
45
+ /** Breakpoints between snap points. */
46
+ breakPoints: Accessor<(Size | null)[]>;
47
+ /** The point to snap to when the drawer opens. */
48
+ defaultSnapPoint: Accessor<Size>;
49
+ /** The active snap point. */
50
+ activeSnapPoint: Accessor<Size>;
51
+ /** Change the active snap point. */
52
+ setActiveSnapPoint: (snapPoint: Size) => void;
53
+ /** The side of the viewport the drawer appears. Is used to properly calculate dragging. */
54
+ side: Accessor<Side>;
55
+ /** Whether the drawer is currently being dragged by the user. */
56
+ isDragging: Accessor<boolean>;
57
+ /** Whether the drawer is currently transitioning to a snap point after the user stopped dragging or the drawer opens/closes. */
58
+ isTransitioning: Accessor<boolean>;
59
+ /** The transition state that the drawer is currently in. */
60
+ transitionState: Accessor<'opening' | 'closing' | 'snapping' | 'resizing' | null>;
61
+ /** How much the drawer is currently open. Can be > 1 depending on your `dampFunction`. */
62
+ openPercentage: Accessor<number>;
63
+ /** The current translate value applied to the drawer. Is the same for every side. */
64
+ translate: Accessor<number>;
65
+ /** After how many milliseconds the cached distance used for the velocity function should reset. */
66
+ velocityCacheReset: Accessor<number>;
67
+ /** Whether the user can skip snap points if the velocity is high enough. */
68
+ allowSkippingSnapPoints: Accessor<boolean>;
69
+ /** Whether the logic to handle dragging on scrollable elements is enabled. */
70
+ handleScrollableElements: Accessor<boolean>;
71
+ /** Whether the drawer watches for size changes and applies a fixed width/height for transitions. */
72
+ transitionResize: Accessor<boolean>;
73
+ };
74
+
75
+ type DrawerLabelCorvuProps = LabelCorvuProps;
76
+ type DrawerLabelSharedElementProps<T extends ValidComponent = 'h2'> = LabelSharedElementProps<T>;
77
+ type DrawerLabelElementProps = DrawerLabelSharedElementProps & {
78
+ 'data-corvu-drawer-label': '';
79
+ } & LabelElementProps;
80
+ type DrawerLabelProps<T extends ValidComponent = 'h2'> = DrawerLabelCorvuProps & Partial<DrawerLabelSharedElementProps<T>>;
81
+
82
+ type DrawerOverlayCorvuProps = OverlayCorvuProps;
83
+ type DrawerOverlaySharedElementProps<T extends ValidComponent = 'div'> = OverlaySharedElementProps<T>;
84
+ type DrawerOverlayElementProps = DrawerOverlaySharedElementProps & {
85
+ 'data-side': Side;
86
+ 'data-opening': '' | undefined;
87
+ 'data-closing': '' | undefined;
88
+ 'data-snapping': '' | undefined;
89
+ 'data-transitioning': '' | undefined;
90
+ 'data-resizing': '' | undefined;
91
+ 'data-corvu-drawer-overlay': '';
92
+ } & OverlayElementProps;
93
+ type DrawerOverlayProps<T extends ValidComponent = 'div'> = DrawerOverlayCorvuProps & Partial<DrawerOverlaySharedElementProps<T>>;
94
+
95
+ type DrawerRootProps = {
96
+ /**
97
+ * An array of points to snap to. Can be either percentages of the total drawer height or CSS pixel values.
98
+ * @defaultValue `[0, 1]`
99
+ */
100
+ snapPoints?: Size[];
101
+ /**
102
+ * Optionally override the default breakpoints between snap points. This list has to be the length of `snapPoints.length - 1`. Provide `null` for breakpoints you don't want to override.
103
+ */
104
+ breakPoints?: (Size | null)[];
105
+ /**
106
+ * The point to snap to when the drawer opens.
107
+ * @defaultValue `1`
108
+ */
109
+ defaultSnapPoint?: Size;
110
+ /**
111
+ * The active snap point.
112
+ */
113
+ activeSnapPoint?: Size;
114
+ /**
115
+ * Callback fired when the active snap point changes.
116
+ */
117
+ onActiveSnapPointChange?: (activeSnapPoint: Size) => void;
118
+ /**
119
+ * The side of the viewport the drawer appears. Is used to properly calculate dragging.
120
+ * @defaultValue `'bottom'`
121
+ */
122
+ side?: Side;
123
+ /**
124
+ * Function to create a dampened distance if the user tries to drag the drawer away from the last snap point.
125
+ */
126
+ dampFunction?: (distance: number) => number;
127
+ /**
128
+ * Function to calculate the velocity when the user stop dragging. This velocity modifier is used to calculate the point the drawer will snap to after release. You can disable velocity by always returning 1
129
+ */
130
+ velocityFunction?: (distance: number, time: number) => number;
131
+ /**
132
+ * After how many milliseconds the cached distance used for the velocity function should reset.
133
+ * @defaultValue `200`
134
+ */
135
+ velocityCacheReset?: number;
136
+ /**
137
+ * Whether the user can skip snap points if the velocity is high enough.
138
+ * @defaultValue `true`
139
+ */
140
+ allowSkippingSnapPoints?: boolean;
141
+ /**
142
+ * corvu drawers have logic to make dragging and scrolling work together. If you don't want this behavior or if you want to implement something yourself, you can disable it with this property.
143
+ * @defaultValue `true`
144
+ */
145
+ handleScrollableElements?: boolean;
146
+ /**
147
+ * Whether the drawer should watch for size changes and apply a fixed width/height for transitions.
148
+ * @defaultValue `false`
149
+ */
150
+ transitionResize?: boolean;
151
+ /** @hidden */
152
+ children: JSX.Element | ((props: DrawerRootChildrenProps & RootChildrenProps) => JSX.Element);
153
+ } & Omit<RootProps, 'children'>;
154
+ /** Props that are passed to the Root component children callback. */
155
+ type DrawerRootChildrenProps = {
156
+ /** An array of points to snap to. Can be either percentages of the total drawer height or CSS pixel values. */
157
+ snapPoints: Size[];
158
+ /** Breakpoints between snap points. */
159
+ breakPoints: (Size | null)[];
160
+ /** The point to snap to when the drawer opens. */
161
+ defaultSnapPoint: Size;
162
+ /** The active snap point. */
163
+ activeSnapPoint: Size;
164
+ /** Set the current active snap point. */
165
+ setActiveSnapPoint: (snapPoint: Size) => void;
166
+ /** The side of the viewport the drawer appears. Is used to properly calculate dragging. */
167
+ side: Side;
168
+ /** Whether the drawer is currently being dragged by the user. */
169
+ isDragging: boolean;
170
+ /** Whether the drawer is currently transitioning to a snap point after the user stopped dragging or the drawer opens/closes. */
171
+ isTransitioning: boolean;
172
+ /** The transition state that the drawer is currently in. */
173
+ transitionState: 'opening' | 'closing' | 'snapping' | 'resizing' | null;
174
+ /** How much the drawer is currently open. Can be > 1 depending on your `dampFunction`. */
175
+ openPercentage: number;
176
+ /** The current translate value applied to the drawer. Is the same for every side. */
177
+ translate: number;
178
+ /** After how many milliseconds the cached distance used for the velocity function should reset. */
179
+ velocityCacheReset: number;
180
+ /** Whether the user can skip snap points if the velocity is high enough. */
181
+ allowSkippingSnapPoints: boolean;
182
+ /** Whether the logic to handle dragging on scrollable elements is enabled. */
183
+ handleScrollableElements: boolean;
184
+ /** Whether the drawer watches for size changes and applies a fixed width/height for transitions. */
185
+ transitionResize: boolean;
186
+ };
187
+
188
+ type DrawerTriggerCorvuProps = TriggerCorvuProps;
189
+ type DrawerTriggerSharedElementProps<T extends ValidComponent = 'button'> = TriggerSharedElementProps<T>;
190
+ type DrawerTriggerElementProps = DrawerTriggerSharedElementProps & {
191
+ 'data-corvu-drawer-trigger': '';
192
+ } & TriggerElementProps;
193
+ type DrawerTriggerProps<T extends ValidComponent = 'button'> = DrawerTriggerCorvuProps & Partial<DrawerTriggerSharedElementProps<T>>;
194
+
195
+ declare const Drawer: solid_js.Component<DrawerRootProps> & {
196
+ Trigger: <T extends _solidjs_web.ValidComponent = "button">(props: DynamicProps<T, DrawerTriggerProps<T>>) => _solidjs_web.JSX.Element;
197
+ Portal: (props: PortalProps & _solidjs_web.ComponentProps<typeof _solidjs_web.Portal>) => _solidjs_web.JSX.Element;
198
+ Overlay: <T extends _solidjs_web.ValidComponent = "div">(props: DynamicProps<T, DrawerOverlayProps<T>>) => _solidjs_web.JSX.Element;
199
+ Content: <T extends _solidjs_web.ValidComponent = "div">(props: DynamicProps<T, DrawerContentProps<T>>) => _solidjs_web.JSX.Element;
200
+ Label: <T extends _solidjs_web.ValidComponent = "h2">(props: DynamicProps<T, DrawerLabelProps<T>>) => _solidjs_web.JSX.Element;
201
+ Description: <T extends _solidjs_web.ValidComponent = "p">(props: DynamicProps<T, DrawerDescriptionProps<T>>) => _solidjs_web.JSX.Element;
202
+ Close: <T extends _solidjs_web.ValidComponent = "button">(props: DynamicProps<T, DrawerCloseProps<T>>) => _solidjs_web.JSX.Element;
203
+ useContext: (contextId?: string) => DrawerContextValue;
204
+ useDialogContext: (contextId?: string) => ContextValue;
205
+ };
206
+
207
+ export { type DrawerCloseCorvuProps as CloseCorvuProps, type DrawerCloseElementProps as CloseElementProps, type DrawerCloseProps as CloseProps, type DrawerCloseSharedElementProps as CloseSharedElementProps, type DrawerContentCorvuProps as ContentCorvuProps, type DrawerContentElementProps as ContentElementProps, type DrawerContentProps as ContentProps, type DrawerContentSharedElementProps as ContentSharedElementProps, type DrawerContextValue as ContextValue, type DrawerDescriptionCorvuProps as DescriptionCorvuProps, type DrawerDescriptionElementProps as DescriptionElementProps, type DrawerDescriptionProps as DescriptionProps, type DrawerDescriptionSharedElementProps as DescriptionSharedElementProps, type DrawerLabelCorvuProps as LabelCorvuProps, type DrawerLabelElementProps as LabelElementProps, type DrawerLabelProps as LabelProps, type DrawerLabelSharedElementProps as LabelSharedElementProps, type DrawerOverlayCorvuProps as OverlayCorvuProps, type DrawerOverlayElementProps as OverlayElementProps, type DrawerOverlayProps as OverlayProps, type DrawerOverlaySharedElementProps as OverlaySharedElementProps, type DrawerRootChildrenProps as RootChildrenProps, type DrawerRootProps as RootProps, type DrawerTriggerCorvuProps as TriggerCorvuProps, type DrawerTriggerElementProps as TriggerElementProps, type DrawerTriggerProps as TriggerProps, type DrawerTriggerSharedElementProps as TriggerSharedElementProps, Drawer as default };