import * as RadixToggleGroup from "@radix-ui/react-toggle-group"; import type { ReactNode } from "react"; import { useEffect, useState } from "react"; import { classNames } from "@calcom/lib"; import { Tooltip } from "@calcom/ui"; interface ToggleGroupProps extends Omit { options: { value: string; label: string | ReactNode; disabled?: boolean; tooltip?: string }[]; isFullWidth?: boolean; } const OptionalTooltipWrapper = ({ children, tooltipText, }: { children: ReactNode; tooltipText?: ReactNode; }) => { if (tooltipText) { return ( {children} ); } return <>{children}; }; export const ToggleGroup = ({ options, onValueChange, isFullWidth, ...props }: ToggleGroupProps) => { const [value, setValue] = useState(props.defaultValue); const [activeToggleElement, setActiveToggleElement] = useState(null); useEffect(() => { if (value && onValueChange) onValueChange(value); }, [value, onValueChange]); return ( <> {/* Active toggle. It's a separate element so we can animate it nicely. */} {options.map((option) => ( { if (node && value === option.value && activeToggleElement !== node) { setActiveToggleElement(node); } return node; }}> {option.label} ))} ); };