import * as React from 'react'; import * as PropTypes from 'prop-types'; import DropDown, { DropDownProps } from '../dropdown/dropdown'; import Icon from '../icon'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; export interface BreadcrumbItemProps { prefixCls?: string; separator?: React.ReactNode; href?: string; overlay?: DropDownProps['overlay']; onClick?: React.MouseEventHandler; } export default class BreadcrumbItem extends React.Component { static __ANT_BREADCRUMB_ITEM = true; static defaultProps = { separator: '/', }; static propTypes = { prefixCls: PropTypes.string, separator: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), href: PropTypes.string, }; renderBreadcrumbItem = ({ getPrefixCls }: ConfigConsumerProps) => { const { prefixCls: customizePrefixCls, separator, children, overlay, ...restProps } = this.props; const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls); let link; if ('href' in this.props) { link = ( {children} ); } else { link = ( {children} ); } // wrap to dropDown link = this.renderBreadcrumbNode(link, prefixCls); if (children) { return ( {link} {separator} ); } return null; }; /** * if overlay is have * Wrap a DropDown */ renderBreadcrumbNode = (breadcrumbItem: React.ReactNode, prefixCls: string) => { const { overlay } = this.props; if (overlay) { return ( {breadcrumbItem} ); } return breadcrumbItem; }; render() { return {this.renderBreadcrumbItem}; } }