Axon 911 Frontend DocsAxon 911 Frontend Docs
Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. Code Block
  3. API and Development

Code Block

API and Development

View SourceOpens in a new tabSubmit IssueOpens in a new tab
Import CodeBlock from @prepared911/ui/code-block.
PropTypeDefaultNotes
codestringrequiredThe source. Line breaks may be \n, \r\n or \r; the block uses \n
languagestringtsx, json, bash, an alias, or a language-* class. Names the block and picks the grammar
labelLocalizedMessagerequiredAccessible name of the figure and of its scroll area
showCopytrue | falsetruefalse removes the copy control and the three labels below
copyLabelLocalizedMessagerequired with the copy controlName of the control at rest, and its tooltip
copiedLabelLocalizedMessagerequired with the copy controlName once the code is on the clipboard; announced
copyErrorLabelLocalizedMessagerequired with the copy controlName when the clipboard refused; announced
classNamestringAppended after the generated classes
The props are a union on showCopy: the three labels are required unless showCopy is false, and they are rejected when it is.
Exports
CodeBlock and the types CodeBlockProps, CodeBlockWithCopyProps and CodeBlockWithoutCopyProps.
Dependencies
shiki 3.6.0, loaded only through dynamic import(). See packages/ui/docs/decisions/0008-package-build.md.
Props
NameTypeDefaultDescription
codestring—The source code to show. Data, not copy, so it is a plain string.
labelLocalizedMessage—Accessible name of the code region and its scroll area, for example "Code".
classNamestring—Classes appended after the generated classes. Put overrides in @layer chroma.overrides.
copiedLabelLocalizedMessage—Name of the copy control once the code is on the clipboard. Announced when it appears. Absent without a copy control.
copyErrorLabelLocalizedMessage—Name of the copy control when the clipboard refused the code. Announced when it appears. Absent without a copy control.
copyLabelLocalizedMessage—Accessible name of the copy control at rest. Absent without a copy control.
languagestring—Language of the code, such as tsx, json or bash. It names the block in its header and picks the grammar that highlights it. A language- prefix is accepted. A language the highlighter does not carry, or none, leaves the code plain.
showCopybooleantrueShows the copy control. Hides the copy control.
Storybook
Interactive examples and edge cases for this component are in Storybook.
DefaultOpens in a new tab
Previous
Code Block / Usage
Next
Code Block / Accessibility
On this page
Exports
Dependencies
Props
Storybook