diff --git a/.changeset/itchy-berries-flash.md b/.changeset/itchy-berries-flash.md new file mode 100644 index 0000000000..a91f53cce0 --- /dev/null +++ b/.changeset/itchy-berries-flash.md @@ -0,0 +1,5 @@ +--- +"@marigold/components": patch +--- + +fix([DST-501]): Pass down appearance props and use context from CheckboxGroup to apply label width diff --git a/packages/components/src/Checkbox/Checkbox.tsx b/packages/components/src/Checkbox/Checkbox.tsx index 5b512150fc..92283c93b8 100644 --- a/packages/components/src/Checkbox/Checkbox.tsx +++ b/packages/components/src/Checkbox/Checkbox.tsx @@ -1,13 +1,13 @@ -import { forwardRef, useContext } from 'react'; +import { forwardRef } from 'react'; import { Checkbox } from 'react-aria-components'; import type RAC from 'react-aria-components'; -import { CheckboxGroupStateContext } from 'react-aria-components'; import { StateAttrProps, cn, useClassNames } from '@marigold/system'; import { HtmlProps } from '@marigold/types'; import { useFieldGroupContext } from '../FieldBase'; import { CheckboxField } from './CheckBoxField'; +import { useCheckboxGroupContext } from './Context'; // SVG Icon const CheckMark = () => ( @@ -19,6 +19,7 @@ const CheckMark = () => ( /> ); + const IndeterminateMark = () => ( { 'flex shrink-0 grow-0 basis-4 items-center justify-center', 'h-4 w-4 p-px', 'bg-white', - 'rounded-[3px] border border-solid border-black ', + 'rounded-[3px] border border-solid border-black', className )} {...props} @@ -114,9 +115,13 @@ const _Checkbox = forwardRef( } as const; const { labelWidth } = useFieldGroupContext(); - const classNames = useClassNames({ component: 'Checkbox', variant, size }); - - const state = useContext(CheckboxGroupStateContext); + const group = useCheckboxGroupContext(); + console.log(group); + const classNames = useClassNames({ + component: 'Checkbox', + variant: variant || group?.variant, + size: size || group?.size, + }); const component = ( ( ); - return !state && labelWidth ? ( + // Checkbox is not within a group and should indented based on the labelWidth + return !group && !!labelWidth ? ( {component} ) : ( component diff --git a/packages/components/src/Checkbox/CheckboxGroup.test.tsx b/packages/components/src/Checkbox/CheckboxGroup.test.tsx index 2940cca1c3..8d441cb074 100644 --- a/packages/components/src/Checkbox/CheckboxGroup.test.tsx +++ b/packages/components/src/Checkbox/CheckboxGroup.test.tsx @@ -14,7 +14,7 @@ const theme: Theme = { container: cva([], { variants: { size: { - small: 'py-1', + small: 'text-sm', }, }, }), @@ -251,9 +251,7 @@ test('works with a ', () => { test('horiziontal orientation style', () => { render( - - one - + one two three @@ -266,3 +264,19 @@ test('horiziontal orientation style', () => { expect(presentation[0].className).toContain('flex-row gap-[1.5ch]'); }); + +test('pass down variant and size to ', () => { + render( + + + one + + + ); + + const one = screen + .getAllByTestId('one') + .filter(el => el.classList.contains('group/checkbox'))[0]; + + expect(one).toHaveClass('text-sm'); +}); diff --git a/packages/components/src/Checkbox/Context.tsx b/packages/components/src/Checkbox/Context.tsx index 7390ce7e98..65b159edfc 100644 --- a/packages/components/src/Checkbox/Context.tsx +++ b/packages/components/src/Checkbox/Context.tsx @@ -8,7 +8,6 @@ export interface CheckboxGroupContextProps { width?: WidthProp['width']; } -export const CheckboxGroupContext = createContext( - null as any -); +export const CheckboxGroupContext = + createContext(null); export const useCheckboxGroupContext = () => useContext(CheckboxGroupContext);