import * as React from 'react'; import { css } from '@breakaway/react-styles'; import styles from '@breakaway/react-styles/css/components/ToggleGroup/toggle-group'; import { ToggleGroupItem } from './ToggleGroupItem'; export interface ToggleGroupProps extends React.HTMLProps { /** Content rendered inside the toggle group */ children?: React.ReactNode; /** Additional classes added to the toggle group */ className?: string; /** Modifies the toggle group to include compact styling. */ isCompact?: boolean; /** Disable all toggle group items under this component. */ areAllGroupsDisabled?: boolean; /** Accessible label for the toggle group */ 'aria-label'?: string; } export const ToggleGroup: React.FunctionComponent = ({ className, children, isCompact = false, areAllGroupsDisabled = false, 'aria-label': ariaLabel, ...props }: ToggleGroupProps) => { const toggleGroupItemList = React.Children.map(children, child => { const childCompName = (child as any).type.name; return childCompName !== ToggleGroupItem.name ? child : React.cloneElement(child as React.ReactElement, areAllGroupsDisabled ? { isDisabled: true } : {}); }); return (
{toggleGroupItemList}
); }; ToggleGroup.displayName = 'ToggleGroup';