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

fix: make CheckBox styling respect the figma design #1806

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/mean-dragons-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': patch
---

fix checkbox behaviour when disabled respecting figma design
14 changes: 9 additions & 5 deletions packages/design-system/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface CheckboxElProps extends Checkbox.CheckboxProps {}
type CheckboxElement = HTMLButtonElement;

const CheckboxEl = React.forwardRef<CheckboxElement, CheckboxElProps>(
({ defaultChecked, checked: checkedProp, onCheckedChange, ...props }, forwardedRef) => {
({ defaultChecked, disabled, checked: checkedProp, onCheckedChange, ...props }, forwardedRef) => {
const checkboxRef = React.useRef<CheckboxElement>(null!);
const [checked, setChecked] = useControllableState({
defaultProp: defaultChecked,
Expand All @@ -51,10 +51,13 @@ const CheckboxEl = React.forwardRef<CheckboxElement, CheckboxElProps>(
const composedRefs = useComposedRefs(checkboxRef, forwardedRef);

return (
<CheckboxRoot ref={composedRefs} checked={checked} onCheckedChange={setChecked} {...props}>
<CheckboxIndicator forceMount>
{checked === true ? <CheckIcon width="1.6rem" fill="neutral0" /> : null}
{checked === 'indeterminate' ? <Minus fill="neutral0" /> : null}
<CheckboxRoot ref={composedRefs} checked={checked} disabled={disabled} onCheckedChange={setChecked} {...props}>
<CheckboxIndicator
style={{ display: 'inline-flex', pointerEvents: 'auto', cursor: disabled ? 'not-allowed' : undefined }}
forceMount
>
{checked === true ? <CheckIcon width="1.6rem" fill={disabled ? 'neutral500' : 'neutral0'} /> : null}
{checked === 'indeterminate' ? <Minus fill={disabled ? 'neutral500' : 'neutral0'} /> : null}
</CheckboxIndicator>
</CheckboxRoot>
);
Expand Down Expand Up @@ -82,6 +85,7 @@ const CheckboxRoot = styled(Checkbox.Root)`
}

&[data-disabled] {
border: 1px solid ${(props) => props.theme.colors.neutral400};
background-color: ${(props) => props.theme.colors.neutral200};
}

Expand Down