Skip to content
BigBang

Popular

    ↑↓Navigate↵OpenEscClose
    TR

    Components

    CodeBlock

    Shows code in the mono type with an optional header, line numbers and a copy button.

    Storybook
    Storybook
    Source
    Source
    • To show several lines of code in developer docs, API key set-up steps and integration examples.
    • When the user needs to copy a command or a configuration.
    • To copy a single value: use Copy.
    • For short code inside text: use inline code.
    • To show a key: use Kbd.
    1. Header: an optional figcaption with the title, the language and the copy button.
    2. Scroll region: a focusable, named region; long lines scroll sideways.
    3. Line number: optional; screen readers skip it, and it is not selected or copied.
    4. Code line: mono type; can be highlighted.
    • The code is shown as written; leading and trailing blank lines are removed.
    • The copy button writes the whole code to the clipboard, without line numbers, and confirms it.
    • There is no syntax colouring; language is only written in the header. This is deliberate: a highlighting library adds bundle size and its colours would need contrast checks in every brand and mode, which short code samples in a merchant portal do not justify.
    • Keep examples short and working.
    • Use placeholders instead of real keys or customer data.
    • Use wrap for long commands; prefer sideways scrolling for code.
    • The title is a file name or a short phrase that says what it does: “Install”, config.json.
    • Explain the code in the text before the CodeBlock, not inside the code.
    • Copy: copies a single value.
    • Kbd: shows a key or shortcut.