suiss/ui · Component
Attachment
A compact file card that shows a document or image with its name, details, upload state and actions.
Attachment is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
An Attachment typically contains an AttachmentMedia thumbnail, an AttachmentContent block with AttachmentTitle and AttachmentDescription, and an AttachmentActions slot holding one or more AttachmentAction buttons. AttachmentMedia can hold an icon, an img, or an AttachmentLabel file-type tag. During an upload, put an AttachmentProgress bar inside the content. Add an AttachmentTrigger to make the whole card clickable.
Wrap several attachments in an AttachmentGroup to render them as a single list with inset dividers. Use attachments for files in composers, chat messages and upload forms.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a Attachment:
Examples
Sizes
Use the size prop to switch between the default, sm and xs densities.
States
Use the state prop to show the idle, uploading, processing, error and done states. idle adds a dashed border outside a group, and error colors the description with text-destructive.
Drop zone
Image
Set variant="image" on AttachmentMedia for a cropped image thumbnail.
Vertical
Set orientation="vertical" to stack the media above the content and overlay the actions on the media.
Clickable
Add an AttachmentTrigger to make the whole card a button. A separate download action stays clickable above it.
Group
Wrap several attachments in an AttachmentGroup to show them as one list with inset dividers.
File types
Set variant="document" on AttachmentMedia and add an AttachmentLabel with a color class to show the file extension.
File list
A full-width list of separate attachment cards.
Uploaded
Marks completed uploads with a check icon in the actions slot.
Accessibility
AttachmentProgresswraps the progress primitive and exposes theprogressbarrole witharia-valuenow; give it anaria-label.AttachmentTriggerrenders abuttonwithtype="button"by default; give it anaria-labelthat names the file.- The trigger and each
AttachmentActionare separate tab stops, in that order. - The card shows a focus ring when its trigger has keyboard focus.
API Reference
Attachment
The card container that sets size, orientation and state.
| Prop | Type | Default |
|---|---|---|
size | "default" | "sm" | "xs" | "default" |
orientation | "horizontal" | "vertical" | "horizontal" |
state | "idle" | "uploading" | "processing" | "error" | "done" | "done" |
Also accepts the props of React.ComponentProps<"div">.
orientation="horizontal" places the media beside the content; vertical stacks it above and overlays the actions on the media. Set state to reflect the file's lifecycle: idle adds a dashed border (outside a group), and error colors the description red. The state, size and orientation values are exposed as data-state, data-size and data-orientation for your own styling.
AttachmentLabel
A small uppercase tag, usually the file extension, shown inside the media.
Also accepts the props of React.ComponentProps<"span">.
The label uses bg-primary by default; override it with a color class per file type.
AttachmentMedia
The thumbnail area for an icon, document tag or image.
| Prop | Type | Default |
|---|---|---|
variant | "icon" | "document" | "image" | "icon" |
Also accepts the props of React.ComponentProps<"div">.
Use icon for a bordered icon tile, document for a page shape with a bottom tag, and image for a cropped image. The variant is exposed as data-variant.
AttachmentContent
Wraps the title, description and progress bar.
Also accepts the props of React.ComponentProps<"div">.
AttachmentTitle
The file name, truncated to one line.
Also accepts the props of React.ComponentProps<"span">.
AttachmentDescription
Secondary details such as file size or an error message.
Also accepts the props of React.ComponentProps<"span">.
AttachmentProgress
A progress bar with a value readout for uploads.
Also accepts the props of the primitive part it wraps.
AttachmentActions
The slot for action buttons or status indicators.
Also accepts the props of React.ComponentProps<"div">.
AttachmentAction
A compact button for actions such as remove, cancel or download.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link" | "secondary" |
size | "default" | "xs" | "sm" | "lg" | "xl" | "form" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl" | "icon-xs" |
Also accepts the props of Button.
AttachmentAction renders a Button with the secondary variant and an icon size by default. Pass variant="link" for a text action such as "Try Again"; its size then defaults to "sm". Icon-only actions need an aria-label.
AttachmentTrigger
An invisible button covering the card to make it clickable.
Also accepts the props of useRender.ComponentProps<"button">.
AttachmentTrigger is an invisible button stretched over the card. Give it an aria-label, or use render to turn it into a link. Actions sit above it, so they remain separately clickable.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of React.ComponentProps<"button">.
AttachmentTrigger is an invisible button stretched over the card. Give it an aria-label, or set asChild with a link as its child to turn it into a link. Actions sit above it, so they remain separately clickable.
| Prop | Type | Default |
|---|---|---|
render | (props: React.HTMLAttributes<HTMLElement>) => React.ReactNode | — |
Also accepts the props of React.ComponentProps<"button">.
AttachmentTrigger is an invisible button stretched over the card. Give it an aria-label, or pass a render function that returns a link to turn it into a link. Actions sit above it, so they remain separately clickable.
AttachmentGroup
Stacks attachments into one rounded list with dividers.
Also accepts the props of React.ComponentProps<"div">.
Inside AttachmentGroup, attachments fill the width, lose their own rounding and get inset top dividers.
Each part sets a data-slot, such as attachment, attachment-media or attachment-action, for styling.
Web preview
Attachment is a rounded View that lays out an AttachmentMedia thumbnail, an AttachmentContent column and AttachmentActions. It comes in default, sm and xs sizes and in horizontal or vertical orientation; the vertical layout makes a tile with the actions floating over the media.
The state prop reflects the upload lifecycle: idle draws a dashed border for an empty drop slot, error turns the description red, and uploading, processing and done are passed to the parts through context. Put several attachments in an AttachmentGroup to show them as one list with hairlines between rows.
Installation
- Install the following dependencies:
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/attachment.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/attachment.tsx:
- Update the import paths to match your project setup.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/attachment.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Sizes
The default, sm and xs sizes, set with size.
Web preview
States
The idle, uploading, processing, error and done states, set with state. Add AttachmentProgress with a value while uploading.
Web preview
Image
Use the image variant of AttachmentMedia for a thumbnail.
Web preview
Vertical
Set orientation="vertical" to make tiles with the actions floating over the media.
Web preview
Pressable
Add an AttachmentTrigger to make the whole card pressable. It covers the card while actions stay pressable above it.

