Attachment
A file and its upload state, on its own or in a scrolling row. In the look of the app's style.
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
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScAttachment, ScAttachmentAction, ScAttachmentActions, ScAttachmentContent, ScAttachmentDescription, ScAttachmentGroup, ScAttachmentMedia,States
import { Component, ViewEncapsulation } from '@angular/core';import { ScAttachment, ScAttachmentAction, ScAttachmentActions, ScAttachmentContent, ScAttachmentDescription, ScAttachmentMedia, ScAttachmentTitle, ScSpinner,Sizes
import { Component, ViewEncapsulation } from '@angular/core';import { ScAttachment, ScAttachmentContent, ScAttachmentDescription, ScAttachmentMedia, ScAttachmentTitle,} from '@semantic-components/ui';import { SiFileTextIcon } from '@semantic-icons/lucide-icons';Group
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScAttachment, ScAttachmentAction, ScAttachmentActions, ScAttachmentContent, ScAttachmentDescription, ScAttachmentGroup, ScAttachmentMedia,Trigger
import { Component, ViewEncapsulation } from '@angular/core';import { ScAttachment, ScAttachmentAction, ScAttachmentActions, ScAttachmentContent, ScAttachmentDescription, ScAttachmentMedia, ScAttachmentTitle, ScAttachmentTrigger,RTL
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).
| Part | Selector | Description |
|---|---|---|
ScAttachment | div[scAttachment] | state ('idle', 'uploading', 'processing', 'error', 'done'), size ('default', 'sm', 'xs'), orientation ('horizontal', 'vertical'). |
ScAttachmentMedia | div[scAttachmentMedia] | Your icon or image: variant ('icon', 'image' — your img in it). |
ScAttachmentContent, ScAttachmentTitle, ScAttachmentDescription | div[…] | The text: the file’s name (shimmering while uploading or processing), and a line about it. |
ScAttachmentActions | div[scAttachmentActions] | The actions, above the trigger. |
ScAttachmentAction | button[scAttachmentAction] | An action (remove, retry…): the style's button, variant and size (ghost, icon-xs). Name it. |
ScAttachmentTrigger | a[scAttachmentTrigger], button[scAttachmentTrigger] | Fills the card, behind the actions: a link or a button (with scDialogTrigger, opens a dialog). Name it. |
ScAttachmentGroup | div[scAttachmentGroup] | A row that scrolls and snaps, its edges fading. |