|
| 1 | +import React from 'react'; |
| 2 | +import classNames from 'classnames'; |
| 3 | +import SafeAnchor from './SafeAnchor'; |
| 4 | +import warning from 'react/lib/warning'; |
| 5 | + |
| 6 | +const BreadcrumbItem = React.createClass({ |
| 7 | + propTypes: { |
| 8 | + /** |
| 9 | + * If set to true, renders `span` instead of `a` |
| 10 | + */ |
| 11 | + active: React.PropTypes.bool, |
| 12 | + /** |
| 13 | + * HTML id for the wrapper `li` element |
| 14 | + */ |
| 15 | + id: React.PropTypes.oneOfType([ |
| 16 | + React.PropTypes.string, |
| 17 | + React.PropTypes.number |
| 18 | + ]), |
| 19 | + /** |
| 20 | + * HTML id for the inner `a` element |
| 21 | + */ |
| 22 | + linkId: React.PropTypes.oneOfType([ |
| 23 | + React.PropTypes.string, |
| 24 | + React.PropTypes.number |
| 25 | + ]), |
| 26 | + /** |
| 27 | + * `href` attribute for the inner `a` element |
| 28 | + */ |
| 29 | + href: React.PropTypes.string, |
| 30 | + /** |
| 31 | + * `title` attribute for the inner `a` element |
| 32 | + */ |
| 33 | + title: React.PropTypes.node, |
| 34 | + /** |
| 35 | + * `target` attribute for the inner `a` element |
| 36 | + */ |
| 37 | + target: React.PropTypes.string |
| 38 | + }, |
| 39 | + |
| 40 | + getDefaultProps() { |
| 41 | + return { |
| 42 | + active: false, |
| 43 | + }; |
| 44 | + }, |
| 45 | + |
| 46 | + render() { |
| 47 | + const { |
| 48 | + active, |
| 49 | + className, |
| 50 | + id, |
| 51 | + linkId, |
| 52 | + children, |
| 53 | + href, |
| 54 | + title, |
| 55 | + target, |
| 56 | + ...props } = this.props; |
| 57 | + |
| 58 | + warning(!(href && active), '[react-bootstrap] `href` and `active` properties cannot be set at the same time'); |
| 59 | + |
| 60 | + const linkProps = { |
| 61 | + href, |
| 62 | + title, |
| 63 | + target, |
| 64 | + id: linkId |
| 65 | + }; |
| 66 | + |
| 67 | + return ( |
| 68 | + <li id={id} className={classNames(className, { active })}> |
| 69 | + { |
| 70 | + active ? |
| 71 | + <span {...props}> |
| 72 | + { children } |
| 73 | + </span> : |
| 74 | + <SafeAnchor {...props} {...linkProps}> |
| 75 | + { children } |
| 76 | + </SafeAnchor> |
| 77 | + } |
| 78 | + </li> |
| 79 | + ); |
| 80 | + } |
| 81 | +}); |
| 82 | + |
| 83 | +export default BreadcrumbItem; |
0 commit comments