diff --git a/src/components/Breadcrumbs/Breadcrumbs.md b/src/components/Breadcrumbs/Breadcrumbs.md new file mode 100644 index 00000000..31459631 --- /dev/null +++ b/src/components/Breadcrumbs/Breadcrumbs.md @@ -0,0 +1,25 @@ +A navigation component that indicates the user's current location in the nav hierarchy. + +View the [Rivet documentation for Breadcrumbs](https://rivet.uits.iu.edu/components/navigation/breadcrumb/). + +### Default breadcrumb + +```jsx + + Home + Files + my-file.txt + +``` + +### Callout example + +There is also a call-out modifier class that adds a small amount of padding and a light gray background. This is useful for when you need to draw more attention to the breadcrumb. + +```jsx + + Home + Files + my-file.txt + +``` diff --git a/src/components/Breadcrumbs/Breadcrumbs.test.tsx b/src/components/Breadcrumbs/Breadcrumbs.test.tsx new file mode 100644 index 00000000..cf1fd38c --- /dev/null +++ b/src/components/Breadcrumbs/Breadcrumbs.test.tsx @@ -0,0 +1,46 @@ + +import { mount } from 'enzyme'; +import * as React from 'react'; +import Breadcrumbs from './Breadcrumbs'; + +describe('', () => { + + describe('Rendering and text', ()=>{ + it('should render without throwing an error', () => { + const cut = mount(); + expect(cut.find('nav > ol.rvt-breadcrumbs')).toHaveLength(1); + }); + it('should take an id', () => { + const cut = mount(); + expect(cut.find('nav#the_id')).toHaveLength(1); + }); + it('should show text children', () => { + const cut = mount(The text); + expect(cut.find('nav > ol.rvt-breadcrumbs > li').text()).toEqual("The text"); + }); + it('should wrap multiple children in list items', () => { + const cut = mount( + + Link One + Link Two + ); + expect(cut.find('nav > ol.rvt-breadcrumbs > li').length).toEqual(2); + }); + it('should mark the last child as the current page', () => { + const cut = mount( + + Link One + Link Two + ); + expect(cut.find('nav > ol.rvt-breadcrumbs > li').last().prop('aria-current')).toEqual('page'); + }); + }) + + describe('Styling', ()=>{ + it('should have call-out style', () => { + const cut = mount(); + expect(cut.find('nav > ol.rvt-breadcrumbs').hasClass("rvt-breadcrumbs--call-out")).toEqual(true); + }); + }); + +}); diff --git a/src/components/Breadcrumbs/Breadcrumbs.tsx b/src/components/Breadcrumbs/Breadcrumbs.tsx new file mode 100644 index 00000000..eab0c0e9 --- /dev/null +++ b/src/components/Breadcrumbs/Breadcrumbs.tsx @@ -0,0 +1,30 @@ +import * as classNames from 'classnames'; +import * as React from 'react'; +import * as Rivet from '../util/Rivet'; + +export interface BreadcrumbsProps { + /** + * Optional Rivet style: A call-out styled set of breadcrumbs. + */ + variant?: 'call-out' +} + +const Breadcrumbs: React.SFC> = + ({ children, variant, ...attrs }) => { + const childCount = React.Children.count(children); + const breadcrumbLinks = React.Children.map(children, (child, index) => (index === (childCount - 1)) ?
  • {child}
  • :
  • {child}
  • ); + const classes = classNames({ + ['rvt-breadcrumbs']: true, + [`rvt-breadcrumbs--${variant}`]: variant + }); + return ( + + ); + }; +Breadcrumbs.displayName = 'Breadcrumbs'; + +export default Rivet.rivetize(Breadcrumbs); diff --git a/src/components/Breadcrumbs/index.ts b/src/components/Breadcrumbs/index.ts new file mode 100644 index 00000000..0835ba0b --- /dev/null +++ b/src/components/Breadcrumbs/index.ts @@ -0,0 +1 @@ +export { default as Breadcrumbs } from './Breadcrumbs'; diff --git a/src/components/index.tsx b/src/components/index.tsx index 8122a89d..7f4e1b36 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -1,5 +1,6 @@ export * from './Alert'; export * from './Badge'; +export * from './Breadcrumbs'; export * from './Button'; export * from './Checkbox'; export * from './Dropdown'; diff --git a/styleguide.config.js b/styleguide.config.js index 8f2e9d10..c4e528bf 100644 --- a/styleguide.config.js +++ b/styleguide.config.js @@ -76,7 +76,8 @@ module.exports = { { name: 'Navigation', components: () => [ - 'src/components/Dropdown/*.tsx', + 'src/components/Breadcrumbs/*.tsx', + 'src/components/Dropdown/*.tsx', 'src/components/Footer/*.tsx', 'src/components/Header/Header.tsx', 'src/components/Header/HeaderIdentity.tsx',