@corvu-next/resizable 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,304 @@
1
+ import * as _solidjs_web from '@solidjs/web';
2
+ import { ValidComponent, JSX } from '@solidjs/web';
3
+ import { Accessor, Setter } from 'solid-js';
4
+ import { Size } from '@corvu-next/utils';
5
+ export { Size } from '@corvu-next/utils';
6
+ import { Ref, ElementOf } from '@corvu-next/utils/dom';
7
+ import { DynamicProps } from '@corvu-next/utils/dynamic';
8
+ export { DynamicProps } from '@corvu-next/utils/dynamic';
9
+
10
+ type ResizeStrategy = 'preceding' | 'following' | 'both';
11
+
12
+ type ResizableContextValue = {
13
+ /** The orientation of the resizable. */
14
+ orientation: Accessor<'horizontal' | 'vertical'>;
15
+ /** The sizes of the panels. */
16
+ sizes: Accessor<number[]>;
17
+ /** Change the sizes of the panels. */
18
+ setSizes: Setter<number[]>;
19
+ /** The delta to use when resizing with arrow keys. */
20
+ keyboardDelta: Accessor<Size>;
21
+ /** Whether to handle the cursor style when resizing. */
22
+ handleCursorStyle: Accessor<boolean>;
23
+ /** Resize a panel to a specific size with the given strategy. */
24
+ resize: (panelIndex: number, size: Size, strategy?: ResizeStrategy) => void;
25
+ /** Collapse a panel with the given strategy. Only works if `collapsible` is set to `true`. */
26
+ collapse: (panelIndex: number, strategy?: ResizeStrategy) => void;
27
+ /** Expand a panel with the given strategy. Only works if `collapsible` is set to `true`. */
28
+ expand: (panelIndex: number, strategy?: ResizeStrategy) => void;
29
+ };
30
+ /** Context which exposes various properties to interact with the resizable. Optionally provide a contextId to access a keyed context. */
31
+ declare const useResizableContext: (contextId?: string) => ResizableContextValue;
32
+
33
+ type ResizableHandleCorvuProps = {
34
+ /**
35
+ * Whether the handle is allowed to intersect with another handle at its start (Left/Top of the handle)
36
+ * @defaultValue `true`
37
+ */
38
+ startIntersection?: boolean;
39
+ /**
40
+ * Whether the handle is allowed to intersect with another handle at its end (Right/Bottom of the handle)
41
+ * @defaultValue `true`
42
+ */
43
+ endIntersection?: boolean;
44
+ /**
45
+ * Whether Alt key resize mode is enabled. Set to `'only'` to make it the default and only way to resize.
46
+ * @defaultValue `true`
47
+ */
48
+ altKey?: boolean | 'only';
49
+ /**
50
+ * Callback fired when the handle starts being dragged. Can be prevented by calling `event.preventDefault`.
51
+ */
52
+ onHandleDragStart?: (event: PointerEvent) => void;
53
+ /**
54
+ * Callback fired when the handle is being dragged. Can be prevented by calling `event.preventDefault`.
55
+ */
56
+ onHandleDrag?: (event: CustomEvent) => void;
57
+ /**
58
+ * Callback fired when the handle stops being dragged.
59
+ */
60
+ onHandleDragEnd?: (event: PointerEvent | TouchEvent | MouseEvent) => void;
61
+ /**
62
+ * The `id` of the resizable context to use.
63
+ */
64
+ contextId?: string;
65
+ };
66
+ type ResizableHandleSharedElementProps<T extends ValidComponent = 'button'> = {
67
+ ref: Ref<ElementOf<T>>;
68
+ style: string | JSX.CSSProperties;
69
+ disabled: boolean | undefined;
70
+ onBlur: JSX.EventHandlerUnion<ElementOf<T>, FocusEvent>;
71
+ onFocus: JSX.EventHandlerUnion<ElementOf<T>, FocusEvent>;
72
+ onKeyDown: JSX.EventHandlerUnion<ElementOf<T>, KeyboardEvent>;
73
+ onKeyUp: JSX.EventHandlerUnion<ElementOf<T>, KeyboardEvent>;
74
+ onMouseEnter: JSX.EventHandlerUnion<ElementOf<T>, MouseEvent>;
75
+ onMouseLeave: JSX.EventHandlerUnion<ElementOf<T>, MouseEvent>;
76
+ onPointerDown: JSX.EventHandlerUnion<ElementOf<T>, PointerEvent>;
77
+ children: JSX.Element;
78
+ };
79
+ type ResizableHandleElementProps = ResizableHandleSharedElementProps & {
80
+ role: 'separator';
81
+ 'aria-controls': string | undefined;
82
+ 'aria-orientation': 'horizontal' | 'vertical';
83
+ 'aria-valuemax': number | undefined;
84
+ 'aria-valuemin': number | undefined;
85
+ 'aria-valuenow': number | undefined;
86
+ 'data-active': '' | undefined;
87
+ 'data-dragging': '' | undefined;
88
+ 'data-orientation': 'horizontal' | 'vertical';
89
+ 'data-corvu-resizable-handle': '';
90
+ };
91
+ type ResizableHandleProps<T extends ValidComponent = 'button'> = ResizableHandleCorvuProps & Partial<ResizableHandleSharedElementProps<T>>;
92
+ /** Resizable handle.
93
+ *
94
+ * @data `data-corvu-resizable-handle` - Present on every resizable handle.
95
+ * @data `data-active` - Present when the handle is active.
96
+ * @data `data-dragging` - Present when the handle is being dragged.
97
+ * @data `data-orientation` - The orientation of the resizable.
98
+ */
99
+ declare const ResizableHandle: <T extends ValidComponent = "button">(props: DynamicProps<T, ResizableHandleProps<T>>) => JSX.Element;
100
+
101
+ type ResizablePanelCorvuProps = {
102
+ /**
103
+ * The initial size of the panel. If the panel is rendered on the server, this should be a percentage to avoid layout shifts.
104
+ */
105
+ initialSize?: Size;
106
+ /**
107
+ * The minimum size of the panel.
108
+ * @defaultValue 0
109
+ */
110
+ minSize?: Size;
111
+ /**
112
+ * The maximum size of the panel.
113
+ * @defaultValue 1
114
+ */
115
+ maxSize?: Size;
116
+ /**
117
+ * Whether the panel is collapsible.
118
+ * @defaultValue `false`
119
+ */
120
+ collapsible?: boolean;
121
+ /**
122
+ * The size the panel should collapse to.
123
+ * @defaultValue 0
124
+ */
125
+ collapsedSize?: Size;
126
+ /**
127
+ * How much the user has to "overdrag" for the panel to collapse.
128
+ * @defaultValue 0.05
129
+ */
130
+ collapseThreshold?: Size;
131
+ /**
132
+ * Callback fired when the panel is resized.
133
+ * @param size - The new size of the panel.
134
+ */
135
+ onResize?: (size: number) => void;
136
+ /**
137
+ * Callback fired when the panel is collapsed.
138
+ * @param size - The new size of the panel.
139
+ */
140
+ onCollapse?: (size: number) => void;
141
+ /**
142
+ * Callback fired when the panel is expanded.
143
+ * @param size - The new size of the panel.
144
+ */
145
+ onExpand?: (size: number) => void;
146
+ /**
147
+ * The `id` of the resizable context to use.
148
+ */
149
+ contextId?: string;
150
+ /**
151
+ * The `id` attribute of the resizable panel element.
152
+ * @defaultValue `createUniqueId()`
153
+ */
154
+ panelId?: string;
155
+ };
156
+ type ResizablePanelSharedElementProps<T extends ValidComponent = 'div'> = {
157
+ ref: Ref<ElementOf<T>>;
158
+ style: string | JSX.CSSProperties;
159
+ children: JSX.Element | ((props: ResizablePanelChildrenProps) => JSX.Element);
160
+ };
161
+ type ResizablePanelElementProps = ResizablePanelSharedElementProps & {
162
+ id: string;
163
+ 'data-collapsed': '' | undefined;
164
+ 'data-expanded': '' | undefined;
165
+ 'data-orientation': 'horizontal' | 'vertical';
166
+ 'data-corvu-resizable-panel': '';
167
+ };
168
+ type ResizablePanelProps<T extends ValidComponent = 'div'> = ResizablePanelCorvuProps & Partial<ResizablePanelSharedElementProps<T>>;
169
+ type ResizablePanelChildrenProps = {
170
+ /** The current size of the panel. */
171
+ size: number;
172
+ /** The minimum size of the panel. */
173
+ minSize: Size;
174
+ /** The maximum size of the panel. */
175
+ maxSize: Size;
176
+ /** Whether the panel is collapsible. */
177
+ collapsible: boolean;
178
+ /** The size the panel should collapse to. */
179
+ collapsedSize: Size;
180
+ /** How much the user has to "overdrag" for the panel to collapse. */
181
+ collapseThreshold: Size;
182
+ /** Whether the panel is currently collapsed. */
183
+ collapsed: boolean;
184
+ /** Resize the panel to a specific size with the given strategy. */
185
+ resize: (size: Size, strategy?: ResizeStrategy) => void;
186
+ /** Collapse the panel with the given strategy. Only works if `collapsible` is set to `true`. */
187
+ collapse: (strategy?: ResizeStrategy) => void;
188
+ /** Expand the panel with the given strategy. Only works if `collapsible` is set to `true`. */
189
+ expand: (strategy?: ResizeStrategy) => void;
190
+ /** The `id` attribute of the resizable panel element. */
191
+ panelId: string;
192
+ };
193
+ /** Resizable panel.
194
+ *
195
+ * @data `data-corvu-resizable-panel` - Present on every resizable panel.
196
+ * @data `data-orientation` - The orientation of the resizable.
197
+ * @data `data-collapsed` - Present if the panel is currently collapsed.
198
+ * @data `data-expanded` - Present if the panel is currently expanded. Only present on panels that are collapsible.
199
+ */
200
+ declare const ResizablePanel: <T extends ValidComponent = "div">(props: DynamicProps<T, ResizablePanelProps<T>>) => JSX.Element;
201
+
202
+ type ResizablePanelContextValue = {
203
+ /** The current size of the panel. */
204
+ size: Accessor<number>;
205
+ /** The minimum size of the panel. */
206
+ minSize: Accessor<Size | null>;
207
+ /** The maximum size of the panel. */
208
+ maxSize: Accessor<Size | null>;
209
+ /** Whether the panel is collapsible. */
210
+ collapsible: Accessor<boolean>;
211
+ /** The size the panel should collapse to. */
212
+ collapsedSize: Accessor<Size>;
213
+ /** How much the user has to "overdrag" for the panel to collapse. */
214
+ collapseThreshold: Accessor<Size>;
215
+ /** Whether the panel is currently collapsed. */
216
+ collapsed: Accessor<boolean>;
217
+ /** Resize the panel to a specific size with the given strategy. */
218
+ resize: (size: Size, strategy?: ResizeStrategy) => void;
219
+ /** Collapse the panel with the given strategy. Only works if `collapsible` is set to `true`. */
220
+ collapse: (strategy?: ResizeStrategy) => void;
221
+ /** Expand the panel with the given strategy. Only works if `collapsible` is set to `true`. */
222
+ expand: (strategy?: ResizeStrategy) => void;
223
+ /** The `id` attribute of the resizable panel element. */
224
+ panelId: Accessor<string>;
225
+ };
226
+ /** Context which exposes various properties to interact with a resizable panel. Optionally provide a contextId to access a keyed context. */
227
+ declare const useResizablePanelContext: (contextId?: string) => ResizablePanelContextValue;
228
+
229
+ type ResizableRootCorvuProps = {
230
+ /**
231
+ * The orientation of the resizable.
232
+ * @defaultValue 'horizontal'
233
+ */
234
+ orientation?: 'horizontal' | 'vertical';
235
+ /**
236
+ * Panel sizes in percentage.
237
+ */
238
+ sizes?: number[];
239
+ /**
240
+ * Callback fired when the panel sizes change.
241
+ */
242
+ onSizesChange?: (sizes: number[]) => void;
243
+ /**
244
+ * Initial panel sizes. Gets overridden by the `initialSize` prop on `<Panel />` components.
245
+ */
246
+ initialSizes?: Size[];
247
+ /**
248
+ * The delta to use when resizing with arrow keys.
249
+ * @defaultValue 0.1
250
+ */
251
+ keyboardDelta?: Size;
252
+ /**
253
+ * Whether to handle the cursor style when resizing.
254
+ * @defaultValue true
255
+ */
256
+ handleCursorStyle?: boolean;
257
+ /**
258
+ * The `id` of the resizable context to use.
259
+ */
260
+ contextId?: string;
261
+ };
262
+ type ResizableRootSharedElementProps<T extends ValidComponent = 'div'> = {
263
+ ref: Ref<ElementOf<T>>;
264
+ style: string | JSX.CSSProperties;
265
+ children: JSX.Element | ((props: ResizableRootChildrenProps) => JSX.Element);
266
+ };
267
+ type ResizableRootElementProps = ResizableRootSharedElementProps & {
268
+ 'data-orientation': 'horizontal' | 'vertical';
269
+ 'data-corvu-resizable-root': '';
270
+ };
271
+ type ResizableRootProps<T extends ValidComponent = 'div'> = ResizableRootCorvuProps & Partial<ResizableRootSharedElementProps<T>>;
272
+ type ResizableRootChildrenProps = {
273
+ /** The orientation of the resizable. */
274
+ orientation: 'vertical' | 'horizontal';
275
+ /** The sizes of the panels. */
276
+ sizes: number[];
277
+ /** Change the sizes of the panels. */
278
+ setSizes: Setter<number[]>;
279
+ /** The delta to use when resizing with arrow keys. */
280
+ keyboardDelta: Size;
281
+ /** Whether to handle the cursor style when resizing. */
282
+ handleCursorStyle: boolean;
283
+ /** Resize a panel to a specific size with the given strategy. */
284
+ resize: (panelIndex: number, size: Size, strategy?: ResizeStrategy) => void;
285
+ /** Collapse a panel with the given strategy. Only works if `collapsible` is set to `true`. */
286
+ collapse: (panelIndex: number, strategy?: ResizeStrategy) => void;
287
+ /** Expand a panel with the given strategy. Only works if `collapsible` is set to `true`. */
288
+ expand: (panelIndex: number, strategy?: ResizeStrategy) => void;
289
+ };
290
+ /** Wrapper for the resizable.
291
+ *
292
+ * @data `data-corvu-resizable-root` - Present on every resizable root element.
293
+ * @data `data-orientation` - The orientation of the resizable.
294
+ */
295
+ declare const ResizableRoot: <T extends ValidComponent = "div">(props: DynamicProps<T, ResizableRootProps<T>>) => JSX.Element;
296
+
297
+ declare const Resizable: (<T extends _solidjs_web.ValidComponent = "div">(props: DynamicProps<T, ResizableRootProps<T>>) => _solidjs_web.JSX.Element) & {
298
+ Panel: <T extends _solidjs_web.ValidComponent = "div">(props: DynamicProps<T, ResizablePanelProps<T>>) => _solidjs_web.JSX.Element;
299
+ Handle: <T extends _solidjs_web.ValidComponent = "button">(props: DynamicProps<T, ResizableHandleProps<T>>) => _solidjs_web.JSX.Element;
300
+ useContext: (contextId?: string) => ResizableContextValue;
301
+ usePanelContext: (contextId?: string) => ResizablePanelContextValue;
302
+ };
303
+
304
+ export { type ResizableContextValue as ContextValue, ResizableHandle as Handle, type ResizableHandleCorvuProps as HandleCorvuProps, type ResizableHandleElementProps as HandleElementProps, type ResizableHandleProps as HandleProps, type ResizableHandleSharedElementProps as HandleSharedElementProps, ResizablePanel as Panel, type ResizablePanelChildrenProps as PanelChildrenProps, type ResizablePanelContextValue as PanelContextValue, type ResizablePanelCorvuProps as PanelCorvuProps, type ResizablePanelElementProps as PanelElementProps, type ResizablePanelProps as PanelProps, type ResizablePanelSharedElementProps as PanelSharedElementProps, type ResizeStrategy, ResizableRoot as Root, type ResizableRootChildrenProps as RootChildrenProps, type ResizableRootCorvuProps as RootCorvuProps, type ResizableRootElementProps as RootElementProps, type ResizableRootProps as RootProps, type ResizableRootSharedElementProps as RootSharedElementProps, Resizable as default, useResizableContext as useContext, useResizablePanelContext as usePanelContext };