| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 1× 1× 2× 2× | import { h, Component } from 'preact';
import styles from './Switch.scss';
class Switch extends Component {
onChange = (e) => {
e.preventDefault();
this.props.onChange(e.target.checked);
};
render({ isOn }) {
const id = `switch_${Math.floor(Math.random() * 10000)}`;
return (
<div className={styles.switch} onChange={this.onChange}>
<input id={id} checked={isOn} type="checkbox" />
<label htmlFor={id} >
<span />
</label>
</div>
);
}
}
export default Switch;
|