Skip to content

Commit 7506017

Browse files
committed
feat(platform): add skipRenderLink to breadcrumb
1 parent 01236aa commit 7506017

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

packages/platform/src/app/components/route-header/RouteHeaderBreadcrumb.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import type { DBreadcrumbItem } from '@react-devui/ui/components/breadcrumb';
22

3+
import React from 'react';
34
import { useTranslation } from 'react-i18next';
45
import { Link } from 'react-router-dom';
56

67
import { DBreadcrumb } from '@react-devui/ui';
78
import { getClassName } from '@react-devui/utils';
89

10+
type BreadcrumbItem = DBreadcrumbItem<string> & { skipRenderLink?: boolean };
11+
912
export interface AppRouteHeaderBreadcrumbProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
10-
aList: DBreadcrumbItem<string>[];
11-
aHome?: DBreadcrumbItem<string>;
13+
aList: BreadcrumbItem[];
14+
aHome?: BreadcrumbItem;
1215
aSeparator?: React.ReactNode;
1316
}
1417

@@ -23,7 +26,7 @@ export function AppRouteHeaderBreadcrumb(props: AppRouteHeaderBreadcrumbProps):
2326

2427
const { t } = useTranslation();
2528

26-
const home: DBreadcrumbItem<string> = aHome ?? {
29+
const home: BreadcrumbItem = aHome ?? {
2730
id: '/',
2831
title: t('Home', { ns: 'title' }),
2932
link: true,
@@ -34,13 +37,18 @@ export function AppRouteHeaderBreadcrumb(props: AppRouteHeaderBreadcrumbProps):
3437
<DBreadcrumb
3538
dList={[home].concat(aList).map((item) => ({
3639
...item,
37-
title: item.link ? (
38-
<Link className="app-route-header__breadcrumb-link" to={item.id}>
39-
{item.title}
40-
</Link>
41-
) : (
42-
item.title
43-
),
40+
title:
41+
item.link && !item.skipRenderLink ? (
42+
<Link className="app-route-header__breadcrumb-link" to={item.id}>
43+
{item.title}
44+
</Link>
45+
) : React.isValidElement(item.title) ? (
46+
React.cloneElement<React.HTMLAttributes<HTMLElement>>(item.title as any, {
47+
className: getClassName(item.title.props.className, 'app-route-header__breadcrumb-item'),
48+
})
49+
) : (
50+
<div className="app-route-header__breadcrumb-item">{item.title}</div>
51+
),
4452
}))}
4553
dSeparator={aSeparator}
4654
/>

packages/platform/src/styles/components/route-header.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
}
1111

1212
@include e(breadcrumb-link) {
13+
padding: 0 6px;
1314
font: inherit;
1415
color: inherit;
1516
text-decoration: none;
1617
}
1718

19+
@include e(breadcrumb-item) {
20+
padding: 0 6px;
21+
}
22+
1823
@include e(header) {
1924
display: flex;
2025
flex-wrap: wrap;

0 commit comments

Comments
 (0)