-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
656 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 25 additions & 36 deletions
61
packages/platform/src/app/components/route-header/RouteHeaderBreadcrumb.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,49 @@ | ||
import type { DBreadcrumbItem } from '@react-devui/ui/components/breadcrumb'; | ||
|
||
import { isUndefined } from 'lodash'; | ||
import { useContext } 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'; | ||
|
||
import { RouteStateContext } from '../../Routes'; | ||
|
||
export interface AppRouteHeaderBreadcrumbProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> { | ||
aList: DBreadcrumbItem<string>[]; | ||
aHome?: DBreadcrumbItem<string>; | ||
aSeparator?: React.ReactNode; | ||
} | ||
|
||
export function AppRouteHeaderBreadcrumb(props: AppRouteHeaderBreadcrumbProps): JSX.Element | null { | ||
const { | ||
aList, | ||
aHome, | ||
aSeparator, | ||
|
||
...restProps | ||
} = props; | ||
|
||
const { matchRoutes } = useContext(RouteStateContext); | ||
|
||
const breadcrumb = (() => { | ||
if (matchRoutes) { | ||
const list: DBreadcrumbItem<string>[] = []; | ||
for (const match of matchRoutes) { | ||
if (match.route.data) { | ||
const { title: _title, breadcrumb = {} } = match.route.data; | ||
if (breadcrumb) { | ||
const title = breadcrumb.title ?? _title; | ||
if (!isUndefined(title)) { | ||
const link = breadcrumb.link ?? false; | ||
list.push({ | ||
id: title, | ||
title: link ? ( | ||
<Link className="app-route-header__breadcrumb-link" to={match.pathname}> | ||
{title} | ||
</Link> | ||
) : ( | ||
title | ||
), | ||
link, | ||
separator: breadcrumb.separator, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return list; | ||
} | ||
})(); | ||
const { t } = useTranslation(); | ||
|
||
const home: DBreadcrumbItem<string> = aHome ?? { | ||
id: '/', | ||
title: t('Home', { ns: 'title' }), | ||
link: true, | ||
}; | ||
|
||
return ( | ||
<div {...restProps} className={getClassName(restProps.className, 'app-route-header__breadcrumb')}> | ||
{breadcrumb && <DBreadcrumb dList={breadcrumb} dSeparator={aSeparator} />} | ||
<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 | ||
), | ||
}))} | ||
dSeparator={aSeparator} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.