Add Breadcrumbs

This commit is contained in:
Jerko Steiner 2019-03-25 17:32:12 +08:00
parent fbeea5ad3e
commit 9b5809a1d5
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import React from 'react'
import {Breadcrumbs} from './Breadcrumbs'
import {TestUtils} from '../test-utils'
import {MemoryRouter} from 'react-router-dom'
const t = new TestUtils()
describe('Breadcrumbs', () => {
describe('render', () => {
it('renders', () => {
const {node} = t.render(
<MemoryRouter>
<Breadcrumbs
links={[{
name: 'one',
to: '/one',
}, {
name: 'two',
to: '/two',
}]}
current='three'
/>
</MemoryRouter>,
)
expect(node.innerHTML).toMatch(/href="\/one"/)
expect(node.innerHTML).toMatch(/href="\/two"/)
expect(node.innerHTML).toMatch(/three/)
})
})
})

View File

@ -0,0 +1,28 @@
import React from 'react'
import {Breadcrumb, BreadcrumbItem} from 'bloomer'
import {Link} from 'react-router-dom'
export interface IBreadcrumbsProps {
links: Array<{
name: string
to: string
}>
current: string
}
export class Breadcrumbs extends React.PureComponent<IBreadcrumbsProps> {
render() {
return (
<Breadcrumb>
<ul>
{this.props.links.map((link, i) => (
<BreadcrumbItem key={i}>
<Link to={link.to}>{link.name}</Link>
</BreadcrumbItem>
))}
<BreadcrumbItem>{this.props.current}</BreadcrumbItem>
</ul>
</Breadcrumb>
)
}
}

View File

@ -0,0 +1 @@
export * from './Breadcrumbs'