Item
List row with optional media, a truncating title and description, optional actions and an optional whole-row link.
pnpm dlx shadcn@latest add @haze/item---
import { ChevronRight } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
title: string;
description?: string;
/** When set, the title is a link and the whole row is clickable. A linked row should not hold buttons in its actions slot; use a tag or plain text there. */
href?: string;
/** default has no frame; outline draws a bordered panel. */
variant?: "default" | "outline";
class?: string;
}
const { title, description, href, variant = "default", class: className } = Astro.props;
const hasMedia = Astro.slots.has("media");
const hasActions = Astro.slots.has("actions");
const variants = {
default: "rounded-lg px-3 py-2.5",
outline: "rounded-xl border border-border bg-card p-3",
};
const linkClasses =
"rounded-sm after:absolute after:inset-0 after:content-[''] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring";
---
<div
class={cn(
"group relative flex items-center gap-3",
variants[variant],
href && "transition-colors duration-150 hover:bg-accent",
href && variant === "outline" && "hover:border-frame-strong",
className,
)}
>
{
hasMedia && (
<div class="shrink-0">
<slot name="media" />
</div>
)
}
<div class="grid min-w-0 flex-1 gap-0.5">
{
href ? (
<a href={href} class={cn("w-fit max-w-full truncate text-[0.8125rem]/5 font-medium text-foreground", linkClasses)}>
{title}
</a>
) : (
<p class="truncate text-[0.8125rem]/5 font-medium text-foreground">{title}</p>
)
}
{description && <p class="truncate text-[0.8125rem]/5 text-muted-foreground">{description}</p>}
</div>
{
hasActions && (
<div class="relative z-10 flex shrink-0 items-center gap-2">
<slot name="actions" />
</div>
)
}
{
href && (
<ChevronRight
class="pointer-events-none size-4 shrink-0 text-muted-foreground transition-[translate] duration-200 ease-snappy group-hover:translate-x-0.5"
aria-hidden="true"
/>
)
}
</div>When to use
- Rows of files, people, repositories or settings, each with an icon or avatar and a short description
- A row where the whole area opens a page; add a tag or plain text on the right if needed
- A row with a button on the right and no link
- A bordered row that stands alone, using the outline variant
When not to use
- Comparing many fields across rows; table aligns columns
- A big content box with a header and footer; use card
Installation
Add the Haze registry to components.json once, then install Item with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/itemnpx shadcn@latest add @haze/itemyarn dlx shadcn@latest add @haze/itembunx --bun shadcn@latest add @haze/itemFirst 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
| Prop | Type | Default | Description |
|---|---|---|---|
| title* | string | – | Row title, cut off with an ellipsis when too long. A link when href is set. |
| description | string | – | Muted line under the title, cut off with an ellipsis when too long. |
| href | string | – | Makes the title a link whose click area stretches over the whole row through an after: pseudo-element, and adds a hover fill and a trailing chevron. A linked row should not contain a button. |
| variant | "default" | "outline" | "default" | default has no border; outline draws a bordered panel. |
| class | string | – | Extra classes on the row. |
| media slot | slot | – | Avatar, icon or thumbnail at the left edge. For an icon, wrap it in a 36 px chip: size-9 rounded-lg bg-foreground/5 inset-ring inset-ring-border. |
| actions slot | slot | – | A tag or text at the right edge of a linked row, or buttons in a row with no link. It sits above the link overlay. |
Keyboard interactions
- Tab, Enter
- Focus the row link and follow it; buttons in the right slot of an unlinked row are separate tab stops
Accessibility
- The title and description truncate with an ellipsis instead of wrapping; a linked row shows a chevron that nudges on hover.
- Renders a <div>. To make a list, wrap several items yourself in <ul role="list"> with an <li> each, so the count is announced.
- Only the title is a link, so a screen reader hears one link per row with the title as its name instead of the whole row text.
- A row is either a link or holds buttons, never both: a button inside a link is nested interactive content. The actions slot sits above the stretched link (z-10), which suits non-interactive content such as a tag.
- The chevron is decorative and aria-hidden.
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 "Item" with `npx shadcn@latest add @haze/item`. 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 Item from "@/components/haze/ui/item.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/item.md
Customize with real content
Adapt the Haze item ui for our product. Replace the demo values of these props with our real content: title, description, href, variant, class, media slot, actions slot. Keep the layout, the heading level rules and these accessibility details: The title and description truncate with an ellipsis instead of wrapping; a linked row shows a chevron that nudges on hover. Renders a <div>. To make a list, wrap several items yourself in <ul role="list"> with an <li> each, so the count is announced. Only the title is a link, so a screen reader hears one link per row with the title as its name instead of the whole row text. A row is either a link or holds buttons, never both: a button inside a link is nested interactive content. The actions slot sits above the stretched link (z-10), which suits non-interactive content such as a tag. The chevron is decorative and aria-hidden. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using item, check it fits: use it when rows of files, people, repositories or settings, each with an icon or avatar and a short description; a row where the whole area opens a page; add a tag or plain text on the right if needed; a row with a button on the right and no link; a bordered row that stands alone, using the outline variant. Avoid it when comparing many fields across rows; table aligns columns; a big content box with a header and footer; use card. Alternatives: @haze/card, @haze/table, @haze/avatar.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.