-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: APP-3051 - Implement Breadcrumbs module component (#141)
- Loading branch information
1 parent
45b01ac
commit d06e4f7
Showing
11 changed files
with
160 additions
and
6 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,42 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { Breadcrumbs } from './breadcrumbs'; | ||
|
||
const meta: Meta<typeof Breadcrumbs> = { | ||
title: 'Core/Components/Breadcrumbs', | ||
component: Breadcrumbs, | ||
tags: ['autodocs'], | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/ISSDryshtEpB7SUSdNqAcw/branch/P0GeJKqILL7UXvaqu5Jj7V/Aragon-ODS?type=design&node-id=15704%3A53630&mode=design&t=wK3Bn7hqwwBM55IZ-1', | ||
}, | ||
}, | ||
}; | ||
|
||
type Story = StoryObj<typeof Breadcrumbs>; | ||
|
||
/** | ||
* Default usage example of the Breadcrumb component. | ||
*/ | ||
export const Default: Story = { | ||
args: { | ||
links: [{ label: 'Root', href: '/' }], | ||
}, | ||
}; | ||
|
||
/** | ||
* Usage example of the Breadcrumb component with full props. | ||
*/ | ||
export const Loaded: Story = { | ||
args: { | ||
links: [ | ||
{ label: 'Root', href: '/' }, | ||
{ label: 'Page', href: '/page' }, | ||
{ label: 'Subpage', href: '/page/subpage' }, | ||
{ label: 'Current page', href: '/page/subpage/current' }, | ||
], | ||
tag: { label: 'Tag', variant: 'info' }, | ||
}, | ||
}; | ||
|
||
export default meta; |
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,50 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { Breadcrumbs, type IBreadcrumbsProps } from './breadcrumbs'; // Adjust the import path as necessary | ||
|
||
describe('<Breadcrumbs /> component', () => { | ||
const createTestComponent = (props?: Partial<IBreadcrumbsProps>) => { | ||
const completeProps: IBreadcrumbsProps = { | ||
links: [{ href: '/', label: 'Root' }], | ||
...props, | ||
}; | ||
|
||
return <Breadcrumbs {...completeProps} />; | ||
}; | ||
|
||
it('renders all provided path links', () => { | ||
const links = [ | ||
{ href: '/', label: 'Root' }, | ||
{ href: '/page', label: 'Page' }, | ||
{ href: '/page/subpage', label: 'Subpage' }, | ||
{ href: '/page/subpage/current/', label: 'Current page' }, | ||
]; | ||
render(createTestComponent({ links })); | ||
|
||
const renderedLinks = screen.getAllByRole('link'); | ||
expect(renderedLinks.length).toBe(3); | ||
expect(renderedLinks[0]).toHaveTextContent('Root'); | ||
expect(renderedLinks[1]).toHaveTextContent('Page'); | ||
expect(renderedLinks[2]).toHaveTextContent('Subpage'); | ||
}); | ||
|
||
it('displays the current location correctly', () => { | ||
const links = [ | ||
{ label: 'Root', href: '/' }, | ||
{ label: 'This page', href: '/current' }, | ||
]; | ||
render(createTestComponent({ links })); | ||
|
||
const currentPage = screen.getByText('This page'); | ||
expect(currentPage).toBeInTheDocument(); | ||
expect(currentPage).toHaveAttribute('aria-current', 'page'); | ||
expect(currentPage).not.toHaveAttribute('href'); | ||
}); | ||
|
||
it('renders with the Tag component when props provided', () => { | ||
const tag = { label: 'Tag', variant: 'info' as const }; | ||
render(createTestComponent({ tag })); | ||
|
||
const pillText = screen.getByText('Tag'); | ||
expect(pillText).toBeInTheDocument(); | ||
}); | ||
}); |
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,50 @@ | ||
import { Icon, IconType } from '../icon'; | ||
import { Link } from '../link'; | ||
import { Tag, type ITagProps } from '../tag'; | ||
|
||
export interface IBreadcrumbsLink { | ||
/** | ||
* Label to be displayed in the Breadcrumbs. | ||
*/ | ||
label: string; | ||
/** | ||
* Optional href to be used in the Link component for clickable navigation. | ||
*/ | ||
href?: string; | ||
} | ||
|
||
export interface IBreadcrumbsProps { | ||
/** | ||
* Array of BreadcrumbsLink objects `{label: string, href?: string}` | ||
* The array indicates depth from the current position to be displayed in the Breadcrumbs. | ||
* Starting at index 0 you must define the root up to the current location. | ||
* The final index which will render as non-active and without separator. | ||
*/ | ||
links: IBreadcrumbsLink[]; | ||
/** | ||
* Optional tag pill to be displayed at the end of the Breadcrumbs for extra info. @type ITagProps | ||
*/ | ||
tag?: ITagProps; | ||
} | ||
|
||
export const Breadcrumbs: React.FC<IBreadcrumbsProps> = ({ links, tag, ...otherProps }) => { | ||
const currentPage = links[links.length - 1]; | ||
const pathLinks = links.slice(0, -1); | ||
|
||
return ( | ||
<nav aria-label="Breadcrumbs" className="flex items-center gap-x-2" {...otherProps}> | ||
<ol className="flex items-center gap-x-0.5"> | ||
{pathLinks.map((link) => ( | ||
<li key={link.href} className="flex items-center gap-x-1 whitespace-nowrap"> | ||
<Link href={link.href}>{link.label}</Link> | ||
<Icon icon={IconType.SLASH} className="text-neutral-200" responsiveSize={{ md: 'lg' }} /> | ||
</li> | ||
))} | ||
<li aria-current="page" className="text-sm font-normal leading-tight text-neutral-500 md:text-base"> | ||
{currentPage.label} | ||
</li> | ||
</ol> | ||
{tag && <Tag {...tag} />} | ||
</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 @@ | ||
export { Breadcrumbs, type IBreadcrumbsLink, type IBreadcrumbsProps } from './breadcrumbs'; |
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
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
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