# Attachment Show a file or image with its metadata, upload state and actions. [Interactive guide](/docs/components/attachment) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use Attachment to present a file already associated with a draft or record. Use FileUpload for the pick-and-upload entry point. ### How to compose it Use AttachmentMedia, AttachmentContent and AttachmentActions for a custom file row or image tile. Drive state from the real upload and provide retry or cancel where supported. ### What to verify Test failure, progress and completion with visible labels. Leave the file-open trigger separate from its actions. ## Usage ```tsx import { Attachment, AttachmentMedia, AttachmentContent, AttachmentTitle, AttachmentDescription, AttachmentActions, AttachmentAction, AttachmentTrigger, AttachmentGroup, } from 'wss3-forge' ``` - AttachmentAction supports Button variants and sizes in all three engines. Use a named icon-xs ghost action for a small file action, or a secondary text action for a visible label. - Pass name and description for a file row, or compose AttachmentMedia, AttachmentContent and AttachmentActions inside the root. - Set state to idle, uploading, processing, error or done. Supply visible status text alongside the file name. Your application owns the upload, cancellation and retry. - Use orientation="vertical" for image tiles. Set variant="image" on the media and give the image descriptive alt text. - AttachmentTrigger covers the card. Keep it beside AttachmentActions and label each icon button with its action and target. To scroll a presentational AttachmentGroup with the keyboard, give it tabIndex={0}, role="group" and an accessible name. ```tsx ``` ## Runnable examples ### Files and images ```tsx import { useState } from 'react' import { Code20Regular, Dismiss16Regular } from '@fluentui/react-icons' import { Attachment, AttachmentAction, AttachmentActions, AttachmentContent, AttachmentDescription, AttachmentGroup, AttachmentMedia, AttachmentTitle, Spinner, VStack } from 'wss3-forge' const images = [ { name: 'workspace.png', meta: 'PNG · 820 KB', photo: '1497366754035-f200968a6e72', alt: 'Workspace' }, { name: 'desk-reference.jpg', meta: 'JPG · 1.1 MB', photo: '1497215728101-856f4ea42174', alt: 'Desk' }, { name: 'office-reference.jpg', meta: 'JPG · 940 KB', photo: '1497366811353-6870744d04b2', alt: 'Office' }, ] function ImageAttachment({ image }: { image: typeof images[number] }) { return {image.alt} {image.name} {image.meta} } function AttachmentDemo() { const [uploading, setUploading] = useState(true) const [attached, setAttached] = useState(true) return {images.map(image => )} {uploading && sales-dashboard.pdf Uploading · 64% setUploading(false)}> } {attached && message-renderer.tsx TypeScript · 12 KB setAttached(false)}> } } export default function Example() { return () } ``` ### Image ```tsx import { Attachment, AttachmentContent, AttachmentDescription, AttachmentMedia, AttachmentTitle } from 'wss3-forge' const images = [ { name: 'workspace.png', meta: 'PNG · 820 KB', photo: '1497366754035-f200968a6e72', alt: 'Workspace' }, { name: 'desk-reference.jpg', meta: 'JPG · 1.1 MB', photo: '1497215728101-856f4ea42174', alt: 'Desk' }, { name: 'office-reference.jpg', meta: 'JPG · 940 KB', photo: '1497366811353-6870744d04b2', alt: 'Office' }, ] function ImageAttachment({ image }: { image: typeof images[number] }) { return {image.alt} {image.name} {image.meta} } export default function Example() { return () } ``` ### States ```tsx import { Document20Regular } from '@fluentui/react-icons' import { Attachment, AttachmentContent, AttachmentDescription, AttachmentMedia, AttachmentTitle, VStack, type AttachmentState } from 'wss3-forge' export default function Example() { return ( {([ ['idle', 'selected-file.pdf', 'Ready to upload'], ['uploading', 'design-system.zip', 'Uploading · 64%'], ['processing', 'market-research.pdf', 'Processing document'], ['error', 'financial-model.xlsx', 'Upload failed. Try again.'], ['done', 'uploaded-report.pdf', 'Uploaded · 1.8 MB'], ] satisfies [AttachmentState, string, string][]).map(([state, name, meta]) => {name}{meta} )} ) } ``` ### Sizes ```tsx import { Attachment, VStack } from 'wss3-forge' export default function Example() { return ({(['default', 'sm', 'xs'] as const).map(size => )}) } ``` ### Group ```tsx import { Attachment, AttachmentGroup, Box } from 'wss3-forge' export default function Example() { return ( ) } ``` ### Trigger ```tsx import { useState } from 'react' import { Dismiss16Regular, DocumentSearch20Regular } from '@fluentui/react-icons' import { Attachment, AttachmentAction, AttachmentActions, AttachmentContent, AttachmentDescription, AttachmentMedia, AttachmentTitle, AttachmentTrigger, Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, Text } from 'wss3-forge' function PreviewAttachment() { const [open, setOpen] = useState(false) const [removed, setRemoved] = useState(false) if (removed) return Removed research-summary.pdf return <> research-summary.pdfOpen document preview setOpen(true)} /> setRemoved(true)}> research-summary.pdf Interviews with the design team identified three priorities for the next release. Close } export default function Example() { return () } ``` ### Retry or remove an attachment ```tsx import { useState } from 'react' import { Attachment, Button, Text, VStack, type AttachmentStatus } from 'wss3-forge' function RetryAttachment() { const [status, setStatus] = useState('error') const [removed, setRemoved] = useState(false) if (removed) return Removed release-summary.csv return setStatus('uploading')} onRemove={() => setRemoved(true)} /> {status === 'uploading' && } } export default function Example() { return () } ``` ## Primitive libraries ### Base UI Use a render element or render callback on the trigger. AttachmentAction also accepts Base UI Button props. ```sh npm install wss3-forge @base-ui/react ``` ```tsx import { Attachment, AttachmentContent, AttachmentTitle, AttachmentTrigger } from 'wss3-forge/base-ui' export default function WorkspacePhoto({ url }: { url: string }) { return ( workspace.png } aria-label="Open workspace.png" /> ) } ``` #### Preview ```tsx import { useState } from 'react' import { Code20Regular, Dismiss16Regular } from '@fluentui/react-icons' import { Spinner, VStack } from 'wss3-forge' import { Attachment, AttachmentAction, AttachmentActions, AttachmentContent, AttachmentDescription, AttachmentGroup, AttachmentMedia, AttachmentTitle } from 'wss3-forge/base-ui' const images = [ { name: 'workspace.png', meta: 'PNG · 820 KB', photo: '1497366754035-f200968a6e72', alt: 'Workspace' }, { name: 'desk-reference.jpg', meta: 'JPG · 1.1 MB', photo: '1497215728101-856f4ea42174', alt: 'Desk' }, { name: 'office-reference.jpg', meta: 'JPG · 940 KB', photo: '1497366811353-6870744d04b2', alt: 'Office' }, ] function ImageAttachment({ image }: { image: typeof images[number] }) { return {image.alt} {image.name} {image.meta} } function AttachmentDemo() { const [uploading, setUploading] = useState(true) const [attached, setAttached] = useState(true) return {images.map(image => )} {uploading && sales-dashboard.pdf Uploading · 64% setUploading(false)}> } {attached && message-renderer.tsx TypeScript · 12 KB setAttached(false)}> } } export default function Example() { return () } ``` ### Radix Use asChild to make a link the full-card trigger. Keep separate file actions inside AttachmentActions. ```sh npm install wss3-forge radix-ui ``` ```tsx import { Attachment, AttachmentContent, AttachmentTitle, AttachmentTrigger } from 'wss3-forge/radix' export default function WorkspacePhoto({ url }: { url: string }) { return ( workspace.png ) } ``` #### Preview ```tsx import { useState } from 'react' import { Code20Regular, Dismiss16Regular } from '@fluentui/react-icons' import { Spinner, VStack } from 'wss3-forge' import { Attachment, AttachmentAction, AttachmentActions, AttachmentContent, AttachmentDescription, AttachmentGroup, AttachmentMedia, AttachmentTitle } from 'wss3-forge/radix' const images = [ { name: 'workspace.png', meta: 'PNG · 820 KB', photo: '1497366754035-f200968a6e72', alt: 'Workspace' }, { name: 'desk-reference.jpg', meta: 'JPG · 1.1 MB', photo: '1497215728101-856f4ea42174', alt: 'Desk' }, { name: 'office-reference.jpg', meta: 'JPG · 940 KB', photo: '1497366811353-6870744d04b2', alt: 'Office' }, ] function ImageAttachment({ image }: { image: typeof images[number] }) { return {image.alt} {image.name} {image.meta} } function AttachmentDemo() { const [uploading, setUploading] = useState(true) const [attached, setAttached] = useState(true) return {images.map(image => )} {uploading && sales-dashboard.pdf Uploading · 64% setUploading(false)}> } {attached && message-renderer.tsx TypeScript · 12 KB setAttached(false)}> } } export default function Example() { return () } ``` ### React Aria Use a render callback to forward trigger attributes to a link. AttachmentAction accepts React Aria Button events, including onPress. ```sh npm install wss3-forge react-aria-components ``` ```tsx import { Attachment, AttachmentContent, AttachmentTitle, AttachmentTrigger } from 'wss3-forge/react-aria' export default function WorkspacePhoto({ url }: { url: string }) { return ( workspace.png } /> ) } ``` #### Preview ```tsx import { useState } from 'react' import { Code20Regular, Dismiss16Regular } from '@fluentui/react-icons' import { Spinner, VStack } from 'wss3-forge' import { Attachment, AttachmentAction, AttachmentActions, AttachmentContent, AttachmentDescription, AttachmentGroup, AttachmentMedia, AttachmentTitle } from 'wss3-forge/react-aria' const images = [ { name: 'workspace.png', meta: 'PNG · 820 KB', photo: '1497366754035-f200968a6e72', alt: 'Workspace' }, { name: 'desk-reference.jpg', meta: 'JPG · 1.1 MB', photo: '1497215728101-856f4ea42174', alt: 'Desk' }, { name: 'office-reference.jpg', meta: 'JPG · 940 KB', photo: '1497366811353-6870744d04b2', alt: 'Office' }, ] function ImageAttachment({ image }: { image: typeof images[number] }) { return {image.alt} {image.name} {image.meta} } function AttachmentDemo() { const [uploading, setUploading] = useState(true) const [attached, setAttached] = useState(true) return {images.map(image => )} {uploading && sales-dashboard.pdf Uploading · 64% setUploading(false)}> } {attached && message-renderer.tsx TypeScript · 12 KB setAttached(false)}> } } export default function Example() { return () } ``` ## Root package API ### Attachment Show a file or image with its metadata, upload state and actions. Props type: `AttachmentProps` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes **Composition exports** - `AttachmentMedia` (named export) - `AttachmentContent` (named export) - `AttachmentTitle` (named export) - `AttachmentDescription` (named export) - `AttachmentActions` (named export) - `AttachmentAction` (named export) - `AttachmentTrigger` (named export) - `AttachmentGroup` (named export) - `name?` — `string` File name for the compact API. Omit it when composing the named parts. - `description?` — `string` - `href?` — `string` Links the file name to its destination when the file is ready. - `icon?` — `ReactNode` Default ``. - `status?` — `AttachmentStatus` Default `'ready'`. Options `"error"`, `"ready"`, `"uploading"`, `"processing"`. Compact API status. The ready state corresponds to done. - `progress?` — `number` Upload percentage in the inclusive range 0–100. - `error?` — `string` - `onRemove?` — `() => void` - `onRetry?` — `() => void` - `state?` — `AttachmentState` Default `status === 'ready' ? 'done' : status`. Options `"error"`, `"uploading"`, `"processing"`, `"idle"`, `"done"`. Current upload lifecycle. Takes precedence over status. - `size?` — `'default' | 'sm' | 'xs' | null` Default `'default'`. Options `null`, `"default"`, `"sm"`, `"xs"`. Controls media dimensions, spacing and typography. - `orientation?` — `'horizontal' | 'vertical' | null` Default `'horizontal'`. Options `null`, `"horizontal"`, `"vertical"`. Places the media beside the content or above it. - `ref?` — `React.LegacyRef | undefined` ### AttachmentMedia Props type: `AttachmentMediaProps` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `variant?` — `'icon' | 'image' | null` Default `'icon'`. Options `null`, `"icon"`, `"image"`. - `ref?` — `React.LegacyRef | undefined` ### AttachmentContent Props type: `HTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `ref?` — `React.LegacyRef | undefined` ### AttachmentTitle Props type: `HTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `ref?` — `React.LegacyRef | undefined` ### AttachmentDescription Props type: `HTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `ref?` — `React.LegacyRef | undefined` ### AttachmentActions Props type: `HTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `ref?` — `React.LegacyRef | undefined` ### AttachmentAction Props type: `AttachmentActionProps` Native attributes: AriaAttributes, ButtonHTMLAttributes, DOMAttributes, HTMLAttributes - `variant?` — `ButtonProps['variant'] | null` Default `'secondary'`. Options `null`, `"default"`, `"primary"`, `"secondary"`, `"danger"`, `"destructive"`, `"ghost"`, `"outline"`, `"link"`. - `size?` — `ButtonSize | null` Default `'icon-xs'`. Options `null`, `"default"`, `"icon"`, `"sm"`, `"md"`, `"lg"`, `"xs"`, `"xl"`, `"icon-xs"`, `"icon-sm"`, `"icon-lg"`, `"icon-xl"`. - `children?` — `ReactNode` - `icon?` — `ReactNode` - `loading?` — `boolean` Default `false`. - `tone?` — `ButtonTone` Options `"default"`, `"danger"`. Semantic tone. When omitted, danger and destructive use the danger tone. - `loadingPosition?` — `'start' | 'end'` Default `'start'`. Options `"start"`, `"end"`. Side of the label where the spinner replaces the icon while loading. - `rightIcon?` — `ReactNode` - `fullWidth?` — `boolean` - `compact?` — `boolean` - `gradient?` — `boolean` Default `false`. - `ref?` — `React.LegacyRef | undefined` ### AttachmentTrigger Props type: `AttachmentTriggerProps` Native attributes: AriaAttributes, ButtonHTMLAttributes, DOMAttributes, HTMLAttributes - `render?` — `(props: HTMLAttributes) => ReactNode` Render a link or another interactive element with the trigger attributes. - `ref?` — `React.LegacyRef | undefined` ### AttachmentGroup Props type: `HTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `ref?` — `React.LegacyRef | undefined` ## Related types ```ts export type AttachmentStatus = 'ready' | 'uploading' | 'processing' | 'error' export type AttachmentState = 'idle' | 'uploading' | 'processing' | 'error' | 'done' export interface AttachmentProps extends HTMLAttributes { /** File name for the compact API. Omit it when composing the named parts. */ name?: string description?: string href?: string icon?: ReactNode status?: AttachmentStatus /** Upload percentage in the inclusive range 0–100. */ progress?: number error?: string onRemove?: () => void onRetry?: () => void /** Current upload lifecycle. Takes precedence over status. */ state?: AttachmentState size?: 'default' | 'sm' | 'xs' | null orientation?: 'horizontal' | 'vertical' | null } export interface AttachmentMediaProps extends HTMLAttributes { variant?: 'icon' | 'image' | null } export interface ButtonProps extends ButtonAppearanceProps, Omit, 'children'> {} export type ButtonSize = ControlSize | 'default' | 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg' | 'icon-xl' export type ControlSize = keyof typeof SIZES export type ButtonTone = 'default' | 'danger' export interface AttachmentActionProps extends Omit { variant?: ButtonProps['variant'] | null size?: ButtonSize | null } export interface AttachmentTriggerProps extends ButtonHTMLAttributes { /** Render a link or another interactive element with the trigger attributes. */ render?: (props: HTMLAttributes) => ReactNode } ``` ## Optional primitive contracts - [wss3-forge/base-ui · Attachment contract](/ai/skill/primitive-api/Attachment.json) - [wss3-forge/radix · Attachment contract](/ai/skill/primitive-api/Attachment.json) - [wss3-forge/react-aria · Attachment contract](/ai/skill/primitive-api/Attachment.json)