Skip to content

Commit

Permalink
frontend: Add breadcrumbs component (#3145)
Browse files Browse the repository at this point in the history
  • Loading branch information
septum authored Oct 18, 2024
1 parent 3d39574 commit 56d96b2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frontend/packages/core/src/Breadcrumbs/breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";

import { Link } from "../link";
import styled from "../styled";
import { Typography } from "../typography";

import type { BreadcrumbEntry } from "./types";

const StyledTypography = styled(Typography)({
fontWeight: 500,
});

const Breadcrumb = ({ label, url }: BreadcrumbEntry) => {
return url ? (
<Link href={url} target="_self" whiteSpace="nowrap">
<StyledTypography variant="caption2" color="inherit">
{label}
</StyledTypography>
</Link>
) : (
<StyledTypography variant="caption2">{label}</StyledTypography>
);
};

export default Breadcrumb;
31 changes: 31 additions & 0 deletions frontend/packages/core/src/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { Breadcrumbs as MuiBreadcrumbs, Theme } from "@mui/material";
import { alpha } from "@mui/system";

import styled from "../styled";

import Breadcrumb from "./breadcrumb";
import type { BreadcrumbEntry } from "./types";

interface BreadcrumbsProps {
entries: BreadcrumbEntry[];
}

const StyledBreadcrumbs = styled(MuiBreadcrumbs)(({ theme }: { theme: Theme }) => ({
margin: theme.spacing(theme.clutch.spacing.sm, theme.clutch.spacing.none),
"& .MuiBreadcrumbs-separator": {
color: alpha(theme.colors.neutral[900], 0.6),
},
}));

const Breadcrumbs = ({ entries }: BreadcrumbsProps) => (
<StyledBreadcrumbs>
{entries.map((entry: BreadcrumbEntry) => (
<Breadcrumb key={entry.label} {...entry} />
))}
</StyledBreadcrumbs>
);

export * from "./types";

export default Breadcrumbs;
4 changes: 4 additions & 0 deletions frontend/packages/core/src/Breadcrumbs/types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface BreadcrumbEntry {
label: string;
url?: string;
}
2 changes: 2 additions & 0 deletions frontend/packages/core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export { useTheme } from "./AppProvider/themes";
export { ThemeProvider } from "./Theme";
export { getDisplayName } from "./utils";
export { default as WorkflowLayout } from "./WorkflowLayout";
export { default as Breadcrumbs } from "./Breadcrumbs";

export { css as EMOTION_CSS, keyframes as EMOTION_KEYFRAMES } from "@emotion/react";

Expand All @@ -84,3 +85,4 @@ export type {
export type { ClutchError } from "./Network/errors";
export type { TypographyProps } from "./typography";
export type { StyledComponent } from "@emotion/styled";
export type { BreadcrumbEntry } from "./Breadcrumbs";

0 comments on commit 56d96b2

Please sign in to comment.