insomnia/app/ui/components/dropdowns/PreviewModeDropdown.js

46 lines
1.4 KiB
JavaScript
Raw Normal View History

import React, {PureComponent, PropTypes} from 'react';
2016-11-11 22:01:21 +00:00
import {Dropdown, DropdownDivider, DropdownButton, DropdownItem} from '../base/dropdown';
2016-11-10 02:40:53 +00:00
import {PREVIEW_MODES, getPreviewModeName} from '../../../common/constants';
import {trackEvent} from '../../../analytics/index';
2016-04-30 05:01:57 +00:00
class PreviewModeDropdown extends PureComponent {
_handleClick = previewMode => {
this.props.updatePreviewMode(previewMode);
trackEvent('Response', 'Preview Mode Change', previewMode);
};
render () {
const {download, previewMode} = this.props;
return (
<Dropdown>
<DropdownButton className="tall">
<i className="fa fa-caret-down"></i>
</DropdownButton>
<DropdownDivider>Preview Mode</DropdownDivider>
{PREVIEW_MODES.map(mode => (
<DropdownItem key={mode} onClick={this._handleClick} value={mode}>
{previewMode === mode ? <i className="fa fa-check"/> : <i className="fa fa-empty"/>}
{getPreviewModeName(mode)}
</DropdownItem>
))}
<DropdownDivider>Actions</DropdownDivider>
<DropdownItem onClick={download}>
<i className="fa fa-save"></i>
Save to File
</DropdownItem>
</Dropdown>
)
}
}
2016-04-30 05:01:57 +00:00
PreviewModeDropdown.propTypes = {
// Functions
updatePreviewMode: PropTypes.func.isRequired,
2016-10-28 17:51:08 +00:00
download: PropTypes.func.isRequired,
2016-04-30 05:01:57 +00:00
// Required
previewMode: PropTypes.string.isRequired
};
export default PreviewModeDropdown;