insomnia/app/ui/components/base/FileInputButton.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-11-22 22:26:52 +00:00
import React, {Component, PropTypes} from 'react';
import {remote} from 'electron';
import {Dropdown, DropdownButton, DropdownItem} from '../base/dropdown';
import PromptButton from '../base/PromptButton';
class FileInputButton extends Component {
_handleUnsetFile () {
this.props.onChange('');
}
_handleChooseFile () {
const options = {
title: 'Import File',
buttonLabel: 'Import',
properties: ['openFile']
};
remote.dialog.showOpenDialog(options, async paths => {
if (!paths || paths.length === 0) {
return;
}
const path = paths[0];
this.props.onChange(path);
})
}
render () {
const {className} = this.props;
return (
<Dropdown>
<DropdownButton className={className}>
Choose File <i className="fa fa-caret-down"></i>
</DropdownButton>
<DropdownItem onClick={e => this._handleChooseFile()}>
<i className="fa fa-file"></i>
Choose File
</DropdownItem>
<DropdownItem buttonClass={PromptButton}
addIcon={true}
onClick={e => this._handleUnsetFile()}>
<i className="fa fa-close"></i>
2016-11-23 03:07:35 +00:00
Clear File
2016-11-22 22:26:52 +00:00
</DropdownItem>
</Dropdown>
)
}
}
FileInputButton.propTypes = {
onChange: PropTypes.func.isRequired,
path: PropTypes.string.isRequired,
};
export default FileInputButton;