-
Notifications
You must be signed in to change notification settings - Fork 9
Admin: Add new Breadcrumbs component
#4936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juliawegmayr
wants to merge
15
commits into
feature/admin-breadcrumbs
Choose a base branch
from
breadcrumbs-desktop
base: feature/admin-breadcrumbs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−0
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
301c039
add Breadcrumbs component
juliawegmayr a81be9e
export breadcrumb component and types
juliawegmayr 8ce54ee
add breadcrumbs story
juliawegmayr c92b175
code improvements
juliawegmayr 7af44ca
remove id from BreadcrumbsItemProps
juliawegmayr 23236cd
move story directly to admin package
juliawegmayr c16fb9e
add key to separator
juliawegmayr a261678
set key on fragment
juliawegmayr 1ad1ea8
fix lint error by remoing unused exports
juliawegmayr 6ef2b48
use BreadcrumbsList as Root and remove unneccesary div
juliawegmayr d1fdb9f
rename BreadcrumbsItem interface
juliawegmayr b90fd82
remove breadcrumbsList from type
juliawegmayr 123a88b
remove breadcrumbsList slot
juliawegmayr 4b05587
rename BreadcrumbsItem type to Breadcrumb
juliawegmayr 6cd0785
rename BreadcrumbsItem to Item
juliawegmayr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
packages/admin/admin/src/common/breadcrumbs/Breadcrumbs.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { ChevronRight } from "@comet/admin-icons"; | ||
| import { type ComponentsOverrides, Typography } from "@mui/material"; | ||
| import { css, type Theme, useThemeProps } from "@mui/material/styles"; | ||
| import { Fragment, type ReactNode } from "react"; | ||
|
|
||
| import { createComponentSlot } from "../../helpers/createComponentSlot"; | ||
| import { type ThemedComponentBaseProps } from "../../helpers/ThemedComponentBaseProps"; | ||
|
|
||
| type BreadcrumbsClassKey = "root" | "breadcrumbsList" | "breadcrumbsItem" | "separator"; | ||
|
|
||
| export interface BreadcrumbsItemProps { | ||
jamesricky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| url: string; | ||
| title: ReactNode; | ||
| } | ||
|
|
||
| interface BreadcrumbsProps | ||
| extends ThemedComponentBaseProps<{ | ||
| root: "div"; | ||
| breadcrumbsList: "div"; | ||
juliawegmayr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| breadcrumbsItem: typeof Typography; | ||
|
||
| separator: typeof ChevronRight; | ||
| }> { | ||
| items: BreadcrumbsItemProps[]; | ||
| } | ||
|
|
||
| const Root = createComponentSlot("div")<BreadcrumbsClassKey>({ | ||
| componentName: "Breadcrumbs", | ||
| slotName: "root", | ||
| })(); | ||
jamesricky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const BreadcrumbsList = createComponentSlot("div")<BreadcrumbsClassKey>({ | ||
| componentName: "Breadcrumbs", | ||
| slotName: "breadcrumbsList", | ||
| })( | ||
| ({ theme }) => css` | ||
| display: flex; | ||
| align-items: center; | ||
| height: 50px; | ||
| padding: 0 ${theme.spacing(2)}; | ||
| `, | ||
| ); | ||
|
|
||
| const BreadcrumbsItem = createComponentSlot(Typography)<BreadcrumbsClassKey>({ | ||
| componentName: "Breadcrumbs", | ||
| slotName: "breadcrumbsItem", | ||
| })( | ||
| ({ theme }) => css` | ||
| color: ${theme.palette.grey[900]}; | ||
| white-space: nowrap; | ||
|
|
||
| &:not(:last-child):hover { | ||
| color: ${theme.palette.primary.main}; | ||
| } | ||
|
|
||
| &:last-child { | ||
| font-weight: bold; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| } | ||
jamesricky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `, | ||
| ) as typeof Typography; | ||
|
|
||
| const Separator = createComponentSlot(ChevronRight)<BreadcrumbsClassKey>({ | ||
| componentName: "Breadcrumbs", | ||
| slotName: "separator", | ||
| })(css` | ||
| margin: 0 5px; | ||
| `); | ||
|
|
||
| export const Breadcrumbs = (inProps: BreadcrumbsProps) => { | ||
| const { items, slotProps, ...restProps } = useThemeProps({ props: inProps, name: "CometAdminBreadcrumbs" }); | ||
| return ( | ||
| <Root {...slotProps?.root} {...restProps}> | ||
| <BreadcrumbsList {...slotProps?.breadcrumbsList}> | ||
| {items.map((item, index) => { | ||
| const isCurrentPage = index === items.length - 1; | ||
|
|
||
| if (isCurrentPage) { | ||
| return ( | ||
| <BreadcrumbsItem key={item.url} {...slotProps?.breadcrumbsItem}> | ||
| {item.title} | ||
| </BreadcrumbsItem> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Fragment key={item.url}> | ||
| {/* @ts-expect-error The component prop does not work properly with MUIs `styled()`, see: https://mui.com/material-ui/guides/typescript/#complications-with-the-component-prop */} | ||
| <BreadcrumbsItem component="a" href={item.url} {...slotProps?.breadcrumbsItem}> | ||
| {item.title} | ||
| </BreadcrumbsItem> | ||
| <Separator {...slotProps?.separator} /> | ||
| </Fragment> | ||
| ); | ||
| })} | ||
| </BreadcrumbsList> | ||
| </Root> | ||
| ); | ||
| }; | ||
|
|
||
| declare module "@mui/material/styles" { | ||
| interface ComponentsPropsList { | ||
| CometAdminBreadcrumbs: BreadcrumbsProps; | ||
| } | ||
|
|
||
| interface ComponentNameToClassKey { | ||
| CometAdminBreadcrumbs: BreadcrumbsClassKey; | ||
| } | ||
|
|
||
| interface Components { | ||
| CometAdminBreadcrumbs?: { | ||
| defaultProps?: Partial<ComponentsPropsList["CometAdminBreadcrumbs"]>; | ||
| styleOverrides?: ComponentsOverrides<Theme>["CometAdminBreadcrumbs"]; | ||
| }; | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
packages/admin/admin/src/common/breadcrumbs/__stories__/Breadcrumbs.stories.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { Breadcrumbs, type BreadcrumbsItemProps } from "../Breadcrumbs"; | ||
|
|
||
| export default { | ||
| title: "components/breadcrumbs/Breadcrumbs", | ||
| }; | ||
|
|
||
| const singleItem: BreadcrumbsItemProps[] = [{ url: "/one", title: "Breadcrumb One" }]; | ||
| const twoItems: BreadcrumbsItemProps[] = [...singleItem, { url: "/two", title: "BC 2" }]; | ||
| const threeItems: BreadcrumbsItemProps[] = [...twoItems, { url: "/three", title: "BrdCrmb 3" }]; | ||
| const fiveItems: BreadcrumbsItemProps[] = [ | ||
| ...threeItems, | ||
| { url: "/four", title: "Really long Breadcrumb Number Four" }, | ||
| { url: "/five", title: "Breadcrumb Five" }, | ||
| ]; | ||
| const sevenItems: BreadcrumbsItemProps[] = [...fiveItems, { url: "/six", title: "Breadcrumb Six" }, { url: "/seven", title: "Breadcrumb Seven" }]; | ||
|
|
||
| export const Single = () => { | ||
| return <Breadcrumbs items={singleItem} />; | ||
| }; | ||
|
|
||
| export const Two = () => { | ||
| return <Breadcrumbs items={twoItems} />; | ||
| }; | ||
|
|
||
| export const Three = () => { | ||
| return <Breadcrumbs items={threeItems} />; | ||
| }; | ||
|
|
||
| export const Five = () => { | ||
| return <Breadcrumbs items={fiveItems} />; | ||
| }; | ||
|
|
||
| export const Seven = () => { | ||
| return <Breadcrumbs items={sevenItems} />; | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.