Files
remark42/web/app/components/button/button.jsx
T
Igor AdamenkoandUmputun 6f1b9037d5 Dark theme (#228)
* add with-theme hoc

* add dark theme styles for components

* add toggle theme button to the dev demo page

* add info about widget themes to README
2018-12-15 17:10:41 -06:00

75 lines
1.3 KiB
React

/** @jsx h */
import { Component, h } from 'preact';
import noop from '../../utils/noop';
export default class Button extends Component {
constructor(props) {
super(props);
this.state = {
isClicked: false,
isFocused: false,
};
this.onMouseDown = this.onMouseDown.bind(this);
this.onFocus = this.onFocus.bind(this);
this.onBlur = this.onBlur.bind(this);
}
onMouseDown() {
this.setState({
isClicked: true,
});
}
onClick(e) {
this.props.onClick(e);
}
onBlur(e) {
this.setState({
isClicked: false,
isFocused: false,
});
this.props.onBlur(e);
}
onFocus(e) {
this.setState({
isFocused: true,
});
this.props.onFocus(e);
}
render(props, state) {
const { children } = props;
const { isClicked, isFocused } = state;
const localProps = { ...props };
delete localProps.children;
delete localProps.mix;
delete localProps.mods;
return (
<button
{...localProps}
className={b('button', props, { clicked: isClicked, focused: isFocused })}
onMouseDown={this.onMouseDown}
onBlur={this.onBlur}
onFocus={this.onFocus}
>
{children}
</button>
);
}
}
Button.defaultProps = {
type: 'button',
onClick: noop,
onBlur: noop,
onFocus: noop,
};