Skip to content

Commit

Permalink
feat(Checkbox): nowrap modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Dec 29, 2018
1 parent 08bd214 commit 916de2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type CheckboxProps = {
hasError?: boolean,
/** show disabled styles */
disabled?: boolean,
/** no wrap text */
nowrap?: boolean,

/** callback to change chcked state */
onChange?: (boolean, SyntheticInputEvent<HTMLInputElement>) => void,
Expand All @@ -38,7 +40,7 @@ class Checkbox extends PureComponent<CheckboxProps> {
}

render() {
const { onChange, checked, hasError, disabled, label, ...rest } = this.props;
const { onChange, checked, hasError, disabled, label, nowrap, ...rest } = this.props;

return (
<CheckboxWrapperTag { ...rest } tagName="label">
Expand All @@ -54,7 +56,7 @@ class Checkbox extends PureComponent<CheckboxProps> {
type="checkbox"
tagName="input"
/>
<CheckboxTextTag tagName="div">{ label }</CheckboxTextTag>
<CheckboxTextTag tagName="div" nowrap={ nowrap }>{ label }</CheckboxTextTag>
</CheckboxWrapperTag>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/Checkbox/Checkbox.theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const themeText = createComponentTheme(`${name}Text`, ({ COLORS }: *): * => ({
color: COLORS.SECONDARY_TEXT_COLOR,
fontSize: COLORS.BODY_TEXT,
},

modifiers: {
nowrap: {
whiteSpace: 'nowrap',
},
},
}));

const theme = {
Expand Down
4 changes: 4 additions & 0 deletions src/components/CheckboxField/CheckboxField.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type CheckboxFieldProps = {|
color ?: 'primary' | 'secondary',
/** show disabled styles */
disabled ?: boolean,
/** no wrap text */
nowrap?: boolean,
|};

const CheckboxField = ({
Expand All @@ -27,6 +29,7 @@ const CheckboxField = ({
meta,
disabled,
color,
nowrap,
...rest
}: CheckboxFieldProps) => {
const { name, value, onChange, onFocus, onBlur } = input;
Expand All @@ -44,6 +47,7 @@ const CheckboxField = ({
hasError={ hasError }
disabled={ disabled }
color={ color }
nowrap={ nowrap }
/>
</FormField>
);
Expand Down

0 comments on commit 916de2c

Please sign in to comment.