insomnia/app/components/RequestUrlBar.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-03-20 23:20:00 +00:00
import React, {Component, PropTypes} from 'react'
2016-03-22 05:01:58 +00:00
import Input from './base/Input';
import Dropdown from './base/Dropdown';
2016-03-21 05:47:49 +00:00
import {METHODS} from '../constants/global';
2016-03-20 23:20:00 +00:00
class UrlInput extends Component {
2016-03-22 18:20:05 +00:00
shouldComponentUpdate(nextProps) {
return this.props.request.url !== nextProps.request.url;
}
2016-03-20 23:20:00 +00:00
render () {
2016-03-22 18:20:05 +00:00
const {onUrlChange, onMethodChange, request} = this.props;
2016-03-20 23:20:00 +00:00
return (
2016-03-21 05:47:49 +00:00
<div className="grid form-control form-control--left form-control--right">
<Dropdown>
<button className="btn txt-lg">
2016-03-22 18:20:05 +00:00
{request.method}&nbsp;&nbsp;<i className="fa fa-caret-down"></i>
2016-03-21 05:47:49 +00:00
</button>
<ul className="bg-super-light">
{METHODS.map((method) => (
<li key={method}>
<button onClick={onMethodChange.bind(null, method)}>
2016-03-21 05:47:49 +00:00
{method}
</button>
</li>
))}
</ul>
</Dropdown>
2016-03-20 23:20:00 +00:00
<Input type="text"
2016-03-21 05:47:49 +00:00
className="txt-lg"
2016-03-20 23:20:00 +00:00
placeholder="https://google.com"
2016-03-22 18:20:05 +00:00
initialValue={request.url}
2016-03-20 23:20:00 +00:00
onChange={onUrlChange}/>
2016-03-21 05:47:49 +00:00
<button className="btn">
2016-03-20 23:20:00 +00:00
<i className="fa fa-repeat txt-xl"></i>
</button>
</div>
)
}
}
UrlInput.propTypes = {
onUrlChange: PropTypes.func.isRequired,
2016-03-20 23:27:46 +00:00
onMethodChange: PropTypes.func.isRequired,
2016-03-22 18:20:05 +00:00
request: PropTypes.shape({
url: PropTypes.string.isRequired,
method: PropTypes.string.isRequired
}).isRequired
2016-03-20 23:20:00 +00:00
};
export default UrlInput;