all files / src/modal/ Switch.js

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 4/4
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                                             
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;