Get started
Quickstart
Build the smallest Jali app, a note whose button opens the next note beside it.
On this page
This page builds a small app, one file at a time: a note with a button that opens the next note beside it. The finished app is examples/minimal in the repo, which adds a launcher and makes the panes the page's <main>.
You need Node and a React app. Start from a new one, or skip this step and use your own:
npm create vite@latest notes -- --template react-tscd notesInstall Jali
Link to this section: Install Jalinpm install jali-layoutpnpm add jali-layoutyarn add jali-layoutbun add jali-layoutvp add jali-layoutOne package:
jali-layoutholds the model (the layout, the panes and their commands) and has no framework;jali-layout/reactrenders it. If your app links Jali from a checkout or a monorepo, see Installation.Define a pane
Link to this section: Define a paneA pane kind says what one kind of pane shows and how. This one shows a note.
note.tsx import { definePane } from "jali-layout/react";// A kind of pane: what it shows (its params), its title, and the component that renders it.export const note = definePane("note", { params: { id: Number }, title: ({ id }) => `Note ${id}`, Component: ({ params }) => ( <article className="note"> <h3>Note {params.id}</h3> </article> ),});"note"is the kind's name. Every pane of this kind carries it.paramssays what a note pane needs to know: itsid, a number. A link turns every value into text, soNumberreads it back as a number.titlenames the pane in its header, its tab and ⌘K.Componentrenders the pane. It gets the params, typed, along with the functions a pane uses to open other panes.
noteis now also how you name a note:note({ id: 1 })is the ref of note 1,{ kind: "note", params: { id: 1 } }. You use refs to open panes and to write layouts.Create the instance
Link to this section: Create the instancecreateJalimakes the instance: it holds the panes, focus, history and settings. It takes the kinds it can show and the layout it opens on.jali.ts import { createJali } from "jali-layout";import { defaultFeatures } from "jali-layout/features";import { note } from "./note";export const jali = createJali({ panes: [note], layout: note({ id: 1 }), features: defaultFeatures(),});The layout here is one pane, note 1. Several are written the same way:
row(note({ id: 1 }), note({ id: 2 }))puts panes side by side, andcolumn(...)one above the other. See Lay out panes.featuresturns on what Jali does beyond laying out panes.defaultFeatures()is Jali's usual set: the layout in the address bar, the ⌘K palette, Settings and the chooser. Reload the page and the layout comes back; Back and Forward step through changes. If the address already holds a layout, that one opens instead. An app that wants less picks each feature from its own entry, and ships only those: see Features.Render it
Link to this section: Render it<JaliRoot>draws the panes and the features' dialogs, such as the ⌘K palette. While it is on the page, it also turns on the keyboard, Back and Forward, the theme and saving.main.tsx import { createRoot } from "react-dom/client";import { JaliRoot } from "jali-layout/react";import "jali-layout/styles.css";import "./app.css";import { jali } from "./jali";createRoot(document.getElementById("root")!).render(<JaliRoot jali={jali} className="app" />);The panes fill the box you give them, so that box needs a height: here
html,bodyand#rootare the full window. To add your own top bar or sidebar, put it inside<JaliRoot>with<JaliView />where the panes go: the panes take the room it leaves. If the box has no height, the panes have none either, and a warning in the console says so while you develop.Screen readers meet the panes as a region named "Panes", inside your page's own
<main>. When Jali is the whole page and it has no<main>of its own, passlandmark: "main"tocreateJaliso the panes are the page's<main>.Add the styles and the layer line
Link to this section: Add the styles and the layer linejali/styles.cssis Jali's default theme and the panes' layout. Every rule in it sits in a CSS cascade layer namedjali.app.css /* Name the layers once. Jali's styles sit in `jali`; anything in a later layer wins without !important. */@layer base, jali;@layer base { html, body, #root { height: 100%; margin: 0; } body { font-family: system-ui, sans-serif; background: var(--jali-canvas); color: var(--jali-text); }}/* Jali fills whatever box you give it. */.app { height: 100%; display: grid;}.note { padding: 1rem;}The
@layerline names the order of the layers once. Your resets go in a layer beforejali; your own styles go after it, or outside any layer, and win without!important. With Tailwind, the line is@layer theme, base, jali, components, utilities;.Run the app. You see note 1, filling the window. Press ⌘K (Ctrl+K on Windows and Linux) to see every command.
Open a pane beside
Link to this section: Open a pane besideA pane opens another with
openBeside. Pass it the ref of what to open.note.tsx import { definePane } from "jali-layout/react";export const note = definePane("note", { params: { id: Number }, title: ({ id }) => `Note ${id}`, Component: ({ params, openBeside }) => ( <article className="note"> <h3>Note {params.id}</h3> <button onClick={() => openBeside(note({ id: params.id + 1 }))}> Open the next note beside </button> </article> ),});Click the button in note 1. Note 2 opens to its right, and focus stays in note 1, so you can keep working where you were. Drag the line between them to resize.
Click note 1's button again. Note 2 is already beside it, so Jali opens no copy: it lights note 2 up for a moment and says "Already open". A link never opens a second copy of a pane it opened.
Keep clicking the button in the newest note. Each click opens the next note beside the one you clicked in. When the panes no longer fit at their minimum width, some fold into tabs, and the note you are working in stays on screen. Widen the window and they come back. How a layout fits explains the order, and Opening and linking explains what
openBesidedoes when a pane opens several links.