
* feat: ✨ add empty packages/ui * feat: ⚗️ move taxes app-grid to packages/ui * build: ⬆️ upgrade macaw-ui in packages/ui * add app sdk * feat: ✨ add basic breadcrumbs component * refactor: ♻️ simplify breadcrumbs api * Update packages/ui/src/breadcrumbs.tsx Co-authored-by: Lukasz Ostrowski <lukasz.ostrowski@saleor.io> * refactor: 🔥 next-env.d.ts * refactor: ♻️ address breadcrumbs feedback * chore: 🔥 remove eslint disable * build: 👷 add changeset --------- Co-authored-by: Lukasz Ostrowski <lukasz.ostrowski@saleor.io>
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { Box, PropsWithBox, Text } from "@saleor/macaw-ui/next";
|
|
import Link from "next/link";
|
|
import React from "react";
|
|
import styles from "./breadcrumbs.module.css";
|
|
|
|
export type BreadcrumbsItemProps = PropsWithBox<{
|
|
href?: string;
|
|
isLast?: boolean;
|
|
}>;
|
|
|
|
const BreadcrumbsItem = ({ children, href, isLast = false, ...p }: BreadcrumbsItemProps) => {
|
|
return (
|
|
<Box fontSize="titleMedium" as="li" {...p}>
|
|
<Text
|
|
__fontSize={"inherit"}
|
|
variant="title"
|
|
color={isLast ? "textNeutralDefault" : "textNeutralSubdued"}
|
|
>
|
|
{href && !isLast ? (
|
|
<Link className={styles.link} href={href}>
|
|
{children}
|
|
</Link>
|
|
) : (
|
|
children
|
|
)}
|
|
</Text>
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
export type BreadcrumbsProps = PropsWithBox<{}>;
|
|
|
|
export const Breadcrumbs = ({ children, ...p }: BreadcrumbsProps) => {
|
|
return (
|
|
<nav aria-label="breadcrumb">
|
|
<Box
|
|
className={styles.breadcrumbs}
|
|
alignItems={"center"}
|
|
display={"flex"}
|
|
padding={0}
|
|
margin={0}
|
|
style={{ listStyle: "none" }}
|
|
as="ol"
|
|
{...p}
|
|
>
|
|
{React.Children.map(children, (child, index) => {
|
|
const isLast = index === React.Children.count(children) - 1;
|
|
|
|
return React.cloneElement(child as React.ReactElement<BreadcrumbsItemProps>, {
|
|
isLast,
|
|
});
|
|
})}
|
|
</Box>
|
|
</nav>
|
|
);
|
|
};
|
|
|
|
Breadcrumbs.Item = BreadcrumbsItem;
|