|
| 1 | +import { |
| 2 | + Box, |
| 3 | + CheckboxGroup as PrimerCheckboxGroup, |
| 4 | + type CheckboxGroupProps as PrimerCheckboxGroupProps, |
| 5 | +} from '@primer/react' |
| 6 | +import React, {type PropsWithChildren} from 'react' |
| 7 | +import type {SxProp} from '../sx' |
| 8 | + |
| 9 | +export type CheckboxGroupProps = PropsWithChildren<PrimerCheckboxGroupProps> & SxProp |
| 10 | + |
| 11 | +const CheckboxGroupImpl = (props: CheckboxGroupProps) => { |
| 12 | + return <Box as={PrimerCheckboxGroup} {...props} /> |
| 13 | +} |
| 14 | + |
| 15 | +// Define local types based on the internal component props |
| 16 | +type CheckboxOrRadioGroupLabelProps = PropsWithChildren< |
| 17 | + { |
| 18 | + className?: string |
| 19 | + visuallyHidden?: boolean |
| 20 | + } & SxProp |
| 21 | +> |
| 22 | +const CheckboxOrRadioGroupLabel = (props: CheckboxOrRadioGroupLabelProps) => { |
| 23 | + return <Box as={PrimerCheckboxGroup.Label} {...props} /> |
| 24 | +} |
| 25 | + |
| 26 | +type CheckboxOrRadioGroupCaptionProps = PropsWithChildren< |
| 27 | + { |
| 28 | + className?: string |
| 29 | + } & SxProp |
| 30 | +> |
| 31 | +const CheckboxOrRadioGroupCaption = (props: CheckboxOrRadioGroupCaptionProps) => { |
| 32 | + return <Box as={PrimerCheckboxGroup.Caption} {...props} /> |
| 33 | +} |
| 34 | + |
| 35 | +type CheckboxOrRadioGroupValidationProps = PropsWithChildren< |
| 36 | + { |
| 37 | + className?: string |
| 38 | + variant: 'error' | 'success' |
| 39 | + } & SxProp |
| 40 | +> |
| 41 | +const CheckboxOrRadioGroupValidation = (props: CheckboxOrRadioGroupValidationProps) => { |
| 42 | + return <Box as={PrimerCheckboxGroup.Validation} {...props} /> |
| 43 | +} |
| 44 | + |
| 45 | +export const CheckboxGroup = Object.assign(CheckboxGroupImpl, { |
| 46 | + Label: CheckboxOrRadioGroupLabel, |
| 47 | + Caption: CheckboxOrRadioGroupCaption, |
| 48 | + Validation: CheckboxOrRadioGroupValidation, |
| 49 | +}) |
0 commit comments