Group
Several attachments in an AttachmentGroup, one of them uploading.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
File types
Use the document variant of AttachmentMedia for a page shape, and pair it with AttachmentLabel to show a colored file extension.
Web preview
Accessibility
AttachmentProgresshas theprogressbarrole with its value exposed.AttachmentTriggerhas thebuttonrole; give it anaccessibilityLabelsuch as "Open Invoice.pdf".- Icon-only actions need an
accessibilityLabel.
API Reference
Attachment
Card that provides state, size and orientation to its parts.
| Prop | Type | Default |
|---|---|---|
state | AttachmentState | "done" |
size | AttachmentSize | "default" |
orientation | AttachmentOrientation | "horizontal" |
Also accepts the props of ViewProps.
state is one of idle, uploading, processing, error or done and is passed to the parts through context. Separators and action positions use start and end offsets, so they flip in right-to-left layouts.
AttachmentMedia
Thumbnail area for an icon, document shape or image.
| Prop | Type | Default |
|---|---|---|
variant | "icon" | "document" | "image" | "icon" |
Also accepts the props of ViewProps.
Use icon for a glyph, document for a page shape and image for a thumbnail.
AttachmentLabel
Small uppercase tag, such as a file extension.
Also accepts the props of ViewProps.
AttachmentContent
Column for the title, description and progress.
Also accepts the props of ViewProps.
AttachmentTitle
File name, one line by default.
Also accepts the props of React.ComponentProps<typeof Text>.
AttachmentDescription
Secondary details, red in the error state.
Also accepts the props of React.ComponentProps<typeof Text>.
AttachmentProgress
Progress bar with a percentage value.
Also accepts the props of React.ComponentProps<typeof ProgressPrimitive.Root>.
AttachmentActions
Row of actions; floats over the media in vertical layout.
Also accepts the props of ViewProps.
AttachmentAction
Small button sized to the attachment.
Also accepts the props of React.ComponentProps<typeof Button>.
AttachmentAction defaults to the secondary variant and a small icon size scaled to the attachment, with an enlarged hit area. Use variant="link" for a text action.
AttachmentTrigger
Pressable overlay that makes the whole card pressable.
| Prop | Type | Default |
|---|---|---|
render | RenderProp<Record<string, unknown>, Record<string, never>> | - |
Also accepts the props of React.ComponentProps<typeof Pressable>, React.RefAttributes<View>.
Use render to render another element in place of the default Pressable.
AttachmentGroup
List container that joins attachments with separators.
Also accepts the props of ViewProps.
AttachmentState
Values: .idle, .uploading, .processing, .error, .done.
AttachmentSize
Values: .default, .sm, .xs.
AttachmentOrientation
Values: .horizontal, .vertical.
AttachmentMediaVariant
Values: .icon, .document, .image.
Attachment
Card that provides state, size and orientation to its parts.
| Parameter | Type | Default |
|---|---|---|
state | AttachmentState: .idle | .uploading | .processing | .error | .done | .done |
size | Size: .default | .sm | .xs | .default |
orientation | Orientation: .horizontal | .vertical | .horizontal |
block | Bool | false |
content | () -> Content | - |
AttachmentMedia
Thumbnail area for an icon, document shape or image.
| Parameter | Type | Default |
|---|---|---|
_Â variant | Variant: .icon | .document | .image | .icon |
content | () -> Content | - |
icon | Image | - |
image | Image | - |
url | URL? | - |
Overloads: init(_:content:), init(icon:), init(image:), init(url:).
AttachmentIcon
| Parameter | Type | Default |
|---|---|---|
_Â image | Image | - |
AttachmentImage
| Parameter | Type | Default |
|---|---|---|
_Â image | Image | - |
url | URL? | - |
Overloads: init(_:), init(url:).
AttachmentLabel
Small uppercase tag, such as a file extension.
| Parameter | Type | Default |
|---|---|---|
_Â text | LocalizedStringKey | - |
tint | Color | EsuissColor.primary |
verbatim | String | - |
Overloads: init(_:tint:), init(verbatim:tint:).
AttachmentContent
Column for the title, description and progress.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AttachmentTitle
File name, one line by default.
| Parameter | Type | Default |
|---|---|---|
_Â text | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(_:), init(verbatim:).
AttachmentDescription
Secondary details, red in the error state.
| Parameter | Type | Default |
|---|---|---|
_Â text | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(_:), init(verbatim:).
AttachmentProgress
Progress bar with a percentage value.
| Parameter | Type | Default |
|---|---|---|
value | Double | - |
total | Double | 100 |
label | LocalizedStringKey | "Uploading" |
AttachmentActions
Row of actions; floats over the media in vertical layout.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AttachmentAction
Small button sized to the attachment.
| Parameter | Type | Default |
|---|---|---|
variant | VariantButtonStyle.Variant | .secondary |
action | () -> Void | - |
label | () -> Label | - |
_Â title | LocalizedStringKey | - |
icon | Image | - |
Overloads: init(variant:action:label:), init(_:icon:variant:action:), init(_:variant:action:).
AttachmentActionIcon
| Parameter | Type | Default |
|---|---|---|
_Â title | LocalizedStringKey | - |
image | Image | - |
AttachmentTrigger
An invisible button covering the card to make it clickable.
| Parameter | Type | Default |
|---|---|---|
_Â label | LocalizedStringKey | - |
action | () -> Void | - |
AttachmentGroup
List container that joins attachments with separators.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AttachmentState
Values: Idle, Uploading, Processing, Error, Done.
AttachmentSize
Values: Default, Sm, Xs.
AttachmentOrientation
Values: Horizontal, Vertical.
AttachmentMediaVariant
Values: Icon, Document, Image.
Attachment
Card that provides state, size and orientation to its parts.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
state | AttachmentState: Idle | Uploading | Processing | Error | Done | AttachmentState.Done |
size | AttachmentSize: Default | Sm | Xs | AttachmentSize.Default |
orientation | AttachmentOrientation: Horizontal | Vertical | AttachmentOrientation.Horizontal |
onClick | (() -> Unit)? | null |
onClickLabel | String? | null |
content | @Composable () -> Unit | - |
AttachmentGroup
List container that joins attachments with separators.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable () -> Unit | - |
AttachmentMedia
Thumbnail area for an icon, document shape or image.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
variant | AttachmentMediaVariant: Icon | Document | Image | AttachmentMediaVariant.Icon |
content | @Composable BoxScope.() -> Unit | - |
image | Painter | - |
contentDescription | String? | - |
Overloads: AttachmentMedia(variant, content), AttachmentMedia(image, contentDescription).
AttachmentLabel
Small uppercase tag, such as a file extension.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
background | Color | EsuissTheme.colors.primary |
AttachmentContent
Column for the title, description and progress.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
AttachmentTitle
File name, one line by default.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
AttachmentDescription
Secondary details, red in the error state.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
AttachmentProgress
Progress bar with a percentage value.
| Parameter | Type | Default |
|---|---|---|
value | Float | - |
modifier | Modifier | Modifier |
max | Float | 100f |
contentDescription | String? | null |
AttachmentActions
Row of actions; floats over the media in vertical layout.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable RowScope.() -> Unit | - |
AttachmentAction
Small button sized to the attachment.
| Parameter | Type | Default |
|---|---|---|
onClick | () -> Unit | - |
contentDescription | String? | - |
modifier | Modifier | Modifier |
variant | ButtonVariant | ButtonVariant.Secondary |
enabled | Boolean | true |
content | @Composable () -> Unit | - |
text | String | - |
Overloads: AttachmentAction(onClick, contentDescription, variant, content), AttachmentAction(text, onClick).
