hometown/app/assets/javascripts/components/components/button.jsx

60 lines
1.4 KiB
React
Raw Normal View History

import PureRenderMixin from 'react-addons-pure-render-mixin';
const Button = React.createClass({
propTypes: {
text: React.PropTypes.string,
onClick: React.PropTypes.func,
disabled: React.PropTypes.bool,
block: React.PropTypes.bool,
secondary: React.PropTypes.bool,
size: React.PropTypes.number,
},
getDefaultProps () {
return {
size: 36
};
},
mixins: [PureRenderMixin],
handleClick (e) {
if (!this.props.disabled) {
this.props.onClick();
}
},
render () {
2016-09-27 21:12:33 +00:00
const style = {
fontFamily: 'inherit',
2016-09-27 21:12:33 +00:00
display: this.props.block ? 'block' : 'inline-block',
width: this.props.block ? '100%' : 'auto',
position: 'relative',
boxSizing: 'border-box',
textAlign: 'center',
border: '10px none',
color: '#fff',
fontSize: '14px',
fontWeight: '500',
letterSpacing: '0',
textTransform: 'uppercase',
padding: `0 ${this.props.size / 2.25}px`,
height: `${this.props.size}px`,
2016-09-27 21:12:33 +00:00
cursor: 'pointer',
lineHeight: `${this.props.size}px`,
2016-09-27 21:12:33 +00:00
borderRadius: '4px',
textDecoration: 'none'
};
return (
<button className={`button ${this.props.secondary ? 'button-secondary' : ''}`} disabled={this.props.disabled} onClick={this.handleClick} style={{ ...style, ...this.props.style }}>
{this.props.text || this.props.children}
2016-08-31 20:58:10 +00:00
</button>
);
}
});
export default Button;