Skip to content
Haze UI

Snippet

One-line command in a mono field that scrolls sideways, with an optional prompt prefix and a copy button added by script.

pnpm dlx shadcn@latest add @haze/snippet
Open preview in a new tab
Livesmall script

When to use

  • An install or CLI command that readers will paste into a terminal
  • A short token-like value such as a package name or a URL that people copy
  • Docs and landing pages where one command is the main call to action

When not to use

  • Several lines or a file; code-block shows multi-line code with a header
  • Secrets that must not reach the clipboard history of a shared machine

Installation

Add the Haze registry to components.json once, then install Snippet with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/snippet
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
text*string–The command. It is displayed as written and copied unchanged.
prefixstring–Leading marker such as "$". Hidden from screen readers and from selection, and not copied.
copyLabelstring"Copy"Accessible name of the copy button.
copiedLabelstring"Copied"Text announced after a successful copy.
failedLabelstring"Copy failed"Text announced when the browser refuses the copy, for example without clipboard permission.
classstring–Extra classes on the box.

Keyboard interactions

Tab
Move to the command box, then to the copy button
EnterSpace
Copy the command to the clipboard
Arrow LeftRight
Scroll a long command while the command box has focus

Accessibility

  • The copy button starts with the hidden attribute and script reveals it, so without script the command is still selectable text and no dead button appears.
  • After a copy, copiedLabel (or failedLabel when the copy was refused) goes into a role="status" region, so screen reader users hear the result; the icon swap alone would be silent.
  • The icon shows a check for 2 seconds on success and a cross on failure, then returns to the copy icon; the status text is cleared at the same time.
  • The scrolling <code> is focusable, so a command longer than the box can be scrolled with the keyboard.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Snippet" with `npx shadcn@latest add @haze/snippet`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Snippet from "@/components/haze/ui/snippet.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/snippet.md

  • Customize with real content

    Adapt the Haze snippet ui for our product. Replace the demo values of these props with our real content: text, prefix, copyLabel, copiedLabel, failedLabel, class. Keep the layout, the heading level rules and these accessibility details: The copy button starts with the hidden attribute and script reveals it, so without script the command is still selectable text and no dead button appears. After a copy, copiedLabel (or failedLabel when the copy was refused) goes into a role="status" region, so screen reader users hear the result; the icon swap alone would be silent. The icon shows a check for 2 seconds on success and a cross on failure, then returns to the copy icon; the status text is cleared at the same time. The scrolling <code> is focusable, so a command longer than the box can be scrolled with the keyboard. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using snippet, check it fits: use it when an install or cli command that readers will paste into a terminal; a short token-like value such as a package name or a url that people copy; docs and landing pages where one command is the main call to action. Avoid it when several lines or a file; code-block shows multi-line code with a header; secrets that must not reach the clipboard history of a shared machine. Alternatives: @haze/code-block, @haze/kbd, @haze/input-group.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog