Skip to content
Haze UI

Star button

A secondary-style Star button with a compact count segment, whose accessible name carries the exact number of stars.

pnpm dlx shadcn@latest add @haze/star-button
Open preview in a new tab
Liveno JavaScript

When to use

  • A project, template or repository page links to where people can star it and shows how many already did.
  • A count must sit inside the control, such as stars, likes or followers, without any brand mark.
  • A docs or open-source landing page needs social proof next to the install command.

When not to use

  • A row of joined actions with no count is needed; use button-group.
  • A plain action or link is enough; use button.
  • The user rates something from 1 to 5; use rating.

Installation

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

pnpm dlx shadcn@latest add @haze/star-button
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
countnumber12431Number of stars. The segment shows it compactly (12.4K); the accessible name carries the exact figure.
hrefstring–A non-empty string renders an <a> to the project page. Leave it out to render a <button type="button"> with aria-pressed; that button is inert until your own script toggles it.
labelstring"Star"Visible action text.
starredLabelstring"Starred"Visible text when starred is true.
countLabelstring"stars"Word after the exact count in the accessible name.
countLabelOnestring"star"Singular of countLabel for a count of 1.
starredbooleanfalseFilled star in the warning color plus the starred label. Never color alone.
localestring"en-US"BCP 47 locale for compact and exact number formatting.
size"sm" | "md" | "lg""md"Height 32, 40 or 44 px, matching button.
classstring–Extra classes, merged with tailwind-merge.
...attributesHTML anchor or button attributes–Passed to the element: target, rel, form, data-* hooks for your own script.

Keyboard interactions

Enter
Follow the link, or press the button
Space
Press the button (not when rendered as a link)

Accessibility

  • The accessible name is the visible label followed by the exact count in screen-reader text, such as "Star, 12,431 stars" or "Starred, 12,431 stars". The compact "12.4K" segment is hidden from assistive technology, and no aria-label overrides the visible label.
  • The button variant also sets aria-pressed to match starred; the link variant has no pressed state, so its name carries the state.
  • The button variant is inert without your script: it toggles nothing on its own, so wire click handling (and update starred, aria-pressed and the label) in your page or form, since this component ships no script.
  • The star glyph is decorative. It is filled and the text changes when starred, so state is never color alone.

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 "Star button" with `npx shadcn@latest add @haze/star-button`. 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 StarButton from "@/components/haze/ui/star-button.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/star-button.md

  • Customize with real content

    Adapt the Haze star-button ui for our product. Replace the demo values of these props with our real content: count, href, label, starredLabel, countLabel, countLabelOne, starred, locale, size, class, ...attributes. Keep the layout, the heading level rules and these accessibility details: The accessible name is the visible label followed by the exact count in screen-reader text, such as "Star, 12,431 stars" or "Starred, 12,431 stars". The compact "12.4K" segment is hidden from assistive technology, and no aria-label overrides the visible label. The button variant also sets aria-pressed to match starred; the link variant has no pressed state, so its name carries the state. The button variant is inert without your script: it toggles nothing on its own, so wire click handling (and update starred, aria-pressed and the label) in your page or form, since this component ships no script. The star glyph is decorative. It is filled and the text changes when starred, so state is never color alone. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using star-button, check it fits: use it when a project, template or repository page links to where people can star it and shows how many already did.; a count must sit inside the control, such as stars, likes or followers, without any brand mark.; a docs or open-source landing page needs social proof next to the install command.. Avoid it when a row of joined actions with no count is needed; use button-group.; a plain action or link is enough; use button.; the user rates something from 1 to 5; use rating.. Alternatives: @haze/button-group, @haze/button, @haze/copy-button.

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