/** * @file Checkbox * @author fex */ import React from 'react'; import {ClassNamesFn, themeable} from '../theme'; import {autobind} from '../utils/helper'; const preventEvent = (e: any) => e.stopPropagation(); interface CheckboxProps { type: 'checkbox' | 'radio'; size?: 'sm' | 'lg' | 'small' | 'large'; label?: string; labelClassName?: string; className?: string; onChange?: (value: any) => void; value?: any; inline?: boolean; trueValue?: any; falseValue?: any; disabled?: boolean; readOnly?: boolean; checked?: boolean; name?: string; description?: string; classPrefix: string; classnames: ClassNamesFn; partial?: boolean; } export class Checkbox extends React.Component { static defaultProps: Pick< CheckboxProps, 'trueValue' | 'falseValue' | 'type' > = { trueValue: true, falseValue: false, type: 'checkbox' }; @autobind handleCheck(e: React.ChangeEvent) { const {trueValue, falseValue, onChange} = this.props; if (!onChange) { return; } onChange(e.currentTarget.checked ? trueValue : falseValue); } render() { let { size, className, classnames: cx, value, label, partial, trueValue, children, disabled, description, readOnly, checked, type, name, labelClassName } = this.props; return ( ); } } export default themeable(Checkbox);