Skip to content

Commit

Permalink
feat(checkbox): theme checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaKashuba committed Jul 31, 2024
1 parent 9ed44de commit a2503e7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-waves-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@zopauk/react-components': minor
---

checkbox
48 changes: 40 additions & 8 deletions src/components/molecules/CheckboxField/CheckboxField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { colors, typography } from '../../../constants';
import tealCheckMark from '../../../content/images/teal-check-mark.svg';
import greenCheckMark from '../../../content/images/green-check-mark.svg';
import unbrandedTick from '../../../content/images/unbranded-tick.svg';
import unbrandedTickWhite from '../../../content/images/unbranded-tick-white.svg';
import ErrorMessage from '../../atoms/ErrorMessage/ErrorMessage';
import InputLabel from '../../atoms/InputLabel/InputLabel';
import SizedContainer from '../../layout/SizedContainer/SizedContainer';
Expand Down Expand Up @@ -37,6 +38,24 @@ const getTickIcon = ({ isValid, theme }: Pick<InputProps, 'disabled' | 'isValid'
return tealCheckMark;
};

const getCheckboxBorderColorByStatus = ({
hasError,
isValid,
disabled,
theme,
}: Pick<InputProps, 'disabled' | 'isValid' | 'hasError'> & AppThemeProps) => {
if (hasError) {
return theme.input.checkBox.borderColorByStatus.error;
}
if (isValid) {
return theme.input.checkBox.borderColorByStatus.valid;
}
if (disabled) {
return theme.input.checkBox.borderColorByStatus.disabled;
}
return theme.input.checkBox.borderColorByStatus.default;
};

const zoomOut = keyframes`
from {
transform: scale(0.4);
Expand Down Expand Up @@ -74,7 +93,7 @@ const Label = styled(InputLabel)<Pick<InputProps, 'disabled' | 'hasError' | 'isV
transition-property: border, box-shadow;
transition: 0.2s ease-in-out;
box-shadow: 0 0 4px 0 transparent;
border: 1px ${getBorderColorByStatus} solid;
border: 1px ${getCheckboxBorderColorByStatus} solid;
display: block;
}
&:after {
Expand All @@ -100,36 +119,49 @@ const Input = styled.input<InputProps & GroupingControlsProps>`
&:hover:not(:disabled) + label,
&:focus + label {
border-color: ${({ theme }) => theme.input.checkBox.defaultColor};
box-shadow: ${({ theme }) => `${theme.input.hover.boxShadow} ${theme.input.hover.border}`};
border-color: ${({ theme, hasError }) => (hasError ? theme.input.hover.error : theme.input.hover.border)};
box-shadow: ${({ hasError, theme }) =>
hasError
? `${theme.input.hover.boxShadow} ${theme.input.hover.error}`
: `${theme.input.hover.boxShadow} ${theme.input.hover.border}`};
&:before {
border-color: ${({ theme }) => theme.input.checkBox.defaultColor};
border-color: ${({ theme }) => theme.input.hover.border};
box-shadow: ${({ theme }) => `${theme.input.hover.boxShadow} ${theme.input.hover.border}`};
}
background-color: ${({ theme }) => theme.input.hover.backgroundColor};
}
&:hover:checked:not(:disabled) + label,
&:focus:checked + label {
&:before {
background-color: ${({ theme }) => theme.input.checkBox.checkboxBackgroundColor.hover};
}
&:after {
background-image: ${({ theme }) =>
theme.input.checkBox.customIcon ? `url(${unbrandedTick})` : `url(${tealCheckMark})`};
theme.input.checkBox.customIcon ? `url(${unbrandedTickWhite})` : `url(${tealCheckMark})`};
}
}
&:disabled + label {
cursor: not-allowed;
color: ${colors.grey};
background-color: ${colors.greyLightest};
color: ${({ theme }) => theme.input.disabled.color};
background-color: ${({ theme }) => theme.input.disabled.backgroundColor};
}
&:disabled:not(:checked) + label {
border-color: ${colors.greyLight};
&:before {
border-color: ${colors.greyLight};
}
}
&:disabled {
&:before {
background-color: ${({ theme }) => theme.input.checkBox.checkboxBackgroundColor.disabled};
}
}
&:checked + label {
border-color: ${getCheckedColor};
background-color: ${({ theme }) => theme.input.checkBox.label.backgroundColor};
box-shadow: none;
box-shadow: ${({ theme }) => `${theme.input.checkBox.checked.boxShadow} ${theme.input.hover.border}`};
&:before {
background-color: ${({ theme }) => theme.input.checkBox.checkboxBackgroundColor.checked};
border-color: ${getCheckedColor};
box-shadow: none;
}
Expand Down
28 changes: 28 additions & 0 deletions src/components/styles/Theme/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ export interface InputTheme {
backgroundColor: string;
};
customIcon: boolean;
checked: {
boxShadow: string;
};
borderColorByStatus: {
error: string;
valid: string;
disabled: string;
default: string;
};
checkboxBackgroundColor: {
checked: string;
hover: string;
disabled: string;
};
};
}

Expand Down Expand Up @@ -557,6 +571,20 @@ export const zopaTheme: AppTheme = {
backgroundColor: colors.brandLight,
},
customIcon: false,
checked: {
boxShadow: 'none',
},
borderColorByStatus: {
error: colors.alert,
valid: colors.success,
disabled: colors.greyLight,
default: colors.grey,
},
checkboxBackgroundColor: {
checked: colors.white,
hover: colors.white,
disabled: colors.white,
},
},
},
link: {
Expand Down
17 changes: 17 additions & 0 deletions src/content/images/unbranded-tick-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a2503e7

Please sign in to comment.