Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Item for Astro

Astro content rows for lists, linked summaries, and grouped details.

Item Title

Page content is ready for a final check.

Outline Variant

This item has an outline variant

Muted Variant

This item has a muted variant

Installation

bunx --bun shadcn@latest add @gnostic/item
npx shadcn@latest add @gnostic/item
pnpm dlx shadcn@latest add @gnostic/item

Component classes: Default Gnostic.

Complete the Installation guide first. Then copy the component files below.

No extra packages are required.

Copy the files

src/components/ui/item/index.ts
export { default as Item } from "./item.astro"
export { default as ItemActions } from "./item-actions.astro"
export { default as ItemContent } from "./item-content.astro"
export { default as ItemDescription } from "./item-description.astro"
export { default as ItemFooter } from "./item-footer.astro"
export { default as ItemGroup } from "./item-group.astro"
export { default as ItemHeader } from "./item-header.astro"
export { default as ItemMedia } from "./item-media.astro"
export { default as ItemSeparator } from "./item-separator.astro"
export { default as ItemTitle } from "./item-title.astro"
src/components/ui/item/item-actions.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div
  data-slot="item-actions"
  class={cn("flex items-center gap-2", className)}
  {...props}
>
  <slot />
</div>
src/components/ui/item/item-content.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div
  data-slot="item-content"
  class={cn(
    "flex flex-1 flex-col gap-1 group-data-[size=xs]/item:gap-0",
    "[&+[data-slot=item-content]]:flex-none",
    className,
  )}
  {...props}
>
  <slot />
</div>
src/components/ui/item/item-description.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"p">

const { class: className, ...props } = Astro.props
---

<p
  data-slot="item-description"
  class={cn("text-muted-foreground [&>a:hover]:text-primary line-clamp-2 text-left text-sm leading-normal font-normal group-data-[size=xs]/item:text-xs [&>a]:underline [&>a]:underline-offset-4", className)}
  {...props}
>
  <slot />
</p>
src/components/ui/item/item-footer.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div data-slot="item-footer" class={cn("flex basis-full items-center justify-between gap-2", className)} {...props}>
  <slot />
</div>
src/components/ui/item/item-group.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div
  role="list"
  data-slot="item-group"
  class={cn("flex w-full flex-col gap-4 has-data-[size=sm]:gap-2.5 has-data-[size=xs]:gap-2 group/item-group", className)}
  {...props}
>
  <slot />
</div>
src/components/ui/item/item-header.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div data-slot="item-header" class={cn("flex basis-full items-center justify-between gap-2", className)} {...props}>
  <slot />
</div>
src/components/ui/item/item-media.astro
---
import type { HTMLAttributes } from "astro/types"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "cn"

const variants = cva("flex shrink-0 items-center justify-center gap-2 group-has-data-[slot=item-description]/item:translate-y-0.5 group-has-data-[slot=item-description]/item:self-start [&_svg]:pointer-events-none", {
  variants: {
    variant: {
      default: "bg-transparent",
      icon: "[&_svg:not([class*='size-'])]:size-4",
      image: "size-10 overflow-hidden rounded-sm group-data-[size=sm]/item:size-8 group-data-[size=xs]/item:size-6 [&_img]:size-full [&_img]:object-cover",
    },
  },
  defaultVariants: {
    variant: "default",
  },
})

type Props = HTMLAttributes<"div"> & VariantProps<typeof variants>

const { class: className, variant = "default", ...props } = Astro.props
---

<div
  data-slot="item-media"
  data-variant={variant}
  class={cn(variants({ variant }), className)}
  {...props}
>
  <slot />
</div>
src/components/ui/item/item-separator.astro
---
import type { ComponentProps } from "astro/types"

import { cn } from "cn"
import { Separator } from "../separator/index.ts"

type Props = ComponentProps<typeof Separator>

const { class: className, ...props } = Astro.props
---

<Separator
  data-slot="item-separator"
  orientation="horizontal"
  class={cn("my-2", className)}
  {...props}
/>
src/components/ui/item/item-title.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div data-slot="item-title" class={cn("line-clamp-1 flex w-fit items-center gap-2 text-sm leading-snug font-medium underline-offset-4", className)} {...props}>
  <slot />
</div>
src/components/ui/item/item.astro
---
import type { HTMLAttributes } from "astro/types"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "cn"

type Props = VariantProps<typeof variants> &
  HTMLAttributes<"div"> &
  HTMLAttributes<"a">

const variants = cva("[a]:hover:bg-muted focus-visible:border-ring focus-visible:ring-ring/50 flex w-full flex-wrap items-center rounded-md border text-sm transition-colors duration-100 outline-none focus-visible:ring-[3px] [a]:transition-colors group/item", {
  variants: {
    variant: {
      default: "border-transparent",
      outline: "border-border",
      muted: "bg-muted/50 border-transparent",
    },
    size: {
      default: "gap-3.5 px-4 py-3.5",
      sm: "gap-2.5 px-3 py-2.5",
      xs: "gap-2 px-2.5 py-2 in-data-[slot=dropdown-menu-content]:p-0",
    },
  },
  defaultVariants: {
    variant: "default",
    size: "default",
  },
})

const {
  class: className,
  variant = "default",
  size = "default",
  href,
  ...props
} = Astro.props

const Comp = href ? "a" : "div"
---

<Comp
  data-slot="item"
  data-variant={variant}
  data-size={size}
  class={cn(variants({ variant, size }), className)}
  href={href}
  {...props}
>
  <slot />
</Comp>

Usage

import { Item, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "@/components/ui/item"
---
import Heart from "@lucide/astro/icons/heart"
---

<Item>
  <ItemMedia>
    <Heart />
  </ItemMedia>
  <ItemContent>
    <ItemTitle>Title</ItemTitle>
    <ItemDescription>Description</ItemDescription>
  </ItemContent>
</Item>

Composition

Arrange the parts as shown for an Item:

ItemGroup
└── Item
    ├── ItemHeader
    ├── ItemMedia
    ├── ItemContent
    │   ├── ItemTitle
    │   └── ItemDescription
    ├── ItemActions
    └── ItemFooter

Notes

  • Use ItemContent to group the title and description instead of hand-rolled wrappers.
  • Passing href turns the root Item into an anchor, which works well for list rows and navigational cards.
  • Use variants for emphasis changes before adding custom surface styles.

API Reference

Read the installed source for the complete prop types.

When to use Item

Use Item for a compact unit with media, title, description, and actions. Set href when the whole item is a link. Choose its size and surface variant to fit the density of the list.

Keyboard and behavior

Avoid nested links or buttons inside an Item rendered as an anchor. Use a non-link item when the row has several independent actions. Keep reading order logical when media and actions move on small screens.

Theme and layout

Default, outline, and muted variants share page tokens. Test long titles and descriptions without relying on fixed row heights. An item does not fetch data or select itself.