Skip to content

Commit

Permalink
feat(checkbox-input): Allow custom icon (#164)
Browse files Browse the repository at this point in the history
* feat(checkbox-input): Custom icon added

* fix(checkbox-input): Default margin removed

* fix(checkbox-input): Label's display value changed to inline-flex, removed isSelected check for display icon

* fix(checkbox-input): labels's display value changed to inline-flex
  • Loading branch information
Anlerkan authored Oct 26, 2021
1 parent 7ba99e6 commit d890006
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/form/input/checkbox/CheckboxInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CheckboxInputProps {
) => void;
isSelected: boolean;
isDisabled?: boolean;
customIcon?: React.ReactNode;
customClassName?: string;
testid?: string;
}
Expand All @@ -25,6 +26,7 @@ function CheckboxInput({
customClassName,
isSelected,
isDisabled,
customIcon,
testid
}: CheckboxInputProps) {
const {
Expand All @@ -35,6 +37,7 @@ function CheckboxInput({
"checkbox-input-label--is-selected": isSelected,
"checkbox-input-label--is-disabled": isDisabled
});
const icon = customIcon || <CheckIcon />;

return (
<label data-testid={testid} htmlFor={htmlFor} className={containerClassName}>
Expand All @@ -49,9 +52,7 @@ function CheckboxInput({
disabled={isDisabled}
/>

<span className={"checkbox-input-label__icon"}>
<CheckIcon />
</span>
<span className={"checkbox-input-label__icon"}>{icon}</span>

{content}
</label>
Expand Down
4 changes: 1 addition & 3 deletions src/form/input/checkbox/_checkbox-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

position: relative;

display: flex;
display: inline-flex;
align-items: center;

margin-bottom: 10px;

cursor: pointer;
user-select: none;

Expand Down
4 changes: 4 additions & 0 deletions stories/2-CheckboxInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ storiesOf("Checkbox", module).add("Checkbox", () => {
}}
/>

<br />

<CheckboxInput
onSelect={() =>
setState({...state, termsAndConditions: !state.termsAndConditions})
Expand All @@ -46,6 +48,8 @@ storiesOf("Checkbox", module).add("Checkbox", () => {
}}
/>

<br />

<CheckboxInput
onSelect={() => setState({...state, privacyPolicy: !state.privacyPolicy})}
isSelected={state.privacyPolicy}
Expand Down

0 comments on commit d890006

Please sign in to comment.