Attachment

A file and its upload state, on its own or in a scrolling row. In the look of the app's style.

Data DisplayExperimental

Usage

import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScAttachment,  ScAttachmentAction,  ScAttachmentActions,  ScAttachmentContent,  ScAttachmentDescription,  ScAttachmentGroup,  ScAttachmentMedia,  ScAttachmentTitle,  ScSpinner,} from '@semantic-components/ui';import {  SiFileCodeIcon,  SiLoaderCircleIcon,  SiXIcon,} from '@semantic-icons/lucide-icons';
@Component({  selector: 'app-attachment-usage-demo',  imports: [    NgOptimizedImage,    ScAttachment,    ScAttachmentMedia,    ScAttachmentContent,    ScAttachmentTitle,    ScAttachmentDescription,    ScAttachmentActions,    ScAttachmentAction,    ScAttachmentGroup,    ScSpinner,    SiFileCodeIcon,    SiLoaderCircleIcon,    SiXIcon,  ],  template: `    <div class="flex w-full max-w-sm flex-col gap-3">      <div scAttachmentGroup tabindex="0" role="group" aria-label="Images">        <div scAttachment orientation="vertical">          <div scAttachmentMedia variant="image">            <img              ngSrc="/images/gallery/cafe-thumb.jpg"              fill              priority              alt="Café"            />          </div>          <div scAttachmentContent>            <div scAttachmentTitle>cafe.jpg</div>            <div scAttachmentDescription>JPG · 820 KB</div>          </div>        </div>        <div scAttachment orientation="vertical">          <div scAttachmentMedia variant="image">            <img ngSrc="/images/gallery/coast-thumb.jpg" fill alt="Coast" />          </div>          <div scAttachmentContent>            <div scAttachmentTitle>coast.jpg</div>            <div scAttachmentDescription>JPG · 1.1 MB</div>          </div>        </div>        <div scAttachment orientation="vertical">          <div scAttachmentMedia variant="image">            <img ngSrc="/images/gallery/forest-thumb.jpg" fill alt="Forest" />          </div>          <div scAttachmentContent>            <div scAttachmentTitle>forest.jpg</div>            <div scAttachmentDescription>JPG · 940 KB</div>          </div>        </div>      </div>      <div scAttachment state="uploading" class="w-full">        <div scAttachmentMedia>          <svg scSpinner siLoaderCircleIcon aria-label="Uploading"></svg>        </div>        <div scAttachmentContent>          <div scAttachmentTitle>sales-dashboard.pdf</div>          <div scAttachmentDescription>Uploading · 64%</div>        </div>        <div scAttachmentActions>          <button scAttachmentAction>            <svg siXIcon></svg>            <span class="sr-only">Cancel upload</span>          </button>        </div>      </div>      <div scAttachment class="w-full">        <div scAttachmentMedia><svg siFileCodeIcon></svg></div>        <div scAttachmentContent>          <div scAttachmentTitle>message-renderer.ts</div>          <div scAttachmentDescription>TypeScript · 12 KB</div>        </div>        <div scAttachmentActions>          <button scAttachmentAction>            <svg siXIcon></svg>            <span class="sr-only">Remove message-renderer.ts</span>          </button>        </div>      </div>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class AttachmentUsageDemo {}

Anatomy

Every part is a directive on your element; the icons, images, text and names are yours.

import {  ScAttachment, ScAttachmentMedia, ScAttachmentContent, ScAttachmentTitle,  ScAttachmentDescription, ScAttachmentActions, ScAttachmentAction,  ScAttachmentTrigger, ScAttachmentGroup,} from '@semantic-components/ui';
<div scAttachmentGroup>  <div scAttachment state="…">    <div scAttachmentMedia>…</div>    <div scAttachmentContent>      <div scAttachmentTitle>…</div>      <div scAttachmentDescription>…</div>    </div>    <div scAttachmentActions>      <button scAttachmentAction>…</button>    </div>    <a scAttachmentTrigger href="…">…</a>  </div></div>

Accessibility

  • Name each action after what it does and to which file — "Remove report.pdf", not "Remove" — in sr-only text.
  • Name the trigger after what it opens — "Preview report.pdf": it fills the card and has no text of its own.
  • A group scrolls sideways: its attachments' buttons and links bring it along as they take focus.
  • Say the state in words too, in the description ("Upload failed"): its colour and shimmer are not enough. A spinner in the media needs its name.

Examples

Image

Café
cafe.jpg
JPG · 820 KB
Open cafe.jpg
Coast
coast.jpg
JPG · 1.1 MB
Open coast.jpg
Forest
forest.jpg
JPG · 940 KB
Open forest.jpg
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScAttachment,  ScAttachmentAction,  ScAttachmentActions,  ScAttachmentContent,  ScAttachmentDescription,  ScAttachmentGroup,  ScAttachmentMedia,

States

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
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAttachment,  ScAttachmentAction,  ScAttachmentActions,  ScAttachmentContent,  ScAttachmentDescription,  ScAttachmentMedia,  ScAttachmentTitle,  ScSpinner,

Sizes

Default attachment
PDF · 2.4 MB
Small attachment
PDF · 2.4 MB
Extra small attachment
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAttachment,  ScAttachmentContent,  ScAttachmentDescription,  ScAttachmentMedia,  ScAttachmentTitle,} from '@semantic-components/ui';import { SiFileTextIcon } from '@semantic-icons/lucide-icons';

Group

briefing-notes.pdf
PDF · 1.4 MB
Café
cafe.jpg
JPG · 820 KB
customers.csv
CSV · 18 KB
renderer.ts
TS · 12 KB
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScAttachment,  ScAttachmentAction,  ScAttachmentActions,  ScAttachmentContent,  ScAttachmentDescription,  ScAttachmentGroup,  ScAttachmentMedia,

Trigger

research-summary.pdf
Open preview dialog
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAttachment,  ScAttachmentAction,  ScAttachmentActions,  ScAttachmentContent,  ScAttachmentDescription,  ScAttachmentMedia,  ScAttachmentTitle,  ScAttachmentTrigger,

RTL

report.pdf
PDF · 2.4 ميغابايت
notes.txt
جارٍ الرفع · 64٪
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScAttachment,  ScAttachmentAction,  ScAttachmentActions,  ScAttachmentContent,  ScAttachmentDescription,  ScAttachmentMedia,  ScAttachmentTitle,

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScAttachmentdiv[scAttachment] state ('idle', 'uploading', 'processing', 'error', 'done'), size ('default', 'sm', 'xs'), orientation ('horizontal', 'vertical').
ScAttachmentMediadiv[scAttachmentMedia] Your icon or image: variant ('icon', 'image' — your img in it).
ScAttachmentContent, ScAttachmentTitle, ScAttachmentDescriptiondiv[…] The text: the file’s name (shimmering while uploading or processing), and a line about it.
ScAttachmentActionsdiv[scAttachmentActions] The actions, above the trigger.
ScAttachmentActionbutton[scAttachmentAction] An action (remove, retry…): the style's button, variant and size (ghost, icon-xs). Name it.
ScAttachmentTriggera[scAttachmentTrigger], button[scAttachmentTrigger] Fills the card, behind the actions: a link or a button (with scDialogTrigger, opens a dialog). Name it.
ScAttachmentGroupdiv[scAttachmentGroup] A row that scrolls and snaps, its edges fading.