web: components: modified the IconButton component. added icons for hover and click
This commit is contained in:
parent
e08efa3d4b
commit
ea70f66d24
@ -8,23 +8,52 @@ const StyledOuter = styled.div`
|
||||
cursor: ${props => props.isDisabled ? 'default' : 'pointer'};
|
||||
line-height: 0;
|
||||
`;
|
||||
class IconButton extends React.Component{
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
const IconButton = (props) => {
|
||||
const { color, isFill, iconName, size, isDisabled } = props;
|
||||
return (
|
||||
<StyledOuter
|
||||
size={size}
|
||||
isDisabled={isDisabled}
|
||||
onClick={!props.isDisabled ? props.onClick : undefined}
|
||||
onMouseEnter={!props.isDisabled ? props.onMouseEnter : undefined}
|
||||
onMouseLeave={!props.isDisabled ? props.onMouseLeave : undefined}
|
||||
onMouseOver={!props.isDisabled ? props.onMouseOver : undefined}
|
||||
onMouseOut={!props.isDisabled ? props.onMouseOut : undefined}
|
||||
this.state = {
|
||||
currentIconName: this.props.iconName
|
||||
};
|
||||
this.onMouseEnter = this.onMouseEnter.bind(this);
|
||||
this.onMouseLeave = this.onMouseLeave.bind(this);
|
||||
this.onMouseDown = this.onMouseDown.bind(this);
|
||||
this.onMouseUp = this.onMouseUp.bind(this);
|
||||
}
|
||||
|
||||
>
|
||||
{React.createElement(Icons[iconName], {size: "scale", color: color, isfill: isFill})}
|
||||
</StyledOuter>
|
||||
);
|
||||
|
||||
onMouseEnter(e){
|
||||
this.setState({currentIconName: this.props.iconHoverName ? this.props.iconHoverName : this.props.iconName});
|
||||
this.props.onMouseEnter && this.props.onMouseEnter(e);
|
||||
}
|
||||
onMouseLeave(e){
|
||||
this.setState({currentIconName: this.props.iconName});
|
||||
this.props.onMouseDown && this.props.onMouseDown(e);
|
||||
}
|
||||
onMouseDown(e){
|
||||
this.setState({currentIconName: this.props.iconClickName ? this.props.iconClickName : this.props.iconName});
|
||||
this.props.onMouseDown && this.props.onMouseDown(e);
|
||||
}
|
||||
onMouseUp(e){
|
||||
this.setState({currentIconName: this.props.iconHoverName ? this.props.iconHoverName : this.props.iconName});
|
||||
this.props.onClick && this.props.onClick(e);
|
||||
this.props.onMouseUp && this.props.onMouseUp(e);
|
||||
}
|
||||
render(){
|
||||
return (
|
||||
<StyledOuter
|
||||
size={this.props.size}
|
||||
isDisabled={this.props.isDisabled}
|
||||
|
||||
onMouseEnter={this.onMouseEnter}
|
||||
onMouseLeave={this.onMouseLeave}
|
||||
onMouseDown={this.onMouseDown}
|
||||
onMouseUp={this.onMouseUp}
|
||||
>
|
||||
{React.createElement(Icons[this.state.currentIconName], {size: "scale", color: this.props.color, isfill: this.props.isFill})}
|
||||
</StyledOuter>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
IconButton.propTypes = {
|
||||
@ -33,6 +62,8 @@ IconButton.propTypes = {
|
||||
isFill: PropTypes.bool,
|
||||
isDisabled: PropTypes.bool,
|
||||
iconName: PropTypes.string.isRequired,
|
||||
iconHoverName: PropTypes.string,
|
||||
iconClickName: PropTypes.string,
|
||||
onClick:PropTypes.func
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user