react-resizable-panels 1.0.6 → 1.0.7

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +20 -4
  3. package/dist/declarations/src/Panel.d.ts +7 -7
  4. package/dist/declarations/src/PanelGroup.d.ts +6 -6
  5. package/dist/declarations/src/PanelResizeHandle.d.ts +4 -4
  6. package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -1
  7. package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -1
  8. package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -1
  9. package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -1
  10. package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -1
  11. package/dist/react-resizable-panels.browser.cjs.js +8 -8
  12. package/dist/react-resizable-panels.browser.development.cjs.js +8 -8
  13. package/dist/react-resizable-panels.browser.development.esm.js +8 -8
  14. package/dist/react-resizable-panels.browser.esm.js +8 -8
  15. package/dist/react-resizable-panels.cjs.js +8 -8
  16. package/dist/react-resizable-panels.development.cjs.js +8 -8
  17. package/dist/react-resizable-panels.development.esm.js +8 -8
  18. package/dist/react-resizable-panels.development.node.cjs.js +8 -8
  19. package/dist/react-resizable-panels.development.node.esm.js +8 -8
  20. package/dist/react-resizable-panels.esm.js +8 -8
  21. package/dist/react-resizable-panels.node.cjs.js +8 -8
  22. package/dist/react-resizable-panels.node.esm.js +8 -8
  23. package/package.json +1 -1
  24. package/src/Panel.ts +7 -4
  25. package/src/PanelGroup.ts +7 -4
  26. package/src/PanelResizeHandle.ts +15 -12
  27. package/src/hooks/useWindowSplitterBehavior.ts +1 -1
  28. package/src/utils/dom/getPanelElement.ts +2 -2
  29. package/src/utils/dom/getPanelElementsForGroup.ts +1 -1
  30. package/src/utils/dom/getPanelGroupElement.ts +2 -2
  31. package/src/utils/dom/getResizeHandleElement.ts +2 -2
  32. package/src/utils/dom/getResizeHandleElementsForGroup.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.7
