Code
A code block with a language label and a copy button. The text is the block’s content. It doesn’t apply syntax highlighting on its own, which keeps the package light and dependency-free.
Helpers · TaishoDS Core, in plain HTML.
Examples
One working example per case. Each example is the HTML of its preview—copy it as is, and with Core’s CSS and JS loaded, it looks and works the same.
Install command
npm i -D @taishods/core
Alternatives with tabs
npm i -D @taishods/core
pnpm add -D @taishods/core
When to use
- You’re showing a snippet the reader will copy and paste.
- It’s a multi-line block, like a command, a config file, or a snippet.
- It helps to say what language it’s in.
- The same code has alternatives (CDN or npm): the tabs go in the block’s header, not above it.
When not to use
- It’s a prop or file name inside a sentence →
inline-code. - It’s a key or a shortcut →
kbd.
Do
- Keep the block copyable. That’s why the button exists.
- Show the smallest snippet that makes sense on its own.
Don’t
- Don’t paste whole files when ten lines will do.
- Don’t use it to highlight text that isn’t code.
Related
TaishoDS Core
Needs Core’s JS, which hooks in through data-ts-* attributes.
The copy button confirms the action with brief feedback, and Core handles that.
Core hooks into it through these attributes. They go in the markup, and there’s nothing to initialize.
data-ts-copied-icondata-ts-copied-labeldata-ts-copydata-ts-tabsdata-ts-tabs-paneldata-ts-tabs-tabdata-ts-value
What it does: Copies the text to the clipboard and shows the confirmation for 2 seconds—the “Copied” name (data-ts-copied-label) and the ✓ (<template data-ts-copied-icon>). Then it returns to rest. Pressing it again restarts the 2 seconds.
From the CDN, without a build, load taisho.code.css along with taisho.base.css. Also load:
taisho.button.csstaisho.icon.csstaisho.spinner.css
For how Core works in general, see Behavior.
Accessibility
- The scrollable block gets
tabindex="0". The copy button exposes anaria-labeland confirms the action with text, not just color. After copying, its accessible name changes from “Copy code” to “Copied” (and the icon to ✓) for 2 s, so a screen reader announces the success. - With tabs in the header, the content becomes
role="tabpanel"(it stays in the tab order) named by the active tab, and each tab points to the panel witharia-controlsand the tabs follow the tabs pattern: arrow keys, Home and End switch tabs.
Keyboard
On top of what the browser already does (Tab moves focus, Enter activates a button).
| Key | What it does |
|---|---|
| →←/Home/End | Only with tabs in the header: they switch to the next, previous, first, and last tab, as in Tabs. |
Verification
What was actually tested. Anything that wasn’t tested says so—we’d rather say “not verified” than claim too much.
- axe WCAG 2.2 A + AA in a real browser, in light and dark mode, before every release.
- keyboard Key map documented above, checked against the component.
- screen reader Not verified with a screen reader. Test it in your own combination of components, not just here, where each one appears alone and on its happy path.