import { cloneElement } from "react"; import { Link } from "react-router-dom"; import { BiCheck } from "react-icons/bi"; import { VuiFlexContainer } from "../flex/FlexContainer"; import { VuiFlexItem } from "../flex/FlexItem"; import { VuiIcon } from "../icon/Icon"; import { OptionListItem } from "./types"; import classNames from "classnames"; export const colorIcon = (icon: OptionListItem["icon"], color: OptionListItem["color"]) => { return icon ? cloneElement(icon, { color, size: "s" }) : null; }; type Props = OptionListItem & { isSelectable?: boolean; isSelected?: boolean; }; // https://github.com/typescript-eslint/typescript-eslint/issues/4062 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint export const VuiOptionsListItem = ({ value, label, icon, color = "neutral", href, target, onClick, isSelectable, isSelected, testId, ...rest }: Props) => { const labelContent = icon ? ( {colorIcon(icon, color)} {label} ) : ( label ); const content = ( {isSelectable && ( )} {labelContent} ); const classes = classNames("vuiOptionsListItem", `vuiOptionsListItem--${color}`); if (href) { return ( onClick?.(value)} data-testid={testId} {...rest} > {content} ); } return ( ); };