import { cloneElement, forwardRef, memo } from "react"; import { Link } from "../../link"; import { CrumbText, Crumb as StyledCrumb, StyledCrumbButton } from "../breadcrumbs.styled"; import type { CrumbProps } from "./crumb-props"; const BaseCrumbComponent = forwardRef< HTMLAnchorElement | HTMLButtonElement, Omit >( // eslint-disable-next-line max-lines-per-function ({ crumb, isLast, iconPosition, ellipsis = true, ...rest }, ref) => { if ("linkElement" in crumb) { return cloneElement( crumb.linkElement, { style: { ...crumb.linkElement.props.style, width: "100%", display: "block" }, ...rest, ref: ref as React.ForwardedRef, }, {crumb.Icon} {crumb.linkElement.props.children && ( {crumb.linkElement.props.children} )} ); } if ("href" in crumb) { return ( } {...crumb.linkProps} href={crumb.href} css={{ width: "100%" }} {...rest} data-crumb-item-type={crumb.Icon ? "icon" : "text"} > {crumb.Icon} {crumb.label && ( {crumb.label} )} ); } if ("onClick" in crumb) { return ( } {...crumb.buttonProps} {...rest} onClick={crumb.onClick} data-crumb-item-type={crumb.Icon ? "icon" : "text"} > {crumb.Icon} {crumb.label && ( {crumb.label} )} ); } return ( {crumb.Icon} {crumb.label} ); } ); BaseCrumbComponent.displayName = "BaseCrumb"; export const BaseCrumb = memo(BaseCrumbComponent);