Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: checkbox #179

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const meta: Meta<typeof Checkbox> = {
onChange: eventMockFn,
id: testId,
label: 'Enable Settings',
disabled: false,
checked: false,
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
Expand Down
5 changes: 4 additions & 1 deletion src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type CheckboxProps = {
name?: string;
id?: string;
style?: CSSProperties;
disabled?: boolean;
};

const Checkbox: FC<CheckboxProps> = ({
Expand All @@ -22,8 +23,9 @@ const Checkbox: FC<CheckboxProps> = ({
name,
error,
style,
disabled,
}): JSX.Element => (
<Wrapper>
<Wrapper enabled={!disabled}>
<FormError error={error}>
<CheckboxRoot htmlFor={id} style={style}>
<Check
Expand All @@ -32,6 +34,7 @@ const Checkbox: FC<CheckboxProps> = ({
checked={checked}
onChange={onChange}
name={name}
disabled={disabled}
/>
<Label>{label}</Label>
</CheckboxRoot>
Expand Down
54 changes: 28 additions & 26 deletions src/components/Checkbox/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import styled from 'styled-components';
import { getTheme } from '@platformbuilders/theme-toolkit';
import { getTheme, ifStyle } from '@platformbuilders/theme-toolkit';

const brandPrimaryMain = getTheme('brand.primary.main');
const brandPrimaryContrast = getTheme('brand.primary.contrast');
const infoMain = getTheme('info.main');
const spacingSm = getTheme('spacing.sm');
const borderRadiusSm = getTheme('borderRadius.sm');

export const Wrapper = styled.div`
// Ifs
const isEnabled = ifStyle('enabled');

type WrapperProps = {
enabled?: boolean;
};

export const Wrapper = styled.div<WrapperProps>`
display: flex;
flex-direction: column;
width: 100%;
margin-bottom: 10px;
padding: ${spacingSm}px;
border-radius: ${borderRadiusSm}px;
transition: 0.5s;

&:hover {
background-color: ${isEnabled(infoMain)}20;
}
`;

export const CheckboxRoot = styled.label`
Expand All @@ -21,8 +37,8 @@ export const CheckboxRoot = styled.label`

input:checked + span::before,
input:indeterminate + span::before {
border-color: ${brandPrimaryMain};
background-color: ${brandPrimaryMain};
border-color: ${infoMain};
background-color: ${infoMain};
}

input:checked + span::after,
Expand All @@ -35,23 +51,8 @@ export const CheckboxRoot = styled.label`
transform: translate(4px, 3px);
}

&:hover {
input {
opacity: 0.12;

:focus {
opacity: 0.16;
}
}
}

input:active + span::before {
border-color: ${brandPrimaryMain};
}

input:checked:active + span::before {
border-color: transparent;
background-color: rgba(0, 0, 0, 0.6);
border-color: ${infoMain};
}

input:disabled + span {
Expand All @@ -60,13 +61,14 @@ export const CheckboxRoot = styled.label`
}

input:disabled + span::before {
border-color: currentColor;
border-color: ${infoMain};
opacity: 0.5;
}

input:checked:disabled + span::before,
input:indeterminate:disabled + span::before {
border-color: transparent;
background-color: currentColor;
background-color: ${infoMain};
}
`;

Expand All @@ -91,7 +93,7 @@ export const Check = styled.input`

&:checked,
&:indeterminate {
background-color: ${brandPrimaryMain};
background-color: ${infoMain};
}

&:focus {
Expand Down Expand Up @@ -120,8 +122,8 @@ export const Label = styled.span`
box-sizing: border-box;
margin: 3px 11px 3px 1px;
border: solid 2px; /* Safari */
border-color: rgba(0, 0, 0, 0.6);
border-radius: 2px;
border-color: ${infoMain};
border-radius: 3px;
width: 18px;
height: 18px;
vertical-align: top;
Expand Down
Loading