forked from react-bootstrap/react-bootstrap
-
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
11 changed files
with
396 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
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,15 @@ | ||
const breadcrumbInstance = ( | ||
<Breadcrumb> | ||
<BreadcrumbItem href="#"> | ||
Home | ||
</BreadcrumbItem> | ||
<BreadcrumbItem href="http://getbootstrap.com/components/#breadcrumbs"> | ||
Library | ||
</BreadcrumbItem> | ||
<BreadcrumbItem> | ||
Data | ||
</BreadcrumbItem> | ||
</Breadcrumb> | ||
); | ||
|
||
React.render(breadcrumbInstance, mountNode); |
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
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,37 @@ | ||
import React, { cloneElement } from 'react'; | ||
import classNames from 'classnames'; | ||
import BootstrapMixin from './BootstrapMixin'; | ||
import ValidComponentChildren from './utils/ValidComponentChildren'; | ||
|
||
const Breadcrumb = React.createClass({ | ||
mixins: [BootstrapMixin], | ||
|
||
getDefaultProps() { | ||
return { | ||
bsClass: 'breadcrumb' | ||
}; | ||
}, | ||
|
||
render() { | ||
const classes = this.getBsClassSet(); | ||
const { className, ...props } = this.props; | ||
|
||
return ( | ||
<ol {...props} role="navigation" aria-label="breadcrumbs" className={classNames(className, classes)}> | ||
{ValidComponentChildren.map(this.props.children, this.renderBreadcrumbItem)} | ||
</ol> | ||
); | ||
}, | ||
|
||
renderBreadcrumbItem(child, index) { | ||
return cloneElement( | ||
child, | ||
{ | ||
key: child.key ? child.key : index, | ||
navItem: true | ||
} | ||
); | ||
} | ||
}); | ||
|
||
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,61 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import BootstrapMixin from './BootstrapMixin'; | ||
import SafeAnchor from './SafeAnchor'; | ||
import warning from 'react/lib/warning'; | ||
|
||
const BreadcrumbItem = React.createClass({ | ||
mixins: [BootstrapMixin], | ||
|
||
propTypes: { | ||
id: React.PropTypes.string, | ||
active: React.PropTypes.bool, | ||
linkId: React.PropTypes.string, | ||
href: React.PropTypes.string, | ||
title: React.PropTypes.node, | ||
target: React.PropTypes.string | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
active: false, | ||
}; | ||
}, | ||
|
||
render() { | ||
warning(!(this.props.href && this.props.active), '[react-bootstrap] href and active properties cannot be set at the same time'); | ||
|
||
const { | ||
id, | ||
active, | ||
linkId, | ||
children, | ||
href, | ||
title, | ||
target, | ||
...props } = this.props; | ||
const classes = { active }; | ||
const linkProps = { | ||
href, | ||
title, | ||
target, | ||
id: linkId | ||
}; | ||
|
||
return ( | ||
<li id={id} className={classNames(props.className, classes)}> | ||
{ | ||
active ? | ||
<span {...props}> | ||
{ children } | ||
</span> : | ||
<SafeAnchor {...props} {...linkProps}> | ||
{ children } | ||
</SafeAnchor> | ||
} | ||
</li> | ||
); | ||
} | ||
}); | ||
|
||
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
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,137 @@ | ||
import React from 'react'; | ||
import ReactTestUtils from 'react/lib/ReactTestUtils'; | ||
import BreadcrumbItem from '../src/BreadcrumbItem'; | ||
|
||
describe('BreadcrumbItem', function () { | ||
it('Should add active class', function () { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem active> | ||
Active Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'active')); | ||
}); | ||
|
||
it('Should not add active class', function () { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
let liNode = React.findDOMNode(instance); | ||
assert.notInclude(liNode.className, 'active'); | ||
}); | ||
|
||
it('Should add custom classes', function () { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem className="custom-one custom-two" active> | ||
Active Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
let liNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'active')); | ||
|
||
let classes = liNode.className; | ||
assert.include(classes, 'active'); | ||
assert.include(classes, 'custom-one'); | ||
assert.include(classes, 'custom-two'); | ||
}); | ||
|
||
it('Should spread props onto an active item', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem herpa='derpa' active> | ||
Active Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
let spanNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span'); | ||
|
||
spanNode.props.herpa.should.equal('derpa'); | ||
}); | ||
|
||
it('Should spread props onto anchor', function(done) { | ||
const handleClick = () => { | ||
done(); | ||
}; | ||
|
||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#' onClick={handleClick} herpa='derpa'> | ||
Crumb 1 | ||
</BreadcrumbItem> | ||
); | ||
|
||
let anchorNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'); | ||
ReactTestUtils.Simulate.click(anchorNode); | ||
|
||
anchorNode.props.herpa.should.equal('derpa'); | ||
}); | ||
|
||
it('Should add id for li element', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#' id='test-li-id'> | ||
Crumb 1 | ||
</BreadcrumbItem> | ||
); | ||
|
||
let liNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'li')); | ||
assert.equal(liNode.id, 'test-li-id'); | ||
}); | ||
|
||
it('Should add linkId', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#' linkId='test-link-id'> | ||
Crumb 1 | ||
</BreadcrumbItem> | ||
); | ||
|
||
let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.id, 'test-link-id'); | ||
}); | ||
|
||
it('Should add href', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='http://getbootstrap.com/components/#breadcrumbs'> | ||
Crumb 1 | ||
</BreadcrumbItem> | ||
); | ||
|
||
let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.href, 'http://getbootstrap.com/components/#breadcrumbs'); | ||
}); | ||
|
||
it('Should have a title', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem title='test-title' href='http://getbootstrap.com/components/#breadcrumbs'> | ||
Crumb 1 | ||
</BreadcrumbItem> | ||
); | ||
|
||
let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.title, 'test-title'); | ||
}); | ||
|
||
it('Should not add anchor properties to li', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem title='test-title' href='/hi'> | ||
Crumb 1 | ||
</BreadcrumbItem> | ||
); | ||
|
||
let liNode = React.findDOMNode(instance); | ||
assert.notOk(liNode.hasAttribute('href')); | ||
assert.notOk(liNode.hasAttribute('title')); | ||
}); | ||
|
||
it('Should set target attribute on anchor', function () { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem target='_blank' href='http://getbootstrap.com/components/#breadcrumbs'> | ||
Crumb 1 | ||
</BreadcrumbItem> | ||
); | ||
|
||
let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.target, '_blank'); | ||
}); | ||
}); |
Oops, something went wrong.