2020-03-02 12:09:38 +08:00
|
|
|
import DownOutlined from '@ant-design/icons/DownOutlined';
|
2022-06-22 14:57:09 +08:00
|
|
|
import * as React from 'react';
|
2022-10-23 00:33:45 +08:00
|
|
|
import warning from '../_util/warning';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { DropdownProps } from '../dropdown/dropdown';
|
|
|
|
import Dropdown from '../dropdown/dropdown';
|
2016-03-31 17:46:35 +08:00
|
|
|
|
2016-09-13 15:31:29 +08:00
|
|
|
export interface BreadcrumbItemProps {
|
2016-12-19 15:19:15 +08:00
|
|
|
prefixCls?: string;
|
2016-07-14 13:29:50 +08:00
|
|
|
separator?: React.ReactNode;
|
|
|
|
href?: string;
|
2022-10-23 00:33:45 +08:00
|
|
|
menu?: DropdownProps['menu'];
|
2022-04-21 22:09:59 +08:00
|
|
|
dropdownProps?: DropdownProps;
|
2019-03-11 23:48:37 +08:00
|
|
|
onClick?: React.MouseEventHandler<HTMLAnchorElement | HTMLSpanElement>;
|
2020-12-04 09:37:04 +08:00
|
|
|
className?: string;
|
2022-04-08 22:55:42 +08:00
|
|
|
children?: React.ReactNode;
|
2022-10-23 00:33:45 +08:00
|
|
|
|
|
|
|
// Deprecated
|
|
|
|
/** @deprecated Please use `menu` instead */
|
|
|
|
overlay?: DropdownProps['overlay'];
|
2016-07-14 13:29:50 +08:00
|
|
|
}
|
2022-12-01 14:33:51 +08:00
|
|
|
type CompoundedComponent = React.FC<BreadcrumbItemProps> & {
|
2020-05-28 15:22:00 +08:00
|
|
|
__ANT_BREADCRUMB_ITEM: boolean;
|
2022-12-01 14:33:51 +08:00
|
|
|
};
|
|
|
|
const BreadcrumbItem: CompoundedComponent = (props) => {
|
2022-10-23 00:33:45 +08:00
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
separator = '/',
|
|
|
|
children,
|
|
|
|
menu,
|
|
|
|
overlay,
|
|
|
|
dropdownProps,
|
|
|
|
...restProps
|
|
|
|
} = props;
|
|
|
|
|
2020-05-28 15:22:00 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls);
|
2022-10-23 00:33:45 +08:00
|
|
|
|
|
|
|
// Warning for deprecated usage
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
warning(
|
|
|
|
!('overlay' in props),
|
|
|
|
'Breadcrumb.Item',
|
|
|
|
'`overlay` is deprecated. Please use `menu` instead.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-21 22:09:59 +08:00
|
|
|
/** If overlay is have Wrap a Dropdown */
|
2020-05-28 15:22:00 +08:00
|
|
|
const renderBreadcrumbNode = (breadcrumbItem: React.ReactNode) => {
|
2022-10-23 00:33:45 +08:00
|
|
|
if (menu || overlay) {
|
2023-01-18 15:39:00 +08:00
|
|
|
const mergeDropDownProps: DropdownProps = {
|
|
|
|
...dropdownProps,
|
|
|
|
};
|
|
|
|
if ('overlay' in props) {
|
|
|
|
mergeDropDownProps.overlay = overlay;
|
|
|
|
}
|
2019-05-06 12:04:39 +08:00
|
|
|
return (
|
2023-01-18 15:39:00 +08:00
|
|
|
<Dropdown menu={menu} placement="bottom" {...mergeDropDownProps}>
|
2019-06-03 16:13:15 +08:00
|
|
|
<span className={`${prefixCls}-overlay-link`}>
|
2019-05-06 12:04:39 +08:00
|
|
|
{breadcrumbItem}
|
2019-11-28 12:34:33 +08:00
|
|
|
<DownOutlined />
|
2019-06-03 16:13:15 +08:00
|
|
|
</span>
|
2022-04-21 22:09:59 +08:00
|
|
|
</Dropdown>
|
2019-05-06 12:04:39 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return breadcrumbItem;
|
|
|
|
};
|
2019-08-05 18:38:10 +08:00
|
|
|
|
2022-10-14 11:37:48 +08:00
|
|
|
let link: React.ReactNode;
|
2020-05-28 15:22:00 +08:00
|
|
|
if ('href' in restProps) {
|
|
|
|
link = (
|
|
|
|
<a className={`${prefixCls}-link`} {...restProps}>
|
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
link = (
|
|
|
|
<span className={`${prefixCls}-link`} {...restProps}>
|
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
);
|
2018-12-05 19:12:18 +08:00
|
|
|
}
|
2020-05-28 15:22:00 +08:00
|
|
|
|
|
|
|
// wrap to dropDown
|
|
|
|
link = renderBreadcrumbNode(link);
|
2022-10-14 11:37:48 +08:00
|
|
|
if (children !== undefined && children !== null) {
|
2020-05-28 15:22:00 +08:00
|
|
|
return (
|
2022-03-10 11:46:42 +08:00
|
|
|
<li>
|
2020-05-28 15:22:00 +08:00
|
|
|
{link}
|
2022-01-13 13:34:34 +08:00
|
|
|
{separator && <span className={`${prefixCls}-separator`}>{separator}</span>}
|
2022-03-10 11:46:42 +08:00
|
|
|
</li>
|
2020-05-28 15:22:00 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
BreadcrumbItem.__ANT_BREADCRUMB_ITEM = true;
|
|
|
|
|
|
|
|
export default BreadcrumbItem;
|