2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2018-08-07 21:07:52 +08:00
|
|
|
import * as PropTypes from 'prop-types';
|
2018-12-05 19:12:18 +08:00
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class BreadcrumbItem extends React.Component<BreadcrumbItemProps, any> {
|
2017-01-27 17:08:05 +08:00
|
|
|
static __ANT_BREADCRUMB_ITEM = true;
|
|
|
|
|
2016-03-31 17:46:35 +08:00
|
|
|
static defaultProps = {
|
|
|
|
separator: '/',
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-31 17:46:35 +08:00
|
|
|
|
|
|
|
static propTypes = {
|
2016-12-19 15:19:15 +08:00
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
separator: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.element,
|
2016-03-31 17:46:35 +08:00
|
|
|
]),
|
2016-12-19 15:19:15 +08:00
|
|
|
href: PropTypes.string,
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-31 17:46:35 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
renderBreadcrumbItem = ({ getPrefixCls }: ConfigConsumerProps) => {
|
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
separator, children, ...restProps
|
|
|
|
} = this.props;
|
|
|
|
const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls);
|
2016-03-31 17:46:35 +08:00
|
|
|
let link;
|
|
|
|
if ('href' in this.props) {
|
|
|
|
link = <a className={`${prefixCls}-link`} {...restProps}>{children}</a>;
|
|
|
|
} else {
|
|
|
|
link = <span className={`${prefixCls}-link`} {...restProps}>{children}</span>;
|
|
|
|
}
|
2017-03-29 15:13:20 +08:00
|
|
|
if (children) {
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{link}
|
|
|
|
<span className={`${prefixCls}-separator`}>{separator}</span>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
2016-03-31 17:46:35 +08:00
|
|
|
}
|
2018-12-05 19:12:18 +08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ConfigConsumer>
|
|
|
|
{this.renderBreadcrumbItem}
|
|
|
|
</ConfigConsumer>
|
|
|
|
);
|
|
|
|
}
|
2016-03-31 17:46:35 +08:00
|
|
|
}
|