{"name":"code-block","title":"Code Block","description":"","kind":"component","category":"display","status":"beta","props":{"variant":{"type":"enum","values":["code","diff","command"],"default":"code","description":"code: line-numbered listing. diff: unified diff. command: one line to copy (an install command): no header, no line numbers, copy at the end."},"filename":{"type":"string","default":"example.ts","description":"The file's name in the header, and the name of the scroll region."},"value":{"type":"string","model":true,"description":"The code, lines separated by \\n: shown, copied, and, when editable, edited (valueChange). The command variant shows it as one line."},"diff":{"type":"array","items":{"old":"number|null","cur":"number|null","type":"ctx|add|del","pieces":"{ text: string; change?: 'add'|'del' }[]"}},"maxHeight":{"type":"number","description":"Height in px of the code past which it scrolls: passed to the Code View (the header is not counted)."},"labels":{"type":"object","description":"{ copy, copied, copyCode, files, file, previousFile, nextFile } and the Code View's editor words (find, replace, …), passed on"},"highlighted":{"type":"array","description":"Lines already highlighted elsewhere (shiki and the like), as trusted HTML, one string per line; shown instead of value. Display only: Copy takes value, and editable shows value with the tokenizer's colours."},"files":{"type":"array","items":{"path":"string","label":"string?","value":"string?","highlighted":"string[]?"},"description":"Files as tabs (the tabs component, underline, inHeader) in one 44px header row: the tabs at the start, their underline resting on the header's hairline, then the active file's path and the block's one Copy (it copies the active file), placed as in a single file's header. Each panel holds the file's Code View; editable, the block keeps each file's edits while another is open. The path shrinks first (cut in the middle). Names of choices are shown whole: when the tabs do not fit beside Copy (measured on mount and on every change of width, code-block.logic.ts), the root takes data-fit=\"select\", the tab list is hidden and a pager plus a select of every file stand in for it; the tabs come back once they fit."},"file":{"type":"string","model":true,"description":"The active file's path (defaults to the first)."},"height":{"type":"number","description":"Fixed height in px of the code: the box keeps its size whatever the code (loading, switching files). Passed to the Code View."},"fill":{"type":"boolean","default":false,"description":"Fill the container's height: the block is a column as tall as its parent (give the parent a height), the header keeps its 44px and the Code View takes the rest and scrolls; no max width. Not for the command variant."},"currentLine":{"type":"number","description":"The current line, 1-based, of the listing or of the active file: passed to the Code View, which tints it and keeps it in view; editable, a new value moves the caret there. A diff ignores it."},"wrap":{"type":"boolean","default":true,"description":"Long lines wrap (default) or, false, scroll sideways under a gutter that stays: passed to the Code View."},"editable":{"type":"boolean","default":false,"description":"The code is an editor (the Code View's editable: undo, find and replace, several cursors, folding); Copy takes the edited text and every edit is reported (valueChange). Not for a diff or a command. The editor keeps a 12px fold column, so turning editable on or off on a live block moves the code by that much."}},"playground":{"name":"Playground","props":{"variant":"code","filename":"scripts/deploy.ts","value":"await northwind.deploys.create({\n  project: \"web-app\",\n  target: \"production\",\n});"}},"exampleFiles":[{"file":"create-deploy","title":"Create a deploy from the SDK"},{"file":"pull-request-diff","title":"Review a change"},{"file":"install-command","title":"Install command"},{"file":"sdk-setup","title":"Setup across two files"},{"file":"project-config","title":"A long config file"}],"worstCase":[{"name":"400-character line, long filename, non-Latin and right-to-left","props":{"variant":"code","filename":"northwind-industries-holdings-wholesale-cloud-services-division-billing-schedule.ts","value":"  const note = \"invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-invoicing-ok\";\n  const name = \"請求書と領収書のまとめ\";\n  const label = \"فواتير الشهر\";\n  return { name, label };"}},{"name":"Sixty lines","props":{"variant":"code","filename":"batches.ts","maxHeight":320,"value":"charge(\"batch-1\");\ncharge(\"batch-2\");\ncharge(\"batch-3\");\ncharge(\"batch-4\");\ncharge(\"batch-5\");\ncharge(\"batch-6\");\ncharge(\"batch-7\");\ncharge(\"batch-8\");\ncharge(\"batch-9\");\ncharge(\"batch-10\");\ncharge(\"batch-11\");\ncharge(\"batch-12\");\ncharge(\"batch-13\");\ncharge(\"batch-14\");\ncharge(\"batch-15\");\ncharge(\"batch-16\");\ncharge(\"batch-17\");\ncharge(\"batch-18\");\ncharge(\"batch-19\");\ncharge(\"batch-20\");\ncharge(\"batch-21\");\ncharge(\"batch-22\");\ncharge(\"batch-23\");\ncharge(\"batch-24\");\ncharge(\"batch-25\");\ncharge(\"batch-26\");\ncharge(\"batch-27\");\ncharge(\"batch-28\");\ncharge(\"batch-29\");\ncharge(\"batch-30\");\ncharge(\"batch-31\");\ncharge(\"batch-32\");\ncharge(\"batch-33\");\ncharge(\"batch-34\");\ncharge(\"batch-35\");\ncharge(\"batch-36\");\ncharge(\"batch-37\");\ncharge(\"batch-38\");\ncharge(\"batch-39\");\ncharge(\"batch-40\");\ncharge(\"batch-41\");\ncharge(\"batch-42\");\ncharge(\"batch-43\");\ncharge(\"batch-44\");\ncharge(\"batch-45\");\ncharge(\"batch-46\");\ncharge(\"batch-47\");\ncharge(\"batch-48\");\ncharge(\"batch-49\");\ncharge(\"batch-50\");\ncharge(\"batch-51\");\ncharge(\"batch-52\");\ncharge(\"batch-53\");\ncharge(\"batch-54\");\ncharge(\"batch-55\");\ncharge(\"batch-56\");\ncharge(\"batch-57\");\ncharge(\"batch-58\");\ncharge(\"batch-59\");\ncharge(\"batch-60\");"}},{"name":"One line","props":{"variant":"code","filename":"a.ts","value":"export {};"}},{"name":"Zero lines","props":{"variant":"code","filename":"empty.ts","value":""}},{"name":"Five files, long path","props":{"files":[{"path":"packages/core/src/behaviors/some/really/deeply/nested/directory/structure/invoice-batch-scheduler.ts","label":"invoice-batch-scheduler.ts","value":"export const invoice = (amount: number) => amount * 2;"},{"path":"src/ledger.ts","label":"ledger.ts","value":"export const terms = 30;"},{"path":"src/billing.ts","label":"billing.ts","value":"export const billing = {};"},{"path":"src/accounts.ts","label":"accounts.ts","value":"export const accounts = [];"},{"path":"src/index.ts","label":"index.ts","value":"export * from \"./invoice\";"}],"height":120}}],"anatomy":[{"part":"root","element":"div","description":"Card, max-width 420; fill: no max width, as tall as its container"},{"part":"header","element":"div","description":"44px: icon · filename · copy | stat. With files the same 44px row is the tabs' header part: file tabs · path · copy, or, when the tabs do not fit, pager · select · path · copy"},{"part":"file-icon","element":"i","description":"Phosphor code icon"},{"part":"filename","element":"span","description":"Cut in the middle while it does not fit (a file name keeps its end: \"invoice-batch-…-scheduler.ts\"), full name in title while cut (lib/truncate.ts middleTruncation)"},{"part":"copy","element":"button","optional":true,"description":"A Button (ghost, xs, rounded, muted) with two labels in one cell (icon part: copy and check; label part: Copy and Copied); data-swapped while \"Copied\" shows; aria-label \"Copy code\". Its green while swapped is the code block's. Beside it a visually hidden role=status (sr-only) announces \"Copied\". The real Button, marked data-code-block=\"copy\"; swapped while Copied shows."},{"part":"status","element":"span","description":"Visually hidden role=status beside Copy; says Copied while the button is swapped."},{"part":"stat","element":"span","optional":true,"description":"+N -M for the diff variant"},{"part":"view","element":"div","description":"The Code View (code-view), marked data-code-block=\"view\", under the header: the listing, the highlighted lines, the diff or the editor, named by the filename (the active file's path with files). It takes the block's value, wrap, currentLine, height, maxHeight and editable; with fill it takes what the header leaves."},{"part":"path","element":"span","optional":true,"description":"With files: the active file's path in the header row, pushed to the end before Copy; mono, xs, ink-2; the first thing to shrink, cut in the middle so the file name stays (\"packages/…/select.tsx\"), full path in title while cut; hidden while the pager and the select stand in for the tabs (the select names the file)"},{"part":"pager","element":"div","optional":true,"description":"With files, while the tabs do not fit (data-fit=\"select\" on the root): the pager component (loop, \"2 of 5\", Previous file / Next file) in the header, before the select"},{"part":"file-select","element":"div","optional":true,"description":"With files, while the tabs do not fit: the select component (sm, subtle) listing every file by its label, its value cut in the middle when it does not fit; it and the pager stand in for the hidden tab list (and the path) and go once the tabs fit again"},{"part":"command","element":"div","optional":true,"description":"variant=command: the one row: the code and a trailing copy"},{"part":"code","element":"code","optional":true,"description":"variant=command: the command, one line that scrolls sideways (no scrollbar)"}],"events":{"copy":"(text: string) after a successful copy","valueChange":"(value: string) after every edit in the editor: the block's text, or the open file's","currentLineChange":"(line: number) when the editor's caret moves to another line","fileChange":"(path: string) when another file is opened"},"states":["hover","press","focus-visible","disabled","copied"],"tokens":["color.surface","color.ink","color.ink-2","color.ink-3","color.line","color.green","color.red","shadow.card","radius.card","font.mono","text.xs","text.dense","duration.fast","duration.base","duration.press","easing.out-strong","motion.press-scale"],"a11y":{"role":"region (the Code View, while it scrolls)","keyboard":["Enter / Space on Copy copy the code; focus stays on the button","Tab reaches the code while it overflows (the Code View's scroll region); the arrow keys and Page Up / Page Down scroll it"],"notes":["Copy is named \"Copy code\"; its visible labels are aria-hidden. A visually hidden role=status region announces \"Copied\" politely and empties when the label reverts.","Line numbers, the scroll region and right-to-left reading are the Code View's (see code-view)."]},"motion":["copy: icon and label crossfade with opacity and a 2px blur over duration.base; colour over duration.fast; press scales to motion.press-scale over duration.press","\"Copied\" holds for 1.5s, then crossfades back; with files it belongs to the file that was copied: opening another file shows Copy at once (no fade) and the status empties","Code / Diff switch: no animation","Tabs ↔ pager + select switch (width): no animation; nothing plays on first paint"]}