2023-01-26 08:52:06 +00:00
|
|
|
import type { CSSProperties, ExtractPropTypes } 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';
|
2023-01-26 08:52:06 +00:00
|
|
|
import type { DropdownProps } from '../dropdown/dropdown';
|
2022-05-10 07:48:14 +00:00
|
|
|
import Dropdown from '../dropdown/dropdown';
|
2020-03-28 07:28:06 +00:00
|
|
|
import DownOutlined from '@ant-design/icons-vue/DownOutlined';
|
2023-01-27 08:00:17 +00:00
|
|
|
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
2022-03-26 14:52:54 +00:00
|
|
|
import type { MouseEventHandler } from '../_util/EventInterface';
|
2023-01-26 08:52:06 +00:00
|
|
|
import { eventType, objectType } from '../_util/type';
|
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,
|
2023-01-26 08:52:06 +00:00
|
|
|
dropdownProps: objectType<DropdownProps>(),
|
2021-06-08 13:54:26 +00:00
|
|
|
overlay: PropTypes.any,
|
2023-01-26 08:52:06 +00:00
|
|
|
onClick: eventType<MouseEventHandler>(),
|
2022-03-26 14:52:54 +00:00
|
|
|
});
|
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({
|
2022-09-26 13:33:41 +00:00
|
|
|
compatConfig: { MODE: 3 },
|
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'],
|
2023-01-26 08:52:06 +00:00
|
|
|
setup(props, { slots, attrs, 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
|
2022-05-10 07:48:14 +00:00
|
|
|
* Wrap a Dropdown
|
2020-03-07 11:45:13 +00:00
|
|
|
*/
|
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 (
|
2023-01-26 08:52:06 +00:00
|
|
|
<Dropdown {...props.dropdownProps} 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>
|
2022-05-10 07:48:14 +00:00
|
|
|
</Dropdown>
|
2020-03-07 11:45:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return breadcrumbItem;
|
2021-06-08 13:54:26 +00:00
|
|
|
};
|
2023-01-26 08:52:06 +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);
|
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 = (
|
2023-01-26 08:52:06 +00:00
|
|
|
<a class={`${prefixCls.value}-link`} onClick={handleClick} {...restAttrs}>
|
2022-03-26 14:52:54 +00:00
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
);
|
2021-06-08 13:54:26 +00:00
|
|
|
} else {
|
2022-03-26 14:52:54 +00:00
|
|
|
link = (
|
2023-01-26 08:52:06 +00:00
|
|
|
<span class={`${prefixCls.value}-link`} onClick={handleClick} {...restAttrs}>
|
2022-03-26 14:52:54 +00:00
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
);
|
2021-06-08 13:54:26 +00:00
|
|
|
}
|
|
|
|
// wrap to dropDown
|
|
|
|
link = renderBreadcrumbNode(link, prefixCls.value);
|
2023-01-26 08:52:06 +00:00
|
|
|
if (children !== undefined && children !== null) {
|
2021-06-08 13:54:26 +00:00
|
|
|
return (
|
2022-05-21 07:14:29 +00:00
|
|
|
<li class={cls} style={style as CSSProperties}>
|
2021-06-08 13:54:26 +00:00
|
|
|
{link}
|
|
|
|
{separator && <span class={`${prefixCls.value}-separator`}>{separator}</span>}
|
2022-05-10 07:48:14 +00:00
|
|
|
</li>
|
2021-06-08 13:54:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
2018-03-19 02:47:23 +00:00
|
|
|
},
|
2020-10-13 10:04:02 +00:00
|
|
|
});
|