UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

1 lines 1.46 kB
{"version":3,"file":"DownloadButton.mjs","names":[],"sources":["../../src/DownloadButton/DownloadButton.tsx"],"sourcesContent":["'use client';\n\nimport { Download } from 'lucide-react';\nimport React, { memo } from 'react';\n\nimport ActionIcon from '@/ActionIcon';\nimport { downloadBlob } from '@/utils/downloadBlob';\n\nimport type { DownloadButtonProps } from './type';\n\nconst DownloadButton = memo<DownloadButtonProps>(\n ({ fileName = 'download', fileType = 'svg', disabled = false, blobUrl, ...rest }) => {\n const handleDownload = async () => {\n if (!blobUrl || disabled) return;\n try {\n await downloadBlob(blobUrl, `${fileName.replace(/\\.[^./]+$/, '')}.${fileType}`);\n } catch (error) {\n console.error('Download failed:', error);\n }\n };\n return (\n <ActionIcon\n title={`Download ${fileType.toUpperCase()}`}\n {...rest}\n icon={Download}\n onClick={handleDownload}\n />\n );\n },\n);\n\nDownloadButton.displayName = 'DownloadButton';\n\nexport default DownloadButton;\n"],"mappings":";;;;;;;AAUA,MAAM,iBAAiB,MACpB,EAAE,WAAW,YAAY,WAAW,OAAO,WAAW,OAAO,SAAS,GAAG,WAAW;CACnF,MAAM,iBAAiB,YAAY;EACjC,IAAI,CAAC,WAAW,UAAU;EAC1B,IAAI;GACF,MAAM,aAAa,SAAS,GAAG,SAAS,QAAQ,aAAa,EAAE,EAAE,GAAG,UAAU;EAChF,SAAS,OAAO;GACd,QAAQ,MAAM,oBAAoB,KAAK;EACzC;CACF;CACA,OACE,oBAAC,YAAD;EACE,OAAO,YAAY,SAAS,YAAY;EACxC,GAAI;EACJ,MAAM;EACN,SAAS;CACV,CAAA;AAEL,CACF;AAEA,eAAe,cAAc"}