组件

Item

A row for lists of things: an icon or photo, a title with a line of description, some actions. Rows sit on ruled paper, a link row lights up under a highlighter swipe, and none of it carries ink of its own, so a list of hundreds costs nothing.

安装

terminal
npx shadcn@latest add @wobko/item

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Variants and sizes

Bare, outlined in ruled pencil, and washed in paper-shade. The small size trims the padding. None of these rows draws an svg: the pencil is CSS.

A ruled list of links

ruled puts a blue pencil line under every row, so the rules always match the rows. Link rows (asChild) light up under a highlighter swipe when you point at them, and take the focus ring from the keyboard.

An inbox

Rows doing real work in a card: photographs that lie a little crooked, a status badge in the title, actions on the right, and a header and footer on the row that needs them.

Basic and link

shadcn's `item-demo`: an outlined row with a title, a description and a button, and a small row made a link with `asChild`, a verified badge in front and a chevron behind. The pencil outline is CSS, so a long list costs no svg.

Sizes

shadcn's `item-size` (its source is the same two rows as the demo): `default` gives a row 16 px of padding, `sm` trims it. Here the same content is set at both sizes, one under the other, so the difference is easy to see.

Variants

shadcn's `item-variant`: `default` is bare, `outline` has a ruled pencil line round it, `muted` is a wash of paper-shade. The same three words as upstream.

Icon

shadcn's `item-icon`: `ItemMedia variant="icon"` sets a glyph in a square of its own at the start of the row.

Image

shadcn's `item-image`: a list of tracks, each a link row with a small picture (`variant="image"`), a title with the album in muted type, the artist below and the running time at the far end. The pictures are doodles, pasted in a little crooked; the original's `role="listitem"` is not needed, the group already makes each link one.

Avatar

shadcn's `item-avatar`: a single face with a round invite button, and a stack of faces (the first two hide below `sm`) beside an invite text button. Faces are initials on marker; the photographs of the original are left out.

Group with separators

shadcn's `item-group`: ItemGroup makes the rows a list and ItemSeparator draws the pencil line between them (the last row has none). Nothing here is an svg per row.

Header

shadcn's `item-header`: ItemHeader takes the first, full-width line of a row, so a picture sits above the words. Three cards in a grid; the photographs of the original are doodles here.

In a dropdown

shadcn's `item-dropdown`: each menu row is an Item (`className="p-0"` on the menu item, `p-2` on the Item), so a menu can show a face, a name and a line of detail. Arrow keys and typeahead still belong to the menu.

Links

shadcn's `item-link`: `asChild` turns the row into an `<a>`. The row gets the highlighter swipe on hover and a focus outline; an external link carries `target="_blank"` and `rel`.

API 参考

Item

A flex row (a div, or your own element with asChild). The ruled pencil box of variant=outline, the wash of muted and the highlighter hover of a link or button row are CSS (masks made from a few tiny drawn tiles, defined once per page in one hoisted stylesheet), never an svg per row. Inside an ItemGroup it is a list item; an asChild row is wrapped in one, so the link keeps its own role.

属性类型默认值说明
variant"default" | "outline" | "muted""default"default = bare; outline = a ruled pencil box whose corners meet (three hands, by seed); muted = a paper-shade wash with rounded corners.
size"default" | "sm""default"Roomy (gap 16, padding 16) or snug (gap 10, padding 16 x 12). Compact and calm density are a step tighter each.
asChildbooleanfalseRender your own element (a link, a button); it hovers under the highlighter swipe, and takes the focus ring.
seedstring | number-Picks which of the three hands draws this row's outline and rule. Default: derived from useId().

ItemGroup

A role=list column of rows.

属性类型默认值说明
ruledbooleanfalseRuled paper: a blue pencil line under each row, drawn by the stylesheet so it always matches the height of the row.

ItemMedia

The leading (or trailing) picture.

属性类型默认值说明
variant"default" | "icon" | "image""default"icon = a 36 px well with a ruled box and a paper-shade wash; image = a 40 px photograph with a white border that lies a degree crooked (alternating rows, straight in calm density).

无障碍

  • ItemGroup is role=list and every Item inside it is role=listitem (upstream leaves that to you, and axe reports the group otherwise). An asChild link or button is wrapped in a listitem, so it keeps its own role, name and keyboard behavior.
  • A link or button row is one big hit area. Its focus mark is a plain 2 px blue outline, not the drawn felt ring of a Button (a row carries no drawing, so its ring is CSS too); hover is a highlighter swipe that is also visible without its hue (the swipe changes the background's lightness), and is off on touch screens.
  • The drawing (outline, rules, wash) is decoration in CSS: it has no role, cannot take focus and does not change layout. In Windows high contrast it becomes a real 1 px border and a real rule.
  • Muted text is 8.9:1 on paper; the description is clamped to two lines, so put anything essential in the title.

源码

CLI 会复制进你项目的文件。

正在加载源码