import React from 'react'; import { css } from '@leafygreen-ui/emotion'; import { spacing } from '@leafygreen-ui/tokens'; import { useId } from '@react-aria/utils'; import { Link, Checkbox, Label } from './leafygreen'; import FormFieldContainer from './form-field-container'; const infoLinkStyles = css({ marginLeft: spacing[1], }); const fieldsetStyles = css({ paddingLeft: spacing[4], }); export type CollapsibleFieldSetProps = { ['data-testid']?: string; children?: React.ReactElement; label: string; description?: React.ReactElement | string; disabled?: boolean; helpUrl?: string; onToggle: (checked: boolean) => void; toggled?: boolean; }; export const CollapsibleFieldSet = ({ description, disabled, helpUrl, label, onToggle, toggled, children, ...props }: React.PropsWithChildren): React.ReactElement => { const checkboxId = useId(); return ( { onToggle(event.target.checked); }} disabled={disabled} label={ } description={ !description ? '' : (( <> {description} {!!helpUrl && ( Learn More )} ) as any) // LG Checkbox expects a string description, but we use Description component to include helpUrl. } checked={toggled} id={checkboxId} /> {toggled &&
{children}
}
); };