(
+ (props, ref) => {
+ const { as, active, ...rest } = transformModifiers(props);
+ return (
+
+ {React.createElement(as!, { ref, ...rest })}
+
+ );
+ },
+ "a",
+);
diff --git a/src/components/breadcrumb/breadcrumb.story.tsx b/src/components/breadcrumb/breadcrumb.story.tsx
index 5664e20c..57209d9d 100644
--- a/src/components/breadcrumb/breadcrumb.story.tsx
+++ b/src/components/breadcrumb/breadcrumb.story.tsx
@@ -4,7 +4,6 @@ import React from "react";
import { Box } from "@/components/box";
import { Breadcrumb } from "@/components/breadcrumb";
-import { BreadcrumbProps } from "@/components/breadcrumb/breadcrumb";
const makeSeparator = () =>
select(
@@ -19,45 +18,44 @@ const makeSeparator = () =>
);
const items = [
- {
- name: "Storybook",
- url: "#1",
- },
- {
- name: "Breadcrumb",
- url: "#2",
- },
- {
- active: true,
- name: "Breadcrumb Types",
- url: "#3",
- },
+ { href: "#1", name: "Storybook" },
+ { href: "#2", name: "Breadcrumb" },
+ { active: true, href: "#3", name: "Breadcrumb Types" },
];
storiesOf("Breadcrumb", module)
.add("Default", () => (
-
+
+ {items.map(({ active, href, name }, i) => (
+
+ {name}
+
+ ))}
+
))
.add("Use Custom render Element", () => {
- const Anchor = ({ children, unselectable, ...props }: BreadcrumbProps) => (
-
- {children}
-
+ const Link: React.FC<{ children: React.ReactNode; to: string }> = props => (
+ {props.children}
);
-
return (
-
- as={Anchor}
- hrefAttr="href"
- separator={makeSeparator()}
- items={items}
- />
+
+ {items.map(({ active, href: to, name }, i) => (
+
+ as={Link}
+ active={active}
+ to={to}
+ key={i}
+ >
+ {name}
+
+ ))}
+
);
diff --git a/src/components/breadcrumb/breadcrumb.tsx b/src/components/breadcrumb/breadcrumb.tsx
index e598b1bb..f80c69e3 100644
--- a/src/components/breadcrumb/breadcrumb.tsx
+++ b/src/components/breadcrumb/breadcrumb.tsx
@@ -3,19 +3,20 @@ import React from "react";
import { forwardRefAs } from "@/components/exotic";
import { ModifierProps, transformModifiers } from "@/modifiers";
+import { tuple } from "@/utils";
+import { BreadcrumbItem } from "./breadcrumb-item";
-export interface BreadcrumbItemProps {
- url: string;
- active?: boolean;
- name?: React.ReactNode;
-}
+export const BREADCRUMB_SEPARATORS = tuple(
+ "arrow",
+ "bullet",
+ "dot",
+ "succeeds",
+);
+export type BreadcrumbSeparators = (typeof BREADCRUMB_SEPARATORS)[number];
export type BreadcrumbModifierProps = Partial<{
align: "right" | "center";
- className: string;
- hrefAttr: string;
- items: BreadcrumbItemProps[];
- separator: "arrow" | "bullet" | "dot" | "succeeds";
+ separator: BreadcrumbSeparators;
size: "small" | "medium" | "large";
}>;
@@ -24,47 +25,27 @@ export type BreadcrumbProps = Prefer<
React.HTMLAttributes
>;
-// TODO: should split up Breadcrumb -> Breadcrumb & BreadcrumbItem
-// this is because the `ref` is passed down to the breadcrumb container
-// but the `as` is passed to the bredcrumb item.
-// Ergo: the type system expects `as` to be compatible with the `Ref`,
-// but it won't be. (the item defaults to an , and the container is fixed as
-// a