Skip to content

Commit 03f378c

Browse files
authored
Merge pull request #78 from re-marked/codex/docs-correct-viewport-box-defaults
docs: correct viewport hook and box defaults
2 parents 3c111b0 + 94d3014 commit 03f378c

9 files changed

Lines changed: 21 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ See [release notes](https://github.com/re-marked/yokai/releases) for what's in e
191191
| `useApp()` | `{ exit }` |
192192
| `useStdin()` | Stdin stream + `isRawModeSupported` |
193193
| `useStdout()` | Stdout stream + `write` |
194-
| `useTerminalViewport()` | `{ columns, rows }`, updates on resize |
194+
| `useTerminalViewport()` | `[ref, entry]`, where `entry.isVisible` tracks whether the referenced element is currently in the terminal viewport |
195195
| `useFocus(options?)` | `{ ref, isFocused, focus }` per-element focus tracking + imperative focus |
196196
| `useFocusManager()` | `{ focused, focus, focusNext, focusPrevious, blur }` global focus actions, reactive to changes |
197197
| `useInterval(fn, ms)` | Stable interval that cleans up on unmount |

docs/AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Guide for AI agents writing code that uses yokai. Read this before generating yo
2222
| `<AlternateScreen mouseTracking pasteThreshold={n}>` | Manually writing `\x1b[?1049h`, `\x1b[?1000h`, `\x1b[?2004h`, parsing `200~`/`201~` for paste |
2323
| `<ScrollBox stickyScroll>` | Manual scroll-offset tracking + viewport math |
2424
| `<Link>` | Hand-rolled OSC 8 escape sequences |
25-
| `useTerminalViewport()` | Reading `process.stdout.columns` directly |
25+
| `<Box onResize>` / `TerminalSizeContext` | Reading `process.stdout.columns` directly |
2626
| `useApp().exit()` | `process.exit()` |
2727

2828
The high-level component handles edge cases (lost-release recovery, gesture cancellation on FOCUS_OUT, drag-time z-boost, focus-visible chrome) that hand-rolled equivalents miss.

docs/concepts/layout.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ Percent values (`width: '50%'`, `marginLeft: '10%'`) resolve against the parent'
1010

1111
## Defaults
1212

13+
These are the consumer-facing defaults applied by `<Box>`. The underlying Yoga port keeps its own native defaults internally, but `<Box>` sets the values most Yokai apps actually see.
14+
1315
| Property | Yokai default | CSS default |
1416
|---|---|---|
15-
| `flexDirection` | `'column'` | `'row'` |
16-
| `flexShrink` | `0` | `1` |
17+
| `flexDirection` | `'row'` | `'row'` |
18+
| `flexShrink` | `1` | `1` |
1719
| `alignItems` | `'stretch'` | `'stretch'` |
1820
| `display` | `'flex'` | `'inline'` |
1921

20-
`flexDirection: 'column'` matches Yoga's default and aligns with terminal stacking. `flexShrink: 0` is the port's default — children keep their measured size unless the parent overflows. Set `flexShrink={1}` to opt into CSS-style shrink.
22+
Use `flexDirection="column"` for the common terminal pattern where rows stack vertically. Set `flexShrink={0}` on chrome that must not collapse, such as title bars, footers, and fixed-width sidebars.
2123

2224
## Spacing
2325

docs/faq.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Short answers to recurring questions. Each links to the canonical doc page when
88
A React reconciler for the terminal. Pure-TS Yoga flexbox, diff-based screen output, ScrollBox with viewport culling. Mount React components, get ANSI on stdout. See [README](./README.md).
99

1010
**How is it different from Ink?**
11-
Forked from Ink via claude-code-kit. Pure-TypeScript Yoga (no WASM), per-cell frame diffing with DECSTBM scroll hints, native ScrollBox with viewport culling, mouse events with gesture capture, drag/drop/resize primitives, focus groups with arrow navigation, alt-screen, z-index for absolutes. `flexShrink` defaults to `0` (matches Yoga, not CSS or Ink).
11+
Forked from Ink via claude-code-kit. Pure-TypeScript Yoga (no WASM), per-cell frame diffing with DECSTBM scroll hints, native ScrollBox with viewport culling, mouse events with gesture capture, drag/drop/resize primitives, focus groups with arrow navigation, alt-screen, z-index for absolutes. The public `<Box>` component defaults `flexShrink` to `1` (matching CSS and Ink) while the low-level Yoga port keeps Yoga's native defaults internally.
1212

1313
**When NOT to use yokai?**
1414
For one-shot CLI output (a `--help` screen, a single status line) reach for plain `console.log` or `chalk`. yokai's payoff is interactive trees and sustained renders.
@@ -32,8 +32,8 @@ Standard package install. The build artifacts are emitted by the workspace; no s
3232
**Why is my Box empty?**
3333
A Box with no `width`/`height` and no children collapses to zero. Add `flexGrow={1}` to take available space, or set explicit dimensions. See [styles reference](./reference/styles.md).
3434

35-
**Why does flexShrink behave differently from CSS?**
36-
Yokai inherits Yoga's default of `flexShrink: 0`. CSS and Ink default to `1`. To allow a child to shrink past content size, set `flexShrink={1}` explicitly. See [styles reference](./reference/styles.md).
35+
**Why does my fixed chrome collapse under layout pressure?**
36+
`<Box>` defaults to `flexShrink={1}`, matching CSS and Ink. That is usually right for content, but fixed chrome such as title bars, footers, and sidebars should opt out with `flexShrink={0}`. See [styles reference](./reference/styles.md).
3737

3838
**Why is my absolute element not where I put it?**
3939
`top`/`left`/`right`/`bottom` are relative to the nearest positioned ancestor (the parent Box, in yokai). Percent strings are percent of parent. `zIndex` is honored only on `position: 'absolute'` and only sorts among siblings of the same parent. See [styles reference](./reference/styles.md).
@@ -71,7 +71,7 @@ The capture cannot be released mid-flight (matches `setPointerCapture`). Track a
7171
## Resize
7272

7373
**Why does my content get clipped?**
74-
`<Resizable>` clips overflow by default — content larger than the resized box is hidden. Set the inner content to `flexShrink={1}` or use a ScrollBox inside.
74+
`<Resizable>` clips overflow by default — content larger than the resized box is hidden. Let flexible inner content keep the default `flexShrink={1}`, mark fixed chrome with `flexShrink={0}`, or use a ScrollBox inside.
7575

7676
**Can I shrink past content size?**
7777
Yes — pass `minSize={{ width: 1, height: 1 }}` or whatever floor you want. The default min is content size.
@@ -85,4 +85,4 @@ Use `import { logForDebugging } from '@yokai-tui/shared'`. Direct `console.log`
8585
Use `renderSync` with a fake `stdout`, then assert on the captured frame. See [testing guide](./guides/testing.md).
8686

8787
**How do I handle terminal resize?**
88-
Read viewport reactively via `useTerminalViewport()`, or bind `onResize` on a Box. SIGWINCH can pulse rapidly during a window-drag-resize debounce reactive reads. See [troubleshooting](./troubleshooting.md).
88+
Bind `onResize` on a Box to receive `{ columns, rows }` from SIGWINCH. `useTerminalViewport()` is for visibility tracking of a referenced element, not terminal dimensions. Resize can pulse rapidly during a window-drag-resize, so debounce expensive state updates. See [troubleshooting](./troubleshooting.md).

docs/guides/debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ See [troubleshooting.md](./troubleshooting.md). The frequent ones:
8080
- Output mixes with `console.log` → set `patchConsole: true` (default) or write to stderr
8181
- Mouse events do nothing → wrap the tree in `<AlternateScreen>`
8282
- `useFocus` reports never-focused → attach `ref` AND pass `tabIndex={0}` on the Box
83-
- Layout collapses unexpectedly set `flexShrink={1}` (yokai's default is 0, not 1)
83+
- Layout chrome collapses unexpectedly -> set `flexShrink={0}` on title bars, footers, and other fixed chrome
8484
- Ctrl+C does not exit → check `exitOnCtrlC: true` on render options, or that no `useInput` handler is swallowing the event

docs/guides/migration-from-ink.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,9 @@ Yokai honors `Styles.zIndex` on `position: 'absolute'` nodes. Stacking is per-pa
6969

7070
### Pure-TS Yoga
7171

72-
Layout runs through `@yokai-tui/shared`'s pure-TypeScript flexbox engine — no WASM, no native binding. One default differs from Ink:
72+
Layout runs through `@yokai-tui/shared`'s pure-TypeScript flexbox engine — no WASM, no native binding. The low-level Yoga port keeps Yoga's native defaults internally, but the public `<Box>` component applies Ink/CSS-like defaults (`flexDirection="row"`, `flexShrink={1}`).
7373

74-
| Property | Ink default | yokai default |
75-
|----------|-------------|---------------|
76-
| `flexShrink` | 1 (CSS) | 0 |
77-
78-
Existing Ink layouts that relied on automatic shrinking need `flexShrink={1}` set explicitly.
74+
If fixed chrome such as title bars, footers, or sidebars disappears under layout pressure, set `flexShrink={0}` on that chrome.
7975

8076
## Removed / renamed APIs
8177

docs/reference/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Terminal resize. Source: `events/resize-event.ts`. Extends `Event`.
207207
208208
**Methods**: `stopImmediatePropagation()`.
209209
210-
**Fires when**: SIGWINCH on the controlling stdout. Bound via `onResize` on `<Box>` (bubble only) or read reactively via `useTerminalViewport`.
210+
**Fires when**: SIGWINCH on the controlling stdout. Bound via `onResize` on `<Box>` (bubble only). `useTerminalViewport()` is a referenced-element visibility hook and does not expose terminal `{ columns, rows }`.
211211
212212
**Propagation**: bubble only.
213213

docs/reference/styles.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Every property on the `Styles` type. Source: `packages/renderer/src/styles.ts`.
2525

2626
| Prop | Type | Default | Notes |
2727
|------|------|---------|-------|
28-
| `flexDirection` | `'row' \| 'column' \| 'row-reverse' \| 'column-reverse'` | `'column'` | Yoga default |
28+
| `flexDirection` | `'row' \| 'column' \| 'row-reverse' \| 'column-reverse'` | `'row'` | `<Box>` default; pass `'column'` for stacked rows |
2929
| `flexGrow` | `number` | `0` | |
30-
| `flexShrink` | `number` | `0` | **Differs from CSS / Ink (which default to 1).** Pass `1` to enable shrinking |
30+
| `flexShrink` | `number` | `1` | `<Box>` default matches CSS / Ink. Pass `0` for chrome that must not collapse |
3131
| `flexBasis` | `number \| string` | `NaN` | Cells or percent string |
3232
| `flexWrap` | `'nowrap' \| 'wrap' \| 'wrap-reverse'` | `'nowrap'` | |
3333
| `alignItems` | `'flex-start' \| 'center' \| 'flex-end' \| 'stretch'` | `'stretch'` | Cross-axis |

docs/troubleshooting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ Tab cycling is global; arrow navigation is opt-in. Wrap the focusable region in
1616

1717
### Box overflows its parent
1818

19-
Yoga does not shrink children by default. Set `flexShrink={1}` on the child, or `overflow="hidden"` on the parent to clip. For text, also set `wrap="truncate"` or similar.
19+
`<Box>` children shrink by default (`flexShrink={1}`), matching CSS and Ink. If overflow is intentional chrome, set `flexShrink={0}` on that fixed child; otherwise add `overflow="hidden"` on the parent to clip. For text, also set `wrap="truncate"` or similar.
2020

2121
### Text is cut off mid-word
2222

23-
Set `wrap="wrap"` on the `<Text>`, or widen the parent container. Wrapping respects terminal width via `useTerminalViewport`. For fixed columns, set `width` on the enclosing Box.
23+
Set `wrap="wrap"` on the `<Text>`, or widen the parent container. Wrapping follows the terminal width reported through layout/resize; for fixed columns, set `width` on the enclosing Box.
2424

2525
### Colors don't show
2626

2727
Check the terminal's color capability. Set `FORCE_COLOR=1` to override detection in pipes and CI. `FORCE_COLOR=3` forces 24-bit. If colors render as raw ANSI escapes in output, the terminal is not interpreting them — check `TERM` is set.
2828

2929
### Layout flickers on resize
3030

31-
Debounce reactive reads from `useTerminalViewport`, or batch state changes in a single `setState` call. Resize fires SIGWINCH, which can pulse rapidly during a drag-resize of the terminal window itself.
31+
Debounce `onResize` work, or batch state changes in a single `setState` call. Resize fires SIGWINCH, which can pulse rapidly during a drag-resize of the terminal window itself. `useTerminalViewport()` tracks referenced-element visibility, not terminal dimensions.
3232

3333
### Drag handle doesn't respond after I add a wrapper around it
3434

0 commit comments

Comments
 (0)