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
|
|
|
|
2022-03-18 01:30:37 +00:00
|
|
|
export const breadcrumbItemProps = {
|
2021-06-08 13:54:26 +00:00
|
|
|
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,
|
2021-11-02 08:38:17 +00:00
|
|
|
emits: ['click'],
|
2021-06-08 13:54:26 +00:00
|
|
|
slots: ['separator', 'overlay'],
|
2021-11-05 01:51:44 +00:00
|
|
|
setup(props, { slots, emit }) {
|
2021-06-08 13:54:26 +00:00
|
|
|
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 (
|
2022-03-12 01:56:32 +00:00
|
|
|
<DropDown overlay={overlay} placement="bottom">
|
2020-03-07 11:45:13 +00:00
|
|
|
<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
|
|
|
};
|
|
|
|
|
2021-11-05 01:51:44 +00:00
|
|
|
const handleClick = (e: MouseEvent) => {
|
|
|
|
emit('click', e);
|
|
|
|
};
|
|
|
|
|
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 (
|
2021-11-05 01:51:44 +00:00
|
|
|
<span onClick={handleClick}>
|
2021-06-08 13:54:26 +00:00
|
|
|
{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
|
|
|
});
|