UNPKG

feeles-ide

Version:

The hackable and serializable IDE to make learning material

117 lines (100 loc) 3.43 kB
import _Promise from 'babel-runtime/core-js/promise'; import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _createClass from 'babel-runtime/helpers/createClass'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import Dialog from 'material-ui/Dialog'; import { Abort } from './Buttons'; /** * HTML5 a要素のdownload属性が実装されていないブラウザのためのfallback */ var SaveDialog = function (_PureComponent) { _inherits(SaveDialog, _PureComponent); function SaveDialog() { var _ref; var _temp, _this, _ret; _classCallCheck(this, SaveDialog); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = SaveDialog.__proto__ || _Object$getPrototypeOf(SaveDialog)).call.apply(_ref, [this].concat(args))), _this), _this.state = { contents: _this.props.content instanceof Array ? _this.props.content : [_this.props.content], results: [] }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(SaveDialog, [{ key: 'componentDidMount', value: function componentDidMount() { var _this2 = this; _Promise.all(this.state.contents.map(function (item) { return new _Promise(function (resolve) { var reader = new FileReader(); reader.onload = function () { return resolve({ name: item.name, href: reader.result }); }; reader.readAsDataURL(item.blob); }); })).then(function (results) { return _this2.setState({ results: results }); }); } }, { key: 'render', value: function render() { var _props = this.props, onRequestClose = _props.onRequestClose, localization = _props.localization; var actions = [React.createElement(Abort, { key: 'cancel', primary: true, onClick: onRequestClose, label: localization.saveDialog.cancel })]; var divStyle = { textAlign: 'center' }; var linkStyle = { fontSize: '2rem' }; return React.createElement( Dialog, { title: localization.saveDialog.title, actions: actions, modal: false, open: true, onRequestClose: onRequestClose }, this.state.results.map(function (item, i) { return React.createElement( 'div', { key: i, style: divStyle }, React.createElement( 'a', { target: '_blank', href: item.href, style: linkStyle }, item.name ), React.createElement( 'p', null, localization.saveDialog.description(item.name) ) ); }) ); } }]); return SaveDialog; }(PureComponent); SaveDialog.propTypes = { onRequestClose: PropTypes.func.isRequired, content: PropTypes.any, localization: PropTypes.object.isRequired }; export default SaveDialog;