mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
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.
31 lines
926 B
TypeScript
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);
|
|
}
|