From d97b167746d99cc4e50f409308bf52651f53854c Mon Sep 17 00:00:00 2001 From: shan8851 Date: Fri, 11 Oct 2024 13:43:04 +0100 Subject: [PATCH 1/9] feat: Implement new children property to radio and checkbox cards as well as make description optional for radio --- .../checkboxCard/checkboxCard.stories.tsx | 14 +++ .../forms/checkboxCard/checkboxCard.tsx | 85 ++++++++++++------- .../checkboxGroup/checkboxGroup.stories.tsx | 35 ++++++++ .../forms/radioCard/radioCard.stories.tsx | 36 ++++++++ .../components/forms/radioCard/radioCard.tsx | 29 +++++-- .../forms/radioGroup/radioGroup.stories.tsx | 38 +++++++++ 6 files changed, 198 insertions(+), 39 deletions(-) diff --git a/src/core/components/forms/checkboxCard/checkboxCard.stories.tsx b/src/core/components/forms/checkboxCard/checkboxCard.stories.tsx index 9562e7410..0c380aeef 100644 --- a/src/core/components/forms/checkboxCard/checkboxCard.stories.tsx +++ b/src/core/components/forms/checkboxCard/checkboxCard.stories.tsx @@ -30,6 +30,20 @@ export const Default: Story = { }, }; +/** + * Usage of the CheckboxCard component with children when checked + */ +export const WithChildrenWhenChecked: Story = { + render: (props) => , + args: { + avatar: 'https://assets-global.website-files.com/5e997428d0f2eb13a90aec8c/63f47db62df04b569e4e004e_icon_aragon.svg', + label: 'Checkbox label', + description: 'Checkbox description', + tag: { label: 'Tag', variant: 'info' }, + children:
Children
, + }, +}; + /** * CheckboxCard in indeterminate state */ diff --git a/src/core/components/forms/checkboxCard/checkboxCard.tsx b/src/core/components/forms/checkboxCard/checkboxCard.tsx index e42d09bf3..d4366b678 100644 --- a/src/core/components/forms/checkboxCard/checkboxCard.tsx +++ b/src/core/components/forms/checkboxCard/checkboxCard.tsx @@ -1,6 +1,6 @@ import * as RadixCheckbox from '@radix-ui/react-checkbox'; import classNames from 'classnames'; -import { forwardRef, type ComponentProps } from 'react'; +import { forwardRef, type ReactNode, type ComponentProps } from 'react'; import { useRandomId } from '../../../hooks'; import { Avatar } from '../../avatars'; import { Icon, IconType } from '../../icon'; @@ -40,10 +40,26 @@ export interface ICheckboxCardProps extends ComponentProps<'button'> { * Id of the checkbox. */ id?: string; + /** + * Additional children to render when the checkbox is checked. + */ + children?: ReactNode; } export const CheckboxCard = forwardRef((props, ref) => { - const { id, avatar, label, description, tag, className, checked, onCheckedChange, disabled, ...otherProps } = props; + const { + id, + avatar, + label, + description, + tag, + className, + checked, + onCheckedChange, + disabled, + children, + ...otherProps + } = props; const randomId = useRandomId(id); const labelId = `${randomId}-label`; @@ -57,7 +73,7 @@ export const CheckboxCard = forwardRef((p onCheckedChange={onCheckedChange} disabled={disabled} className={classNames( - 'group flex h-16 min-w-0 flex-row items-center gap-3 outline-none transition-all md:h-20', // Layout + 'group flex min-w-0 flex-col gap-3 outline-none transition-all', // Layout 'rounded-xl border bg-neutral-0 px-4 py-3 md:gap-4 md:px-6 md:py-4', // Style 'focus:outline-none focus-visible:ring focus-visible:ring-primary focus-visible:ring-offset', // Focus 'border-primary-400 shadow-primary hover:shadow-primary-md', // Checked/indeterminate & hover @@ -69,37 +85,44 @@ export const CheckboxCard = forwardRef((p )} {...otherProps} > - {avatar && } -
-

- {label} -

-

- {description} -

-
- {tag && } -