-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(breadcrumb): Add Breadcrumb and BreadcrumbItem
- Loading branch information
1 parent
1adcf67
commit d34d738
Showing
11 changed files
with
231 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */ | ||
import React from 'react'; | ||
import { PrismCode } from 'react-prism'; | ||
import Helmet from 'react-helmet'; | ||
|
||
import BreadcrumbExample from '../examples/Breadcrumb'; | ||
const BreadcrumbExampleSource = require('!!raw!../examples/Breadcrumb.jsx'); | ||
|
||
import BreadcrumbNoListExample from '../examples/BreadcrumbNoList'; | ||
const BreadcrumbNoListExampleSource = require('!!raw!../examples/BreadcrumbNoList.jsx'); | ||
|
||
export default class BreadcrumbsPage extends React.Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Helmet title="Breadcrumbs" /> | ||
<h3>Breadcrumbs</h3> | ||
<div className="docs-example"> | ||
<BreadcrumbExample /> | ||
</div> | ||
<pre> | ||
<PrismCode className="language-jsx"> | ||
{BreadcrumbExampleSource} | ||
</PrismCode> | ||
</pre> | ||
<h3>No list</h3> | ||
<hr /> | ||
<p>Breadcrumbs can work without the usage of list markup.</p> | ||
<div className="docs-example"> | ||
<BreadcrumbNoListExample /> | ||
</div> | ||
<pre> | ||
<PrismCode className="language-jsx"> | ||
{BreadcrumbNoListExampleSource} | ||
</PrismCode> | ||
</pre> | ||
</div> | ||
); | ||
} | ||
} |
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,23 @@ | ||
import React from 'react'; | ||
import { Breadcrumb, BreadcrumbItem } from 'reactstrap'; | ||
|
||
const Example = (props) => { | ||
return ( | ||
<div> | ||
<Breadcrumb> | ||
<BreadcrumbItem active>Home</BreadcrumbItem> | ||
</Breadcrumb> | ||
<Breadcrumb> | ||
<BreadcrumbItem><a href="#">Home</a></BreadcrumbItem> | ||
<BreadcrumbItem active>Library</BreadcrumbItem> | ||
</Breadcrumb> | ||
<Breadcrumb> | ||
<BreadcrumbItem><a href="#">Home</a></BreadcrumbItem> | ||
<BreadcrumbItem><a href="#">Library</a></BreadcrumbItem> | ||
<BreadcrumbItem active>Data</BreadcrumbItem> | ||
</Breadcrumb> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Example; |
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 { Breadcrumb, BreadcrumbItem } from 'reactstrap'; | ||
|
||
const Example = (props) => { | ||
return ( | ||
<div> | ||
<Breadcrumb tag="nav"> | ||
<BreadcrumbItem tag="a" href="#">Home</BreadcrumbItem> | ||
<BreadcrumbItem tag="a" href="#">Library</BreadcrumbItem> | ||
<BreadcrumbItem tag="a" href="#">Data</BreadcrumbItem> | ||
<BreadcrumbItem active tag="span">Bootstrap</BreadcrumbItem> | ||
</Breadcrumb> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Example; |
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,33 @@ | ||
import React, { PropTypes } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
const propTypes = { | ||
tag: PropTypes.string, | ||
|
||
className: PropTypes.any | ||
}; | ||
|
||
const defaultProps = { | ||
tag: 'ol' | ||
}; | ||
|
||
const Breadcrumb = (props) => { | ||
const { | ||
className, | ||
tag: Tag, | ||
...attributes | ||
} = props; | ||
const classes = classNames( | ||
className, | ||
'breadcrumb' | ||
); | ||
|
||
return ( | ||
<Tag {...attributes} className={classes} /> | ||
); | ||
}; | ||
|
||
Breadcrumb.propTypes = propTypes; | ||
Breadcrumb.defaultProps = defaultProps; | ||
|
||
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,35 @@ | ||
import React, { PropTypes } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
const propTypes = { | ||
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), | ||
active: PropTypes.string, | ||
className: PropTypes.any | ||
}; | ||
|
||
const defaultProps = { | ||
tag: 'li' | ||
}; | ||
|
||
const BreadcrumbItem = (props) => { | ||
const { | ||
className, | ||
active, | ||
tag: Tag, | ||
...attributes | ||
} = props; | ||
const classes = classNames( | ||
className, | ||
active ? 'active' : false, | ||
'breadcrumb-item' | ||
); | ||
|
||
return ( | ||
<Tag {...attributes} className={classes} /> | ||
); | ||
}; | ||
|
||
BreadcrumbItem.propTypes = propTypes; | ||
BreadcrumbItem.defaultProps = defaultProps; | ||
|
||
export default BreadcrumbItem; |
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,30 @@ | ||
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { Breadcrumb } from 'reactstrap'; | ||
|
||
describe('Breadcrumb', () => { | ||
it('should render children', () => { | ||
const wrapper = shallow(<Breadcrumb>Yo!</Breadcrumb>); | ||
|
||
expect(wrapper.text()).toBe('Yo!'); | ||
}); | ||
|
||
it('should render "ol" by default', () => { | ||
const wrapper = shallow(<Breadcrumb>Yo!</Breadcrumb>); | ||
|
||
expect(wrapper.type()).toBe('ol'); | ||
}); | ||
|
||
it('should render with the "breadcrumb" class', () => { | ||
const wrapper = shallow(<Breadcrumb>Default Breadcrumb</Breadcrumb>); | ||
|
||
expect(wrapper.hasClass('breadcrumb')).toBe(true); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = shallow(<Breadcrumb tag="main">Yo!</Breadcrumb>); | ||
|
||
expect(wrapper.type()).toBe('main'); | ||
}); | ||
}); |
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 @@ | ||
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { BreadcrumbItem } from 'reactstrap'; | ||
|
||
describe('BreadcrumbItem', () => { | ||
it('should render children', () => { | ||
const wrapper = shallow(<BreadcrumbItem>Yo!</BreadcrumbItem>); | ||
|
||
expect(wrapper.text()).toBe('Yo!'); | ||
}); | ||
|
||
it('should render "li" by default', () => { | ||
const wrapper = shallow(<BreadcrumbItem>Yo!</BreadcrumbItem>); | ||
|
||
expect(wrapper.type()).toBe('li'); | ||
}); | ||
|
||
it('should render with the "breadcrumb-item" class', () => { | ||
const wrapper = shallow(<BreadcrumbItem>Default BreadcrumbItem</BreadcrumbItem>); | ||
|
||
expect(wrapper.hasClass('breadcrumb-item')).toBe(true); | ||
}); | ||
|
||
it('should not render with the "active" class by default', () => { | ||
const wrapper = shallow(<BreadcrumbItem>Default BreadcrumbItem</BreadcrumbItem>); | ||
|
||
expect(wrapper.hasClass('active')).toBe(false); | ||
}); | ||
|
||
it('should render with the "active" class when the avtive prop is truthy', () => { | ||
const wrapper = shallow(<BreadcrumbItem active>Default BreadcrumbItem</BreadcrumbItem>); | ||
|
||
expect(wrapper.hasClass('active')).toBe(true); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = shallow(<BreadcrumbItem tag="main">Yo!</BreadcrumbItem>); | ||
|
||
expect(wrapper.type()).toBe('main'); | ||
}); | ||
}); |
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