-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Breadcrumbs } from './Breadcrumbs'; | ||
|
||
export default { | ||
title: 'Components/Layout/Breadcrumbs', | ||
component: Breadcrumbs | ||
}; | ||
|
||
export const Basic = () => ( | ||
<Breadcrumbs | ||
breadcrumbs={[ | ||
{ label: 'Home', href: '/' }, | ||
{ label: 'Docs', href: '/' }, | ||
{ | ||
label: 'Breadcrumbs', | ||
href: '/' | ||
} | ||
]} | ||
/> | ||
); | ||
|
||
export const WithCustomSeparator = () => ( | ||
<Breadcrumbs | ||
seperator="/" | ||
breadcrumbs={[ | ||
{ label: 'Home', href: '/' }, | ||
{ label: 'Docs', href: '/' }, | ||
{ | ||
label: 'Breadcrumbs', | ||
href: '/' | ||
} | ||
]} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { cn, useComponentTheme } from '@/utils'; | ||
import React, { FC } from 'react'; | ||
import { BreadcrumbsTheme } from './BreadcrumbsTheme'; | ||
|
||
export interface BreadcrumbsProps extends React.HTMLAttributes<HTMLElement> { | ||
breadcrumbs: { label: string; href: string }[]; | ||
seperator?: React.ReactNode; | ||
theme?: BreadcrumbsTheme; | ||
} | ||
|
||
const Chevron = () => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="16" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
fill="currentColor" | ||
> | ||
<path d="M6.47003 4L5.53003 4.94L8.58336 8L5.53003 11.06L6.47003 12L10.47 8L6.47003 4Z" /> | ||
</svg> | ||
); | ||
|
||
export const Breadcrumbs: FC<BreadcrumbsProps> = ({ | ||
breadcrumbs, | ||
seperator = <Chevron />, | ||
theme: customTheme, | ||
...rest | ||
}) => { | ||
const theme = useComponentTheme('breadcrumbs', customTheme); | ||
|
||
return ( | ||
<nav aria-label={rest?.['aria-label'] ?? 'breadcrumbs'}> | ||
<ol className={theme.base}> | ||
{breadcrumbs.map((breadcrumb, index) => { | ||
const isActiveBreadcrumb = index === breadcrumbs.length - 1; | ||
|
||
return ( | ||
<li | ||
className="flex gap-2 items-center" | ||
key={`breadcrumb-${breadcrumb?.label}-${index}`} | ||
> | ||
<a | ||
className={cn( | ||
theme.breadcrumb, | ||
isActiveBreadcrumb && theme.activeBreadcrumb | ||
)} | ||
{...(isActiveBreadcrumb | ||
? { | ||
'aria-current': 'location' | ||
} | ||
: {})} | ||
href={breadcrumb.href} | ||
> | ||
{breadcrumb.label} | ||
</a> | ||
<span aria-hidden={true}> | ||
{index < breadcrumbs.length - 1 && seperator} | ||
</span> | ||
</li> | ||
); | ||
})} | ||
</ol> | ||
</nav> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface BreadcrumbsTheme { | ||
base: string; | ||
breadcrumb: string; | ||
activeBreadcrumb: string; | ||
} | ||
|
||
export const breadcrumbsTheme: BreadcrumbsTheme = { | ||
base: 'flex gap-2 items-center', | ||
breadcrumb: | ||
'hover:text-panel-content text-panel-secondary-content transition-colors', | ||
activeBreadcrumb: 'text-primary pointer-events-none' | ||
}; | ||
|
||
export const legacyBreadcrumbTheme: BreadcrumbsTheme = breadcrumbsTheme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './Breadcrumbs'; | ||
export * from './BreadcrumbsTheme'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters