2021-06-26 01:35:40 +00:00
|
|
|
import type { ExtractPropTypes } from 'vue';
|
|
|
|
import { defineComponent } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2021-06-08 13:54:26 +00:00
|
|
|
import { getPropsSlot } from '../_util/props-util';
|
2020-03-07 11:45:13 +00:00
|
|
|
import DropDown from '../dropdown/dropdown';
|
2020-03-28 07:28:06 +00:00
|
|
|
import DownOutlined from '@ant-design/icons-vue/DownOutlined';
|
2021-06-08 13:54:26 +00:00
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2018-01-15 02:52:16 +00:00
|
|
|
|
2021-06-08 13:54:26 +00:00
|
|
|
const breadcrumbItemProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
href: PropTypes.string,
|
|
|
|
separator: PropTypes.any,
|
|
|
|
overlay: PropTypes.any,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type BreadcrumbItemProps = Partial<ExtractPropTypes<typeof breadcrumbItemProps>>;
|
2020-10-13 10:04:02 +00:00
|
|
|
export default defineComponent({
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'ABreadcrumbItem',
|
2018-03-19 02:47:23 +00:00
|
|
|
__ANT_BREADCRUMB_ITEM: true,
|
2021-06-08 13:54:26 +00:00
|
|
|
props: breadcrumbItemProps,
|
|
|
|
slots: ['separator', 'overlay'],
|
|
|
|
setup(props, { slots }) {
|
|
|
|
const { prefixCls } = useConfigInject('breadcrumb', props);
|
2020-03-07 11:45:13 +00:00
|
|
|
/**
|
|
|
|
* if overlay is have
|
|
|
|
* Wrap a DropDown
|
|
|
|
*/
|
2021-06-08 13:54:26 +00:00
|
|
|
const renderBreadcrumbNode = (breadcrumbItem: JSX.Element, prefixCls: string) => {
|
|
|
|
const overlay = getPropsSlot(slots, props, 'overlay');
|
2020-03-07 11:45:13 +00:00
|
|
|
if (overlay) {
|
|
|
|
return (
|
|
|
|
<DropDown overlay={overlay} placement="bottomCenter">
|
|
|
|
<span class={`${prefixCls}-overlay-link`}>
|
|
|
|
{breadcrumbItem}
|
2020-03-28 07:28:06 +00:00
|
|
|
<DownOutlined />
|
2020-03-07 11:45:13 +00:00
|
|
|
</span>
|
|
|
|
</DropDown>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return breadcrumbItem;
|
2021-06-08 13:54:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
const separator = getPropsSlot(slots, props, 'separator') ?? '/';
|
|
|
|
const children = getPropsSlot(slots, props);
|
|
|
|
let link: JSX.Element;
|
|
|
|
|
|
|
|
if (props.href !== undefined) {
|
|
|
|
link = <a class={`${prefixCls.value}-link`}>{children}</a>;
|
|
|
|
} else {
|
|
|
|
link = <span class={`${prefixCls.value}-link`}>{children}</span>;
|
|
|
|
}
|
|
|
|
// wrap to dropDown
|
|
|
|
link = renderBreadcrumbNode(link, prefixCls.value);
|
|
|
|
if (children) {
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{link}
|
|
|
|
{separator && <span class={`${prefixCls.value}-separator`}>{separator}</span>}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
2018-03-19 02:47:23 +00:00
|
|
|
},
|
2020-10-13 10:04:02 +00:00
|
|
|
});
|