Homelogologo
Sponsor

Download

A component that initiates a file download when clicked.

Usage

The Download component (internally using DownloadTrigger) initiates a client-side file download using in-memory data.

Render the component; when it is activated (e.g., clicked), the browser will prompt the user to download the file.

import { Download, Button } from "@elemnts-ui/react" <Download data="Hello, world!" fileName="hello.txt" mimeType="text/plain" asChild > <Button>Download Text</Button> </Download>

Download SVG

Pass the SVG markup as a string to data, set fileName to a .svg filename, and use mimeType "image/svg+xml".

Asynchronous Data

You can also trigger downloads from a function that returns a Promise resolving to a Blob, File, or string.

File Size

Pair the Download component with the Format.Byte component to display the file size in a human-readable format.

API Reference

Download

The component (internally using DownloadTrigger) initiates a client-side file download using in-memory data.

PropTypeDefault
dataDownloadableData | (() => MaybePromise<DownloadableData>)-
fileNamestring-
mimeTypeFileMimeType-
asChildbooleanfalse