Skip to content

SplitView

Recursive binary-tree pane tiling component. Renders a layout tree of split panes using flexbox. Each leaf renders via renderPane(id). Splits divide space according to ratio (0-1, proportion given to first child).

Import

tsx
import { SplitView } from "silvery"

Props

PropTypeDefaultDescription
layoutLayoutNoderequiredLayout tree describing the split arrangement
renderPane(id: string) => ReactNoderequiredRender function for each leaf pane
focusedPaneIdstring--ID of the focused pane (for border highlighting)
showBordersbooleantrueShow borders around panes
focusedBorderColorstring"green"Border color for focused pane
unfocusedBorderColorstring"gray"Border color for unfocused panes
renderPaneTitle(id: string) => string--Render pane title in border

LayoutNode

The layout tree is built using helper functions:

ts
import { createLeaf, splitPane, removePane, getPaneIds, findAdjacentPane, resizeSplit, swapPanes } from "silvery"

// Create a single pane
const single = createLeaf("main")

// Split horizontally
const split = splitPane(single, "main", "horizontal", "sidebar")

// Split vertically
const nested = splitPane(split, "main", "vertical", "bottom")

Usage

tsx
<SplitView
  layout={layout}
  renderPane={(id) => {
    switch (id) {
      case "main":
        return <MainContent />
      case "sidebar":
        return <Sidebar />
      default:
        return <Text>Unknown pane: {id}</Text>
    }
  }}
  focusedPaneId={focusedPane}
  renderPaneTitle={(id) => id.toUpperCase()}
/>

Helper Functions

FunctionDescription
createLeaf(id)Create a single leaf pane
splitPane(layout, paneId, direction, newId)Split a pane into two
removePane(layout, paneId)Remove a pane from the tree
getPaneIds(layout)Get all pane IDs
findAdjacentPane(layout, paneId, direction)Find adjacent pane
resizeSplit(layout, splitId, ratio)Resize a split
swapPanes(layout, id1, id2)Swap two panes
getSplitTabOrder(layout)Get tab order of panes

See Also

  • Box -- base layout container
  • Screen -- fullscreen root component

Released under the MIT License.