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

Adds custom breadcrumb component #19

Merged
merged 3 commits into from
Sep 6, 2019
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
45 changes: 45 additions & 0 deletions packages/components/Breadcrumb/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import PropTypes from 'prop-types';
import Breadcrumb from 'react-bootstrap/Breadcrumb';
import { LinkContainer } from 'react-router-bootstrap';

const CustomBreadcrumb = (props) => {

const breadcrumbs = props.items.map((item) => {
if (item.link) {
return (
<LinkContainer key={ item.name } to={ item.link }>
<Breadcrumb.Item>{item.name}</Breadcrumb.Item>
</LinkContainer>
);
} else {
return (
<Breadcrumb.Item key={ item.name } active>
{item.name}
</Breadcrumb.Item>
);
}
});

return (
<div>
<Breadcrumb>
{breadcrumbs}
</Breadcrumb>
</div>
);
};

CustomBreadcrumb.propTypes = {
items: PropTypes.list,
};

CustomBreadcrumb.defaultProps = {
items: [ {
name: 'Projects',
link: '/projects',
}, {
name: 'Sample Project Name'
} ] };

export default CustomBreadcrumb;
49 changes: 49 additions & 0 deletions packages/components/Breadcrumb/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import StoryRouter from 'storybook-react-router';
import Breadcrumb from '../index.js';

export const breadcrumbItems = {
projects: [ {
name: 'Projects',
link: '/projects',
}, {
name: 'Example project name'
} ], paperEdits: [ {
allishultes marked this conversation as resolved.
Show resolved Hide resolved
name: 'Projects',
link: '/projects'
},
{
name: 'Project: The Sample',
link: '/projects/the-sample'
},
{
name: 'PaperEdits',
},
{
name: 'Example programme title'
}
]
};
allishultes marked this conversation as resolved.
Show resolved Hide resolved

storiesOf('Breadcrumb', module)
.addDecorator(StoryRouter())
.add('Projects', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<Breadcrumb
items = { breadcrumbItems.projects }
/>
</section>
);
})
.add('Paper Edits', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<Breadcrumb
items={ breadcrumbItems.paperEdits }
/>
</section>

);
});