react-toolbox/components/list/ListCheckbox.js

72 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-05-29 21:59:54 +03:00
import React, { PropTypes } from 'react';
2016-05-22 20:08:47 +03:00
import classnames from 'classnames';
import { themr } from 'react-css-themr';
2017-01-26 20:05:32 +03:00
import { LIST } from '../identifiers';
import InjectCheckbox from '../checkbox/Checkbox';
import InjectListItemContent from './ListItemContent';
2015-10-19 03:38:25 +03:00
2016-05-29 21:59:54 +03:00
const factory = (Checkbox, ListItemContent) => {
2017-01-26 20:05:32 +03:00
const ListCheckbox = ({
caption,
checked,
className,
disabled,
legend,
name,
onBlur,
onChange,
onFocus,
theme,
}) => {
2016-05-29 21:59:54 +03:00
const _className = classnames(theme.item, theme.checkboxItem, {
2017-01-26 20:05:32 +03:00
[theme.disabled]: disabled,
2016-05-29 21:59:54 +03:00
}, className);
2015-10-19 03:38:25 +03:00
2016-05-29 21:59:54 +03:00
return (
<li className={_className}>
<Checkbox
checked={checked}
className={theme.checkbox}
disabled={disabled}
label={<ListItemContent caption={caption} legend={legend} />}
name={name}
onBlur={onBlur}
onChange={onChange}
onFocus={onFocus}
/>
</li>
);
};
2015-10-19 03:38:25 +03:00
2016-05-29 21:59:54 +03:00
ListCheckbox.propTypes = {
caption: PropTypes.string,
2016-05-29 21:59:54 +03:00
checked: PropTypes.bool,
className: PropTypes.string,
disabled: PropTypes.bool,
legend: PropTypes.string,
name: PropTypes.string,
onBlur: PropTypes.func,
onChange: PropTypes.func,
onFocus: PropTypes.func,
theme: PropTypes.shape({
checkbox: PropTypes.string,
checkboxItem: PropTypes.string,
disabled: PropTypes.string,
2017-01-26 20:05:32 +03:00
item: PropTypes.string,
}),
2016-05-29 21:59:54 +03:00
};
2015-10-19 03:38:25 +03:00
2016-05-29 21:59:54 +03:00
ListCheckbox.defaultProps = {
checked: false,
2017-01-26 20:05:32 +03:00
disabled: false,
2016-05-29 21:59:54 +03:00
};
return ListCheckbox;
};
2015-10-19 03:38:25 +03:00
2016-05-29 21:59:54 +03:00
const ListCheckbox = factory(InjectCheckbox, InjectListItemContent);
export default themr(LIST)(ListCheckbox);
export { factory as listCheckboxFactory };
export { ListCheckbox };