UNPKG

react-mdl

Version:

React Components wrapper for Material Design Lite UI

48 lines (41 loc) 1.48 kB
import React, { PropTypes } from 'react'; import { findDOMNode } from 'react-dom'; import classNames from 'classnames'; import mdlUpgrade from './utils/mdlUpgrade'; class Checkbox extends React.Component { static propTypes = { checked: PropTypes.bool, className: PropTypes.string, disabled: PropTypes.bool, label: PropTypes.string, onChange: PropTypes.func, ripple: PropTypes.bool }; componentDidUpdate(prevProps) { if(this.props.disabled !== prevProps.disabled) { const fnName = this.props.disabled ? 'disable' : 'enable'; findDOMNode(this).MaterialCheckbox[fnName](); } if(this.props.checked !== prevProps.checked) { const fnName = this.props.checked ? 'check' : 'uncheck'; findDOMNode(this).MaterialCheckbox[fnName](); } } render() { const { className, label, ripple, ...inputProps } = this.props; const classes = classNames('mdl-checkbox mdl-js-checkbox', { 'mdl-js-ripple-effect': ripple }, className); return ( <label className={classes}> <input type="checkbox" className="mdl-checkbox__input" { ...inputProps } /> {label && <span className="mdl-checkbox__label">{label}</span>} </label> ); } } export default mdlUpgrade(Checkbox);