<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-file-preview/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-file-preview

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-file-preview>` web component is the Magma Design System card that previews an uploaded or referenced file, surfacing its name, size, type, and a format-aware icon or thumbnail. It pairs with `<mds-input-upload>` to represent each attached file and adds download/delete affordances around the bare file metadata.

#### Semantic Behavior

- **Format auto-detection**: The `filename` extension determines the icon, badge colour, and human-readable description; `suffix` forces a specific known format and `format` is the resolved category.
- **Download interaction**: With `downloadable` the card is a button in the tab order: a click, Enter or Space emits `mdsFileDownload` with `{ target, filename, extension }`, once. Without it the card is not interactive and emits nothing. `downloadable` renders no download icon.
- **Delete affordance**: When `deletable` is set, a light icon button renders in the corner and emits `mdsFileDelete` with the same detail payload, leaving the actual removal to the consumer.
- **Filesize formatting**: A numeric `filesize` string is treated as bytes and formatted automatically; any non-numeric string is shown verbatim.
- **Preview vs. icon vs. status**: A thumbnail renders only when `src` is set, the format supports preview, and no `message` is present; otherwise a format icon is shown, and when `message` is present the card switches to a status layout displaying that feedback text.
- **Localization**: Default type descriptions and action titles resolve through the locale system (el/en/es/it).

#### Properties & Visual Configurations

- **`filename`** is the source of truth: beyond being the title, it drives icon, badge, and description inference, so prefer a real name with extension over a cosmetic label.
- **`suffix`** overrides extension detection when the filename is unreliable or missing an extension; pick from the known format set rather than passing the description directly.
- **`description`** overrides only the textual filetype caption, leaving icon and badge inference intact. The caption is shown only without `filesize`; with a size it stays as the badge tooltip.
- **`src`** supplies a thumbnail (e.g. a logo or downscaled image) shown in place of the generic icon when the format is previewable and no message is active.
- **`message`** turns the card into a feedback/status state (validation, error, progress text) and suppresses the thumbnail.

#### Component-specific variants and tones

The shared `variant` / `tone` ladders are defined in [`agents/variants.md`](../../../../agents/variants.md). `variant` here is an avatar-flavored value and is rendered **only when `message` is set**, coloring the status layout; the format badge derives its own colour from the detected filetype independently (its tone is always `weak`).

#### Other behavioral props

- **`icon`** overrides the auto-detected glyph with a Magma icon slug, an inline `<svg ...>` string or a `data:image/svg+xml;base64,` URI.
- **`truncate`** controls how the filename is shortened when it overflows, defaulting to `'word'`.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-file-preview--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `deletable` | `deletable` | `boolean \| undefined` | - | Enables the cross icon to perform cancel/delete action on element |
| `description` | `description` | `string \| undefined` | - | Overrides the default filetype description |
| `downloadable` | `downloadable` | `boolean \| undefined` | - | Turns the card into a button that asks for the download: a tab stop that the pointer, Enter and Space activate, emitting `mdsFileDownload`. Without it the card is not interactive |
| `filename` | `filename` | `string` | - | **Required**. The filename shown as component title, is used to auto assign one of the filetype known in the filetype dictionary |
| `filesize` | `filesize` | `string \| undefined` | - | The filesize shown, if you pass a string you can write whathever you want, if you pass a number it expect filesize in bytes, the component will format it automatically. |
| `format` | `format` | `string \| undefined` | - | The kind of file, recognised from the extension of `filename` or from `suffix`: it selects the colours of the icon. The component writes it on load and whenever `filename` changes, set `suffix` to choose it |
| `icon` | `icon` | `string` | - | The name of the icon or a base64 string to render it as an svg |
| `message` | `message` | `string \| undefined` | - | Sets a feedback message related to the component |
| `src` | `src` | `string \| undefined` | - | The image preview src if available of a file, useful if you have a logo to display, or a smaller version of a bigger image |
| `suffix` | `suffix` | `"7z" \| "ace" \| "ai" \| "db" \| "default" \| "dmg" \| "doc" \| "docm" \| "docx" \| "eml" \| "eps" \| "exe" \| "flac" \| "gif" \| "heic" \| "htm" \| "html" \| "jpe" \| "jpeg" \| "jpg" \| "js" \| "json" \| "jsx" \| "m2v" \| "mp2" \| "mp3" \| "mp4" \| "mp4v" \| "mpeg" \| "mpg" \| "mpg4" \| "mpga" \| "odf" \| "odp" \| "ods" \| "odt" \| "ole" \| "p7m" \| "pdf" \| "php" \| "png" \| "ppt" \| "rar" \| "rtf" \| "sass" \| "shtml" \| "svg" \| "tar" \| "tiff" \| "ts" \| "tsd" \| "txt" \| "wav" \| "webp" \| "xar" \| "xls" \| "xlsx" \| "xml" \| "zip" \| undefined` | - | Overrides the automatic filetype recongition by forcing the suffix to one of the available formats choosen |
| `truncate` | `truncate` | `"all" \| "none" \| "word" \| undefined` | `'word'` | Truncates the filename shown |
| `variant` | `variant` | `"amaranth" \| "aqua" \| "blue" \| "error" \| "green" \| "info" \| "lime" \| "orange" \| "orchid" \| "primary" \| "purple" \| "red" \| "sky" \| "success" \| "violet" \| "warning" \| "yellow" \| undefined` | - | The variant of the component, is shown only if the message attribute is defined |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsFileDelete` | `MdsFilePreviewEventDetail` | Emits when the component is removed, returning file infos |
| `mdsFileDownload` | `MdsFilePreviewEventDetail` | Emits when the component is clicked, returning file infos |

## Parts

| Part | Description |
| --- | --- |
| `card` | The preview of the file: its thumbnail or format icon, its name and its details |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-file-preview-background-color` | Sets the background color of the file preview container |
| `--mds-file-preview-border-radius` | Sets the border-radius of the file preview container |
| `--mds-file-preview-color` | Sets the text color used inside the file preview |

Only these are public. Its other 2 are internal: they may change in any release, do not set them.

## Dependencies

Uses: `mds-button`, `mds-img`, `mds-icon`, `mds-text`, `mds-badge`.
Used by: `mds-input-upload`.
