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(mui-breadcrumbs): add LinkProps prop to pass props to the links #603

Merged
merged 1 commit into from
Dec 11, 2024
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
12 changes: 12 additions & 0 deletions packages/breadcrumbs/src/lib/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export const _Breadcrumbs: StoryObj<typeof Breadcrumbs> = {
},
};

export const _BreadcrumbsLinkProps: StoryObj<typeof Breadcrumbs> = {
render: (args: BreadcrumbsProps) => <Breadcrumbs {...args} />,
args: {
active: 'Current Page',
'aria-label': 'test-breadcrumbs',
crumbs: [{ name: 'Previous Page', url: '/previous-page' }],
LinkProps: {
loadApp: false,
},
},
};

export const _BreadcrumbsChildren: StoryObj<typeof Breadcrumbs> = {
render: (args: BreadcrumbsProps) => (
<Breadcrumbs {...args}>
Expand Down
13 changes: 9 additions & 4 deletions packages/breadcrumbs/src/lib/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { default as MuiBreadcrumbs, BreadcrumbsProps as MuiBreadcrumbsProps } from '@mui/material/Breadcrumbs';
import Typography from '@mui/material/Typography';
import { NavigateNextIcon, MoreHorizontalIcon } from '@availity/mui-icon';
import { Link } from '@availity/mui-link';
import { Link, LinkProps } from '@availity/mui-link';

interface Crumb {
/** The name of the ancestor page. */
Expand All @@ -12,6 +12,8 @@ interface Crumb {
* @default _top
*/
target?: string;
/** Props passed to the Links */
LinkProps?: Omit<LinkProps, 'href'>;
}

export interface BreadcrumbsProps extends Omit<MuiBreadcrumbsProps, 'separator' | 'slotProps' | 'slots'> {
Expand All @@ -32,15 +34,17 @@ export interface BreadcrumbsProps extends Omit<MuiBreadcrumbsProps, 'separator'
/** A string value that can be used to name an element
* @default breadcrumbs */
'aria-label'?: string;
/** Props passed to the Links */
LinkProps?: Omit<LinkProps, 'href'>;
}

const Breadcrumb = ({ name, url, target = '_top' }: Crumb) => {
const Breadcrumb = ({ name, url, target = '_top', LinkProps }: Crumb) => {
const props = {
'aria-label': name,
children: name,
};

return url ? <Link {...props} href={url} target={target} /> : <Typography {...props} />;
return url ? <Link {...props} {...LinkProps} href={url} target={target} /> : <Typography {...props} />;
};

export const Breadcrumbs = ({
Expand All @@ -49,6 +53,7 @@ export const Breadcrumbs = ({
crumbs,
emptyState = '...',
homeUrl = '/public/apps/dashboard',
LinkProps,
...rest
}: BreadcrumbsProps): JSX.Element => {
return (
Expand All @@ -65,7 +70,7 @@ export const Breadcrumbs = ({
{crumbs &&
crumbs.length > 0 &&
crumbs.map(({ name = emptyState, url, target }) => (
<Breadcrumb name={name} url={url} target={target} key={name} />
<Breadcrumb name={name} url={url} target={target} key={name} LinkProps={LinkProps} />
))}
{children}
<Typography>{active || emptyState}</Typography>
Expand Down
Loading