A versatile component that you can use to display any content.
The
Item
component is a straightforward flex container that can house nearly any type of content. Use it to display a title, description, and actions. Group it with the
ItemGroup
component to create a list of items.
You can pretty much achieve the same result with the
div
element and some classes, but
I've built this so many times
that I decided to create a component for it. Now I use it all the time.
Verify via email or phone number.
import { Button } from '@/components/ui/button';
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';
import BadgeCheck from '~icons/lucide/badge-check';
import ChevronRight from '~icons/lucide/chevron-right';
<template>
<div class="flex w-full max-w-md flex-col gap-6">
<Item @variant="outline">
<ItemContent>
<ItemTitle>Two-factor authentication</ItemTitle>
<ItemDescription @class="text-pretty xl:hidden 2xl:block">
Verify via email or phone number.
</ItemDescription>
</ItemContent>
<ItemActions>
<Button @size="sm">Enable</Button>
</ItemActions>
</Item>
<Item @asChild={{true}} @size="sm" @variant="outline" as |item|>
<a
class={{item.class}}
data-size={{item.size}}
data-slot={{item.slot}}
data-variant={{item.variant}}
href="#"
>
<ItemMedia>
<BadgeCheck class="size-5" />
</ItemMedia>
<ItemContent>
<ItemTitle>Your profile has been verified.</ItemTitle>
</ItemContent>
<ItemActions>
<ChevronRight class="size-4" />
</ItemActions>
</a>
</Item>
</div>
</template>Installation
Copy and paste the following code into your project.
import Component from '@glimmer/component';
import { Separator } from '@/components/ui/separator';
import { cn } from '@/lib/utils';
import type { TOC } from '@ember/component/template-only';
type ItemVariant = 'default' | 'outline' | 'muted';
type ItemSize = 'default' | 'sm';
type ItemMediaVariant = 'default' | 'icon' | 'image';
function itemVariants(
variant: ItemVariant = 'default',
size: ItemSize = 'default',
className?: string
): string {
const baseClasses =
'group/item flex items-center border border-transparent text-sm rounded-md transition-colors [a]:hover:bg-accent/50 [a]:transition-colors duration-100 flex-wrap outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]';
const variantClasses: Record<ItemVariant, string> = {
default: 'bg-transparent',
outline: 'border-border',
muted: 'bg-muted/50',
};
const sizeClasses: Record<ItemSize, string> = {
default: 'p-4 gap-4',
sm: 'py-3 px-4 gap-2.5',
};
return cn(baseClasses, variantClasses[variant], sizeClasses[size], className);
}
function itemMediaVariants(
variant: ItemMediaVariant = 'default',
className?: string
): string {
const baseClasses =
'flex shrink-0 items-center justify-center gap-2 group-has-[[data-slot=item-description]]/item:self-start [&_svg]:pointer-events-none group-has-[[data-slot=item-description]]/item:translate-y-0.5';
const variantClasses: Record<ItemMediaVariant, string> = {
default: 'bg-transparent',
icon: "size-8 border rounded-sm bg-muted [&_svg:not([class*='size-'])]:size-4",
image:
'size-10 rounded-sm overflow-hidden [&_img]:size-full [&_img]:object-cover',
};
return cn(baseClasses, variantClasses[variant], className);
}
interface ItemGroupSignature {
Element: HTMLDivElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemGroup: TOC<ItemGroupSignature> = <template>
<div
class={{cn "group/item-group flex flex-col" @class}}
data-slot="item-group"
role="list"
...attributes
>
{{yield}}
</div>
</template>;
interface ItemSeparatorSignature {
Element: HTMLDivElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemSeparator: TOC<ItemSeparatorSignature> = <template>
<Separator
@class={{cn "my-0" @class}}
@orientation="horizontal"
data-slot="item-separator"
...attributes
/>
</template>;
interface ItemSignature {
Element: HTMLDivElement;
Args: {
class?: string;
variant?: ItemVariant;
size?: ItemSize;
asChild?: boolean;
};
Blocks: {
default: [
{
slot: string;
variant: ItemVariant;
size: ItemSize;
class: string;
},
];
};
}
class Item extends Component<ItemSignature> {
get variant(): ItemVariant {
return this.args.variant ?? 'default';
}
get size(): ItemSize {
return this.args.size ?? 'default';
}
get classes(): string {
return itemVariants(this.variant, this.size, this.args.class);
}
get yieldedContext() {
return {
slot: 'item',
variant: this.variant,
size: this.size,
class: this.classes,
};
}
<template>
{{#if @asChild}}
{{yield this.yieldedContext}}
{{else}}
<div
class={{this.classes}}
data-size={{this.size}}
data-slot="item"
data-variant={{this.variant}}
...attributes
>
{{yield this.yieldedContext}}
</div>
{{/if}}
</template>
}
interface ItemMediaSignature {
Element: HTMLDivElement;
Args: {
class?: string;
variant?: ItemMediaVariant;
};
Blocks: {
default: [];
};
}
class ItemMedia extends Component<ItemMediaSignature> {
get variant(): ItemMediaVariant {
return this.args.variant ?? 'default';
}
get classes(): string {
return itemMediaVariants(this.variant, this.args.class);
}
<template>
<div
class={{this.classes}}
data-slot="item-media"
data-variant={{this.variant}}
...attributes
>
{{yield}}
</div>
</template>
}
interface ItemContentSignature {
Element: HTMLDivElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemContent: TOC<ItemContentSignature> = <template>
<div
class={{cn
"flex flex-1 flex-col gap-1 [&+[data-slot=item-content]]:flex-none"
@class
}}
data-slot="item-content"
...attributes
>
{{yield}}
</div>
</template>;
interface ItemTitleSignature {
Element: HTMLDivElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemTitle: TOC<ItemTitleSignature> = <template>
<div
class={{cn
"flex w-fit items-center gap-2 text-sm leading-snug font-medium"
@class
}}
data-slot="item-title"
...attributes
>
{{yield}}
</div>
</template>;
interface ItemDescriptionSignature {
Element: HTMLParagraphElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemDescription: TOC<ItemDescriptionSignature> = <template>
<p
class={{cn
"text-muted-foreground line-clamp-2 text-sm leading-normal font-normal text-balance [&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4"
@class
}}
data-slot="item-description"
...attributes
>
{{yield}}
</p>
</template>;
interface ItemActionsSignature {
Element: HTMLDivElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemActions: TOC<ItemActionsSignature> = <template>
<div
class={{cn "flex items-center gap-2" @class}}
data-slot="item-actions"
...attributes
>
{{yield}}
</div>
</template>;
interface ItemHeaderSignature {
Element: HTMLDivElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemHeader: TOC<ItemHeaderSignature> = <template>
<div
class={{cn "flex basis-full items-center justify-between gap-2" @class}}
data-slot="item-header"
...attributes
>
{{yield}}
</div>
</template>;
interface ItemFooterSignature {
Element: HTMLDivElement;
Args: {
class?: string;
};
Blocks: {
default: [];
};
}
const ItemFooter: TOC<ItemFooterSignature> = <template>
<div
class={{cn "flex basis-full items-center justify-between gap-2" @class}}
data-slot="item-footer"
...attributes
>
{{yield}}
</div>
</template>;
export {
Item,
ItemMedia,
ItemContent,
ItemActions,
ItemGroup,
ItemSeparator,
ItemTitle,
ItemDescription,
ItemHeader,
ItemFooter,
};
Update the import paths to match your project setup.
Usage
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemFooter,
ItemHeader,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';<Item>
<ItemHeader>Item Header</ItemHeader>
<ItemMedia />
<ItemContent>
<ItemTitle>Item</ItemTitle>
<ItemDescription>Item</ItemDescription>
</ItemContent>
<ItemActions />
<ItemFooter>Item Footer</ItemFooter>
</Item>Item vs Field
Use
Field
if you need to display a form input such as a checkbox, input, radio, or select.
If you only need to display content such as a title, description, and actions, use
Item
.
Examples
Variants
Standard styling with subtle background and borders.
Outlined style with clear borders and transparent background.
Subdued appearance with muted colors for secondary content.
import { Button } from '@/components/ui/button';
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemTitle,
} from '@/components/ui/item';
<template>
<div class="flex flex-col gap-6">
<Item>
<ItemContent>
<ItemTitle>Default Variant</ItemTitle>
<ItemDescription>
Standard styling with subtle background and borders.
</ItemDescription>
</ItemContent>
<ItemActions>
<Button @size="sm" @variant="outline">
Open
</Button>
</ItemActions>
</Item>
<Item @variant="outline">
<ItemContent>
<ItemTitle>Outline Variant</ItemTitle>
<ItemDescription>
Outlined style with clear borders and transparent background.
</ItemDescription>
</ItemContent>
<ItemActions>
<Button @size="sm" @variant="outline">
Open
</Button>
</ItemActions>
</Item>
<Item @variant="muted">
<ItemContent>
<ItemTitle>Muted Variant</ItemTitle>
<ItemDescription>
Subdued appearance with muted colors for secondary content.
</ItemDescription>
</ItemContent>
<ItemActions>
<Button @size="sm" @variant="outline">
Open
</Button>
</ItemActions>
</Item>
</div>
</template>Size
The
Item
component has different sizes for different use cases. For example, you can use the
sm
size for a compact item or the
default
size for a standard item.
A simple item with title and description.
import { Button } from '@/components/ui/button';
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';
import BadgeCheckIcon from '~icons/lucide/badge-check';
import ChevronRightIcon from '~icons/lucide/chevron-right';
<template>
<div class="flex w-full max-w-md flex-col gap-6">
<Item @variant="outline">
<ItemContent>
<ItemTitle>Basic Item</ItemTitle>
<ItemDescription>
A simple item with title and description.
</ItemDescription>
</ItemContent>
<ItemActions>
<Button @size="sm" @variant="outline">
Action
</Button>
</ItemActions>
</Item>
<Item @asChild={{true}} @size="sm" @variant="outline" as |item|>
<a
class={{item.class}}
data-size={{item.size}}
data-slot={{item.slot}}
data-variant={{item.variant}}
href="#"
>
<ItemMedia>
<BadgeCheckIcon class="size-5" />
</ItemMedia>
<ItemContent>
<ItemTitle>Your profile has been verified.</ItemTitle>
</ItemContent>
<ItemActions>
<ChevronRightIcon class="size-4" />
</ItemActions>
</a>
</Item>
</div>
</template>Icon
New login detected from unknown device.
import { Button } from '@/components/ui/button';
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';
import ShieldAlertIcon from '~icons/lucide/shield-alert';
<template>
<div class="flex w-full max-w-lg flex-col gap-6">
<Item @variant="outline">
<ItemMedia @variant="icon">
<ShieldAlertIcon />
</ItemMedia>
<ItemContent>
<ItemTitle>Security Alert</ItemTitle>
<ItemDescription>
New login detected from unknown device.
</ItemDescription>
</ItemContent>
<ItemActions>
<Button @size="sm" @variant="outline">
Review
</Button>
</ItemActions>
</Item>
</div>
</template>Avatar
Last seen 5 months ago
Invite your team to collaborate on this project.
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Button } from '@/components/ui/button';
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';
import Plus from '~icons/lucide/plus';
<template>
{{! template-lint-disable no-potential-path-strings }}
<div class="flex w-full max-w-lg flex-col gap-6">
<Item @variant="outline">
<ItemMedia>
<Avatar @class="size-10">
<AvatarImage @src="https://github.com/evilrabbit.png" />
<AvatarFallback>ER</AvatarFallback>
</Avatar>
</ItemMedia>
<ItemContent>
<ItemTitle>Evil Rabbit</ItemTitle>
<ItemDescription>Last seen 5 months ago</ItemDescription>
</ItemContent>
<ItemActions>
<Button
@class="rounded-full"
@size="icon-sm"
@variant="outline"
aria-label="Invite"
>
<Plus />
</Button>
</ItemActions>
</Item>
<Item @variant="outline">
<ItemMedia>
<div
class="*:data-[slot=avatar]:ring-background flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:grayscale"
>
<Avatar @class="hidden sm:flex">
<AvatarImage @alt="@shadcn" @src="https://github.com/shadcn.png" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>
<Avatar @class="hidden sm:flex">
<AvatarImage
@alt="@maxleiter"
@src="https://github.com/maxleiter.png"
/>
<AvatarFallback>LR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
@alt="@evilrabbit"
@src="https://github.com/evilrabbit.png"
/>
<AvatarFallback>ER</AvatarFallback>
</Avatar>
</div>
</ItemMedia>
<ItemContent>
<ItemTitle>No Team Members</ItemTitle>
<ItemDescription>
Invite your team to collaborate on this project.
</ItemDescription>
</ItemContent>
<ItemActions>
<Button @size="sm" @variant="outline">
Invite
</Button>
</ItemActions>
</Item>
</div>
</template>Image
import {
Item,
ItemContent,
ItemDescription,
ItemGroup,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';
const music = [
{
title: 'Midnight City Lights',
artist: 'Neon Dreams',
album: 'Electric Nights',
duration: '3:45',
},
{
title: 'Coffee Shop Conversations',
artist: 'The Morning Brew',
album: 'Urban Stories',
duration: '4:05',
},
{
title: 'Digital Rain',
artist: 'Cyber Symphony',
album: 'Binary Beats',
duration: '3:30',
},
];
<template>
<div class="flex w-full max-w-md flex-col gap-6">
<ItemGroup @class="gap-4">
{{#each music as |song|}}
<Item @asChild={{true}} @variant="outline" as |item|>
<a
class={{item.class}}
data-size={{item.size}}
data-slot={{item.slot}}
data-variant={{item.variant}}
href="#"
>
<ItemMedia @variant="image">
<img
alt={{song.title}}
class="object-cover grayscale"
height="32"
src="https://avatar.vercel.sh/{{song.title}}"
width="32"
/>
</ItemMedia>
<ItemContent>
<ItemTitle @class="line-clamp-1">
{{song.title}}
-
<span class="text-muted-foreground">{{song.album}}</span>
</ItemTitle>
<ItemDescription>{{song.artist}}</ItemDescription>
</ItemContent>
<ItemContent @class="flex-none text-center">
<ItemDescription>{{song.duration}}</ItemDescription>
</ItemContent>
</a>
</Item>
{{/each}}
</ItemGroup>
</div>
</template>Group0p
shadcn@vercel.com
maxleiter@vercel.com
evilrabbit@vercel.com
import { lt } from 'ember-truth-helpers';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Button } from '@/components/ui/button';
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemGroup,
ItemMedia,
ItemSeparator,
ItemTitle,
} from '@/components/ui/item';
import PlusIcon from '~icons/lucide/plus';
const people = [
{
username: 'shadcn',
avatar: 'https://github.com/shadcn.png',
email: 'shadcn@vercel.com',
},
{
username: 'maxleiter',
avatar: 'https://github.com/maxleiter.png',
email: 'maxleiter@vercel.com',
},
{
username: 'evilrabbit',
avatar: 'https://github.com/evilrabbit.png',
email: 'evilrabbit@vercel.com',
},
];
<template>
<div class="flex w-full max-w-md flex-col gap-6">
<ItemGroup>
{{#each people as |person index|}}
<Item>
<ItemMedia>
<Avatar>
<AvatarImage @class="grayscale" @src={{person.avatar}} />
<AvatarFallback>{{person.username}}</AvatarFallback>
</Avatar>
</ItemMedia>
<ItemContent @class="gap-1">
<ItemTitle>{{person.username}}</ItemTitle>
<ItemDescription>{{person.email}}</ItemDescription>
</ItemContent>
<ItemActions>
<Button @class="rounded-full" @size="icon" @variant="ghost">
<PlusIcon />
</Button>
</ItemActions>
</Item>
{{#if (lt index 2)}}
<ItemSeparator />
{{/if}}
{{/each}}
</ItemGroup>
</div>
</template>Header
Everyday tasks and UI generation.
Advanced thinking or reasoning.
Open Source model for everyone.
import {
Item,
ItemContent,
ItemDescription,
ItemGroup,
ItemHeader,
ItemTitle,
} from '@/components/ui/item';
const models = [
{
name: 'v0-1.5-sm',
description: 'Everyday tasks and UI generation.',
image:
'https://images.unsplash.com/photo-1650804068570-7fb2e3dbf888?q=80&w=640&auto=format&fit=crop',
credit: 'Valeria Reverdo on Unsplash',
},
{
name: 'v0-1.5-lg',
description: 'Advanced thinking or reasoning.',
image:
'https://images.unsplash.com/photo-1610280777472-54133d004c8c?q=80&w=640&auto=format&fit=crop',
credit: 'Michael Oeser on Unsplash',
},
{
name: 'v0-2.0-mini',
description: 'Open Source model for everyone.',
image:
'https://images.unsplash.com/photo-1602146057681-08560aee8cde?q=80&w=640&auto=format&fit=crop',
credit: 'Cherry Laithang on Unsplash',
},
];
<template>
<div class="flex w-full max-w-xl flex-col gap-6">
<ItemGroup @class="grid grid-cols-3 gap-4">
{{#each models as |model|}}
<Item @variant="outline">
<ItemHeader>
<img
alt={{model.name}}
class="aspect-square w-full rounded-sm object-cover"
height="128"
src={{model.image}}
width="128"
/>
</ItemHeader>
<ItemContent>
<ItemTitle>{{model.name}}</ItemTitle>
<ItemDescription>{{model.description}}</ItemDescription>
</ItemContent>
</Item>
{{/each}}
</ItemGroup>
</div>
</template>Link
To render an item as a link, use the yielded element. The hover and focus states will be applied to the anchor element.
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemTitle,
} from '@/components/ui/item';
import ChevronRightIcon from '~icons/lucide/chevron-right';
import ExternalLinkIcon from '~icons/lucide/external-link';
<template>
<div class="flex w-full max-w-md flex-col gap-4">
<Item @asChild={{true}} as |item|>
<a
class={{item.class}}
data-size={{item.size}}
data-slot={{item.slot}}
data-variant={{item.variant}}
href="#"
>
<ItemContent>
<ItemTitle>Visit our documentation</ItemTitle>
<ItemDescription>
Learn how to get started with our components.
</ItemDescription>
</ItemContent>
<ItemActions>
<ChevronRightIcon class="size-4" />
</ItemActions>
</a>
</Item>
<Item @asChild={{true}} @variant="outline" as |item|>
<a
class={{item.class}}
data-size={{item.size}}
data-slot={{item.slot}}
data-variant={{item.variant}}
href="#"
rel="noopener noreferrer"
target="_blank"
>
<ItemContent>
<ItemTitle>External resource</ItemTitle>
<ItemDescription>
Opens in a new tab with security attributes.
</ItemDescription>
</ItemContent>
<ItemActions>
<ExternalLinkIcon class="size-4" />
</ItemActions>
</a>
</Item>
</div>
</template>Dropdown
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import {
Item,
ItemContent,
ItemDescription,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';
import ChevronDownIcon from '~icons/lucide/chevron-down';
const people = [
{
username: 'shadcn',
avatar: 'https://github.com/shadcn.png',
email: 'shadcn@vercel.com',
},
{
username: 'maxleiter',
avatar: 'https://github.com/maxleiter.png',
email: 'maxleiter@vercel.com',
},
{
username: 'evilrabbit',
avatar: 'https://github.com/evilrabbit.png',
email: 'evilrabbit@vercel.com',
},
];
<template>
<div class="flex min-h-64 w-full max-w-md flex-col items-center gap-6">
<DropdownMenu>
<DropdownMenuTrigger @asChild={{true}} as |trigger|>
<Button
@class="w-fit"
@size="sm"
@variant="outline"
{{trigger.modifiers}}
>
Select
<ChevronDownIcon />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent @class="w-72 [--radius:0.65rem]">
{{#each people as |person|}}
<DropdownMenuItem @class="p-0">
<Item @class="w-full p-2" @size="sm">
<ItemMedia>
<Avatar @class="size-8">
<AvatarImage @class="grayscale" @src={{person.avatar}} />
<AvatarFallback>{{person.username}}</AvatarFallback>
</Avatar>
</ItemMedia>
<ItemContent @class="gap-0.5">
<ItemTitle>{{person.username}}</ItemTitle>
<ItemDescription>{{person.email}}</ItemDescription>
</ItemContent>
</Item>
</DropdownMenuItem>
{{/each}}
</DropdownMenuContent>
</DropdownMenu>
</div>
</template>API Reference
Item
The main component for displaying content with media, title, description, and actions.
<Item @variant="outline" @size="sm">
<ItemMedia />
<ItemContent>
<ItemTitle>Item</ItemTitle>
<ItemDescription>Item</ItemDescription>
</ItemContent>
<ItemActions />
</Item>ItemGroup
The
ItemGroup
component is a container that groups related items together with consistent styling.
<ItemGroup>
<Item />
<Item />
</ItemGroup>ItemSeparator
The
ItemSeparator
component is a separator that separates items in the item group.
<ItemGroup>
<Item />
<ItemSeparator />
<Item />
</ItemGroup>ItemMedia
Use the
ItemMedia
component to display media content such as icons, images, or avatars.
<ItemMedia @variant="icon">
<Icon />
</ItemMedia><ItemMedia @variant="image">
<img src="..." alt="..." />
</ItemMedia>ItemContent
The
ItemContent
component wraps the title and description of the item.
You can skip
ItemContent
if you only need a title.
<ItemContent>
<ItemTitle>Item</ItemTitle>
<ItemDescription>Item</ItemDescription>
</ItemContent>ItemTitle
Use the
ItemTitle
component to display the title of the item.
<ItemTitle>Item Title</ItemTitle>ItemDescription
Use the
ItemDescription
component to display the description of the item.
<ItemDescription>Item description</ItemDescription>ItemActions
Use the
ItemActions
component to display action buttons or other interactive elements.
<ItemActions>
<Button>Action</Button>
<Button>Action</Button>
</ItemActions>ItemHeader
Use the
ItemHeader
component to display a header in the item.
<ItemHeader>Item Header</ItemHeader>ItemFooter
Use the
ItemFooter
component to display a footer in the item.
<ItemFooter>Item Footer</ItemFooter>