gridland
Components

TUI

The root mounting component for Gridland

TUI is the single entry point for rendering TUI content to a canvas. It handles client detection, canvas creation, React reconciler setup, and automatic resizing. Gridland is built on the opentui engine.

Primitives
?

Run demo

Terminal
bunx @gridland/demo primitives
Terminal
curl -fsSL https://raw.githubusercontent.com/thoughtfulllc/gridland/main/scripts/run-demo.sh | bash -s primitives

Usage

Example
import { TUI } from "@gridland/web"

<TUI style={{ width: "100vw", height: "100vh" }}>
  <box border padding={1}>
    <text>Your TUI content here</text>
  </box>
</TUI>

Props

PropTypeDescription
childrenReactNodeTUI elements to render (<box>, <text>, etc.)
styleCSSPropertiesCSS styles for the outer container div
classNamestringCSS class for the outer container div

SSR Behavior

On the server, TUI renders an empty <div> with the provided style and className. On the client, it hydrates and creates the canvas automatically. No dynamic(() => import(...), { ssr: false }) wrapper is needed.

The client-side hydration process:

  1. Detects the browser environment via useEffect
  2. Creates a <canvas> element inside the container
  3. Initializes the React reconciler with a BrowserRenderContext
  4. Sets up ResizeObserver for automatic canvas resizing
  5. Renders children through the TUI reconciler to the canvas

Architecture

React JSX
  |
  v
@opentui/react reconciler
  |
  v
Renderable tree (Box, Text, etc.)
  |
  v
Yoga layout engine (flexbox)
  |
  v
BrowserBuffer (cell grid)
  |
  v
CanvasPainter (pixels)
  |
  v
HTML5 Canvas