import * as React from "react"; import { cn } from "tailwind-variants"; export interface SlotProps extends React.HTMLAttributes { children: React.ReactNode; } export const Slot = React.forwardRef( ( { children, onClick: externalOnClick, style: styleProp, className: classNameProp, ...props }, ref, ) => { if (!React.isValidElement(children)) return null; const child = children as React.ReactElement>; const mergedClassName = cn(child.props.className as string, classNameProp); const mergedStyle = { ...(child.props.style ?? {}), ...(styleProp ?? {}), } as React.CSSProperties; const childOnClick = child.props.onClick as | ((e: React.MouseEvent) => void) | undefined; const mergedOnClick = (e: React.MouseEvent) => { childOnClick?.(e); externalOnClick?.(e); }; return React.cloneElement(child, { ...child.props, ...props, ref, style: mergedStyle, className: mergedClassName, onClick: mergedOnClick, }); }, ); Slot.displayName = "Slot";