Updated
Download Button
NewCustomize
Duration2.8s
Reset after3.0s
Success colour
Medium
Installation
npx shadcn@latest add https://uibrik.com/r/download-button.jsonInstall the packages
npm install @number-flow/react motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/download-button/download-button.tsx"use client"; import NumberFlow from "@number-flow/react"; import { AnimatePresence, animate, motion, useMotionValue, useReducedMotion, type AnimationPlaybackControls } from "motion/react"; import { useEffect, useRef, useState } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 32, padX: 12, font: 13, icon: 15 }, md: { height: 40, padX: 15, font: 14, icon: 17 }, lg: { height: 48, padX: 18, font: 15, icon: 19 }, } as const; type Phase = "idle" | "loading" | "done"; export type DownloadButtonProps = { label?: string; /** Shown once the download finishes; clicking it calls onOpen. */ doneLabel?: string; /** Drive the bar yourself, from 0 to 1. Leave out to simulate a download of `duration` seconds. */ progress?: number;
Adds the files to
components/uibrik/download-button and installs @number-flow/react, motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/download-button.Usage
import { DownloadButton } from "@/components/uibrik/download-button/download-button";<DownloadButton label="Download" doneLabel="Open" duration={2.8} resetAfter={3} successColor="#16a34a" size="md" onDownload={() => {}} onCancel={() => {}} onOpen={() => {}} // progress={0}/>Where to use Download Button
Exports and reports
Progress lives inside the button, so an export never needs a separate bar or toast.
Pairs with Data Table
Invoices and receipts
The finished state turns into Open, the next thing people want to do.
Pairs with Billing Page
App and asset downloads
Pass real progress from 0 to 1, or let it simulate one for a marketing page.
Pairs with File Card
Props
DownloadButton- label
- Type string
- "Download"
- Label at rest.
- doneLabel
- Type string
- "Open"
- Shown once the download finishes.
- duration
- Type number
- 2.8
- How long a simulated download takes.
- resetAfter
- Type number
- 3
- How long the finished state shows. 0 keeps it.
- successColor
- Type string
- "#16a34a"
- Colour of the check once done.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- progress
- Type number
- –
- Real progress from 0 to 1. Leave out to simulate.
- onDownload
- Type () => void
- –
- Called when pressed at rest.
- onCancel
- Type () => void
- –
- Called when a download in flight is pressed again.
- onOpen
- Type () => void
- –
- Called when the finished button is pressed.
- className
- Type string
- –
- Classes for the button.