4
+
5
+ - Narrow `tagName` prop to only allow `HTMLElement` names (rather than the broader `Element` type) (#251)
6
+
3
7
  ## 1.0.6
4
8
 
5
9
  - Export internal DOM helper methods.
package/README.md CHANGED
@@ -46,7 +46,9 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
46
46
  `PanelGroup` components also expose an imperative API for manual resizing:
47
47
  | method | description
48
48
  | :-------------------------------- | :---
49
- | `setLayout(panelSizes: number[])` | Resize panel group to the specified _panelSizes_ (`[1 - 100, ...]`).
49
+ | `getId(): string` | Gets the panel group's ID.
50
+ | `getLayout(): number[]` | Gets the panel group's current _layout_ (`[1 - 100, ...]`).
51
+ | `setLayout(layout: number[])` | Resize panel group to the specified _layout_ (`[1 - 100, ...]`).
50
52
 
51
53
  ### `Panel`
52
54
 
@@ -73,9 +75,12 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
73
75
  | :--------------------------- | :---
74
76
  | `collapse()` | If panel is `collapsible`, collapse it fully.
75
77
  | `expand()` | If panel is currently _collapsed_, expand it to its most recent size.
76
- | `getCollapsed(): boolean` | Returns `true` if the panel is currently _collapsed_ (`size === 0`).
78
+ | `getId(): string` | Gets the ID of the panel.
79
+ | `getSize(): number` | Gets the current size of the panel as a percentage (`1 - 100`).
80
+ | `isCollapsed(): boolean` | Returns `true` if the panel is currently _collapsed_ (`size === 0`).
81
+ | `isExpanded(): boolean` | Returns `true` if the panel is currently _not collapsed_ (`!isCollapsed()`).
77
82
  | `getSize(): number` | Returns the most recently commited size of the panel as a percentage (`1 - 100`).
78
- | `resize(percentage: number)` | Resize panel to the specified _percentage_ (`1 - 100`).
83
+ | `resize(size: number)` | Resize panel to the specified _percentage_ (`1 - 100`).
79
84
 
80
85
  ### `PanelResizeHandle`
81
86
 
@@ -178,6 +183,15 @@ No. Pixel-based constraints [added significant complexity](https://github.com/bv
178
183
  No. I think exposing two refs (one for the component's imperative API and one for a DOM element) would be awkward. This library does export several utility methods for accessing the underlying DOM elements though. For example:
179
184
 
180
185
  ```tsx
186
+ import {
187
+ getPanelElement,
188
+ getPanelGroupElement,
189
+ getResizeHandleElement,
190
+ Panel,
191
+ PanelGroup,
192
+ PanelResizeHandle,
193
+ } from "react-resizable-panels";
194
+
181
195
  export function Example() {
182
196
  const refs = useRef();
183
197
 
@@ -185,19 +199,21 @@ export function Example() {
185
199
  const groupElement = getPanelGroupElement("group");
186
200
  const leftPanelElement = getPanelElement("left-panel");
187
201
  const rightPanelElement = getPanelElement("right-panel");
202
+ const resizeHandleElement = getResizeHandleElement("resize-handle");
188
203
 
189
204
  // If you want to, you can store them in a ref to pass around
190
205
  refs.current = {
191
206
  groupElement,
192
207
  leftPanelElement,
193
208
  rightPanelElement,
209
+ resizeHandleElement,
194
210
  };
195
211
  }, []);
196
212
 
197
213
  return (
198
214
  <PanelGroup direction="horizontal" id="group">
199
215
  <Panel id="left-panel">{/* ... */}</Panel>
200
- <PanelResizeHandle />
216
+ <PanelResizeHandle id="resize-handle" />
201
217
  <Panel id="right-panel">{/* ... */}</Panel>
202
218
  </PanelGroup>
203
219
  );
@@ -1,4 +1,4 @@
1
- import { ElementType, ForwardedRef, HTMLAttributes, PropsWithChildren } from "./vendor/react.js";
1
+ import { ForwardedRef, HTMLAttributes, PropsWithChildren, ReactNode } from "./vendor/react.js";
2
2
  export type PanelOnCollapse = () => void;
3
3
  export type PanelOnExpand = () => void;
4
4
  export type PanelOnResize = (size: number, prevSize: number | undefined) => void;
@@ -30,7 +30,7 @@ export type ImperativePanelHandle = {
30
30
  isExpanded: () => boolean;
31
31
  resize: (size: number) => void;
32
32
  };
33
- export type PanelProps = Omit<HTMLAttributes<ElementType>, "id" | "onResize"> & PropsWithChildren<{
33
+ export type PanelProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id" | "onResize"> & PropsWithChildren<{
34
34
  className?: string;
35
35
  collapsedSize?: number | undefined;
36
36
  collapsible?: boolean | undefined;
@@ -43,15 +43,15 @@ export type PanelProps = Omit<HTMLAttributes<ElementType>, "id" | "onResize"> &
43
43
  onResize?: PanelOnResize;
44
44
  order?: number;
45
45
  style?: object;
46
- tagName?: ElementType;
46
+ tagName?: keyof HTMLElementTagNameMap;
47
47
  }>;
48
48
  export declare function PanelWithForwardedRef({ children, className: classNameFromProps, collapsedSize, collapsible, defaultSize, forwardedRef, id: idFromProps, maxSize, minSize, onCollapse, onExpand, onResize, order, style: styleFromProps, tagName: Type, ...rest }: PanelProps & {
49
49
  forwardedRef: ForwardedRef<ImperativePanelHandle>;
50
- }): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
50
+ }): ReactNode;
51
51
  export declare namespace PanelWithForwardedRef {
52
52
  var displayName: string;
53
53
  }
54
- export declare const Panel: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<ElementType>, "id" | "onResize"> & {
54
+ export declare const Panel: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id" | "onResize"> & {
55
55
  className?: string | undefined;
56
56
  collapsedSize?: number | undefined;
57
57
  collapsible?: boolean | undefined;
@@ -64,7 +64,7 @@ export declare const Panel: import("react").ForwardRefExoticComponent<Omit<HTMLA
64
64
  onResize?: PanelOnResize | undefined;
65
65
  order?: number | undefined;
66
66
  style?: object | undefined;
67
- tagName?: ElementType | undefined;
67
+ tagName?: keyof HTMLElementTagNameMap | undefined;
68
68
  } & {
69
- children?: import("react").ReactNode;
69
+ children?: ReactNode;
70
70
  } & import("react").RefAttributes<ImperativePanelHandle>>;
@@ -1,5 +1,5 @@
1
1
  import { Direction } from "./types.js";
2
- import { CSSProperties, ElementType, HTMLAttributes, PropsWithChildren } from "./vendor/react.js";
2
+ import { CSSProperties, HTMLAttributes, PropsWithChildren, ReactNode } from "./vendor/react.js";
3
3
  export type ImperativePanelGroupHandle = {
4
4
  getId: () => string;
5
5
  getLayout: () => number[];
@@ -10,7 +10,7 @@ export type PanelGroupStorage = {
10
10
  setItem(name: string, value: string): void;
11
11
  };
12
12
  export type PanelGroupOnLayout = (layout: number[]) => void;
13
- export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> & PropsWithChildren<{
13
+ export type PanelGroupProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"> & PropsWithChildren<{
14
14
  autoSaveId?: string | null;
15
15
  className?: string;
16
16
  direction: Direction;
@@ -19,9 +19,9 @@ export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> & PropsWit
19
19
  onLayout?: PanelGroupOnLayout | null;
20
20
  storage?: PanelGroupStorage;
21
21
  style?: CSSProperties;
22
- tagName?: ElementType;
22
+ tagName?: keyof HTMLElementTagNameMap;
23
23
  }>;
24
- export declare const PanelGroup: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<ElementType>, "id"> & {
24
+ export declare const PanelGroup: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"> & {
25
25
  autoSaveId?: string | null | undefined;
26
26
  className?: string | undefined;
27
27
  direction: Direction;
@@ -30,7 +30,7 @@ export declare const PanelGroup: import("react").ForwardRefExoticComponent<Omit<
30
30
  onLayout?: PanelGroupOnLayout | null | undefined;
31
31
  storage?: PanelGroupStorage | undefined;
32
32
  style?: CSSProperties | undefined;
33
- tagName?: ElementType | undefined;
33
+ tagName?: keyof HTMLElementTagNameMap | undefined;
34
34
  } & {
35
- children?: import("react").ReactNode;
35
+ children?: ReactNode;
36
36
  } & import("react").RefAttributes<ImperativePanelGroupHandle>>;
@@ -1,15 +1,15 @@
1
- import { CSSProperties, ElementType, HTMLAttributes, PropsWithChildren } from "./vendor/react.js";
1
+ import { CSSProperties, HTMLAttributes, PropsWithChildren, ReactNode } from "./vendor/react.js";
2
2
  export type PanelResizeHandleOnDragging = (isDragging: boolean) => void;
3
- export type PanelResizeHandleProps = Omit<HTMLAttributes<ElementType>, "id"> & PropsWithChildren<{
3
+ export type PanelResizeHandleProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"> & PropsWithChildren<{
4
4
  className?: string;
5
5
  disabled?: boolean;
6
6
  id?: string | null;
7
7
  onDragging?: PanelResizeHandleOnDragging;
8
8
  style?: CSSProperties;
9
9
  tabIndex?: number;
10
- tagName?: ElementType;
10
+ tagName?: keyof HTMLElementTagNameMap;
11
11
  }>;
12
- export declare function PanelResizeHandle({ children, className: classNameFromProps, disabled, id: idFromProps, onDragging, style: styleFromProps, tabIndex, tagName: Type, ...rest }: PanelResizeHandleProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
12
+ export declare function PanelResizeHandle({ children, className: classNameFromProps, disabled, id: idFromProps, onDragging, style: styleFromProps, tabIndex, tagName: Type, ...rest }: PanelResizeHandleProps): ReactNode;
13
13
  export declare namespace PanelResizeHandle {
14
14
  var displayName: string;
15
15
  }
@@ -1 +1 @@
1
- export declare function getPanelElement(id: string): HTMLDivElement | null;
1
+ export declare function getPanelElement(id: string): HTMLElement | null;
@@ -1 +1 @@
1
- export declare function getPanelElementsForGroup(groupId: string): HTMLDivElement[];
1
+ export declare function getPanelElementsForGroup(groupId: string): HTMLElement[];
@@ -1 +1 @@
1
- export declare function getPanelGroupElement(id: string): HTMLDivElement | null;
1
+ export declare function getPanelGroupElement(id: string): HTMLElement | null;
@@ -1 +1 @@
1
- export declare function getResizeHandleElement(id: string): HTMLDivElement | null;
1
+ export declare function getResizeHandleElement(id: string): HTMLElement | null;
@@ -1 +1 @@
1
- export declare function getResizeHandleElementsForGroup(groupId: string): HTMLDivElement[];
1
+ export declare function getResizeHandleElementsForGroup(groupId: string): HTMLElement[];
@@ -1689,7 +1689,7 @@ function PanelResizeHandle({
1689
1689
  tagName: Type = "div",
1690
1690
  ...rest
1691
1691
  }) {
1692
- const divElementRef = useRef(null);
1692
+ const elementRef = useRef(null);
1693
1693
 
1694
1694
  // Use a ref to guard against users passing inline props
1695
1695
  const callbacksRef = useRef({
@@ -1717,9 +1717,9 @@ function PanelResizeHandle({
1717
1717
  const stopDraggingAndBlur = useCallback(() => {
1718
1718
  // Clicking on the drag handle shouldn't leave it focused;
1719
1719
  // That would cause the PanelGroup to think it was still active.
1720
- const divElement = divElementRef.current;
1721
- assert(divElement);
1722
- divElement.blur();
1720
+ const element = elementRef.current;
1721
+ assert(element);
1722
+ element.blur();
1723
1723
  stopDragging();
1724
1724
  const {
1725
1725
  onDragging
@@ -1746,9 +1746,9 @@ function PanelResizeHandle({
1746
1746
  const onMouseLeave = event => {
1747
1747
  resizeHandler(event);
1748
1748
  };
1749
- const divElement = divElementRef.current;
1750
- assert(divElement);
1751
- const targetDocument = divElement.ownerDocument;
1749
+ const element = elementRef.current;
1750
+ assert(element);
1751
+ const targetDocument = element.ownerDocument;
1752
1752
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1753
1753
  targetDocument.body.addEventListener("mousemove", onMove);
1754
1754
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1805,7 +1805,7 @@ function PanelResizeHandle({
1805
1805
  onDragging(true);
1806
1806
  }
1807
1807
  },
1808
- ref: divElementRef,
1808
+ ref: elementRef,
1809
1809
  role: "separator",
1810
1810
  style: {
1811
1811
  ...style,
@@ -1794,7 +1794,7 @@ function PanelResizeHandle({
1794
1794
  tagName: Type = "div",
1795
1795
  ...rest
1796
1796
  }) {
1797
- const divElementRef = useRef(null);
1797
+ const elementRef = useRef(null);
1798
1798
 
1799
1799
  // Use a ref to guard against users passing inline props
1800
1800
  const callbacksRef = useRef({
@@ -1822,9 +1822,9 @@ function PanelResizeHandle({
1822
1822
  const stopDraggingAndBlur = useCallback(() => {
1823
1823
  // Clicking on the drag handle shouldn't leave it focused;
1824
1824
  // That would cause the PanelGroup to think it was still active.
1825
- const divElement = divElementRef.current;
1826
- assert(divElement);
1827
- divElement.blur();
1825
+ const element = elementRef.current;
1826
+ assert(element);
1827
+ element.blur();
1828
1828
  stopDragging();
1829
1829
  const {
1830
1830
  onDragging
@@ -1851,9 +1851,9 @@ function PanelResizeHandle({
1851
1851
  const onMouseLeave = event => {
1852
1852
  resizeHandler(event);
1853
1853
  };
1854
- const divElement = divElementRef.current;
1855
- assert(divElement);
1856
- const targetDocument = divElement.ownerDocument;
1854
+ const element = elementRef.current;
1855
+ assert(element);
1856
+ const targetDocument = element.ownerDocument;
1857
1857
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1858
1858
  targetDocument.body.addEventListener("mousemove", onMove);
1859
1859
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1910,7 +1910,7 @@ function PanelResizeHandle({
1910
1910
  onDragging(true);
1911
1911
  }
1912
1912
  },
1913
- ref: divElementRef,
1913
+ ref: elementRef,
1914
1914
  role: "separator",
1915
1915
  style: {
1916
1916
  ...style,
@@ -1770,7 +1770,7 @@ function PanelResizeHandle({
1770
1770
  tagName: Type = "div",
1771
1771
  ...rest
1772
1772
  }) {
1773
- const divElementRef = useRef(null);
1773
+ const elementRef = useRef(null);
1774
1774
 
1775
1775
  // Use a ref to guard against users passing inline props
1776
1776
  const callbacksRef = useRef({
@@ -1798,9 +1798,9 @@ function PanelResizeHandle({
1798
1798
  const stopDraggingAndBlur = useCallback(() => {
1799
1799
  // Clicking on the drag handle shouldn't leave it focused;
1800
1800
  // That would cause the PanelGroup to think it was still active.
1801
- const divElement = divElementRef.current;
1802
- assert(divElement);
1803
- divElement.blur();
1801
+ const element = elementRef.current;
1802
+ assert(element);
1803
+ element.blur();
1804
1804
  stopDragging();
1805
1805
  const {
1806
1806
  onDragging
@@ -1827,9 +1827,9 @@ function PanelResizeHandle({
1827
1827
  const onMouseLeave = event => {
1828
1828
  resizeHandler(event);
1829
1829
  };
1830
- const divElement = divElementRef.current;
1831
- assert(divElement);
1832
- const targetDocument = divElement.ownerDocument;
1830
+ const element = elementRef.current;
1831
+ assert(element);
1832
+ const targetDocument = element.ownerDocument;
1833
1833
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1834
1834
  targetDocument.body.addEventListener("mousemove", onMove);
1835
1835
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1886,7 +1886,7 @@ function PanelResizeHandle({
1886
1886
  onDragging(true);
1887
1887
  }
1888
1888
  },
1889
- ref: divElementRef,
1889
+ ref: elementRef,
1890
1890
  role: "separator",
1891
1891
  style: {
1892
1892
  ...style,
@@ -1665,7 +1665,7 @@ function PanelResizeHandle({
1665
1665
  tagName: Type = "div",
1666
1666
  ...rest
1667
1667
  }) {
1668
- const divElementRef = useRef(null);
1668
+ const elementRef = useRef(null);
1669
1669
 
1670
1670
  // Use a ref to guard against users passing inline props
1671
1671
  const callbacksRef = useRef({
@@ -1693,9 +1693,9 @@ function PanelResizeHandle({
1693
1693
  const stopDraggingAndBlur = useCallback(() => {
1694
1694
  // Clicking on the drag handle shouldn't leave it focused;
1695
1695
  // That would cause the PanelGroup to think it was still active.
1696
- const divElement = divElementRef.current;
1697
- assert(divElement);
1698
- divElement.blur();
1696
+ const element = elementRef.current;
1697
+ assert(element);
1698
+ element.blur();
1699
1699
  stopDragging();
1700
1700
  const {
1701
1701
  onDragging
@@ -1722,9 +1722,9 @@ function PanelResizeHandle({
1722
1722
  const onMouseLeave = event => {
1723
1723
  resizeHandler(event);
1724
1724
  };
1725
- const divElement = divElementRef.current;
1726
- assert(divElement);
1727
- const targetDocument = divElement.ownerDocument;
1725
+ const element = elementRef.current;
1726
+ assert(element);
1727
+ const targetDocument = element.ownerDocument;
1728
1728
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1729
1729
  targetDocument.body.addEventListener("mousemove", onMove);
1730
1730
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1781,7 +1781,7 @@ function PanelResizeHandle({
1781
1781
  onDragging(true);
1782
1782
  }
1783
1783
  },
1784
- ref: divElementRef,
1784
+ ref: elementRef,
1785
1785
  role: "separator",
1786
1786
  style: {
1787
1787
  ...style,
@@ -1691,7 +1691,7 @@ function PanelResizeHandle({
1691
1691
  tagName: Type = "div",
1692
1692
  ...rest
1693
1693
  }) {
1694
- const divElementRef = useRef(null);
1694
+ const elementRef = useRef(null);
1695
1695
 
1696
1696
  // Use a ref to guard against users passing inline props
1697
1697
  const callbacksRef = useRef({
@@ -1719,9 +1719,9 @@ function PanelResizeHandle({
1719
1719
  const stopDraggingAndBlur = useCallback(() => {
1720
1720
  // Clicking on the drag handle shouldn't leave it focused;
1721
1721
  // That would cause the PanelGroup to think it was still active.
1722
- const divElement = divElementRef.current;
1723
- assert(divElement);
1724
- divElement.blur();
1722
+ const element = elementRef.current;
1723
+ assert(element);
1724
+ element.blur();
1725
1725
  stopDragging();
1726
1726
  const {
1727
1727
  onDragging
@@ -1748,9 +1748,9 @@ function PanelResizeHandle({
1748
1748
  const onMouseLeave = event => {
1749
1749
  resizeHandler(event);
1750
1750
  };
1751
- const divElement = divElementRef.current;
1752
- assert(divElement);
1753
- const targetDocument = divElement.ownerDocument;
1751
+ const element = elementRef.current;
1752
+ assert(element);
1753
+ const targetDocument = element.ownerDocument;
1754
1754
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1755
1755
  targetDocument.body.addEventListener("mousemove", onMove);
1756
1756
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1807,7 +1807,7 @@ function PanelResizeHandle({
1807
1807
  onDragging(true);
1808
1808
  }
1809
1809
  },
1810
- ref: divElementRef,
1810
+ ref: elementRef,
1811
1811
  role: "separator",
1812
1812
  style: {
1813
1813
  ...style,
@@ -1801,7 +1801,7 @@ function PanelResizeHandle({
1801
1801
  tagName: Type = "div",
1802
1802
  ...rest
1803
1803
  }) {
1804
- const divElementRef = useRef(null);
1804
+ const elementRef = useRef(null);
1805
1805
 
1806
1806
  // Use a ref to guard against users passing inline props
1807
1807
  const callbacksRef = useRef({
@@ -1829,9 +1829,9 @@ function PanelResizeHandle({
1829
1829
  const stopDraggingAndBlur = useCallback(() => {
1830
1830
  // Clicking on the drag handle shouldn't leave it focused;
1831
1831
  // That would cause the PanelGroup to think it was still active.
1832
- const divElement = divElementRef.current;
1833
- assert(divElement);
1834
- divElement.blur();
1832
+ const element = elementRef.current;
1833
+ assert(element);
1834
+ element.blur();
1835
1835
  stopDragging();
1836
1836
  const {
1837
1837
  onDragging
@@ -1858,9 +1858,9 @@ function PanelResizeHandle({
1858
1858
  const onMouseLeave = event => {
1859
1859
  resizeHandler(event);
1860
1860
  };
1861
- const divElement = divElementRef.current;
1862
- assert(divElement);
1863
- const targetDocument = divElement.ownerDocument;
1861
+ const element = elementRef.current;
1862
+ assert(element);
1863
+ const targetDocument = element.ownerDocument;
1864
1864
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1865
1865
  targetDocument.body.addEventListener("mousemove", onMove);
1866
1866
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1917,7 +1917,7 @@ function PanelResizeHandle({
1917
1917
  onDragging(true);
1918
1918
  }
1919
1919
  },
1920
- ref: divElementRef,
1920
+ ref: elementRef,
1921
1921
  role: "separator",
1922
1922
  style: {
1923
1923
  ...style,
@@ -1777,7 +1777,7 @@ function PanelResizeHandle({
1777
1777
  tagName: Type = "div",
1778
1778
  ...rest
1779
1779
  }) {
1780
- const divElementRef = useRef(null);
1780
+ const elementRef = useRef(null);
1781
1781
 
1782
1782
  // Use a ref to guard against users passing inline props
1783
1783
  const callbacksRef = useRef({
@@ -1805,9 +1805,9 @@ function PanelResizeHandle({
1805
1805
  const stopDraggingAndBlur = useCallback(() => {
1806
1806
  // Clicking on the drag handle shouldn't leave it focused;
1807
1807
  // That would cause the PanelGroup to think it was still active.
1808
- const divElement = divElementRef.current;
1809
- assert(divElement);
1810
- divElement.blur();
1808
+ const element = elementRef.current;
1809
+ assert(element);
1810
+ element.blur();
1811
1811
  stopDragging();
1812
1812
  const {
1813
1813
  onDragging
@@ -1834,9 +1834,9 @@ function PanelResizeHandle({
1834
1834
  const onMouseLeave = event => {
1835
1835
  resizeHandler(event);
1836
1836
  };
1837
- const divElement = divElementRef.current;
1838
- assert(divElement);
1839
- const targetDocument = divElement.ownerDocument;
1837
+ const element = elementRef.current;
1838
+ assert(element);
1839
+ const targetDocument = element.ownerDocument;
1840
1840
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1841
1841
  targetDocument.body.addEventListener("mousemove", onMove);
1842
1842
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1893,7 +1893,7 @@ function PanelResizeHandle({
1893
1893
  onDragging(true);
1894
1894
  }
1895
1895
  },
1896
- ref: divElementRef,
1896
+ ref: elementRef,
1897
1897
  role: "separator",
1898
1898
  style: {
1899
1899
  ...style,
@@ -1590,7 +1590,7 @@ function PanelResizeHandle({
1590
1590
  tagName: Type = "div",
1591
1591
  ...rest
1592
1592
  }) {
1593
- const divElementRef = useRef(null);
1593
+ const elementRef = useRef(null);
1594
1594
 
1595
1595
  // Use a ref to guard against users passing inline props
1596
1596
  const callbacksRef = useRef({
@@ -1618,9 +1618,9 @@ function PanelResizeHandle({
1618
1618
  const stopDraggingAndBlur = useCallback(() => {
1619
1619
  // Clicking on the drag handle shouldn't leave it focused;
1620
1620
  // That would cause the PanelGroup to think it was still active.
1621
- const divElement = divElementRef.current;
1622
- assert(divElement);
1623
- divElement.blur();
1621
+ const element = elementRef.current;
1622
+ assert(element);
1623
+ element.blur();
1624
1624
  stopDragging();
1625
1625
  const {
1626
1626
  onDragging
@@ -1647,9 +1647,9 @@ function PanelResizeHandle({
1647
1647
  const onMouseLeave = event => {
1648
1648
  resizeHandler(event);
1649
1649
  };
1650
- const divElement = divElementRef.current;
1651
- assert(divElement);
1652
- const targetDocument = divElement.ownerDocument;
1650
+ const element = elementRef.current;
1651
+ assert(element);
1652
+ const targetDocument = element.ownerDocument;
1653
1653
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1654
1654
  targetDocument.body.addEventListener("mousemove", onMove);
1655
1655
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1706,7 +1706,7 @@ function PanelResizeHandle({
1706
1706
  onDragging(true);
1707
1707
  }
1708
1708
  },
1709
- ref: divElementRef,
1709
+ ref: elementRef,
1710
1710
  role: "separator",
1711
1711
  style: {
1712
1712
  ...style,
@@ -1566,7 +1566,7 @@ function PanelResizeHandle({
1566
1566
  tagName: Type = "div",
1567
1567
  ...rest
1568
1568
  }) {
1569
- const divElementRef = useRef(null);
1569
+ const elementRef = useRef(null);
1570
1570
 
1571
1571
  // Use a ref to guard against users passing inline props
1572
1572
  const callbacksRef = useRef({
@@ -1594,9 +1594,9 @@ function PanelResizeHandle({
1594
1594
  const stopDraggingAndBlur = useCallback(() => {
1595
1595
  // Clicking on the drag handle shouldn't leave it focused;
1596
1596
  // That would cause the PanelGroup to think it was still active.
1597
- const divElement = divElementRef.current;
1598
- assert(divElement);
1599
- divElement.blur();
1597
+ const element = elementRef.current;
1598
+ assert(element);
1599
+ element.blur();
1600
1600
  stopDragging();
1601
1601
  const {
1602
1602
  onDragging
@@ -1623,9 +1623,9 @@ function PanelResizeHandle({
1623
1623
  const onMouseLeave = event => {
1624
1624
  resizeHandler(event);
1625
1625
  };
1626
- const divElement = divElementRef.current;
1627
- assert(divElement);
1628
- const targetDocument = divElement.ownerDocument;
1626
+ const element = elementRef.current;
1627
+ assert(element);
1628
+ const targetDocument = element.ownerDocument;
1629
1629
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1630
1630
  targetDocument.body.addEventListener("mousemove", onMove);
1631
1631
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1682,7 +1682,7 @@ function PanelResizeHandle({
1682
1682
  onDragging(true);
1683
1683
  }
1684
1684
  },
1685
- ref: divElementRef,
1685
+ ref: elementRef,
1686
1686
  role: "separator",
1687
1687
  style: {
1688
1688
  ...style,
@@ -1667,7 +1667,7 @@ function PanelResizeHandle({
1667
1667
  tagName: Type = "div",
1668
1668
  ...rest
1669
1669
  }) {
1670
- const divElementRef = useRef(null);
1670
+ const elementRef = useRef(null);
1671
1671
 
1672
1672
  // Use a ref to guard against users passing inline props
1673
1673
  const callbacksRef = useRef({
@@ -1695,9 +1695,9 @@ function PanelResizeHandle({
1695
1695
  const stopDraggingAndBlur = useCallback(() => {
1696
1696
  // Clicking on the drag handle shouldn't leave it focused;
1697
1697
  // That would cause the PanelGroup to think it was still active.
1698
- const divElement = divElementRef.current;
1699
- assert(divElement);
1700
- divElement.blur();
1698
+ const element = elementRef.current;
1699
+ assert(element);
1700
+ element.blur();
1701
1701
  stopDragging();
1702
1702
  const {
1703
1703
  onDragging
@@ -1724,9 +1724,9 @@ function PanelResizeHandle({
1724
1724
  const onMouseLeave = event => {
1725
1725
  resizeHandler(event);
1726
1726
  };
1727
- const divElement = divElementRef.current;
1728
- assert(divElement);
1729
- const targetDocument = divElement.ownerDocument;
1727
+ const element = elementRef.current;
1728
+ assert(element);
1729
+ const targetDocument = element.ownerDocument;
1730
1730
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1731
1731
  targetDocument.body.addEventListener("mousemove", onMove);
1732
1732
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1783,7 +1783,7 @@ function PanelResizeHandle({
1783
1783
  onDragging(true);
1784
1784
  }
1785
1785
  },
1786
- ref: divElementRef,
1786
+ ref: elementRef,
1787
1787
  role: "separator",
1788
1788
  style: {
1789
1789
  ...style,
@@ -1490,7 +1490,7 @@ function PanelResizeHandle({
1490
1490
  tagName: Type = "div",
1491
1491
  ...rest
1492
1492
  }) {
1493
- const divElementRef = useRef(null);
1493
+ const elementRef = useRef(null);
1494
1494
 
1495
1495
  // Use a ref to guard against users passing inline props
1496
1496
  const callbacksRef = useRef({
@@ -1518,9 +1518,9 @@ function PanelResizeHandle({
1518
1518
  const stopDraggingAndBlur = useCallback(() => {
1519
1519
  // Clicking on the drag handle shouldn't leave it focused;
1520
1520
  // That would cause the PanelGroup to think it was still active.
1521
- const divElement = divElementRef.current;
1522
- assert(divElement);
1523
- divElement.blur();
1521
+ const element = elementRef.current;
1522
+ assert(element);
1523
+ element.blur();
1524
1524
  stopDragging();
1525
1525
  const {
1526
1526
  onDragging
@@ -1547,9 +1547,9 @@ function PanelResizeHandle({
1547
1547
  const onMouseLeave = event => {
1548
1548
  resizeHandler(event);
1549
1549
  };
1550
- const divElement = divElementRef.current;
1551
- assert(divElement);
1552
- const targetDocument = divElement.ownerDocument;
1550
+ const element = elementRef.current;
1551
+ assert(element);
1552
+ const targetDocument = element.ownerDocument;
1553
1553
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1554
1554
  targetDocument.body.addEventListener("mousemove", onMove);
1555
1555
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1606,7 +1606,7 @@ function PanelResizeHandle({
1606
1606
  onDragging(true);
1607
1607
  }
1608
1608
  },
1609
- ref: divElementRef,
1609
+ ref: elementRef,
1610
1610
  role: "separator",
1611
1611
  style: {
1612
1612
  ...style,
@@ -1466,7 +1466,7 @@ function PanelResizeHandle({
1466
1466
  tagName: Type = "div",
1467
1467
  ...rest
1468
1468
  }) {
1469
- const divElementRef = useRef(null);
1469
+ const elementRef = useRef(null);
1470
1470
 
1471
1471
  // Use a ref to guard against users passing inline props
1472
1472
  const callbacksRef = useRef({
@@ -1494,9 +1494,9 @@ function PanelResizeHandle({
1494
1494
  const stopDraggingAndBlur = useCallback(() => {
1495
1495
  // Clicking on the drag handle shouldn't leave it focused;
1496
1496
  // That would cause the PanelGroup to think it was still active.
1497
- const divElement = divElementRef.current;
1498
- assert(divElement);
1499
- divElement.blur();
1497
+ const element = elementRef.current;
1498
+ assert(element);
1499
+ element.blur();
1500
1500
  stopDragging();
1501
1501
  const {
1502
1502
  onDragging
@@ -1523,9 +1523,9 @@ function PanelResizeHandle({
1523
1523
  const onMouseLeave = event => {
1524
1524
  resizeHandler(event);
1525
1525
  };
1526
- const divElement = divElementRef.current;
1527
- assert(divElement);
1528
- const targetDocument = divElement.ownerDocument;
1526
+ const element = elementRef.current;
1527
+ assert(element);
1528
+ const targetDocument = element.ownerDocument;
1529
1529
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1530
1530
  targetDocument.body.addEventListener("mousemove", onMove);
1531
1531
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1582,7 +1582,7 @@ function PanelResizeHandle({
1582
1582
  onDragging(true);
1583
1583
  }
1584
1584
  },
1585
- ref: divElementRef,
1585
+ ref: elementRef,
1586
1586
  role: "separator",
1587
1587
  style: {
1588
1588
  ...style,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
package/src/Panel.ts CHANGED
@@ -4,10 +4,10 @@ import { PanelGroupContext } from "./PanelGroupContext";
4
4
  import useIsomorphicLayoutEffect from "./hooks/useIsomorphicEffect";
5
5
  import useUniqueId from "./hooks/useUniqueId";
6
6
  import {
7
- ElementType,
8
7
  ForwardedRef,
9
8
  HTMLAttributes,
10
9
  PropsWithChildren,
10
+ ReactNode,
11
11
  createElement,
12
12
  forwardRef,
13
13
  useContext,
@@ -54,7 +54,10 @@ export type ImperativePanelHandle = {
54
54
  resize: (size: number) => void;
55
55
  };
56
56
 
57
- export type PanelProps = Omit<HTMLAttributes<ElementType>, "id" | "onResize"> &
57
+ export type PanelProps = Omit<
58
+ HTMLAttributes<keyof HTMLElementTagNameMap>,
59
+ "id" | "onResize"
60
+ > &
58
61
  PropsWithChildren<{
59
62
  className?: string;
60
63
  collapsedSize?: number | undefined;
@@ -68,7 +71,7 @@ export type PanelProps = Omit<HTMLAttributes<ElementType>, "id" | "onResize"> &
68
71
  onResize?: PanelOnResize;
69
72
  order?: number;
70
73
  style?: object;
71
- tagName?: ElementType;
74
+ tagName?: keyof HTMLElementTagNameMap;
72
75
  }>;
73
76
 
74
77
  export function PanelWithForwardedRef({
@@ -90,7 +93,7 @@ export function PanelWithForwardedRef({
90
93
  ...rest
91
94
  }: PanelProps & {
92
95
  forwardedRef: ForwardedRef<ImperativePanelHandle>;
93
- }) {
96
+ }): ReactNode {
94
97
  const context = useContext(PanelGroupContext);
95
98
  if (context === null) {
96
99
  throw Error(
package/src/PanelGroup.ts CHANGED
@@ -28,10 +28,10 @@ import { validatePanelConstraints } from "./utils/validatePanelConstraints";
28
28
  import { validatePanelGroupLayout } from "./utils/validatePanelGroupLayout";
29
29
  import {
30
30
  CSSProperties,
31
- ElementType,
32
31
  ForwardedRef,
33
32
  HTMLAttributes,
34
33
  PropsWithChildren,
34
+ ReactNode,
35
35
  createElement,
36
36
  forwardRef,
37
37
  useCallback,
@@ -68,7 +68,10 @@ const defaultStorage: PanelGroupStorage = {
68
68
  },
69
69
  };
70
70
 
71
- export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> &
71
+ export type PanelGroupProps = Omit<
72
+ HTMLAttributes<keyof HTMLElementTagNameMap>,
73
+ "id"
74
+ > &
72
75
  PropsWithChildren<{
73
76
  autoSaveId?: string | null;
74
77
  className?: string;
@@ -78,7 +81,7 @@ export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> &
78
81
  onLayout?: PanelGroupOnLayout | null;
79
82
  storage?: PanelGroupStorage;
80
83
  style?: CSSProperties;
81
- tagName?: ElementType;
84
+ tagName?: keyof HTMLElementTagNameMap;
82
85
  }>;
83
86
 
84
87
  const debounceMap: {
@@ -100,7 +103,7 @@ function PanelGroupWithForwardedRef({
100
103
  ...rest
101
104
  }: PanelGroupProps & {
102
105
  forwardedRef: ForwardedRef<ImperativePanelGroupHandle>;
103
- }) {
106
+ }): ReactNode {
104
107
  const groupId = useUniqueId(idFromProps);
105
108
 
106
109
  const [dragState, setDragState] = useState<DragState | null>(null);
@@ -2,10 +2,10 @@ import useUniqueId from "./hooks/useUniqueId";
2
2
  import {
3
3
  createElement,
4
4
  CSSProperties,
5
- ElementType,
6
5
  HTMLAttributes,
7
6
  PropsWithChildren,
8
7
  MouseEvent as ReactMouseEvent,
8
+ ReactNode,
9
9
  TouchEvent,
10
10
  useCallback,
11
11
  useContext,
@@ -25,7 +25,10 @@ import { getCursorStyle } from "./utils/cursor";
25
25
 
26
26
  export type PanelResizeHandleOnDragging = (isDragging: boolean) => void;
27
27
 
28
- export type PanelResizeHandleProps = Omit<HTMLAttributes<ElementType>, "id"> &
28
+ export type PanelResizeHandleProps = Omit<
29
+ HTMLAttributes<keyof HTMLElementTagNameMap>,
30
+ "id"
31
+ > &
29
32
  PropsWithChildren<{
30
33
  className?: string;
31
34
  disabled?: boolean;
@@ -33,7 +36,7 @@ export type PanelResizeHandleProps = Omit<HTMLAttributes<ElementType>, "id"> &
33
36
  onDragging?: PanelResizeHandleOnDragging;
34
37
  style?: CSSProperties;
35
38
  tabIndex?: number;
36
- tagName?: ElementType;
39
+ tagName?: keyof HTMLElementTagNameMap;
37
40
  }>;
38
41
 
39
42
  export function PanelResizeHandle({
@@ -46,8 +49,8 @@ export function PanelResizeHandle({
46
49
  tabIndex = 0,
47
50
  tagName: Type = "div",
48
51
  ...rest
49
- }: PanelResizeHandleProps) {
50
- const divElementRef = useRef<HTMLDivElement>(null);
52
+ }: PanelResizeHandleProps): ReactNode {
53
+ const elementRef = useRef<HTMLElement>(null);
51
54
 
52
55
  // Use a ref to guard against users passing inline props
53
56
  const callbacksRef = useRef<{
@@ -85,9 +88,9 @@ export function PanelResizeHandle({
85
88
  const stopDraggingAndBlur = useCallback(() => {
86
89
  // Clicking on the drag handle shouldn't leave it focused;
87
90
  // That would cause the PanelGroup to think it was still active.
88
- const divElement = divElementRef.current;
89
- assert(divElement);
90
- divElement.blur();
91
+ const element = elementRef.current;
92
+ assert(element);
93
+ element.blur();
91
94
 
92
95
  stopDragging();
93
96
 
@@ -119,10 +122,10 @@ export function PanelResizeHandle({
119
122
  resizeHandler(event);
120
123
  };
121
124
 
122
- const divElement = divElementRef.current;
123
- assert(divElement);
125
+ const element = elementRef.current;
126
+ assert(element);
124
127
 
125
- const targetDocument = divElement.ownerDocument;
128
+ const targetDocument = element.ownerDocument;
126
129
 
127
130
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
128
131
  targetDocument.body.addEventListener("mousemove", onMove);
@@ -186,7 +189,7 @@ export function PanelResizeHandle({
186
189
  onDragging(true);
187
190
  }
188
191
  },
189
- ref: divElementRef,
192
+ ref: elementRef,
190
193
  role: "separator",
191
194
  style: {
192
195
  ...style,
@@ -62,7 +62,7 @@ export function useWindowSplitterResizeHandlerBehavior({
62
62
  ? index + 1
63
63
  : 0;
64
64
 
65
- const nextHandle = handles[nextIndex] as HTMLDivElement;
65
+ const nextHandle = handles[nextIndex] as HTMLElement;
66
66
  nextHandle.focus();
67
67
 
68
68
  break;
@@ -1,7 +1,7 @@
1
- export function getPanelElement(id: string): HTMLDivElement | null {
1
+ export function getPanelElement(id: string): HTMLElement | null {
2
2
  const element = document.querySelector(`[data-panel-id="${id}"]`);
3
3
  if (element) {
4
- return element as HTMLDivElement;
4
+ return element as HTMLElement;
5
5
  }
6
6
  return null;
7
7
  }
@@ -1,4 +1,4 @@
1
- export function getPanelElementsForGroup(groupId: string): HTMLDivElement[] {
1
+ export function getPanelElementsForGroup(groupId: string): HTMLElement[] {
2
2
  return Array.from(
3
3
  document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`)
4
4
  );
@@ -1,9 +1,9 @@
1
- export function getPanelGroupElement(id: string): HTMLDivElement | null {
1
+ export function getPanelGroupElement(id: string): HTMLElement | null {
2
2
  const element = document.querySelector(
3
3
  `[data-panel-group][data-panel-group-id="${id}"]`
4
4
  );
5
5
  if (element) {
6
- return element as HTMLDivElement;
6
+ return element as HTMLElement;
7
7
  }
8
8
  return null;
9
9
  }
@@ -1,9 +1,9 @@
1
- export function getResizeHandleElement(id: string): HTMLDivElement | null {
1
+ export function getResizeHandleElement(id: string): HTMLElement | null {
2
2
  const element = document.querySelector(
3
3
  `[data-panel-resize-handle-id="${id}"]`
4
4
  );
5
5
  if (element) {
6
- return element as HTMLDivElement;
6
+ return element as HTMLElement;
7
7
  }
8
8
  return null;
9
9
  }
@@ -1,6 +1,6 @@
1
1
  export function getResizeHandleElementsForGroup(
2
2
  groupId: string
3
- ): HTMLDivElement[] {
3
+ ): HTMLElement[] {
4
4
  return Array.from(
5
5
  document.querySelectorAll(
6
6
  `[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`