lm-switch
Version:
* 作者:winber * 邮箱:winberxie@163.com * 版本:**`0.2.0`**
57 lines (45 loc) • 1.06 kB
JavaScript
/**
* Created by winber<winberxie@163.com>.
* ComponentName Switch
* Desc 组件描述内容
* GroupName lm-component
*/
import React from 'react'
import PropTypes from 'prop-types';
import './index.scss';
const Switch = ({
id,
checked,
onChange,
...others
}) => {
const changeHandler = (e) => {
onChange && onChange( e.target.checked);
};
return (
<div className="lm-switch">
<input
id={ id }
type="checkbox"
defaultChecked={ checked }
onChange={changeHandler}
{...others}
/>
<label
className="lm-switch-label"
htmlFor={ id }
>
</label>
</div>
)
};
Switch.propTypes = {
id: PropTypes.string.isRequired,
checked: PropTypes.bool,
disabled: PropTypes.bool
}
Switch.defaultProps = {
disabled: false,
checked: true,
};
export default Switch;