Skip to content

Commit

Permalink
Move the ScopeIndicator from the ToolbarBreadcrumbs to the Toolbar (#…
Browse files Browse the repository at this point in the history
…2220)

This makes more sense because the ScopeIndicator doesn't really have
anything to do with the Breadcrumbs. Also, it makes it possible to
render a ScopeIndicator without breadcrumbs (outside of a Stack).
  • Loading branch information
thomasdax98 authored Jun 28, 2024
1 parent ef575da commit ce5eaed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-hats-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin": major
---

Move the `ScopeIndicator` from the `ToolbarBreadcrumbs` to the `Toolbar`
24 changes: 19 additions & 5 deletions packages/admin/admin/src/common/toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ThemedComponentBaseProps } from "../../helpers/ThemedComponentBaseProps
import { MasterLayoutContext } from "../../mui/MasterLayoutContext";
import { ToolbarBreadcrumbs } from "./ToolbarBreadcrumbs";

export type ToolbarClassKey = "root" | "topBar" | "bottomBar" | "mainContentContainer" | "breadcrumbs";
export type ToolbarClassKey = "root" | "topBar" | "bottomBar" | "mainContentContainer" | "breadcrumbs" | "scopeIndicator";

export interface ToolbarProps
extends ThemedComponentBaseProps<{
Expand All @@ -16,6 +16,7 @@ export interface ToolbarProps
mainContentContainer: "div";
topBar: "div";
breadcrumbs: typeof ToolbarBreadcrumbs;
scopeIndicator: "div";
}> {
elevation?: number;
children?: React.ReactNode;
Expand Down Expand Up @@ -45,9 +46,21 @@ const Root = createComponentSlot(Paper)<ToolbarClassKey, OwnerState>({
const TopBar = createComponentSlot("div")<ToolbarClassKey>({
componentName: "Toolbar",
slotName: "topBar",
})(css`
min-height: 40px;
`);
})(
({ theme }) => css`
min-height: 40px;
display: flex;
align-items: center;
gap: ${theme.spacing(2)};
padding-left: ${theme.spacing(2)};
padding-right: ${theme.spacing(2)};
`,
);

const ScopeIndicator = createComponentSlot("div")<ToolbarClassKey>({
componentName: "Toolbar",
slotName: "scopeIndicator",
})();

const BottomBar = createComponentSlot(MuiToolbar)<ToolbarClassKey>({
componentName: "Toolbar",
Expand Down Expand Up @@ -106,7 +119,8 @@ export const Toolbar = (inProps: ToolbarProps) => {
<Root elevation={elevation} ownerState={ownerState} {...slotProps?.root} {...restProps}>
{!hideTopBar && (
<TopBar {...slotProps?.topBar}>
<Breadcrumbs scopeIndicator={scopeIndicator} {...slotProps?.breadcrumbs} />
{Boolean(scopeIndicator) && <ScopeIndicator {...slotProps?.scopeIndicator}>{scopeIndicator}</ScopeIndicator>}
<Breadcrumbs {...slotProps?.breadcrumbs} />
</TopBar>
)}
{children && (
Expand Down
13 changes: 1 addition & 12 deletions packages/admin/admin/src/common/toolbar/ToolbarBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const __DEBUG__useDebugBreadcrumbData = false;

type ToolbarBreadcrumbsClassKey =
| "root"
| "scopeIndicator"
| "breadcrumbsList"
| "mobileBreadcrumbsButton"
| "currentBreadcrumbsItem"
Expand All @@ -42,7 +41,6 @@ type ToolbarBreadcrumbsClassKey =
interface ToolbarBreadcrumbsProps
extends ThemedComponentBaseProps<{
root: "div";
scopeIndicator: "div";
breadcrumbsList: "div";
mobileBreadcrumbsButton: typeof ButtonBase;
currentBreadcrumbsItem: typeof Typography;
Expand All @@ -55,7 +53,6 @@ interface ToolbarBreadcrumbsProps
mobileMenuItemText: typeof ListItemText;
mobileMenuItemNestingIndicator: "div";
}> {
scopeIndicator?: React.ReactNode;
iconMapping?: {
itemSeparator?: React.ReactNode;
openMobileMenu?: React.ReactNode;
Expand All @@ -64,7 +61,7 @@ interface ToolbarBreadcrumbsProps
}

export const ToolbarBreadcrumbs = (inProps: ToolbarBreadcrumbsProps) => {
const { scopeIndicator, iconMapping = {}, slotProps, ...restProps } = useThemeProps({ props: inProps, name: "CometAdminToolbarBreadcrumbs" });
const { iconMapping = {}, slotProps, ...restProps } = useThemeProps({ props: inProps, name: "CometAdminToolbarBreadcrumbs" });
const {
itemSeparator: itemSeparatorIcon = <ChevronRight />,
openMobileMenu: openMobileMenuIcon = <ChevronDown />,
Expand Down Expand Up @@ -92,7 +89,6 @@ export const ToolbarBreadcrumbs = (inProps: ToolbarBreadcrumbsProps) => {
return (
<>
<Root ref={rootRef} {...slotProps?.root} {...restProps}>
{Boolean(scopeIndicator) && <ScopeIndicator {...slotProps?.scopeIndicator}>{scopeIndicator}</ScopeIndicator>}
<BreadcrumbsList {...slotProps?.breadcrumbsList}>
{breadcrumbs.map(({ title, url }, index) => {
const isCurrentPage = index === breadcrumbs.length - 1;
Expand Down Expand Up @@ -202,16 +198,9 @@ const Root = createComponentSlot("div")<ToolbarBreadcrumbsClassKey>({
display: flex;
align-items: center;
gap: ${theme.spacing(2)};
padding-left: ${theme.spacing(2)};
padding-right: ${theme.spacing(2)};
`,
);

const ScopeIndicator = createComponentSlot("div")<ToolbarBreadcrumbsClassKey>({
componentName: "ToolbarBreadcrumbs",
slotName: "scopeIndicator",
})();

const BreadcrumbsList = createComponentSlot("div")<ToolbarBreadcrumbsClassKey>({
componentName: "ToolbarBreadcrumbs",
slotName: "breadcrumbsList",
Expand Down

0 comments on commit ce5eaed

Please sign in to comment.