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

# mds-file

> `@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>` web component is the Magma Design System control for representing a downloadable file as a rich, clickable card. It pairs a filename with an auto-detected file-type icon, badge, and human-readable description, and tracks whether the file has already been downloaded.

#### Semantic Behavior

- **Clickable card**: The whole host is a button (`role="button"`, unless you set another role) in the tab order: a click, Enter or Space emits `mdsFileDownload`; the component itself does not fetch or download - the consumer wires the actual download to that event.
- **Download event payload**: `mdsFileDownload` carries `description` (the `description` prop, or else the description of the detected type in the page language, the text the card shows), `extension` (empty for a filename without one), `filename`, the host element as `target`, and the detected `type`/format.
- **Downloaded persistence**: On click the component records the file as downloaded in `localStorage`, under a key derived from the filename with a small non-cryptographic hash. Every later render of the same filename on the same origin shows the "done" indicator.
- **Automatic file-type recognition**: From `filename` it derives the format icon, badge variant, and default description; `suffix` overrides this detection.
- **Localization**: Descriptions and the "already downloaded" tooltip are resolved against the active locale.

#### Properties & Visual Configurations

- **`filename`** is the primary input: it provides the displayed title and drives icon, badge, suffix, and description detection. The name and extension are rendered separately, split at the last dot so the dots inside the name are kept (`report.v2.final.docx` shows `report.v2.final` and `.docx`; a leading dot belongs to the name, as in `.env`); the extension is shown only when not explicitly overridden by `suffix`, and a filename without one shows no extension and no badge.
- **`suffix`** forces a specific file type from the supported format set when the filename's extension is missing or wrong; it bypasses automatic recognition.
- **`description`** overrides the derived, localized file-type description when a custom label is needed.
- **`preview`** supplies an image URL (logo or thumbnail) rendered as the preview surface instead of the generic format icon - use it when a meaningful visual of the file exists.
- **`hideDownloadedIcon`** (default `false`) suppresses the persisted "already downloaded" indicator; set it when that affordance is not appropriate.
- **`format`** is normally populated by the component itself from detection rather than set by the consumer.

## 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--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 |
| --- | --- | --- | --- | --- |
| `description` | `description` | `string \| undefined` | - | Overrides the default filetype description |
| `filename` | `filename` | `string` | - | The filename shown as component title, is used to auto assign one of the filetype known in the filetype dictionary |
| `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 |
| `hideDownloadedIcon` | `hide-downloaded-icon` | `boolean \| undefined` | `false` | Hides the download icon |
| `preview` | `preview` | `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 |

## Events

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

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-file-preview-color` | Sets the text color used in 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-icon`, `mds-text`, `mds-badge`.
