import { useContext, createContext } from 'react'; import type { ReactElement, ComponentType, SVGAttributes } from 'react'; import styles from './ToggleGroup.module.css'; interface ToggleGroupProps { role: 'tablist' | 'radiogroup'; value: string; disabled?: boolean; onChange: (val: string) => void; } const ToggleGroupContext = createContext( undefined ); function useToggleGroupProps(): ToggleGroupProps { const context = useContext(ToggleGroupContext); if (!context) { throw new Error('Missing Toggle Group provider.'); } return context; } interface BtnProps { label: string; value: string; icon?: ComponentType>; iconOnly?: boolean; disabled?: boolean; } function Btn(props: BtnProps) { const { label, value, icon: Icon, iconOnly, disabled = false } = props; const { role, value: selectedValue, disabled: isGroupDisabled, onChange, } = useToggleGroupProps(); return ( ); } interface Props extends ToggleGroupProps { ariaLabel?: string; children: ReactElement[]; id?: string; } function ToggleGroup(props: Props) { const { role, ariaLabel, value, disabled, onChange, children, id } = props; return (
{children}
); } ToggleGroup.Btn = Btn; export default ToggleGroup;