Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend breadcrumb for custom divider and crumb #739

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions src/components/Breadcrumb/Breadcrumb.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
LinkButtonVariant,
LinkButtonWidth,
} from '../LinkButton';
import { Avatar } from '../Avatar';

export default {
title: 'Breadcrumb',
Expand Down Expand Up @@ -80,6 +81,7 @@ export const No_Max = Breadcrumb_Story.bind({});
export const Hide_Current = Breadcrumb_Story.bind({});
export const With_Link_Tooltip = Breadcrumb_Story.bind({});
export const With_Custom_Links = Breadcrumb_Story.bind({});
export const With_Custom_Nodes = Breadcrumb_Story.bind({});

const breadcrumbArgs: Object = {
ariaLabel: 'Breadcrumbs',
Expand Down Expand Up @@ -291,3 +293,45 @@ With_Custom_Links.args = {
},
],
};

With_Custom_Nodes.args = {
...breadcrumbArgs,
links: [
{
customCrumb: (
<Avatar theme="green" type="round">
JD
</Avatar>
),
tooltipprops: {
content: 'John Doe',
},
title: 'John Doe',
readonly: true,
},
{
customCrumb: (
<Avatar theme="blue" type="round">
AJ
</Avatar>
),
tooltipprops: {
content: 'Adam John',
},
title: 'Adam John',
readonly: true,
},
{
customCrumb: (
<Avatar theme="red" type="round">
HG
</Avatar>
),
tooltipprops: {
content: 'Hue Grant',
},
title: 'Hue Grant',
readonly: true,
},
],
};
10 changes: 6 additions & 4 deletions src/components/Breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const Breadcrumb: FC<BreadcrumbProps> = React.forwardRef(
ariaLabel: defaultAriaLabel,
classNames,
displayCurrent = true,
divider,
divider = {
path: IconName.mdiSlashForward,
},
id,
linkClassNames,
links,
Expand Down Expand Up @@ -112,7 +114,7 @@ export const Breadcrumb: FC<BreadcrumbProps> = React.forwardRef(

const getDivider = (item?: BreadcrumbLinkProps): JSX.Element => (
<Icon
path={IconName.mdiSlashForward}
path={divider?.path}
rotate={htmlDir === 'rtl' ? 180 : 0}
size={IconSize.Small}
{...item?.divider}
Expand Down Expand Up @@ -207,7 +209,7 @@ export const Breadcrumb: FC<BreadcrumbProps> = React.forwardRef(
item.classNames,
])}
>
{item.title}
{item?.customCrumb ? item.customCrumb : item.title}
</span>
</Tooltip>
{idx < items.length - 1 && getDivider(item)}
Expand Down Expand Up @@ -238,7 +240,7 @@ export const Breadcrumb: FC<BreadcrumbProps> = React.forwardRef(
item.classNames,
])}
>
{item.title}
{item?.customCrumb ? item.customCrumb : item.title}
</Link>
)}
</Tooltip>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Breadcrumb/Breadcrumb.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export interface BreadcrumbLinkProps
* Use with React Router.
*/
dropdownChildren?: React.ReactNode;
/**
* The Breadcrumb custom crumb.
*/
customCrumb?: React.ReactNode;
/**
* The Link is readonly (text)
*/
Expand Down
Loading