Skip to content

Commit

Permalink
feat(platform): add skipRenderLink to breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Feb 17, 2023
1 parent 01236aa commit 7506017
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type { DBreadcrumbItem } from '@react-devui/ui/components/breadcrumb';

import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';

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

type BreadcrumbItem = DBreadcrumbItem<string> & { skipRenderLink?: boolean };

export interface AppRouteHeaderBreadcrumbProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
aList: DBreadcrumbItem<string>[];
aHome?: DBreadcrumbItem<string>;
aList: BreadcrumbItem[];
aHome?: BreadcrumbItem;
aSeparator?: React.ReactNode;
}

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

const { t } = useTranslation();

const home: DBreadcrumbItem<string> = aHome ?? {
const home: BreadcrumbItem = aHome ?? {
id: '/',
title: t('Home', { ns: 'title' }),
link: true,
Expand All @@ -34,13 +37,18 @@ export function AppRouteHeaderBreadcrumb(props: AppRouteHeaderBreadcrumbProps):
<DBreadcrumb
dList={[home].concat(aList).map((item) => ({
...item,
title: item.link ? (
<Link className="app-route-header__breadcrumb-link" to={item.id}>
{item.title}
</Link>
) : (
item.title
),
title:
item.link && !item.skipRenderLink ? (
<Link className="app-route-header__breadcrumb-link" to={item.id}>
{item.title}
</Link>
) : React.isValidElement(item.title) ? (
React.cloneElement<React.HTMLAttributes<HTMLElement>>(item.title as any, {
className: getClassName(item.title.props.className, 'app-route-header__breadcrumb-item'),
})
) : (
<div className="app-route-header__breadcrumb-item">{item.title}</div>
),
}))}
dSeparator={aSeparator}
/>
Expand Down
5 changes: 5 additions & 0 deletions packages/platform/src/styles/components/route-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
}

@include e(breadcrumb-link) {
padding: 0 6px;
font: inherit;
color: inherit;
text-decoration: none;
}

@include e(breadcrumb-item) {
padding: 0 6px;
}

@include e(header) {
display: flex;
flex-wrap: wrap;
Expand Down

0 comments on commit 7506017

Please sign in to comment.