Panels with handles you drag or move with the keys, limits, folding on double-click, and sizes kept between visits.
- Mira PatelQ3 launch checklist: two items left
- Ben OkaforRe: Checkout errors since the 5 PM deploy
- BillingYour invoice for November is ready
- Aleksandra Wiśniewska-KowalczykContract review: redlines on sections 4 and 7 attached
Re: Checkout errors since the 5 PM deploy
Rolled back the payment client. Error rate is back under 0.1%. I'll write up what happened tomorrow morning, and we can decide whether the retry change goes out again on Thursday.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Resizable } from "./ui/uicontext/components/Resizable.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ frame: { inlineSize: "100%", blockSize: 320, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, backgroundColor: color.panel, overflow: "hidden", }, list: { margin: 0, padding: space.xs, listStyle: "none" }, row: { display: "grid", gap: 2, paddingBlock: space.sm, paddingInline: space.md, borderRadius: radius.sm, fontSize: font.sm }, current: { backgroundColor: color.selected }, from: { fontWeight: 600, color: color.fg, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, subject: { color: color.muted, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, message: { padding: space.xl, display: "grid", gap: space.md, alignContent: "start" }, title: { margin: 0, fontSize: font.lg, fontWeight: 600, letterSpacing: "-0.01em" }, body: { margin: 0, fontSize: font.base, lineHeight: 1.6, color: color.muted, maxInlineSize: "65ch" }, folders: { padding: space.md, display: "grid", gap: space.xs, alignContent: "start", fontSize: font.sm }, folder: { color: color.muted, textDecoration: "none", paddingBlock: space.xs, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },})const mail = [ { id: "1", from: "Mira Patel", subject: "Q3 launch checklist: two items left" }, { id: "2", from: "Ben Okafor", subject: "Re: Checkout errors since the 5 PM deploy" }, { id: "3", from: "Billing", subject: "Your invoice for November is ready" }, { id: "4", from: "Aleksandra Wiśniewska-Kowalczyk", subject: "Contract review: redlines on sections 4 and 7 attached" },]// a mail app: folders fold away, the list and the message share the rest; sizes come back after a reloadexport const MailLayout = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( Resizable(h, { label: "Mail", storageKey: "docs-mail-layout", panels: [ { id: "folders", label: "Folders", defaultSize: 20, min: 14, max: 30, collapsible: true, content: h.nav.attrs({ "aria-label": "Folders", ...sx(styles.folders) }).children(["Inbox", "Sent", "Drafts", "Archive"].map((f) => h.a.key(f).attrs({ href: `#${f.toLowerCase()}`, ...sx(styles.folder) }).children(f))), }, { id: "list", label: "Messages", defaultSize: 32, min: 22, max: 50, content: h.ul.attrs(sx(styles.list)).children( mail.map((m, i) => h.li.key(m.id).attrs(sx(styles.row, i === 1 && styles.current)).children(h.span.attrs(sx(styles.from)).children(m.from), h.span.attrs(sx(styles.subject)).children(m.subject))), ), }, { id: "message", label: "Message", defaultSize: 48, min: 30, content: h.article.attrs(sx(styles.message)).children( h.h3.attrs(sx(styles.title)).children("Re: Checkout errors since the 5 PM deploy"), h.p.attrs(sx(styles.body)).children("Rolled back the payment client. Error rate is back under 0.1%. I'll write up what happened tomorrow morning, and we can decide whether the retry change goes out again on Thursday."), ), }, ], }), )Installation
pnpm dlx shadcn@latest add checkfu/uicontext/resizableUsage
import { Resizable } from "./ui/uicontext/components/Resizable.ts"export const DocWithPreview = <M>(h: Html.H<M>, editor: View.Content<M>, preview: View.Content<M>) => Resizable(h, { label: "Editor and preview", storageKey: "doc-preview", panels: [ { id: "editor", label: "Editor", defaultSize: 50, min: 30, content: editor }, { id: "preview", label: "Preview", defaultSize: 50, min: 20, collapsible: true, content: preview }, ], })Examples
Stacked
direction: "vertical": the arrow keys move the handle up and down.
export const retry = (attempt: number) => Math.min(30_000, 2 ** attempt * 250)
$ bun test retry ✓ backs off exponentially (2 ms) ✓ caps at 30 seconds (1 ms) 2 passed
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Resizable } from "./ui/uicontext/components/Resizable.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ frame: { inlineSize: "100%", blockSize: 300, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, overflow: "hidden", backgroundColor: color.panel }, code: { margin: 0, padding: space.lg, fontFamily: font.mono, fontSize: font.sm, lineHeight: 1.6, color: color.fg, whiteSpace: "pre" }, terminal: { margin: 0, padding: space.lg, fontFamily: font.mono, fontSize: font.xs, lineHeight: 1.6, color: color.muted, backgroundColor: color.raised, blockSize: "100%", boxSizing: "border-box", whiteSpace: "pre-wrap" },})// an editor over its terminal: drag the handle up and down, or fold the terminal awayexport const EditorTerminal = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( Resizable(h, { label: "Editor and terminal", direction: "vertical", panels: [ { id: "editor", label: "Editor", defaultSize: 65, min: 30, content: h.pre.attrs(sx(styles.code)).children("export const retry = (attempt: number) =>\n Math.min(30_000, 2 ** attempt * 250)\n") }, { id: "terminal", label: "Terminal", defaultSize: 35, min: 20, collapsible: true, content: h.pre.attrs(sx(styles.terminal)).children("$ bun test retry\n✓ backs off exponentially (2 ms)\n✓ caps at 30 seconds (1 ms)\n\n2 passed") }, ], }), )API reference
ResizablePartsComponent
Props
| Name | Type | Description |
|---|---|---|
labelrequired | string | What the group is: "Mail". |
panelsrequired | ResizablePanel[] | — |
direction | "horizontal" | "vertical" | — |
storageKey | string | Keeps the sizes in this browser under this key. Without it they reset on reload. |
Events
| Event | Payload | Description |
|---|---|---|
Resized | { sizes: Sizes } | The sizes the person settled on, after a drag, a key or a fold: for an app that keeps them on its server. |
ResizableView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
key | string | — | Names the group among others in the same view; needed for more than one. |
labelrequired | string | — | What the group is: "Mail". |
panelsrequired | ReadonlyArray<ResizablePanel & { readonly content: View.Content }> | — | — |
direction | "horizontal" | "vertical" | horizontal | Side by side, or stacked; horizontal by default. |
storageKey | string | — | Keeps the sizes in this browser under this key, so the layout comes back after a reload. |
onResize | (sizes: number[]) => Message | — | The sizes the person settled on, for an app that keeps them on its server. |
style | Style | — | StyleX styles applied after the group's own. |