Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
fix(Checkbox): Add disabled prop (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadenlemmon authored and kylealwyn committed Aug 2, 2018
1 parent 2316a34 commit 5cdb6ac
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Form/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const StyledInput = createComponent({
tag: 'input',
}).extend`
display: none;
pointer-events: ${p => (p.disabled ? 'none' : 'auto')};
`;

const StyledIcon = createComponent({
Expand Down Expand Up @@ -55,6 +56,7 @@ export default class Checkbox extends React.Component {
fontSize: PropTypes.number,
color: PropTypes.string,
horizontal: PropTypes.bool,
disabled: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -66,6 +68,7 @@ export default class Checkbox extends React.Component {
iconSize: 18,
horizontal: false,
onChange() {},
disabled: false,
};

state = {
Expand All @@ -86,6 +89,7 @@ export default class Checkbox extends React.Component {

handleChange = () => {
const { valueTrue, valueFalse, onChange } = this.props;

const newValue = this.checked ? valueFalse : valueTrue;

this.setState(
Expand All @@ -99,12 +103,19 @@ export default class Checkbox extends React.Component {
};

render() {
const { label, id, error, name, fontSize, iconOn, iconOff, iconSize, color, horizontal } = this.props;
const { label, id, error, name, fontSize, iconOn, iconOff, iconSize, color, horizontal, disabled } = this.props;
const { checked } = this;

return (
<CheckboxContainer horizontal={horizontal}>
<StyledInput id={id} name={name} type="checkbox" checked={checked} onChange={this.handleChange} />
<StyledInput
id={id}
name={name}
type="checkbox"
checked={checked}
disabled={disabled}
onChange={this.handleChange}
/>

<Flex alignItems="center">
<StyledIcon size={iconSize} color={color} checked={checked} name={checked ? iconOn : iconOff} />
Expand Down

0 comments on commit 5cdb6ac

Please sign in to comment.