Better looking checkboxes (#3345)

Also showing icon only on hover on control headers
This commit is contained in:
Maxime Beauchemin
2017-08-21 13:47:50 -07:00
committed by GitHub
parent e79adbbc5f
commit 254645773c
7 changed files with 100 additions and 63 deletions

View File

@@ -56,6 +56,7 @@ const defaultProps = {
export default class Control extends React.PureComponent {
constructor(props) {
super(props);
this.state = { hovered: false };
this.validate = this.validate.bind(this);
this.onChange = this.onChange.bind(this);
}
@@ -65,6 +66,9 @@ export default class Control extends React.PureComponent {
onChange(value, errors) {
this.validateAndSetValue(value, errors);
}
setHover(hovered) {
this.setState({ hovered });
}
validateAndSetValue(value, errors) {
let validationErrors = this.props.validationErrors;
let currentErrors = this.validate(value);
@@ -96,9 +100,14 @@ export default class Control extends React.PureComponent {
const ControlType = controlMap[this.props.type];
const divStyle = this.props.hidden ? { display: 'none' } : null;
return (
<div style={divStyle}>
<div
style={divStyle}
onMouseEnter={this.setHover.bind(this, true)}
onMouseLeave={this.setHover.bind(this, false)}
>
<ControlType
onChange={this.onChange}
hovered={this.state.hovered}
{...this.props}
/>
</div>