Files
Tom Moor d57db81c6b feat: Split view (#13044)
Adds the ability to open a second route alongside the current one:

- The secondary route is stored in a `split` query string parameter so
  that reloading the page hydrates both panes.
- The secondary pane runs in its own in-memory router kept in sync with
  the query parameter, so links followed inside the pane navigate the
  pane rather than the primary route.
- Navigation while a split is open preserves the split, is directed to
  the focused pane, and routes that cannot render in a pane (such as
  settings) close the split.
- The focused pane is shown with an accent outline, updated as panes are
  clicked or focused, and keyboard shortcuts only apply to the focused
  pane.
- "Open in split view" added to document and collection menus and the
  command bar.
2026-07-19 11:57:33 -04:00

31 lines
926 B
TypeScript

import { createContext, useContext } from "react";
import type { SplitViewPane } from "~/utils/splitView";
export interface SplitViewContextValue {
/** The pane of the split view this subtree is rendered in. */
pane: SplitViewPane;
/** Whether a split view is currently open. */
isSplitView: boolean;
/** Whether the pane this subtree is rendered in currently has focus. */
isFocused: boolean;
}
/**
* Context describing the split view pane a component is rendered within.
* Outside of a split view the default value describes a focused primary pane.
*/
export const SplitViewContext = createContext<SplitViewContextValue>({
pane: "primary",
isSplitView: false,
isFocused: true,
});
/**
* Returns the split view context for the current component subtree.
*
* @returns the split view context value.
*/
export function useSplitView(): SplitViewContextValue {
return useContext(SplitViewContext);
}