react-resizable-panels 4.0.0-alpha.0 → 4.0.0-alpha.2

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.
@@ -7,31 +7,30 @@ import { Ref } from 'react';
7
7
  import { RefObject } from 'react';
8
8
  import { SetStateAction } from 'react';
9
9
 
10
- /**
11
- * Panel group direction corresponds to the `flex-direction` CSS property.
12
- * It determines how panels are are placed in the group group and the direction they can be resized in.
13
- * Horizontal corresponds to flex "row" and vertical to "column".
14
- */
15
- export declare type Direction = "horizontal" | "vertical";
16
-
17
10
  /**
18
11
  * A Group wraps a set of resizable Panel components.
19
12
  * Group content can be resized _horizontally_ or _vertically_.
20
13
  *
21
- * For unit testing purposes, Group elements always include the following data attributes:
14
+ * Group elements always include the following data attributes:
22
15
  *
23
16
  * ```html
24
- * <div data-group data-group-id="your-group-id">
17
+ * <div data-group data-testid="your-group-id">
25
18
  * ```
19
+ *
20
+ * ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
26
21
  */
27
- export declare function Group({ children, className, defaultLayout, direction, disableCursor, disabled, elementRef, groupRef, id: idProp, onLayoutChange: onLayoutChangeUnstable, style }: GroupProps): JSX.Element;
22
+ export declare function Group({ children, className, defaultLayout, disableCursor, disabled, elementRef, groupRef, id: idProp, onLayoutChange: onLayoutChangeUnstable, orientation, style }: GroupProps): JSX.Element;
28
23
 
29
24
  /**
30
25
  * Imperative Group API.
26
+ *
27
+ * ℹ️ The `useGroupRef` and `useGroupCallbackRef` hooks are exported for convenience use in TypeScript projects.
31
28
  */
