forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created download button component for assets * Added download component to asset manager * Added click handler for downloading assets * Installed mime package. Added extension property to object returned by dataurl.parse. Updated click handler in download component. * Added css to make asset-download float right like asset-copy * removed console log in dataurl * Updated styles for asset manager * Added title attributes to download and clipboard buttons for tooltip
- Loading branch information
Showing
6 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import fileSaver from 'file-saver'; | ||
import { toByteArray } from 'base64-js'; | ||
import { parse } from '../../../common/lib/dataurl'; | ||
|
||
export class Download extends React.PureComponent { | ||
static propTypes = { | ||
children: PropTypes.element.isRequired, | ||
fileName: PropTypes.string, | ||
content: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, | ||
onCopy: PropTypes.func, | ||
}; | ||
|
||
onClick = () => { | ||
const { fileName, content } = this.props; | ||
const asset = parse(content, true); | ||
const assetBlob = new Blob([toByteArray(asset.data)], { type: asset.mimetype }); | ||
const ext = asset.extension ? `.${asset.extension}` : ''; | ||
fileSaver.saveAs(assetBlob, `canvas-${fileName}${ext}`); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="canvas_download" onClick={this.onClick}> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Download as Component } from './download'; | ||
|
||
export const Download = Component; |