-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Bland-UI/feat/breadcrumb
Feat/breadcrumb
- Loading branch information
Showing
7 changed files
with
128 additions
and
0 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,5 @@ | ||
--- | ||
"@blandui/blandui-react": patch | ||
--- | ||
|
||
BreadCrumb added |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { BreadCrumb } from '@blandui/blandui-react'; | ||
import { BreadCrumbItem } from '@blandui/blandui-react/dist/types/components/BreadCrumb/BreadCrumb'; | ||
import { Component, Home, Info, InfoIcon } from 'lucide-react'; | ||
|
||
const meta: Meta<typeof BreadCrumb> = { | ||
title: 'Component/BreadCrumb', | ||
component: BreadCrumb, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof BreadCrumb>; | ||
|
||
|
||
export const Default: Story = { | ||
render: () => { | ||
const items: BreadCrumbItem[] = [ | ||
{ title: 'BlandUI' }, | ||
{ title: 'Components' }, | ||
{ title: 'BreadCrumb' }, | ||
]; | ||
|
||
return ( | ||
<div className="flex flex-col gap-lg items-start justify-center"> | ||
<BreadCrumb items={items} /> | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export const WithIcons: Story = { | ||
render: () => { | ||
const items: BreadCrumbItem[] = [ | ||
{ title: <><Home size="1rem" fontSize={14}/>BlandUI</> }, | ||
{ title: <><Component size="1rem"/>Components</> }, | ||
{ title: <><InfoIcon size="1rem"/>BreadCrumb</> }, | ||
]; | ||
|
||
return ( | ||
<div className="flex flex-col gap-lg items-start justify-center"> | ||
<BreadCrumb items={items} /> | ||
</div> | ||
); | ||
}, | ||
}; |
71 changes: 71 additions & 0 deletions
71
packages/blandui-react/src/components/BreadCrumb/BreadCrumb.tsx
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,71 @@ | ||
import { | ||
forwardRef, Fragment, MouseEventHandler, ReactNode, | ||
} from 'react'; | ||
import { ChevronRight } from 'lucide-react'; | ||
import cn from '../../utils/cn'; | ||
|
||
export interface BreadCrumbItem { | ||
title: ReactNode; | ||
|
||
onClick?: MouseEventHandler; | ||
href?: string; | ||
} | ||
|
||
export interface BreadCrumbProps { | ||
className?: string; | ||
separator?: ReactNode; | ||
items: BreadCrumbItem[]; | ||
} | ||
|
||
export const BreadCrumb = forwardRef<HTMLDivElement, BreadCrumbProps>(({ | ||
className, | ||
separator, | ||
items, | ||
}, ref) => { | ||
const breadCrumbCn = cn( | ||
'flex items-center gap-xs text-link body-md', | ||
className, | ||
); | ||
|
||
const itemCn = cn( | ||
'flex gap-sm items-center px-2xs', | ||
'cursor-pointer', | ||
'focus:ring-2 focus:ring-offset-0 focus:ring-focused focus:rounded-sm', | ||
); | ||
|
||
const contentCn = cn( | ||
'flex items-center gap-sm', | ||
'hover:underline', | ||
); | ||
|
||
return ( | ||
<div className={breadCrumbCn} ref={ref}> | ||
{items.map((item, index) => (<div key={index} className={itemCn}> | ||
{ item.href && <> | ||
<a | ||
href={item.href} | ||
className={cn(contentCn, index === items.length - 1 ? 'font-semibold' : '')} | ||
> | ||
{ item.title } | ||
</a> | ||
</> } | ||
|
||
{ !item.href && <> | ||
<div | ||
onClick={item.onClick} | ||
className={cn(contentCn, index === items.length - 1 ? 'font-semibold' : '')} | ||
> | ||
{ item.title } | ||
</div> | ||
</> } | ||
|
||
{ index < items.length - 1 && <> | ||
{ separator || <ChevronRight size="0.75rem" className="text-subtle" />} | ||
</>} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}); | ||
|
||
BreadCrumb.displayName = 'BreadCrumb'; |
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 { BreadCrumb } from './BreadCrumb'; | ||
export type { BreadCrumbProps } from './BreadCrumb'; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.