);
}
+
+function DragHandle({ id }: { id: string }) {
+ const { activeHandleId } = useContext(PanelContext);
+ const isDragging = activeHandleId === id;
+
+ return (
+
+
+
+ );
+}
diff --git a/packages/react-resizable-panels-website/src/styles.module.css b/packages/react-resizable-panels-website/src/styles.module.css
index dd5e9a1e0..163bca0a8 100644
--- a/packages/react-resizable-panels-website/src/styles.module.css
+++ b/packages/react-resizable-panels-website/src/styles.module.css
@@ -39,15 +39,36 @@
}
.HorizontalResizeHandle {
- padding: 0 0.25rem;
+ width: 0.5rem;
+ position: relative;
+}
+.ResizeHandle,
+.ActiveResizeHandle {
+ position: absolute;
+ top: 0.125rem;
+ bottom: 0.125rem;
+ left: 0.125rem;
+ right: 0.125rem;
+ border-radius: 0.125rem;
+ background-color: transparent;
+ transition: background-color 0.2s linear;
+}
+.ActiveResizeHandle,
+.HorizontalResizeHandle:hover .ResizeHandle {
+ background-color: rgba(255, 255, 255, 0.2);
}
.VerticalResizeBar {
- height: 3px;
width: 100%;
- background-color: #2b2b2b;
- border-bottom: 1px solid #4a4c50;
- border-top: 1px solid #4a4c50;
+ position: relative;
+ padding: 0.25rem 0;
+}
+.VerticalResizeBar::after {
+ content: " ";
+ display: block;
+ height: 1px;
+ width: 100%;
+ background-color: #4a4c50;
}
.Button,
diff --git a/packages/react-resizable-panels/CHANGELOG.md b/packages/react-resizable-panels/CHANGELOG.md
index f74dde80a..22feb2103 100644
--- a/packages/react-resizable-panels/CHANGELOG.md
+++ b/packages/react-resizable-panels/CHANGELOG.md
@@ -1,5 +1,7 @@
# Changelog
+## 0.0.7
+* Add `PanelContext` with `activeHandleId` property identifying the resize handle currently being dragged (or `null`). This enables more customized UI/UX when resizing is in progress.
## 0.0.6
* [#5](https://github.com/bvaughn/react-resizable-panels/issues/5): Removed `panelBefore` and `panelAfter` props from `PanelResizeHandle`. `PanelGroup` now infers this based on position within the group.
## 0.0.5
diff --git a/packages/react-resizable-panels/README.md b/packages/react-resizable-panels/README.md
index 916bfd295..a7cee5868 100644
--- a/packages/react-resizable-panels/README.md
+++ b/packages/react-resizable-panels/README.md
@@ -46,4 +46,10 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
| :------------ | :----------- | :---
| `children` | `?ReactNode` | Custom drag UI; can be any arbitrary React element(s)
| `className` | `?string` | Class name
-| `disabled` | `?boolean` | Disable drag handle
\ No newline at end of file
+| `disabled` | `?boolean` | Disable drag handle
+| `id` | `?string` | Optional resize handle id (must be unique within the current group)
+
+### `PanelContext`
+| prop | type | description
+| :----------- | :------------------- | :---
+| `activeHandleId` | `string \| null` | Resize handle currently being dragged (or `null`)
\ No newline at end of file
diff --git a/packages/react-resizable-panels/package.json b/packages/react-resizable-panels/package.json
index a7dab5e14..172ef05e6 100644
--- a/packages/react-resizable-panels/package.json
+++ b/packages/react-resizable-panels/package.json
@@ -1,6 +1,6 @@
{
"name": "react-resizable-panels",
- "version": "0.0.6",
+ "version": "0.0.7",
"description": "React components for resizable panel groups/layouts",
"author": "Brian Vaughn
",
"license": "MIT",
diff --git a/packages/react-resizable-panels/src/PanelContexts.ts b/packages/react-resizable-panels/src/PanelContexts.ts
index b949e5dd9..93a767267 100644
--- a/packages/react-resizable-panels/src/PanelContexts.ts
+++ b/packages/react-resizable-panels/src/PanelContexts.ts
@@ -2,11 +2,17 @@ import { CSSProperties, createContext } from "react";
import { PanelData, ResizeHandler } from "./types";
+export const PanelContext = createContext<{
+ activeHandleId: string | null;
+} | null>(null);
+
export const PanelGroupContext = createContext<{
direction: "horizontal" | "vertical";
getPanelStyle: (id: string) => CSSProperties;
groupId: string;
registerPanel: (id: string, panel: PanelData) => void;
registerResizeHandle: (id: string) => ResizeHandler;
+ startDragging: (id: string) => void;
+ stopDragging: () => void;
unregisterPanel: (id: string) => void;
} | null>(null);
diff --git a/packages/react-resizable-panels/src/PanelGroup.tsx b/packages/react-resizable-panels/src/PanelGroup.tsx
index 8147f283b..7a681743e 100644
--- a/packages/react-resizable-panels/src/PanelGroup.tsx
+++ b/packages/react-resizable-panels/src/PanelGroup.tsx
@@ -10,8 +10,9 @@ import {
} from "react";
import useUniqueId from "./hooks/useUniqueId";
-import { PanelGroupContext } from "./PanelContexts";
+import { PanelContext, PanelGroupContext } from "./PanelContexts";
import { Direction, PanelData } from "./types";
+import { loadPanelLayout, savePanelGroupLayout } from "./utils/serialization";
type Props = {
autoSaveId?: string;
@@ -38,6 +39,7 @@ export default function PanelGroup({
}: Props) {
const groupId = useUniqueId();
+ const [activeHandleId, setActiveHandleId] = useState(null);
const [panels, setPanels] = useState