File tree Expand file tree Collapse file tree 2 files changed +29
-19
lines changed
stories/components/semantic-ui Expand file tree Collapse file tree 2 files changed +29
-19
lines changed Original file line number Diff line number Diff line change 11// @flow
22
3- import React , { useState } from 'react' ;
3+ import React from 'react' ;
4+ import uuid from 'react-uuid' ;
45import { Button } from 'semantic-ui-react' ;
56
67type Props = {
8+ filename ?: string ,
79 url : string
810} ;
911
10- const DownloadButton = ( { url, ...button } : Props ) => {
11- const [ loading , setLoading ] = useState ( false ) ;
12-
13- return (
12+ const DownloadButton = ( { filename, url, ...button } : Props ) => (
13+ < a
14+ download = { filename || uuid ( ) }
15+ href = { url }
16+ >
1417 < Button
1518 { ...button }
16- loading = { loading }
17- onClick = { ( ) => {
18- setLoading ( true ) ;
19- return fetch ( url ) . then ( ( response ) => {
20- response . blob ( ) . then ( ( blob ) => {
21- const downloadUrl = window . URL . createObjectURL ( blob ) ;
22- const link = document . createElement ( 'a' ) ;
23- link . href = downloadUrl ;
24- link . click ( ) ;
25- } ) ;
26- } ) . finally ( ( ) => setLoading ( false ) ) ;
27- } }
2819 />
29- ) ;
30- } ;
20+ </ a >
21+ ) ;
3122
3223export default DownloadButton ;
Original file line number Diff line number Diff line change @@ -16,3 +16,22 @@ export const Default = () => (
1616 url = { image }
1717 />
1818) ;
19+
20+ export const LargeFile = ( ) => (
21+ < DownloadButton
22+ content = 'Download'
23+ icon = 'cloud download'
24+ primary
25+ url = 'https://speed.hetzner.de/100MB.bin'
26+ />
27+ ) ;
28+
29+ export const WithFilename = ( ) => (
30+ < DownloadButton
31+ content = 'Download'
32+ filename = 'Test12345'
33+ icon = 'cloud download'
34+ primary
35+ url = { image }
36+ />
37+ ) ;
You can’t perform that action at this time.
0 commit comments