forked from bvaughn/react-resizable-panels
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
221 lines (196 loc) · 6.13 KB
/
types.ts
File metadata and controls
221 lines (196 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import type { CSSProperties, HTMLAttributes, Ref } from "react";
export type PanelSize = {
asPercentage: number;
inPixels: number;
};
/**
* Numeric Panel constraints are represented as numeric percentages (0..100)
* Values specified using other CSS units must be pre-converted.
*/
export type PanelConstraints = {
autoResize?: boolean;
collapsedSize: number;
collapsible: boolean;
defaultSize: number | undefined;
disabled: boolean | undefined;
maxSize: number;
minSize: number;
panelId: string;
};
export type SizeUnit = "px" | "%" | "em" | "rem" | "vh" | "vw";
export type RegisteredPanel = {
id: string;
idIsStable: boolean;
element: HTMLDivElement;
mutableValues: {
expandToSize: number | undefined;
prevSize: PanelSize | undefined;
};
onResize: OnPanelResize | undefined;
panelConstraints: PanelConstraintProps;
};
/**
* Imperative Panel API
*
* ℹ️ The `usePanelRef` and `usePanelCallbackRef` hooks are exported for convenience use in TypeScript projects.
*/
export interface PanelImperativeHandle {
/**
* Collapse the Panel to it's `collapsedSize`.
*
* ⚠️ This method will do nothing if the Panel is not `collapsible` or if it is already collapsed.
*/
collapse: () => void;
/**
* Expand a collapsed Panel to its most recent size.
*
* ⚠️ This method will do nothing if the Panel is not currently collapsed.
*/
expand: () => void;
/**
* Get the current size of the Panel in pixels as well as a percentage of the parent group (0..100).
*
* @return Panel size (in pixels and as a percentage of the parent group)
*/
getSize: () => {
asPercentage: number;
inPixels: number;
};
/**
* The Panel is currently collapsed.
*/
isCollapsed: () => boolean;
/**
* Update the Panel's size.
*
* Size can be in the following formats:
* - Percentage of the parent Group (0..100)
* - Pixels
* - Relative font units (em, rem)
* - Viewport relative units (vh, vw)
*
* ℹ️ Numeric values are assumed to be pixels.
* Strings without explicit units are assumed to be percentages (0%..100%).
* Percentages may also be specified as strings ending with "%" (e.g. "33%")
* Pixels may also be specified as strings ending with the unit "px".
* Other units should be specified as strings ending with their CSS property units (e.g. 1rem, 50vh)
*
* @param size New panel size
* @return Applied size (after validation)
*/
resize: (size: number | string) => void;
}
type BasePanelAttributes = Omit<HTMLAttributes<HTMLDivElement>, "onResize">;
export type PanelProps = BasePanelAttributes & {
/**
* Whether this panel should resize automatically when the Group size changes.
*
* Defaults to true.
*
* Set to false to keep this panel's pixel size stable on window/container resize,
* while sibling panels absorb the remaining delta.
*/
autoResize?: boolean | undefined;
/**
* CSS class name.
*
* ⚠️ Class is applied to nested `HTMLDivElement` to avoid styles that interfere with Flex layout.
*/
className?: string | undefined;
/**
* Panel size when collapsed; defaults to 0%.
*/
collapsedSize?: number | string | undefined;
/**
* This panel can be collapsed.
*
* ℹ️ A collapsible panel will collapse when it's size is less than of the specified `minSize`
*/
collapsible?: boolean | undefined;
/**
* Default size of Panel within its parent group; default is auto-assigned based on the total number of Panels.
*/
defaultSize?: number | string | undefined;
/**
* When disabled, a panel cannot be resized either directly or indirectly (by resizing another panel).
*/
disabled?: boolean | undefined;
/**
* Ref attached to the root `HTMLDivElement`.
*/
elementRef?: Ref<HTMLDivElement | null> | undefined;
/**
* Uniquely identifies this panel within the parent group.
* Falls back to `useId` when not provided.
*
* ℹ️ This prop is used to associate persisted group layouts with the original panel.
*
* ℹ️ This value will also be assigned to the `data-panel` attribute.
*/
id?: string | number | undefined;
/**
* Maximum size of Panel within its parent group; defaults to 100%.
*/
maxSize?: number | string | undefined;
/**
* Minimum size of Panel within its parent group; defaults to 0%.
*/
minSize?: number | string | undefined;
/**
* Called when panel sizes change.
*
* @param panelSize Panel size (both as a percentage of the parent Group and in pixels)
* @param id Panel id (if one was provided as a prop)
* @param prevPanelSize Previous panel size (will be undefined on mount)
*/
onResize?:
| ((
panelSize: PanelSize,
id: string | number | undefined,
prevPanelSize: PanelSize | undefined
) => void)
| undefined;
/**
* Exposes the following imperative API:
* - `collapse(): void`
* - `expand(): void`
* - `getSize(): number`
* - `isCollapsed(): boolean`
* - `resize(size: number): void`
*
* ℹ️ The `usePanelRef` and `usePanelCallbackRef` hooks are exported for convenience use in TypeScript projects.
*/
panelRef?: Ref<PanelImperativeHandle | null> | undefined;
/**
* CSS properties.
*
* ⚠️ Style is applied to nested `HTMLDivElement` to avoid styles that interfere with Flex layout.
*/
style?: CSSProperties | undefined;
};
export type OnPanelResize = PanelProps["onResize"];
/**
* Size constraints may be specified in a variety of ways:
* - Percentage of the parent Group (0..100)
* - Pixels
* - Relative font units (em, rem)
* - Viewport relative units (vh, vw)
*
* Numeric values are assumed to be pixels.
* Strings without explicit units are assumed to be percentages (0%..100%).
*
* Percentages may also be specified as strings ending with "%" (e.g. "33%")
* Pixels may also be specified as strings ending with the unit "px".
*
* Other units should be specified as strings ending with their CSS property units (e.g. 1rem, 50vh)
*/
export type PanelConstraintProps = Pick<
PanelProps,
| "collapsedSize"
| "collapsible"
| "autoResize"
| "defaultSize"
| "disabled"
| "maxSize"
| "minSize"
>;