2022-03-26 14:52:54 +00:00
|
|
|
import type { ExtractPropTypes, PropType } from 'vue';
|
2021-06-26 01:35:40 +00:00
|
|
|
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';
|
2022-03-26 14:52:54 +00:00
|
|
|
import type { MouseEventHandler } from '../_util/EventInterface';
|
2018-01-15 02:52:16 +00:00
|
|
|
|
2022-03-26 14:52:54 +00:00
|
|
|
export const breadcrumbItemProps = () => ({
|
|
|
|
prefixCls: String,
|
|
|
|
href: String,
|
2021-06-08 13:54:26 +00:00
|
|
|
separator: PropTypes.any,
|
|
|
|
overlay: PropTypes.any,
|
2022-03-26 14:52:54 +00:00
|
|
|
onClick: Function as PropType<MouseEventHandler>,
|
|
|
|
});
|
2021-06-08 13:54:26 +00:00
|
|
|
|
2022-03-26 14:52:54 +00:00
|
|
|
export type BreadcrumbItemProps = Partial<ExtractPropTypes<ReturnType<typeof breadcrumbItemProps>>>;
|
2020-10-13 10:04:02 +00:00
|
|
|
export default defineComponent({
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'ABreadcrumbItem',
|
2022-03-26 14:52:54 +00:00
|
|
|
inheritAttrs: false,
|
2018-03-19 02:47:23 +00:00
|
|
|
__ANT_BREADCRUMB_ITEM: true,
|
2022-03-26 14:52:54 +00:00
|
|
|
props: breadcrumbItemProps(),
|
|
|
|
// emits: ['click'],
|
2021-06-08 13:54:26 +00:00
|
|
|
slots: ['separator', 'overlay'],
|
2022-03-26 14:52:54 +00:00
|
|
|
setup(props, { slots, attrs }) {
|
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
|
|
|
};
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
const separator = getPropsSlot(slots, props, 'separator') ?? '/';
|
|
|
|
const children = getPropsSlot(slots, props);
|
2022-03-26 14:52:54 +00:00
|
|
|
const { class: cls, style, ...restAttrs } = attrs;
|
2021-06-08 13:54:26 +00:00
|
|
|
let link: JSX.Element;
|
|
|
|
if (props.href !== undefined) {
|
2022-03-26 14:52:54 +00:00
|
|
|
link = (
|
|
|
|
<a class={`${prefixCls.value}-link`} onClick={props.onClick} {...restAttrs}>
|
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
);
|
2021-06-08 13:54:26 +00:00
|
|
|
} else {
|
2022-03-26 14:52:54 +00:00
|
|
|
link = (
|
|
|
|
<span class={`${prefixCls.value}-link`} onClick={props.onClick} {...restAttrs}>
|
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
);
|
2021-06-08 13:54:26 +00:00
|
|
|
}
|
|
|
|
// wrap to dropDown
|
|
|
|
link = renderBreadcrumbNode(link, prefixCls.value);
|
|
|
|
if (children) {
|
|
|
|
return (
|
2022-03-26 14:52:54 +00:00
|
|
|
<span class={cls} style={style}>
|
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
|
|
|
});
|