Skip to content
GitHub11 stars

Displays a file or image attachment with media, metadata, upload state, and actions.

Workspace
workspace.png PNG · 820 KB
Desk
desk-reference.jpg JPG · 1.1 MB
Office
office-reference.jpg JPG · 940 KB
sales-dashboard.pdf Uploading · 64%
message-renderer.tsx TypeScript · 12 KB
<div class="mx-auto flex w-full max-w-sm flex-col gap-3 py-12">
    <AttachmentGroup>
        @foreach (var image in Images)

The Attachment component displays a file or image attachment, its media, name, and metadata, with optional actions and upload state. Use it for files and images in chat composers, message threads, and upload lists.

Installation

dnx Blazix.Cli add attachment

Usage

<Attachment>
    <AttachmentMedia><Icon Data="LucideIcons.FileText" /></AttachmentMedia>
    <AttachmentContent>
        <AttachmentTitle>sales-dashboard.pdf</AttachmentTitle>
        <AttachmentDescription>PDF · 2.4 MB</AttachmentDescription>
    </AttachmentContent>
    <AttachmentActions>
        <AttachmentAction aria-label="Remove sales-dashboard.pdf"><Icon Data="LucideIcons.X" /></AttachmentAction>
    </AttachmentActions>
</Attachment>

Composition

Use the following composition to build an attachment:

Attachment
├── AttachmentMedia
├── AttachmentContent
│   ├── AttachmentTitle
│   └── AttachmentDescription
├── AttachmentActions
│   └── AttachmentAction
└── AttachmentTrigger

Use AttachmentGroup to lay out multiple attachments in a scrollable row:

AttachmentGroup
├── Attachment
└── Attachment

Features

  • Icon and image media through AttachmentMedia
  • Upload states: idle, uploading, processing, error, and done with built-in styling and a shimmer while in progress
  • Three sizes and horizontal or vertical orientation
  • A full-card AttachmentTrigger that opens a link or dialog while the actions stay independently clickable
  • Scrollable, snapping AttachmentGroup with an edge fade
  • Customizable styling through the Class parameter on every part

Image

Set variant="image" on AttachmentMedia and render an <img> inside it. Use orientation="vertical" to stack the media above the content.

Workspace
workspace.png PNG · 820 KB
Desk
desk-reference.jpg JPG · 1.1 MB
Office
office-reference.jpg JPG · 940 KB
<div class="mx-auto w-full max-w-sm py-12">
    <AttachmentGroup Class="w-full">
        @foreach (var image in Images)

States

Set State to reflect the upload lifecycle. uploading and processing shimmer the title, and error switches to a destructive treatment.

selected-file.pdf Ready to upload
design-system.zip Uploading · 64%
market-research.pdf Processing document
financial-model.xlsx Upload failed. Try again.
uploaded-report.pdf Uploaded · 1.8 MB
<div class="mx-auto flex w-full max-w-sm flex-col gap-2 py-12">
    <Attachment State="AttachmentState.Idle" Class="w-full">
        <AttachmentMedia><Icon Data="LucideIcons.Clock" /></AttachmentMedia>

Sizes

Use Size to switch between default, sm, and xs.

Default attachment PDF · 2.4 MB
Small attachment PDF · 2.4 MB
Extra small attachment
<div class="mx-auto flex w-full max-w-sm flex-col gap-3 py-12">
    <Attachment Size="AttachmentSize.Default" Class="w-full">
        <AttachmentMedia><Icon Data="LucideIcons.FileText" /></AttachmentMedia>

Group

Wrap attachments in AttachmentGroup to lay them out in a horizontally scrollable, snapping row with an edge fade.

briefing-notes.pdf PDF · 1.4 MB
workspace.png
workspace.png PNG · 820 KB
customers.csv CSV · 18 KB
renderer.tsx TSX · 12 KB
<div class="mx-auto w-full max-w-sm py-12">
    <AttachmentGroup Class="w-full">
        @foreach (var item in Items)

Trigger

Add an AttachmentTrigger to make the whole card open a link or dialog. It fills the card behind the actions, so the actions stay clickable.

research-summary.pdf Open preview dialog
<div class="mx-auto w-full max-w-sm py-12">
    <Dialog>
        <Attachment Class="w-full">
<Dialog>
    <Attachment>
        ...
        <DialogTrigger>
            <Render>
                <AttachmentTrigger @attributes="context.Attributes" aria-label="Preview research-summary.pdf" />
            </Render>
        </DialogTrigger>
    </Attachment>
    <DialogContent>...</DialogContent>
</Dialog>

Accessibility

AttachmentAction renders a Button, and AttachmentTrigger renders a real <button> (or your element via Render). Follow the guidance below so both are operable and announced.

Label icon-only actions

AttachmentAction is usually icon-only, so give each one an aria-label describing the action and its target.

<AttachmentAction aria-label="Remove sales-dashboard.pdf"><Icon Data="LucideIcons.X" /></AttachmentAction>

Label the trigger

AttachmentTrigger covers the card with no text of its own, so give it an aria-label for what activating it does.

<AttachmentTrigger>
    <Render Context="trigger">
        <a @attributes="trigger.Attributes" href="@url" target="_blank" rel="noreferrer" aria-label="Open workspace.png"></a>
    </Render>
</AttachmentTrigger>

The trigger sits behind the actions in the stacking order, so an AttachmentAction and the AttachmentTrigger never trap each other — both remain separately focusable and clickable.

Keyboard scrolling

An AttachmentGroup scrolls horizontally. When its attachments are interactive: a trigger or actions, keyboard users reach off-screen items by tabbing to them. For a row of presentational attachments, make the group itself focusable and scrollable by adding tabindex="0", role="group", and an aria-label.

Meaning beyond color

The error state uses a destructive color. Keep the failure reason in AttachmentDescription so the state is not conveyed by color alone.

RTL

To enable RTL support in Blazix, see the RTL configuration guide.

Translated with AI for the demo, so it may have mistakes.

مساحة العمل
workspace.png PNG · ٨٢٠ KB
مكتب
desk-reference.jpg JPG · ١.١ MB
مكتب الشركة
office-reference.jpg JPG · ٩٤٠ KB
sales-dashboard.pdf جاري الرفع · ٦٤%
message-renderer.tsx TypeScript · ١٢ KB
<div class="mx-auto flex w-full max-w-sm flex-col gap-3 py-12">
    <AttachmentGroup>
        @foreach (var image in Images)

API Reference

Attachment

ParameterTypeDefault
State AttachmentState AttachmentState.Done
Size AttachmentSize AttachmentSize.Default
Orientation Orientation Orientation.Horizontal
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentAction

ParameterTypeDefault
Variant ButtonVariant ButtonVariant.Ghost
Size ButtonSize ButtonSize.IconXs
Type ButtonType ButtonType.Button
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentActions

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentContent

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentDescription

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentGroup

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentMedia

ParameterTypeDefault
Variant AttachmentMediaVariant AttachmentMediaVariant.Icon
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentTitle

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

AttachmentTrigger

ParameterTypeDefault
Render RenderFragment<UseRenderProps>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.