import { cloneElement, isValidElement, type PropsWithChildren, type ReactElement, } from "react"; import type { HTMLProps } from "../../shared/types"; import { cn } from "../../shared/utils/cn"; import { Typography } from "../typography/Typography"; import { invariant } from "../../shared/utils/invariant"; import { interactiveChipStyles, type InteractiveChipType } from "./utils"; export type InteractiveChipProps = Omit< HTMLProps<"div">, "label" | "aria-disabled" | "tabIndex" > & { start?: ReactElement>; onStartClick?: React.MouseEventHandler; end?: ReactElement>; onEndClick?: React.MouseEventHandler; type?: InteractiveChipType; disabled?: boolean; }; export const InteractiveChip = ({ className, start, end, type = "elevated", children, disabled = false, onStartClick, onEndClick, ...props }: PropsWithChildren) => { invariant(typeof children === "string", "Children must be string"); const iconCss = cn("w-4 h-4 text-inherit"); const buttonCss = cn(disabled ? "cursor-not-allowed" : "cursor-pointer"); const interactiveChipClassName = interactiveChipStyles[type]; return (
{start && isValidElement(start) ? ( ) : null} {children} {end && isValidElement(end) ? ( ) : null}
); };