"use client"; import clsx from "clsx"; import { motion } from "motion/react"; import { type ComponentProps, useId, useMemo } from "react"; import { type Key, ToggleButtonGroup, ToggleButton, } from "react-aria-components"; import styles from "./index.module.scss"; import buttonStyles from "../Button/index.module.scss"; type OwnProps = { selectedKey?: Key | undefined; onSelectionChange?: (newValue: Key) => void; items: ComponentProps[]; }; type Props = Omit< ComponentProps, keyof OwnProps | "selectionMode" | "selectedKeys" > & OwnProps; export const SingleToggleGroup = ({ selectedKey, onSelectionChange, className, items, ...props }: Props) => { const id = useId(); const handleSelectionChange = useMemo( () => onSelectionChange ? (set: Set) => { const { value } = set.values().next(); if (value !== undefined) { onSelectionChange(value); } } : undefined, [onSelectionChange], ); return ( {items.map(({ className: tabClassName, children, ...toggleButton }) => ( {(args) => ( <> {args.isSelected && ( )} {typeof children === "function" ? children(args) : children} )} ))} ); };