Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Components

Free

Download Trigger for Svelte

Trigger file downloads programmatically.

Framework
UI library
Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Usage

<script lang="ts">
import { DownloadIcon, FileTextIcon } from "lucide-svelte";
import { Button } from "@/components/ui/button";
import { DownloadTrigger } from "@/components/ui/download-trigger";
import { Item, ItemTitle } from "@/components/ui/item";
</script>
const DownloadTriggerDemo = () => (
  <div className="flex flex-col gap-4">
    <Item variant="outline">
      <FileTextIcon />
      <ItemTitle>{content}</ItemTitle>
    </Item>
    <DownloadTrigger
      asChild
      data={content}
      fileName="hello.txt"
      mimeType="text/plain"
    >
      <Button size="lg" variant="outline">
        <DownloadIcon />
        Download
      </Button>
    </DownloadTrigger>
  </div>
);

const content = "Hello, World! This is a sample text file.";

Accessibility

Enter
Activate the focused control.
Space
Activate the focused control.

Demos

Download Svg

Preview width

Promise

Preview width

API Reference

DownloadTrigger

data-slot="download-trigger"

PropType
dataDownloadableData | (() → MaybePromise<DownloadableData>)

The data to download.

Type
DownloadableData | (() → MaybePromise<DownloadableData>)
fileNamestring

The name of the file to download.

mimeTypeImageFileMimeType | ApplicationFileMimeType | TextFileMimeType | FontFileMimeType | VideoFileMimeType | AudioFileMimeType | FileMimeTypeGroup | AnyString

The MIME type of the data to download.

Type
ImageFileMimeType | ApplicationFileMimeType | TextFileMimeType | FontFileMimeType | VideoFileMimeType | AudioFileMimeType | FileMimeTypeGroup | AnyString
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>