<!--
title: Download Button xreact: true colors: pink fontPair: Fugaz One ga: UA-7002862-5 source: https://github.com/notablemind/react-downloadbutton/raw/master/Readme.md css: | .DownloadButton { font-size: 16px; font-family: sans-serif; } styles:
- https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css
- https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.0/css/materialize.min.css scripts:
- download-button.js
- https://code.jquery.com/jquery-2.1.1.min.js
- https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.0/js/materialize.min.js links: home: github: https://github.com/notablemind/react-downloadbutton
-->
View this page rendered at notablemind.github.io/react-downloadbutton
DownloadButton is a simple component for letting the user download a javascript-generated file. It was extracted from Notablemind.
The styling is due to materializecss, and does
not come with the DownloadButton
component. In some examples,
FontAwesome icons are also used.
You are free to style the component however you wish.
// @demobox { // do some calculations return mime: 'text/plain' filename: 'myexportedfile.txt' contents: 'all of the exports' } <DownloadButton // ='waves-effect waves-light btn' =/>
You can also use an asynchronous function to generate the file.
// @demobox { ;}var loading = <span> Crunching hard numbers <i ="fa fa-circle-o-notch fa-spin right"/></span>;var 'Download ' + fileDatafilename; <div => <p>Default titles</p> <DownloadButton ='waves-effect waves-light btn' = =/> <p>Custom titles</p> <DownloadButton ='waves-effect waves-light btn' = = = = =/> </div>
If you already have the file computed, just pass it in as props.
// @demoboxvar fileData = filename: 'hello.txt' contents: 'Hello download!' mime: 'text/plain';var title = <span> Download File <i ="mdi-file-file-download right"/></span>; <DownloadButton ='waves-effect waves-light btn' = =/>