forked from vczb/sagu-ui
-
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.
- Loading branch information
Showing
5 changed files
with
100 additions
and
1 deletion.
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
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,34 @@ | ||
import React from 'react' | ||
import * as S from './styles' | ||
|
||
export type BreadcrumbProps = { | ||
separator?: string | ||
children: React.ReactNode | ||
} | ||
|
||
const Breadcrumb: React.FC<BreadcrumbProps> = ({ | ||
separator = '/', | ||
children | ||
}) => { | ||
// Wrap all items in li tag | ||
const allItems = React.Children.toArray(children) | ||
.filter((child) => React.isValidElement(child)) | ||
.map((child, index) => <li key={`breadcrumb-item-${index}`}>{child}</li>) | ||
|
||
return ( | ||
<S.Breadcrumb> | ||
{allItems.map((item, index) => | ||
index !== 0 | ||
? [ | ||
<S.BreadcrumbItem key={`breadcrumb-separator-${index}`}> | ||
{separator} | ||
</S.BreadcrumbItem>, | ||
item | ||
] | ||
: item | ||
)} | ||
</S.Breadcrumb> | ||
) | ||
} | ||
|
||
export default 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,36 @@ | ||
import React from 'react' | ||
import { Meta } from '@storybook/react/types-6-0' | ||
import Breadcrumb from '.' | ||
import NavLink from '../NavLink' | ||
import TextContent from '../TextContent' | ||
import { BreadcrumbItem } from './styles' | ||
|
||
export default { | ||
title: 'Breadcrumb', | ||
component: Breadcrumb | ||
} as Meta | ||
|
||
const Template = (args) => ( | ||
<Breadcrumb {...args}> | ||
<BreadcrumbItem> | ||
<NavLink size="small" href="#"> | ||
Link 1 | ||
</NavLink> | ||
</BreadcrumbItem> | ||
<BreadcrumbItem> | ||
<NavLink size="small" href="#"> | ||
Link 2 | ||
</NavLink> | ||
</BreadcrumbItem> | ||
<BreadcrumbItem> | ||
<TextContent value="Link 3" style={{ padding: '0 1.6rem' }} /> | ||
</BreadcrumbItem> | ||
</Breadcrumb> | ||
) | ||
|
||
export const Default = Template.bind({}) | ||
|
||
export const Custom = Template.bind({}) | ||
Custom.args = { | ||
separator: '>' | ||
} |
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,12 @@ | ||
import styled from 'styled-components' | ||
|
||
export const Breadcrumb = styled.ul` | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
list-style: none; | ||
` | ||
|
||
export const BreadcrumbItem = styled.li` | ||
margin: 0 0.5rem; | ||
` |
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,17 @@ | ||
import React from 'react' | ||
import { render } from '../../utils/testUtils' | ||
import Breadcrumb from '.' | ||
|
||
describe('<Breadcrumb>', () => { | ||
it('Should render the breadcrumb', () => { | ||
const { container } = render( | ||
<Breadcrumb> | ||
<a href="#">Link 1</a> | ||
<a href="#">Link 2</a> | ||
<a href="#">Link 3</a> | ||
</Breadcrumb> | ||
) | ||
expect(container).toBeInTheDocument() | ||
expect(container.querySelectorAll('li').length).toBe(5) | ||
}) | ||
}) |