Skip to content

Search

Start typing to search.


Show all pages

Documentation

type

Code block

A block of code with a header for its name and a copy button, that scrolls sideways when wide.

Rich widgetNeeds a script for its behavior.

Usage

A <figure> with a <figcaption> header: the title names the code, the actions hold a copy button. data-ca-copy points at the <pre>.

global.css
@import "tailwindcss";
@import "@calaca/ui/core.css";
@import "@calaca/ui/skins/base.css";

HTML

Examples

Without a header

Leave the header out for short snippets; give the <pre> an aria-label instead.

bun add @calaca/ui tailwindcss
HTML

Guidance and accessibility

When to use

  • Use a code block for snippets people copy, such as configuration or markup.
  • Name the code in the header, with the file name when people paste it into a file.
  • Add syntax colors with your highlighter of choice; the block sets the frame, font and scrolling.

Accessibility

  • Lines do not wrap, so code keeps its shape. Give the <pre> tabindex="0", so keyboard users can reach and scroll it.
  • The copy button names its action in words. ca-copy.js copies the text of the element in data-ca-copy and announces the result in the status part. A text-only button also reads “Copied” for two seconds, so sighted people see the result where they clicked; data-ca-copied-label changes the word.
  • The <figcaption> names the figure for screen readers.

Classes

Generated from the component contract. Parts use __, modifiers use --.

Classes of the code-block component
ClassKindUse it for
ca-code-blockComponentThe <figure> around the header and the code.
ca-code-block__headerPartThe <figcaption> with the title and the actions.
ca-code-block__titlePartWhat the code is, such as the language or the file name.
ca-code-block__actionsPartButtons such as Copy code.
ca-code-block__codePartThe <pre>: keeps its lines and scrolls sideways.
ca-code-block__statusPartVisually hidden live region that announces a copy.

Skins

The same markup, dressed by each skin. Structure and behavior stay the same; only the look changes.

Base skin

Neutral grayscale starting point; product skins extend it and change what differs.

global.css
@import "tailwindcss";
@import "@calaca/ui/core.css";
@import "@calaca/ui/skins/base.css";

Calaca skin

The Calaca UI brand: hueso paper and tinta ink, cempasúchil marigold, rosa and jade.

global.css
@import "tailwindcss";
@import "@calaca/ui/core.css";
@import "@calaca/ui/skins/base.css";

Proof skin

Pilot skin pushed far from base: square, heavy, offset shadows, larger targets.

global.css
@import "tailwindcss";
@import "@calaca/ui/core.css";
@import "@calaca/ui/skins/base.css";

Crossview skin

The CrossView proofing table: cool ground, bond-paper sheets, rule-grey hairlines, one red mark.

global.css
@import "tailwindcss";
@import "@calaca/ui/core.css";
@import "@calaca/ui/skins/base.css";

Framework notes

Link the prebuilt stylesheet of your skin next to your brand theme. No build step.

HTML
<link rel="stylesheet" href="theme.css" />
<link rel="stylesheet" href="ca-base.css" />