Skip to content

DownloadButton

Downloads a file. A file that exists is a link with download; one the app must make first shows the band of light while it works.

import { DownloadButton } from '@sypnia/ui/react'

On this page
  1. A file that exists and one that is made
  2. When to use it
  3. For everyone
  4. Props

A file that exists and one that is made

Download CSV
Code
import { DownloadButton, toast, Toaster } from '@sypnia/ui/react';

// A file that exists is a link with `download`; one the app has to make first shows it is working.
const csv = 'data:text/csv;charset=utf-8,' + encodeURIComponent('id,total\n1,120\n2,80\n');
export default function Files() {
  return (
    <>
      <div className="sy-row">
        <DownloadButton href={csv} filename="orders.csv">Download CSV</DownloadButton>
        <DownloadButton variant="quiet" onPress={() => new Promise<void>((r) => setTimeout(() => { r(); toast('The backup is ready', { tone: 'ok' }); }, 1500))}>Download the backup</DownloadButton>
      </div>
      <Toaster />
    </>
  );
}

When to use it

Use it when

  • Exports, backups, invoices.
  • Say what is downloaded and in what format: «Download CSV».

Do not use it when

  • Opening a file to read in the browser: use a Link.
  • Long exports that take minutes: start them and tell the person when they are ready.

For everyone

  • With href it is a link; with onPress a button that stays focusable while busy.
  • Its words say what is downloaded, not only «Download».

Props

DownloadButtonTypeDefault
busy boolean
disabled boolean
filename

The name the file is saved with.

string
href string
onPress (() => void | Promise<void>)
size "sm" | "md" | "lg"
variant "primary" | "secondary" | "quiet" secondary
  1. A file that exists and one that is made
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms