react-resizable-panels 3.0.6 → 4.2.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.md +21 -0
- package/README.md +296 -238
- package/dist/react-resizable-panels.cjs +2 -0
- package/dist/react-resizable-panels.cjs.map +1 -0
- package/dist/react-resizable-panels.d.ts +387 -2
- package/dist/react-resizable-panels.js +1659 -2344
- package/dist/react-resizable-panels.js.map +1 -0
- package/package.json +97 -66
- package/dist/declarations/src/Panel.d.ts +0 -70
- package/dist/declarations/src/PanelGroup.d.ts +0 -38
- package/dist/declarations/src/PanelResizeHandle.d.ts +0 -23
- package/dist/declarations/src/PanelResizeHandleRegistry.d.ts +0 -19
- package/dist/declarations/src/constants.d.ts +0 -15
- package/dist/declarations/src/hooks/usePanelGroupContext.d.ts +0 -4
- package/dist/declarations/src/index.d.ts +0 -23
- package/dist/declarations/src/types.d.ts +0 -3
- package/dist/declarations/src/utils/assert.d.ts +0 -1
- package/dist/declarations/src/utils/csp.d.ts +0 -2
- package/dist/declarations/src/utils/cursor.d.ts +0 -18
- package/dist/declarations/src/utils/dom/getPanelElement.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +0 -2
- package/dist/declarations/src/utils/rects/getIntersectingRectangle.d.ts +0 -2
- package/dist/declarations/src/utils/rects/intersects.d.ts +0 -2
- package/dist/declarations/src/utils/rects/types.d.ts +0 -6
- package/dist/react-resizable-panels.browser.development.js +0 -2592
- package/dist/react-resizable-panels.browser.js +0 -2486
- package/dist/react-resizable-panels.development.edge-light.js +0 -2365
- package/dist/react-resizable-panels.development.js +0 -2599
- package/dist/react-resizable-panels.edge-light.js +0 -2264
|
@@ -1,2 +1,387 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { Dispatch } from 'react';
|
|
3
|
+
import { HTMLAttributes } from 'react';
|
|
4
|
+
import { JSX } from 'react/jsx-runtime';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
6
|
+
import { Ref } from 'react';
|
|
7
|
+
import { RefObject } from 'react';
|
|
8
|
+
import { SetStateAction } from 'react';
|
|
9
|
+
|
|
10
|
+
declare type BaseAttributes = Omit<HTMLAttributes<HTMLDivElement>, "role" | "tabIndex">;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A Group wraps a set of resizable Panel components.
|
|
14
|
+
* Group content can be resized _horizontally_ or _vertically_.
|
|
15
|
+
*
|
|
16
|
+
* Group elements always include the following attributes:
|
|
17
|
+
*
|
|
18
|
+
* ```html
|
|
19
|
+
* <div data-group data-testid="group-id-prop" id="group-id-prop">
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function Group({ children, className, defaultLayout, disableCursor, disabled, elementRef: elementRefProp, groupRef, id: idProp, onLayoutChange: onLayoutChangeUnstable, orientation, style, ...rest }: GroupProps): JSX.Element;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Imperative Group API.
|
|
28
|
+
*
|
|
29
|
+
* ℹ️ The `useGroupRef` and `useGroupCallbackRef` hooks are exported for convenience use in TypeScript projects.
|
|
30
|
+
*/
|
|
31
|
+
export declare interface GroupImperativeHandle {
|
|
32
|
+
/**
|
|
33
|
+
* Get the Group's current layout as a map of Panel id to percentage (0..100)
|
|
34
|
+
*
|
|
35
|
+
* @return Map of Panel id to percentages (specified as numbers ranging between 0..100)
|
|
36
|
+
*/
|
|
37
|
+
getLayout: () => {
|
|
38
|
+
[panelId: string]: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Set a new layout for the Group
|
|
42
|
+
*
|
|
43
|
+
* @param layout Map of Panel id to percentage (a number between 0..100)
|
|
44
|
+
* @return Applied layout (after validation)
|
|
45
|
+
*/
|
|
46
|
+
setLayout: (layout: {
|
|
47
|
+
[panelId: string]: number;
|
|
48
|
+
}) => Layout;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare type GroupProps = HTMLAttributes<HTMLDivElement> & {
|
|
52
|
+
/**
|
|
53
|
+
* Panel and Separator components that comprise this group.
|
|
54
|
+
*/
|
|
55
|
+
children?: ReactNode | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* CSS class name.
|
|
58
|
+
*/
|
|
59
|
+
className?: string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Default layout for the Group.
|
|
62
|
+
*
|
|
63
|
+
* ℹ️ This value allows layouts to be remembered between page reloads.
|
|
64
|
+
*
|
|
65
|
+
* ⚠️ Refer to the documentation for how to avoid layout shift when using server components.
|
|
66
|
+
*/
|
|
67
|
+
defaultLayout?: Layout | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* This library sets custom mouse cursor styles to indicate drag state.
|
|
70
|
+
* Use this prop to disable that behavior for Panels and Separators in this group.
|
|
71
|
+
*/
|
|
72
|
+
disableCursor?: boolean | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Disable resize functionality.
|
|
75
|
+
*/
|
|
76
|
+
disabled?: boolean | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Ref attached to the root `HTMLDivElement`.
|
|
79
|
+
*/
|
|
80
|
+
elementRef?: Ref<HTMLDivElement> | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Exposes the following imperative API:
|
|
83
|
+
* - `getLayout(): Layout`
|
|
84
|
+
* - `setLayout(layout: Layout): void`
|
|
85
|
+
*
|
|
86
|
+
* ℹ️ The `useGroupRef` and `useGroupCallbackRef` hooks are exported for convenience use in TypeScript projects.
|
|
87
|
+
*/
|
|
88
|
+
groupRef?: Ref<GroupImperativeHandle> | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Uniquely identifies this group within an application.
|
|
91
|
+
* Falls back to `useId` when not provided.
|
|
92
|
+
*
|
|
93
|
+
* ℹ️ This value will also be assigned to the `data-group` attribute.
|
|
94
|
+
*/
|
|
95
|
+
id?: string | number | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Called when panel sizes change; receives a map of Panel id to size.
|
|
98
|
+
*/
|
|
99
|
+
onLayoutChange?: (layout: Layout) => void | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Specifies the resizable orientation ("horizontal" or "vertical"); defaults to "horizontal"
|
|
102
|
+
*/
|
|
103
|
+
orientation?: "horizontal" | "vertical" | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* CSS properties.
|
|
106
|
+
*
|
|
107
|
+
* ⚠️ The following styles cannot be overridden: `display`, `flex-direction`, `flex-wrap`, and `overflow`.
|
|
108
|
+
*/
|
|
109
|
+
style?: CSSProperties | undefined;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Map of Panel id to flexGrow value;
|
|
114
|
+
*/
|
|
115
|
+
export declare type Layout = {
|
|
116
|
+
[id: string]: number;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export declare type LayoutStorage = Pick<Storage, "getItem" | "setItem">;
|
|
120
|
+
|
|
121
|
+
export declare type OnGroupLayoutChange = GroupProps["onLayoutChange"];
|
|
122
|
+
|
|
123
|
+
export declare type OnPanelResize = PanelProps["onResize"];
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Panel group orientation loosely relates to the `aria-orientation` attribute.
|
|
127
|
+
* It determines how panels are are laid out within the group group and the direction they can be resized in.
|
|
128
|
+
*/
|
|
129
|
+
export declare type Orientation = "horizontal" | "vertical";
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A Panel wraps resizable content and can be configured with min/max size constraints and collapsible behavior.
|
|
133
|
+
*
|
|
134
|
+
* Panel size props can be in the following formats:
|
|
135
|
+
* - Percentage of the parent Group (0..100)
|
|
136
|
+
* - Pixels
|
|
137
|
+
* - Relative font units (em, rem)
|
|
138
|
+
* - Viewport relative units (vh, vw)
|
|
139
|
+
*
|
|
140
|
+
* ℹ️ Numeric values are assumed to be pixels.
|
|
141
|
+
* Strings without explicit units are assumed to be percentages (0%..100%).
|
|
142
|
+
* Percentages may also be specified as strings ending with "%" (e.g. "33%")
|
|
143
|
+
* Pixels may also be specified as strings ending with the unit "px".
|
|
144
|
+
* Other units should be specified as strings ending with their CSS property units (e.g. 1rem, 50vh)
|
|
145
|
+
*
|
|
146
|
+
* Panel elements always include the following attributes:
|
|
147
|
+
*
|
|
148
|
+
* ```html
|
|
149
|
+
* <div data-panel data-testid="panel-id-prop" id="panel-id-prop">
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
|
|
153
|
+
*/
|
|
154
|
+
export declare function Panel({ children, className, collapsedSize, collapsible, defaultSize, elementRef: elementRefProp, id: idProp, maxSize, minSize, onResize: onResizeUnstable, panelRef, style, ...rest }: PanelProps): JSX.Element;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Imperative Panel API
|
|
158
|
+
*
|
|
159
|
+
* ℹ️ The `usePanelRef` and `usePanelCallbackRef` hooks are exported for convenience use in TypeScript projects.
|
|
160
|
+
*/
|
|
161
|
+
export declare interface PanelImperativeHandle {
|
|
162
|
+
/**
|
|
163
|
+
* Collapse the Panel to it's `collapsedSize`.
|
|
164
|
+
*
|
|
165
|
+
* ⚠️ This method will do nothing if the Panel is not `collapsible` or if it is already collapsed.
|
|
166
|
+
*/
|
|
167
|
+
collapse: () => void;
|
|
168
|
+
/**
|
|
169
|
+
* Expand a collapsed Panel to its most recent size.
|
|
170
|
+
*
|
|
171
|
+
* ⚠️ This method will do nothing if the Panel is not currently collapsed.
|
|
172
|
+
*/
|
|
173
|
+
expand: () => void;
|
|
174
|
+
/**
|
|
175
|
+
* Get the current size of the Panel in pixels as well as a percentage of the parent group (0..100).
|
|
176
|
+
*
|
|
177
|
+
* @return Panel size (in pixels and as a percentage of the parent group)
|
|
178
|
+
*/
|
|
179
|
+
getSize: () => {
|
|
180
|
+
asPercentage: number;
|
|
181
|
+
inPixels: number;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* The Panel is currently collapsed.
|
|
185
|
+
*/
|
|
186
|
+
isCollapsed: () => boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Update the Panel's size.
|
|
189
|
+
*
|
|
190
|
+
* Size can be in the following formats:
|
|
191
|
+
* - Percentage of the parent Group (0..100)
|
|
192
|
+
* - Pixels
|
|
193
|
+
* - Relative font units (em, rem)
|
|
194
|
+
* - Viewport relative units (vh, vw)
|
|
195
|
+
*
|
|
196
|
+
* ℹ️ Numeric values are assumed to be pixels.
|
|
197
|
+
* Strings without explicit units are assumed to be percentages (0%..100%).
|
|
198
|
+
* Percentages may also be specified as strings ending with "%" (e.g. "33%")
|
|
199
|
+
* Pixels may also be specified as strings ending with the unit "px".
|
|
200
|
+
* Other units should be specified as strings ending with their CSS property units (e.g. 1rem, 50vh)
|
|
201
|
+
*
|
|
202
|
+
* @param size New panel size
|
|
203
|
+
* @return Applied size (after validation)
|
|
204
|
+
*/
|
|
205
|
+
resize: (size: number | string) => void;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export declare type PanelProps = HTMLAttributes<HTMLDivElement> & {
|
|
209
|
+
/**
|
|
210
|
+
* CSS class name.
|
|
211
|
+
*
|
|
212
|
+
* ⚠️ Class is applied to nested `HTMLDivElement` to avoid styles that interfere with Flex layout.
|
|
213
|
+
*/
|
|
214
|
+
className?: string | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Panel size when collapsed; defaults to 0%.
|
|
217
|
+
*/
|
|
218
|
+
collapsedSize?: number | string | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* This panel can be collapsed.
|
|
221
|
+
*
|
|
222
|
+
* ℹ️ A collapsible panel will collapse when it's size is less than of the specified `minSize`
|
|
223
|
+
*/
|
|
224
|
+
collapsible?: boolean | undefined;
|
|
225
|
+
/**
|
|
226
|
+
* Default size of Panel within its parent group; default is auto-assigned based on the total number of Panels.
|
|
227
|
+
*/
|
|
228
|
+
defaultSize?: number | string | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Ref attached to the root `HTMLDivElement`.
|
|
231
|
+
*/
|
|
232
|
+
elementRef?: Ref<HTMLDivElement> | undefined;
|
|
233
|
+
/**
|
|
234
|
+
* Uniquely identifies this panel within the parent group.
|
|
235
|
+
* Falls back to `useId` when not provided.
|
|
236
|
+
*
|
|
237
|
+
* ℹ️ This prop is used to associate persisted group layouts with the original panel.
|
|
238
|
+
*
|
|
239
|
+
* ℹ️ This value will also be assigned to the `data-panel` attribute.
|
|
240
|
+
*/
|
|
241
|
+
id?: string | number | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Maximum size of Panel within its parent group; defaults to 100%.
|
|
244
|
+
*/
|
|
245
|
+
maxSize?: number | string | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* Minimum size of Panel within its parent group; defaults to 0%.
|
|
248
|
+
*/
|
|
249
|
+
minSize?: number | string | undefined;
|
|
250
|
+
/**
|
|
251
|
+
* Called when panel sizes change.
|
|
252
|
+
*
|
|
253
|
+
* @param panelSize Panel size (both as a percentage of the parent Group and in pixels)
|
|
254
|
+
* @param id Panel id (if one was provided as a prop)
|
|
255
|
+
* @param prevPanelSize Previous panel size (will be undefined on mount)
|
|
256
|
+
*/
|
|
257
|
+
onResize?: ((panelSize: PanelSize, id: string | number | undefined, prevPanelSize: PanelSize | undefined) => void) | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Exposes the following imperative API:
|
|
260
|
+
* - `collapse(): void`
|
|
261
|
+
* - `expand(): void`
|
|
262
|
+
* - `getSize(): number`
|
|
263
|
+
* - `isCollapsed(): boolean`
|
|
264
|
+
* - `resize(size: number): void`
|
|
265
|
+
*
|
|
266
|
+
* ℹ️ The `usePanelRef` and `usePanelCallbackRef` hooks are exported for convenience use in TypeScript projects.
|
|
267
|
+
*/
|
|
268
|
+
panelRef?: Ref<PanelImperativeHandle> | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* CSS properties.
|
|
271
|
+
*
|
|
272
|
+
* ⚠️ Style is applied to nested `HTMLDivElement` to avoid styles that interfere with Flex layout.
|
|
273
|
+
*/
|
|
274
|
+
style?: CSSProperties | undefined;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export declare type PanelSize = {
|
|
278
|
+
asPercentage: number;
|
|
279
|
+
inPixels: number;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Separators are not _required_ but they are _recommended_ as they improve keyboard accessibility.
|
|
284
|
+
*
|
|
285
|
+
* Separators should be rendered as the direct child of a Group component.
|
|
286
|
+
*
|
|
287
|
+
* Separator elements always include the following attributes:
|
|
288
|
+
*
|
|
289
|
+
* ```html
|
|
290
|
+
* <div data-separator data-testid="separator-id-prop" id="separator-id-prop" role="separator">
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
|
|
294
|
+
*
|
|
295
|
+
* ℹ️ In addition to the attributes shown above, separator also renders all required [WAI-ARIA properties](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/separator_role#associated_wai-aria_roles_states_and_properties).
|
|
296
|
+
*/
|
|
297
|
+
export declare function Separator({ children, className, elementRef, id: idProp, style, ...rest }: SeparatorProps): JSX.Element;
|
|
298
|
+
|
|
299
|
+
export declare type SeparatorProps = BaseAttributes & {
|
|
300
|
+
/**
|
|
301
|
+
* CSS class name.
|
|
302
|
+
*
|
|
303
|
+
* ℹ️ Use the `data-separator` attribute for custom _hover_ and _active_ styles
|
|
304
|
+
*
|
|
305
|
+
* ⚠️ The following properties cannot be overridden: `flex-grow`, `flex-shrink`
|
|
306
|
+
*/
|
|
307
|
+
className?: string | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Ref attached to the root `HTMLDivElement`.
|
|
310
|
+
*/
|
|
311
|
+
elementRef?: Ref<HTMLDivElement> | undefined;
|
|
312
|
+
/**
|
|
313
|
+
* Uniquely identifies the separator within the parent group.
|
|
314
|
+
* Falls back to `useId` when not provided.
|
|
315
|
+
*
|
|
316
|
+
* ℹ️ This value will also be assigned to the `data-separator` attribute.
|
|
317
|
+
*/
|
|
318
|
+
id?: string | number | undefined;
|
|
319
|
+
/**
|
|
320
|
+
* CSS properties.
|
|
321
|
+
*
|
|
322
|
+
* ℹ️ Use the `data-separator` attribute for custom _hover_ and _active_ styles
|
|
323
|
+
*
|
|
324
|
+
* ⚠️ The following properties cannot be overridden: `flex-grow`, `flex-shrink`
|
|
325
|
+
*/
|
|
326
|
+
style?: CSSProperties | undefined;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
export declare type SizeUnit = "px" | "%" | "em" | "rem" | "vh" | "vw";
|
|
330
|
+
|
|
331
|
+
export declare function useDefaultLayout({ debounceSaveMs, panelIds, storage, ...rest }: {
|
|
332
|
+
/**
|
|
333
|
+
* Debounce save operation by the specified number of milliseconds; defaults to 100ms
|
|
334
|
+
*/
|
|
335
|
+
debounceSaveMs?: number;
|
|
336
|
+
/**
|
|
337
|
+
* For Groups that contain conditionally-rendered Panels, this prop can be used to save and restore multiple layouts.
|
|
338
|
+
*
|
|
339
|
+
* ⚠️ Panel ids must match the Panels rendered within the Group during mount or the initial layout will be incorrect.
|
|
340
|
+
*/
|
|
341
|
+
panelIds?: string[] | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Storage implementation; supports localStorage, sessionStorage, and custom implementations
|
|
344
|
+
* Refer to documentation site for example integrations.
|
|
345
|
+
*/
|
|
346
|
+
storage: LayoutStorage;
|
|
347
|
+
} & ({
|
|
348
|
+
/**
|
|
349
|
+
* Group id; must be unique in order for layouts to be saved separately.
|
|
350
|
+
* @deprecated Use the {@link id} param instead
|
|
351
|
+
*/
|
|
352
|
+
groupId: string;
|
|
353
|
+
} | {
|
|
354
|
+
/**
|
|
355
|
+
* Unique layout identifier.
|
|
356
|
+
*/
|
|
357
|
+
id: string;
|
|
358
|
+
})): {
|
|
359
|
+
defaultLayout: Layout | undefined;
|
|
360
|
+
onLayoutChange: (layout: Layout) => void | undefined;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Convenience hook to return a properly typed ref callback for the Group component.
|
|
365
|
+
*
|
|
366
|
+
* Use this hook when you need to share the ref with another component or hook.
|
|
367
|
+
*/
|
|
368
|
+
export declare function useGroupCallbackRef(): [GroupImperativeHandle | null, Dispatch<SetStateAction<GroupImperativeHandle | null>>];
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Convenience hook to return a properly typed ref for the Group component.
|
|
372
|
+
*/
|
|
373
|
+
export declare function useGroupRef(): RefObject<GroupImperativeHandle | null>;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Convenience hook to return a properly typed ref callback for the Panel component.
|
|
377
|
+
*
|
|
378
|
+
* Use this hook when you need to share the ref with another component or hook.
|
|
379
|
+
*/
|
|
380
|
+
export declare function usePanelCallbackRef(): [PanelImperativeHandle | null, Dispatch<SetStateAction<PanelImperativeHandle | null>>];
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Convenience hook to return a properly typed ref for the Panel component.
|
|
384
|
+
*/
|
|
385
|
+
export declare function usePanelRef(): RefObject<PanelImperativeHandle | null>;
|
|
386
|
+
|
|
387
|
+
export { }
|