Spaces:
Sleeping
Sleeping
Download components/DownloadButton.tsx from codebybrody/codebydante: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/codebybrody/codebydante/resolve/c0f0601edf43a8487f75ea12fdec93d8aa366128/components/DownloadButton.tsx
- Command line
-
hf download hf://spaces/codebybrody/codebydante@c0f0601edf43a8487f75ea12fdec93d8aa366128/components/DownloadButton.tsx
-
curl -L -o DownloadButton.tsx https://huggingface.co/spaces/codebybrody/codebydante/resolve/c0f0601edf43a8487f75ea12fdec93d8aa366128/components/DownloadButton.tsx
1.27 kB
| import React, { useState } from 'react'; | |
| import { Download, Check } from 'lucide-react'; | |
| export const DownloadButton = ({ text, filename = 'download.txt', className = '', ...props }: { text: string, filename?: string, className?: string } & React.ButtonHTMLAttributes<HTMLButtonElement>) => { | |
| const [downloaded, setDownloaded] = useState(false); | |
| const handleDownload = () => { | |
| const element = document.createElement("a"); | |
| const file = new Blob([text], { type: 'text/plain' }); | |
| element.href = URL.createObjectURL(file); | |
| element.download = filename; | |
| document.body.appendChild(element); // Required for this to work in FireFox | |
| element.click(); | |
| document.body.removeChild(element); | |
| setDownloaded(true); | |
| setTimeout(() => setDownloaded(false), 2000); | |
| }; | |
| return ( | |
| <button | |
| onClick={handleDownload} | |
| className={`p-1.5 bg-[#2d2d2d] border border-white/10 rounded-md text-gray-400 hover:text-white hover:bg-primary/20 transition-all z-10 ${className}`} | |
| title="Descargar archivo" | |
| {...props} | |
| > | |
| {downloaded ? <Check size={14} /> : <Download size={14} />} | |
| </button> | |
| ); | |
| }; | |