32
29
  declare interface GroupImperativeHandle {
33
30
  /**
34
31
  * Get the Group's current layout as a map of Panel id to percentage (0..100)
32
+ *
33
+ * @return Map of Panel id to percentage (0..100)
35
34
  */
36
35
  getLayout: () => {
37
36
  [panelId: string]: number;
@@ -51,11 +50,11 @@ export declare type GroupProps = {
51
50
  /**
52
51
  * Panel and Separator components that comprise this group.
53
52
  */
54
- children?: ReactNode;
53
+ children?: ReactNode | undefined;
55
54
  /**
56
55
  * CSS class name.
57
56
  */
58
- className?: string;
57
+ className?: string | undefined;
59
58
  /**
60
59
  * Default layout for the Group.
61
60
  *
@@ -63,24 +62,20 @@ export declare type GroupProps = {
63
62
  *
64
63
  * ⚠️ Refer to the documentation for how to avoid layout shift when using server components.
65
64
  */
66
- defaultLayout?: Layout;
67
- /**
68
- * Specifies the resizable direction ("horizontal" or "vertical"); defaults to "horizontal"
69
- */
70
- direction?: "horizontal" | "vertical";
65
+ defaultLayout?: Layout | undefined;
71
66
  /**
72
67
  * This library sets custom mouse cursor styles to indicate drag state.
73
68
  * Use this prop to disable that behavior for Panels and Separators in this group.
74
69
  */
75
- disableCursor?: boolean;
70
+ disableCursor?: boolean | undefined;
76
71
  /**
77
72
  * Disable resize functionality.
78
73
  */
79
- disabled?: boolean;
74
+ disabled?: boolean | undefined;
80
75
  /**
81
76
  * Ref attached to the root `HTMLDivElement`.
82
77
  */
83
- elementRef?: Ref<HTMLDivElement>;
78
+ elementRef?: Ref<HTMLDivElement> | undefined;
84
79
  /**
85
80
  * Exposes the following imperative API:
86
81
  * - `getLayout(): Layout`
@@ -88,24 +83,28 @@ export declare type GroupProps = {
88
83
  *
89
84
  * ℹ️ The `useGroupRef` and `useGroupCallbackRef` hooks are exported for convenience use in TypeScript projects.
90
85
  */
91
- groupRef?: Ref<GroupImperativeHandle>;
86
+ groupRef?: Ref<GroupImperativeHandle> | undefined;
92
87
  /**
93
88
  * Uniquely identifies this group within an application.
94
89
  * Falls back to `useId` when not provided.
95
90
  *
96
- * ℹ️ This value will also be assigned to the `data-group-id` attribute.
91
+ * ℹ️ This value will also be assigned to the `data-group` attribute.
97
92
  */
98
- id?: string | number;
93
+ id?: string | number | undefined;
99
94
  /**
100
95
  * Called when panel sizes change; receives a map of Panel id to size.
101
96
  */
102
- onLayoutChange?: (layout: Layout) => void;
97
+ onLayoutChange?: (layout: Layout) => void | undefined;
98
+ /**
99
+ * Specifies the resizable orientation ("horizontal" or "vertical"); defaults to "horizontal"
100
+ */
101
+ orientation?: "horizontal" | "vertical" | undefined;
103
102
  /**
104
103
  * CSS properties.
105
104
  *
106
105
  * ⚠️ The following styles cannot be overridden: `display`, `flex-direction`, `flex-wrap`, and `overflow`.
107
106
  */
108
- style?: CSSProperties;
107
+ style?: CSSProperties | undefined;
109
108
  };
110
109
 
111
110
  /**
@@ -115,10 +114,18 @@ export declare type Layout = {
115
114
  [id: string]: number;
116
115
  };
117
116
 
117
+ export declare type LayoutStorage = Pick<Storage, "getItem" | "setItem">;
118
+
118
119
  export declare type OnGroupLayoutChange = GroupProps["onLayoutChange"];
119
120
 
120
121
  export declare type OnPanelResize = PanelProps["onResize"];
121
122
 
123
+ /**
124
+ * Panel group orientation loosely relates to the `aria-orientation` attribute.
125
+ * It determines how panels are are laid out within the group group and the direction they can be resized in.
126
+ */
127
+ export declare type Orientation = "horizontal" | "vertical";
128
+
122
129
  /**
123
130
  * A Panel wraps resizable content and can be configured with min/max size constraints and collapsible behavior.
124
131
  *
@@ -128,30 +135,38 @@ export declare type OnPanelResize = PanelProps["onResize"];
128
135
  * - Font sizes (em, rem)
129
136
  * - Viewport sizes (vh, vw)
130
137
  *
131
- * For unit testing purposes, Panel elements always include the following data attributes:
138
+ * Panel elements always include the following data attributes:
132
139
  *
133
140
  * ```html
134
- * <div data-panel data-panel-id="your-panel-id">
141
+ * <div data-panel data-testid="your-panel-id">
135
142
  * ```
143
+ *
144
+ * ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
136
145
  */
137
146
  export declare function Panel({ children, className, collapsedSize, collapsible, defaultSize, elementRef, id: idProp, maxSize, minSize, onResize: onResizeUnstable, panelRef, style }: PanelProps): JSX.Element;
138
147
 
139
148
  /**
140
149
  * Imperative Panel API
150
+ *
151
+ * ℹ️ The `usePanelRef` and `usePanelCallbackRef` hooks are exported for convenience use in TypeScript projects.
141
152
  */
142
153
  declare interface PanelImperativeHandle {
143
154
  /**
144
155
  * Collapse the Panel to it's `collapsedSize`.
145
- * This method will do nothing if the Panel is not `collapsible` or if it is already collapsed.
156
+ *
157
+ * ⚠️ This method will do nothing if the Panel is not `collapsible` or if it is already collapsed.
146
158
  */
147
159
  collapse: () => void;
148
160
  /**
149
161
  * Expand a collapsed Panel to its most recent size.
150
- * This method will do nothing if the Panel is not currently collapsed.
162
+ *
163
+ * ⚠️ This method will do nothing if the Panel is not currently collapsed.
151
164
  */
152
165
  expand: () => void;
153
166
  /**
154
167
  * Get the current size of the Panel in pixels as well as a percentage of the parent group (0..100).
168
+ *
169
+ * @return Panel size (in pixels and as a percentage of the parent group)
155
170
  */
156
171
  getSize: () => PanelSize;
157
172
  /**
@@ -160,7 +175,11 @@ declare interface PanelImperativeHandle {
160
175
  isCollapsed: () => boolean;
161
176
  /**
162
177
  * Update the Panel's size.
163
- * Size may be specified in pixel format (number) or as a percentage (string).
178
+ *
179
+ * ℹ️ Size may be specified in pixel format (number) or as a percentage (string).
180
+ *
181
+ * @param size New panel size
182
+ * @return Applied size (after validation)
164
183
  */
165
184
  resize: (size: number | string) => void;
166
185
  }
@@ -171,46 +190,46 @@ export declare type PanelProps = PropsWithChildren<{
171
190
  *
172
191
  * ⚠️ Class is applied to nested `HTMLDivElement` to avoid styles that interfere with Flex layout.
173
192
  */
174
- className?: string;
193
+ className?: string | undefined;
175
194
  /**
176
195
  * Panel size when collapsed; defaults to 0.
177
196
  */
178
- collapsedSize?: number | string;
197
+ collapsedSize?: number | string | undefined;
179
198
  /**
180
199
  * This panel can be collapsed.
181
200
  *
182
201
  * ℹ️ A collapsible panel will collapse when it's size is less than of the specified `minSize`
183
202
  */
184
- collapsible?: boolean;
203
+ collapsible?: boolean | undefined;
185
204
  /**
186
205
  * Default size of Panel within its parent group; default is auto-assigned based on the total number of Panels.
187
206
  */
188
- defaultSize?: number | string;
207
+ defaultSize?: number | string | undefined;
189
208
  /**
190
209
  * Ref attached to the root `HTMLDivElement`.
191
210
  */
192
- elementRef?: Ref<HTMLDivElement>;
211
+ elementRef?: Ref<HTMLDivElement> | undefined;
193
212
  /**
194
213
  * Uniquely identifies this panel within the parent group.
195
214
  * Falls back to `useId` when not provided.
196
215
  *
197
216
  * ℹ️ This prop is used to associate persisted group layouts with the original panel.
198
217
  *
199
- * ℹ️ This value will also be assigned to the `data-panel-id` attribute.
218
+ * ℹ️ This value will also be assigned to the `data-panel` attribute.
200
219
  */
201
- id?: string | number;
220
+ id?: string | number | undefined;
202
221
  /**
203
222
  * Maximum size of Panel within its parent group; defaults to 100%.
204
223
  */
205
- maxSize?: number | string;
224
+ maxSize?: number | string | undefined;
206
225
  /**
207
226
  * Minimum size of Panel within its parent group; defaults to 0%.
208
227
  */
209
- minSize?: number | string;
228
+ minSize?: number | string | undefined;
210
229
  /**
211
230
  * Called when panel sizes change; receives a map of Panel id to size.
212
231
  */
213
- onResize?: (panelSize: PanelSize) => void;
232
+ onResize?: ((panelSize: PanelSize, id: string | number | undefined) => void) | undefined;
214
233
  /**
215
234
  * Exposes the following imperative API:
216
235
  * - `collapse(): void`
@@ -222,13 +241,13 @@ export declare type PanelProps = PropsWithChildren<{
222
241
  *
223
242
  * ℹ️ The `usePanelRef` and `usePanelCallbackRef` hooks are exported for convenience use in TypeScript projects.
224
243
  */
225
- panelRef?: Ref<PanelImperativeHandle>;
244
+ panelRef?: Ref<PanelImperativeHandle> | undefined;
226
245
  /**
227
246
  * CSS properties.
228
247
  *
229
248
  * ⚠️ Style is applied to nested `HTMLDivElement` to avoid styles that interfere with Flex layout.
230
249
  */
231
- style?: CSSProperties;
250
+ style?: CSSProperties | undefined;
232
251
  }>;
233
252
 
234
253
  export declare type PanelSize = {
@@ -241,11 +260,13 @@ export declare type PanelSize = {
241
260
  *
242
261
  * Separators should be rendered as the direct child of a Group component.
243
262
  *
244
- * For unit testing purposes, Separator elements always include the following data attributes:
263
+ * Separator elements always include the following data attributes and role:
245
264
  *
246
265
  * ```html
247
- * <div data-separator data-separator-id="your-separator-id" />
266
+ * <div data-separator data-testid="your-separator-id" role="separator" />
248
267
  * ```
268
+ *
269
+ * ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
249
270
  */
250
271
  export declare function Separator({ children, className, elementRef, id: idProp, style }: SeparatorProps): JSX.Element;
251
272
 
@@ -253,40 +274,40 @@ export declare type SeparatorProps = PropsWithChildren<{
253
274
  /**
254
275
  * CSS class name.
255
276
  *
256
- * ℹ️ Use the `data-separator-state` attribute for custom _hover_ and _active_ styles
277
+ * ℹ️ Use the `data-separator` attribute for custom _hover_ and _active_ styles
257
278
  *
258
279
  * ⚠️ The following properties cannot be overridden: `flex-grow`, `flex-shrink`
259
280
  */
260
- className?: string;
281
+ className?: string | undefined;
261
282
  /**
262
283
  * Ref attached to the root `HTMLDivElement`.
263
284
  */
264
- elementRef?: Ref<HTMLDivElement>;
285
+ elementRef?: Ref<HTMLDivElement> | undefined;
265
286
  /**
266
287
  * Uniquely identifies the separator within the parent group.
267
288
  * Falls back to `useId` when not provided.
268
289
  *
269
- * ℹ️ This value will also be assigned to the `data-separator-id` attribute.
290
+ * ℹ️ This value will also be assigned to the `data-separator` attribute.
270
291
  */
271
- id?: string | number;
292
+ id?: string | number | undefined;
272
293
  /**
273
294
  * CSS properties.
274
295
  *
275
- * ℹ️ Use the `data-separator-state` attribute for custom _hover_ and _active_ styles
296
+ * ℹ️ Use the `data-separator` attribute for custom _hover_ and _active_ styles
276
297
  *
277
298
  * ⚠️ The following properties cannot be overridden: `flex-grow`, `flex-shrink`
278
299
  */
279
- style?: CSSProperties;
300
+ style?: CSSProperties | undefined;
280
301
  }>;
281
302
 
282
303
  export declare type SizeUnit = "px" | "%" | "em" | "rem" | "vh" | "vw";
283
304
 
284
305
  export declare function useDefaultLayout({ groupId, storage }: {
285
306
  groupId: string;
286
- storage?: Pick<Storage, "getItem" | "setItem">;
307
+ storage: LayoutStorage;
287
308
  }): {
288
- defaultLayout: Layout | undefined;
289
- onLayoutChange: (layout: Layout) => void;
309
+ defaultLayout: any;
310
+ onLayoutChange: (layout: Layout) => void | undefined;
290
311
  };
291
312
 
292
313
  /**