import * as RadixToggleGroup from "@radix-ui/react-toggle-group"; import type { ReactNode } from "react"; import { useState } from "react"; import classNames from "@calcom/ui/classNames"; import { Tooltip } from "../../tooltip/Tooltip"; interface ToggleGroupProps extends Omit { options: { value: string; label: string | ReactNode; disabled?: boolean; tooltip?: string; iconLeft?: ReactNode; dataTestId?: string; onClick?: VoidFunction; }[]; isFullWidth?: boolean; orientation?: "horizontal" | "vertical"; } const OptionalTooltipWrapper = ({ children, tooltipText, }: { children: ReactNode; tooltipText?: ReactNode; }) => { if (tooltipText) { return ( {children} ); } return <>{children}; }; export const ToggleGroup = ({ options, onValueChange, isFullWidth, orientation = "horizontal", customClassNames, defaultValue, ...props }: ToggleGroupProps & { customClassNames?: string }) => { const isControlled = props.value !== undefined; const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue ?? ""); return ( <> { if (!value) return; if (!isControlled) { setUncontrolledValue(value); } onValueChange?.(value); }} style={{ // @ts-expect-error --toggle-group-shadow is not a valid CSS property but can be a variable "--toggle-group-shadow": "0px 2px 3px 0px rgba(0, 0, 0, 0.03), 0px 2px 2px -1px rgba(0, 0, 0, 0.03)", }} className={classNames( `bg-muted rounded-[10px] p-0.5`, orientation === "horizontal" && "inline-flex gap-0.5 rtl:flex-row-reverse", orientation === "vertical" && "flex w-fit flex-col gap-0.5", props.className, isFullWidth && "w-full", customClassNames )}> {options.map((option) => (
{option.iconLeft && {option.iconLeft}} {option.label}
))}
); };