Created
September 2, 2015 07:20
-
-
Save f15gdsy/418d13a1297fa79412fc to your computer and use it in GitHub Desktop.
A <input type='text'> that hides border, and shows it when hover.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import React from 'react'; | |
import _ from 'lodash'; | |
export default React.createClass ({ | |
propTypes: { | |
// Show border on hover and hide otherwise. | |
borderOnHover: React.PropTypes.bool | |
}, | |
getDefaultProps () { | |
return { | |
style: { | |
borderWidth: 1, | |
borderColor: 'grey' | |
}, | |
borderOnHover: false, | |
onMouseEnter: function () {}, | |
onMouseOut: function () {}, | |
}; | |
}, | |
getInitialState () { | |
return { | |
hover: false, | |
}; | |
}, | |
handleOnMouseEnter (event) { | |
this.setState({ | |
hover: true | |
}); | |
this.props.onMouseEnter(event); | |
}, | |
handleOnMouseOut (event) { | |
this.setState({ | |
hover: false | |
}); | |
this.props.onMouseOut(event); | |
}, | |
getBorderColor () { | |
if (this.props.borderOnHover) { | |
if (!this.state.hover) { | |
return 'transparent'; | |
} | |
} | |
let {style} = this.props; | |
return style.borderColor; | |
}, | |
render () { | |
let {style, onMouseEnter, onMouseOut, ...others} = this.props; | |
let borderColor = this.getBorderColor(); | |
return ( | |
<input | |
style = {_.assign({}, style, {borderColor: borderColor})} | |
type = 'text' | |
onMouseEnter = {this.handleOnMouseEnter} | |
onMouseOut = {this.handleOnMouseOut} | |
{...others} | |
/> | |
); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Treat it like a , and use borderOnHover to make the border shows only when hover.
Like: