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.
Merge pull request react-bootstrap#1358 from AlexKVal/liftup
v0.26-rc liftup
- Loading branch information
Showing
12 changed files
with
357 additions
and
2 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "iojs" | ||
- 4 | ||
cache: | ||
directories: | ||
- node_modules | ||
|
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 active> | ||
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,39 @@ | ||
import React, { cloneElement } from 'react'; | ||
import classNames from 'classnames'; | ||
import ValidComponentChildren from './utils/ValidComponentChildren'; | ||
|
||
const Breadcrumb = React.createClass({ | ||
propTypes: { | ||
/** | ||
* bootstrap className | ||
* @private | ||
*/ | ||
bsClass: React.PropTypes.string | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
bsClass: 'breadcrumb' | ||
}; | ||
}, | ||
|
||
render() { | ||
const { className, ...props } = this.props; | ||
|
||
return ( | ||
<ol | ||
{...props} | ||
role="navigation" | ||
aria-label="breadcrumbs" | ||
className={classNames(className, this.props.bsClass)}> | ||
{ValidComponentChildren.map(this.props.children, this.renderBreadcrumbItem)} | ||
</ol> | ||
); | ||
}, | ||
|
||
renderBreadcrumbItem(child, index) { | ||
return cloneElement( child, { key: child.key ? child.key : index } ); | ||
} | ||
}); | ||
|
||
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,83 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import SafeAnchor from './SafeAnchor'; | ||
import warning from 'react/lib/warning'; | ||
|
||
const BreadcrumbItem = React.createClass({ | ||
propTypes: { | ||
/** | ||
* If set to true, renders `span` instead of `a` | ||
*/ | ||
active: React.PropTypes.bool, | ||
/** | ||
* HTML id for the wrapper `li` element | ||
*/ | ||
id: React.PropTypes.oneOfType([ | ||
React.PropTypes.string, | ||
React.PropTypes.number | ||
]), | ||
/** | ||
* HTML id for the inner `a` element | ||
*/ | ||
linkId: React.PropTypes.oneOfType([ | ||
React.PropTypes.string, | ||
React.PropTypes.number | ||
]), | ||
/** | ||
* `href` attribute for the inner `a` element | ||
*/ | ||
href: React.PropTypes.string, | ||
/** | ||
* `title` attribute for the inner `a` element | ||
*/ | ||
title: React.PropTypes.node, | ||
/** | ||
* `target` attribute for the inner `a` element | ||
*/ | ||
target: React.PropTypes.string | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
active: false, | ||
}; | ||
}, | ||
|
||
render() { | ||
const { | ||
active, | ||
className, | ||
id, | ||
linkId, | ||
children, | ||
href, | ||
title, | ||
target, | ||
...props } = this.props; | ||
|
||
warning(!(href && active), '[react-bootstrap] `href` and `active` properties cannot be set at the same time'); | ||
|
||
const linkProps = { | ||
href, | ||
title, | ||
target, | ||
id: linkId | ||
}; | ||
|
||
return ( | ||
<li id={id} className={classNames(className, { active })}> | ||
{ | ||
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,140 @@ | ||
import React from 'react'; | ||
import ReactTestUtils from 'react/lib/ReactTestUtils'; | ||
import BreadcrumbItem from '../src/BreadcrumbItem'; | ||
import { shouldWarn } from './helpers'; | ||
|
||
describe('BreadcrumbItem', () => { | ||
it('Should warn if `active` and `href` attributes set', () => { | ||
ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#' active> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
shouldWarn('[react-bootstrap] `href` and `active` properties cannot be set at the same time'); | ||
}); | ||
|
||
it('Should render `a` as inner element when is not active', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#'> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.notInclude(React.findDOMNode(instance).className, 'active'); | ||
}); | ||
|
||
it('Should add `active` class with `active` attribute set.', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem active> | ||
Active Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
assert.include(React.findDOMNode(instance).className, 'active'); | ||
}); | ||
|
||
it('Should render `span` as inner element when is active', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem active> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span')); | ||
}); | ||
|
||
it('Should add custom classes onto `li` wrapper element', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem className="custom-one custom-two"> | ||
Active Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
const classes = React.findDOMNode(instance).className; | ||
assert.include(classes, 'custom-one'); | ||
assert.include(classes, 'custom-two'); | ||
}); | ||
|
||
it('Should spread additional props onto inner element', (done) => { | ||
const handleClick = () => { | ||
done(); | ||
}; | ||
|
||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#' onClick={handleClick}> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
const anchorNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'); | ||
ReactTestUtils.Simulate.click(anchorNode); | ||
}); | ||
|
||
it('Should apply id onto `li` wrapper element via `id` property', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#' id='test-li-id'> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
assert.equal(React.findDOMNode(instance).id, 'test-li-id'); | ||
}); | ||
|
||
it('Should apply id onto `a` inner alement via `linkId` property', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='#' linkId='test-link-id'> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.id, 'test-link-id'); | ||
}); | ||
|
||
it('Should apply `href` property onto `a` inner element', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem href='http://getbootstrap.com/components/#breadcrumbs'> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.href, 'http://getbootstrap.com/components/#breadcrumbs'); | ||
}); | ||
|
||
it('Should apply `title` property onto `a` inner element', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem title='test-title' href='http://getbootstrap.com/components/#breadcrumbs'> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.title, 'test-title'); | ||
}); | ||
|
||
it('Should not apply properties for inner `anchor` onto `li` wrapper element', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem title='test-title' href='/hi'> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
const liNode = React.findDOMNode(instance); | ||
assert.notOk(liNode.hasAttribute('href')); | ||
assert.notOk(liNode.hasAttribute('title')); | ||
}); | ||
|
||
it('Should set `target` attribute on `anchor`', () => { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<BreadcrumbItem target='_blank' href='http://getbootstrap.com/components/#breadcrumbs'> | ||
Crumb | ||
</BreadcrumbItem> | ||
); | ||
|
||
const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); | ||
assert.equal(linkNode.target, '_blank'); | ||
}); | ||
}); |
Oops, something went wrong.