| 7 | requireCss('buttons'); |
| 8 | |
| 9 | class Button extends Component { |
| 10 | constructor (props) { |
| 11 | super(props); |
| 12 | this.state = { |
| 13 | disabled: props.disabled, |
| 14 | show: null |
| 15 | }; |
| 16 | this.handleClick = this.handleClick.bind(this); |
| 17 | } |
| 18 | |
| 19 | componentWillReceiveProps(nextProps) { |
| 20 | if (nextProps.disabled !== this.props.disabled) { |
| 21 | this.setState({ disabled: nextProps.disabled }); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | disable(elem) { |
| 26 | this.setState({ disabled: true, show: elem }); |
| 27 | } |
| 28 | |
| 29 | enable(elem) { |
| 30 | this.setState({ disabled: false, show: elem }); |
| 31 | } |
| 32 | |
| 33 | handleClick() { |
| 34 | if (this.props.onClick) { |
| 35 | this.props.onClick(); |
| 36 | } |
| 37 | if (this.props.once) { |
| 38 | this.disable(); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | render() { |
| 43 | let status = this.props.status; |
| 44 | if (status) { |
| 45 | status = `rct-button-${status}`; |
| 46 | } |
| 47 | |
| 48 | const className = classnames( |
| 49 | this.props.className, |
| 50 | getGrid(this.props.grid), |
| 51 | 'rct-button', |
| 52 | status |
| 53 | ); |
| 54 | |
| 55 | return ( |
| 56 | <button onClick={this.handleClick} |
| 57 | style={this.props.style} |
| 58 | disabled={this.state.disabled} |
| 59 | className={className} |
| 60 | type={this.props.type || 'button'}> |
| 61 | { this.state.show || this.props.children } |
| 62 | </button> |
| 63 | ); |
| 64 | } |
| 65 | } |
| 66 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…