Attachment
File and image attachments with metadata, upload progress, failure states, and actions.
c2-attachment
Displays a file or image attachment with a preview, metadata, upload state and optional actions.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
name | string | — | File name shown as the primary label. |
src | string | undefined | undefined | Image preview URL. Omit it to show the generic file preview. |
alt | string | undefined | undefined | Accessible description for the image preview. Defaults to the file name. |
type | string | undefined | undefined | File type or extension shown in the metadata row. |
size | string | undefined | undefined | Human-readable file size, for example 2.4 MB. |
status | 'ready' | 'uploading' | 'complete' | 'error' | ready | Current upload state. |
layout | 'auto' | 'row' | 'tile' | auto | Auto uses a tile for image previews and a row for files. |
progress | number | 0 | Upload completion percentage. Values are clamped between 0 and 100. |
removable | boolean | false | Show the built-in remove action. During upload it is announced as cancel. |
disabled | boolean | false | Disable built-in actions and dim the attachment. |
Slots
| Name | Description |
|---|---|
media | Custom thumbnail or file icon. Replaces the image supplied through src. |
name | Custom file name. Falls back to the name attribute. |
metadata | Custom metadata. Falls back to the type and size attributes. |
actions | Custom controls shown at the end. Replaces the built-in retry and remove buttons. |
Events
| Name | Type | Description |
|---|---|---|
attachment-remove | CustomEvent<{ name: string }> | Fired when the remove or cancel action is pressed. |
attachment-retry | CustomEvent<{ name: string }> | Fired when retry is pressed for a failed upload. |
media-error | Event | Fired when the image preview cannot be loaded; the file fallback is shown. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
media | Media region wrapping the media slot and thumbnail or file-icon fallback. |
content | Text and status region containing the name and metadata. |
name | File-name region wrapping the name slot and fallback name. |
metadata | Metadata region wrapping the metadata slot and type/size fallback. |
actions | Actions region wrapping the actions slot and built-in action fallback. |
CSS custom properties
Grouped by semantic target and state from --c2-component__target__state--property. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-attachment--min-height | pixel | 76px | |
--c2-attachment--gap | pixel | 12px | |
--c2-attachment--padding | padding | 10px 12px | |
--c2-attachment--background | color | #ffffff | |
--c2-attachment--border | border | 1px solid #e4e4e7 | |
--c2-attachment--border-radius | border-radius | 14px | |
--c2-attachment--box-shadow | box-shadow | — | |
--c2-attachment--color | color | #18181b | |
--c2-attachment__media--size | pixel | 48px | |
--c2-attachment__media--background | color | #f4f4f5 | |
--c2-attachment__media--color | color | #71717a | |
--c2-attachment__media--border-radius | border-radius | 10px | |
--c2-attachment__media--object-fit | object-fit | cover | |
--c2-attachment__tile--width | pixel | 220px | |
--c2-attachment__tile--media-aspect-ratio | ratio | 1 | |
--c2-attachment__name--font-size | font-size | 14px | |
--c2-attachment__name--font-weight | font-weight | 500 | |
--c2-attachment__metadata--color | color | #71717a | |
--c2-attachment__metadata--font-size | font-size | 12px | |
--c2-attachment__status--color | color | #71717a | |
--c2-attachment__status__complete--color | color | rgb(0, 122, 77) | |
--c2-attachment__status__error--color | color | #dc2626 | |
--c2-attachment__progress--background | color | #e4e4e7 | |
--c2-attachment__progress--color | color | rgb(2, 101, 220) | |
--c2-attachment__action--size | pixel | 28px | |
--c2-attachment__action--color | color | #71717a | |
--c2-attachment__action__hover--background | color | #f4f4f5 | |
--c2-attachment__action__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-attachment__disabled--opacity | opacity | 0.38 | |
c2-attachment-group
Arranges related attachments as a responsive list or grid.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
layout | 'list' | 'grid' | 'mixed' | list | List stacks rows, grid fills equal columns, and mixed gives image tiles columns while file rows span the group. |
aria-label | string | null | Attachments | Accessible name for the attachment collection. |
Slots
| Name | Description |
|---|---|
(default) | c2-attachment elements. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
list | List region wrapping the default attachment slot. |
CSS custom properties
Grouped by semantic target and state from --c2-component__target__state--property. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-attachment-group--gap | pixel | 8px | |
--c2-attachment-group--min-column-width | pixel | 240px | |