AncrelDocumentationv0.3.0

Search documentation

    Documentation / frontend

    Resizable split

    Give the center pane the content that should keep its space as a workspace narrows. Put navigation on the left, supplementary content on the right, or supply just one side. Each visible side takes a default width and minimum and maximum widths in CSS pixels.

    Live example

    Open playground ↗

    Reading room

    Use either separator to make more room for the text.

    App.tsx

    'use client'
    
    import { ResizableSplit } from '@ancrel/workspace'
    import '@ancrel/tokens/css'
    import '@ancrel/workspace/styles.css'
    
    export default function App() {
      return (
        <ResizableSplit
          left={<nav aria-label="Contents">Contents</nav>}
          leftConfig={{ defaultWidth: 240, minWidth: 180, maxWidth: 360 }}
          right={<aside aria-label="Notes">Notes</aside>}
          rightConfig={{ defaultWidth: 280, minWidth: 200, maxWidth: 480 }}
          labels={{ leftHandle: 'Resize contents', rightHandle: 'Resize notes' }}
          persistKey="reading-room"
        >
          <article><h2>Reading room</h2><p>Use either separator to make more room for the text.</p></article>
        </ResizableSplit>
      )
    }
    

    Expected behavior

    Reading room

    Contents and Notes flank the article. In a wide container they start at 240 and 280 pixels. Focus “Resize contents” and press Shift+Right to expand Contents to 288 pixels. Reload to retain that width. Focus “Resize notes” and press Left to expand Notes to 296 pixels. Double-click that separator to restore 280 pixels. Narrow the container to see the sides yield space to the article. Expand it again to restore the preferred widths.

    Resize a panel

    Drag a separator or focus it with Tab. Left and Right move the separator by 16 pixels in the arrow's direction. Hold Shift for a 48-pixel step. Home and End select the current bounds. Double-click, Enter or 0 restores that panel's default. Give each separator a label that identifies the pane it controls.

    The center requests 360 pixels by default. When space is short, the side panes give up width in proportion to their room above minimum. If both minimums cannot fit, the layout relaxes the center reservation and may reduce the sides below their configured minimums. In very tight containers the fallback floors are 140 pixels on the left and 160 on the right. The separator announces its effective bounds.

    Remember a layout

    Give each workspace a distinct persistKey. The default adapter prefixes each key with ac:split:v1: and appends :left or :right. Server rendering and the first client render use the configured defaults. Saved preferences apply after hydration. Use storage={null} to keep widths local to the mounted split, or inject a SplitStorage adapter for another persistence mechanism. A reset writes an empty preference so later changes to the configured default take effect.

    Use onWidthsChange to respond to a finished drag, keyboard adjustment or reset. Pointer moves preview the layout without sending a commit. For a custom layout, computeEffectiveWidths supplies the side widths, center width and effective bounds to pass into ResizeHandle.

    Styles

    Import @ancrel/tokens/css and @ancrel/workspace/styles.css in the host. The visible separator uses --ac-comp-split-handle-size. Its larger pointer target uses --ac-comp-split-handle-hitArea and overlaps the pane edges without consuming their width budget.

    Props

    PropTypeRequiredDefault
    childrenReactNodeYes—
    classNamestringNo—
    keyReact.Key | null | undefinedNo—
    labelsPartial<ResizableSplitLabels>No—
    leftReactNodeNo—
    leftConfigSideConfigNo—
    minCenterWidthnumberNo—
    onWidthsChange((widths: SplitWidths) => void) | undefinedNo—
    persistKeystringNo—
    refReact.Ref<HTMLDivElement> | undefinedNo—
    rightReactNodeNo—
    rightConfigSideConfigNo—
    storageSplitStorage | nullNo—

    State matrix

    StateTheme / density
    defaultdark/compact, dark/comfortable, light/compact, light/comfortable
    hoverdark/compact, dark/comfortable, light/compact, light/comfortable
    focus-visibledark/compact, dark/comfortable, light/compact, light/comfortable
    activedark/compact, dark/comfortable, light/compact, light/comfortable

    Constraints

    • Supply a SideConfig for each visible side pane, with dimensions in CSS pixels.
    • Use a distinct persistKey for each workspace that should retain its own widths.
    • Import the token CSS and the workspace stylesheet.

    Anti-patterns

    • Persisting the visual width on each pointer move.
    • Assuming the center minimum can fit alongside both side minimums at every container width.