组件

Attachment

A file handed over in a conversation: a slip clipped to the message, or a print taped up. Five states (idle, uploading, processing, error, done), a pencil progress bar and a remove button. The pencil traces the slip, dashes it while it is only a promise and goes red when it fails.

安装

terminal
npx shadcn@latest add @wobko/attachment

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

示例

The five states

Done (a clipped slip), uploading (a pencil bar), processing (the same bar, pulsing), error (red pencil and a retry) and idle (a dashed slot waiting for a file).

A live upload

Progress is a CSS variable: the hatched fill is drawn once and clipped to the value, so a fast upload never redraws anything. The finished slip gets its clip and becomes pressable.

Prints on the wall

orientation="vertical" is a photo with a white border, taped up. Put an `<img>` in the media; here a doodle stands in. A group scrolls sideways and snaps when its prints are wider than the box.

API 参考

Attachment

The root and the drawing: a `Paper` slip (horizontal) or a taped photo (vertical) behind the content, with a hand-traced outline on top. A finished slip carries a paper clip, a finished print a strip of tape.

属性类型默认值说明
state"idle" | "uploading" | "processing" | "error" | "done""done"Idle is a dashed empty slot with no paper, error is red pencil on a red wash, uploading and processing are the same slip with a second, looser pass and a pulsing title.
size"default" | "sm" | "xs""default"Padding and type size.
orientation"horizontal" | "vertical""horizontal"A file chip, or a print with a caption in its white border.
seedstring | number-Pins the hand.

AttachmentMedia

The tile a file's icon or thumbnail sits in: a paper-shade blob and a pencil loop, red in the error state. A bare glyph is held to 16 px (24 px in a print); a `Doodle` or `Sticker` keeps the size you give it.

属性类型默认值说明
variant"icon" | "image""icon"`image` frames a picture (`<img>`) that covers the tile; it is dimmed while the file is uploading or processing.

AttachmentProgress

The pencil bar: a ruled box with a hatched fill. The fill is drawn once at full length and clipped by CSS to the value, so progress never redraws it.

属性类型默认值说明
valuenumber-0 to `max`. Undefined makes an indeterminate bar (the hatching pulses).
maxnumber100The value that means done.

无障碍

  • AttachmentProgress is a `role="progressbar"` with `aria-valuenow`/`min`/`max` (none while indeterminate). Inside an attachment it is named by the AttachmentTitle unless you give it an `aria-label` or `aria-labelledby`; on its own it needs one.
  • An AttachmentTrigger covers the attachment and is the tab stop; the Action buttons above it (z-20) stay separately focusable. Label both: the file name is not enough for 'Remove'.
  • The state is never only color: error is red pencil plus a red message plus (for you) a retry action; idle is dashed; done carries a clip.
  • Sheets, outlines, clips and tape are aria-hidden and take no pointer events. Calm density hides the clip and the tape and traces a plain hairline.
  • Error text is red on slip (4.8:1); titles are ink on slip (14:1).
  • A finished chip carries a paper clip over its end. With no action beside it the content keeps clear of the clip (extra end padding), so a long title truncates before it, not under it.

源码

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

正在加载源码