Download code/web/src/components/download-button.tsx from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/08b0eafba522f5cf00cfab9c2f665cc634200cbb/code/web/src/components/download-button.tsx
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@08b0eafba522f5cf00cfab9c2f665cc634200cbb/code/web/src/components/download-button.tsx
-
curl -L -o download-button.tsx https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/08b0eafba522f5cf00cfab9c2f665cc634200cbb/code/web/src/components/download-button.tsx
1.99 kB
| import { useEffect, useRef, useState } from "react" | |
| import { Check, Download, LoaderCircle } from "lucide-react" | |
| import { backgroundFor, EXPORT_IGNORE, savePng } from "@/lib/export" | |
| /** | |
| * Round icon button in the top right of a chart: saves `target` as a PNG named after `name`. | |
| * `tone` matches what it sits on (a card on the page, or the dark stage). | |
| */ | |
| export function DownloadButton({ target, name, tone = "card", pad = 0, big = false, className = "" }: { | |
| target: React.RefObject<HTMLElement | null>; name: string; tone?: "card" | "stage"; pad?: number; big?: boolean; className?: string | |
| }) { | |
| const [state, setState] = useState<"idle" | "busy" | "done">("idle") | |
| const timer = useRef<number>(0) | |
| useEffect(() => () => window.clearTimeout(timer.current), []) | |
| const run = async () => { | |
| const node = target.current | |
| if (!node || state === "busy") return | |
| setState("busy") | |
| try { | |
| await savePng(node, name, { background: backgroundFor(node), pad }) | |
| setState("done") | |
| timer.current = window.setTimeout(() => setState("idle"), 1400) | |
| } catch { | |
| setState("idle") | |
| } | |
| } | |
| const look = tone === "stage" | |
| ? "border-white/15 bg-white/[0.06] text-white/70 backdrop-blur hover:border-white/35 hover:bg-white/12 hover:text-white focus-visible:outline-white/60" | |
| : "border-border bg-card text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-ring" | |
| const Icon = state === "busy" ? LoaderCircle : state === "done" ? Check : Download | |
| return ( | |
| <button type="button" onClick={run} {...{ [EXPORT_IGNORE]: "" }} | |
| aria-label={`Download ${name} as PNG`} title="Download PNG" aria-busy={state === "busy"} | |
| className={`inline-flex ${big ? "size-10" : "size-9"} shrink-0 items-center justify-center rounded-full border transition-colors focus-visible:outline-2 ${look} ${className}`}> | |
| <Icon className={`size-4 ${state === "busy" ? "animate-spin" : ""}`} strokeWidth={2} /> | |
| </button> | |
| ) | |
| } | |