Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/docs/components/breadcrumb.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Breadcrumb

To display hierarchy with respect to current location and help with navigation.

### Quick start

Here's a quick start guide to get started with the Breadcrumb component

### Importing Component

```jsx
import { Breadcrumb } from "@hover-design/react";
```

### Code Snippets and Examples

import "@hover-design/react/dist/style.css";
import { Breadcrumb, Card } from "@hover-design/react";
export const BreadcrumbComponent = ({ list, separator = "/" }) => (
<Breadcrumb crumbs={list} separator={separator} />
);
const list = [
{ title: "Hover" },
{ title: "Components", href: "#" },
{ title: "Docs", href: "#" },
];

```jsx
const App = () => {
const list = [
{ title: "Hover" },
{ title: "Components", href: "#" },
{ title: "Docs", href: "#" },
];
return (
<div className="App">
<Breadcrumb crumbs={list} separator={"/"} />
</div>
);
};
```

#### Example

<Card variant="shadow">
<BreadcrumbComponent list={list} separator=">" />
</Card>

### Breadcrumb

| Property | Description | Type | Default Version |
| :-------- | :---------------------- | :------------------ | :-------------- |
| crumbs | List of Breadcrumbs | Array[crumb] | - |
| separator | Separator between links | string or ReactNode | `/` |

### crumbs

| Property | Description | Type | Default Version |
| :------- | :---------------------------------------- | :----- | :-------------- |
| crumb | Object with title(must) & href properties | Object | |
23 changes: 23 additions & 0 deletions lib/src/components/Breadcrumb/BreadCrumb.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Breadcrumb, BreadcrumbProps } from "./Breadcrumb";
import type { Story } from "@ladle/react";

export const Controls: Story<BreadcrumbProps> = ({
crumbs,
separator = "/",
className,
...nativeProps
}) => (
<>
<Breadcrumb crumbs={crumbs} separator={separator} {...nativeProps} />
</>
);
const crumbs = [
{ title: "Hover" },
{ title: "Documantation", href: "#" },
{ title: "About", href: "#" },
];
const separator = ">";
Controls.args = {
crumbs,
separator,
};
46 changes: 46 additions & 0 deletions lib/src/components/Breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { forwardRef } from "react";
import {
breadcrumbWrapper,
crumbSeparator,
crumbTitle,
} from "./breadcrumb.css";

type crumb = {
title: string;
href?: string;
};

export interface BreadcrumbProps {
crumbs: Array<crumb>;
separator?: string | React.ReactNode;
className?: string;
}
Comment on lines +8 to +17
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this into a seperate file called breadcrumb.types.ts


const Breadcrumb: React.ForwardRefRenderFunction<
HTMLDivElement,
BreadcrumbProps
> = ({ crumbs, separator = "/", className, ...nativeProps }, ref) => {
return (
<div
ref={ref}
className={`${breadcrumbWrapper} ${className}`}
{...nativeProps}
>
{crumbs.map((b, index, arr) => {
return (
<React.Fragment key={index}>
<a className={`${crumbTitle}`} href={b.href}>
{b.title}
</a>
{arr.length - 1 !== index && (
<span className={`${crumbSeparator}`}>{separator}</span>
)}
</React.Fragment>
);
})}
</div>
);
};
const BreadcrumbWithRef = forwardRef(Breadcrumb);

export { BreadcrumbWithRef as Breadcrumb };
12 changes: 12 additions & 0 deletions lib/src/components/Breadcrumb/breadcrumb.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { style } from "@vanilla-extract/css";

export const breadcrumbWrapper = style({
display: "flex",
alignItems: "center"
});
export const crumbTitle = style({
paddingLeft:"1em"
})
export const crumbSeparator = style({
paddingLeft:"1em"
})
2 changes: 2 additions & 0 deletions lib/src/components/Breadcrumb/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Breadcrumb";
export * from "./breadcrumb.css";
1 change: 1 addition & 0 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./components/Badge";
export * from "./components/Button";
export * from "./components/Breadcrumb";
export * from "./components/Card";
export * from "./components/Checkbox";
export * from "./components/Flex";
Expand Down