2020-06-09 12:54:37 +08:00
|
|
|
import { inject } from 'vue';
|
2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-06-09 12:54:37 +08:00
|
|
|
import { hasProp, getComponent } from '../_util/props-util';
|
2019-03-13 09:38:54 +08:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2020-03-07 19:45:13 +08:00
|
|
|
import DropDown from '../dropdown/dropdown';
|
2020-03-28 15:28:06 +08:00
|
|
|
import DownOutlined from '@ant-design/icons-vue/DownOutlined';
|
2018-01-15 10:52:16 +08:00
|
|
|
|
2018-03-19 10:47:23 +08:00
|
|
|
export default {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ABreadcrumbItem',
|
2018-03-19 10:47:23 +08:00
|
|
|
__ANT_BREADCRUMB_ITEM: true,
|
|
|
|
props: {
|
2019-03-13 09:38:54 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2018-03-19 10:47:23 +08:00
|
|
|
href: PropTypes.string,
|
2020-03-07 19:45:13 +08:00
|
|
|
separator: PropTypes.any.def('/'),
|
|
|
|
overlay: PropTypes.any,
|
2018-03-19 10:47:23 +08:00
|
|
|
},
|
2020-06-09 12:54:37 +08:00
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
configProvider: inject('configProvider', ConfigConsumerProps),
|
|
|
|
};
|
2019-03-13 09:38:54 +08:00
|
|
|
},
|
2020-03-07 19:45:13 +08:00
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* if overlay is have
|
|
|
|
* Wrap a DropDown
|
|
|
|
*/
|
|
|
|
renderBreadcrumbNode(breadcrumbItem, prefixCls) {
|
2020-06-09 12:54:37 +08:00
|
|
|
const overlay = getComponent(this, 'overlay');
|
2020-03-07 19:45:13 +08:00
|
|
|
if (overlay) {
|
|
|
|
return (
|
|
|
|
<DropDown overlay={overlay} placement="bottomCenter">
|
|
|
|
<span class={`${prefixCls}-overlay-link`}>
|
|
|
|
{breadcrumbItem}
|
2020-03-28 15:28:06 +08:00
|
|
|
<DownOutlined />
|
2020-03-07 19:45:13 +08:00
|
|
|
</span>
|
|
|
|
</DropDown>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return breadcrumbItem;
|
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2019-03-13 09:38:54 +08:00
|
|
|
const { prefixCls: customizePrefixCls, $slots } = this;
|
2019-09-11 22:35:25 +08:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-13 09:38:54 +08:00
|
|
|
const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls);
|
2020-06-09 12:54:37 +08:00
|
|
|
const separator = getComponent(this, 'separator');
|
|
|
|
const children = $slots.default && $slots.default();
|
2019-01-12 11:33:27 +08:00
|
|
|
let link;
|
2018-03-19 10:47:23 +08:00
|
|
|
if (hasProp(this, 'href')) {
|
2019-01-12 11:33:27 +08:00
|
|
|
link = <a class={`${prefixCls}-link`}>{children}</a>;
|
2018-03-19 10:47:23 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
link = <span class={`${prefixCls}-link`}>{children}</span>;
|
2018-03-19 10:47:23 +08:00
|
|
|
}
|
2020-03-07 19:45:13 +08:00
|
|
|
// wrap to dropDown
|
|
|
|
link = this.renderBreadcrumbNode(link, prefixCls);
|
2018-03-19 10:47:23 +08:00
|
|
|
if (children) {
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{link}
|
2020-03-07 19:45:13 +08:00
|
|
|
{separator && separator !== '' && (
|
|
|
|
<span class={`${prefixCls}-separator`}>{separator}</span>
|
|
|
|
)}
|
2018-03-19 10:47:23 +08:00
|
|
|
</span>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-03-19 10:47:23 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
return null;
|
2018-03-19 10:47:23 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|