li.js 690 B

12345678910111213141516171819202122232425262728293031
  1. import React from 'react';
  2. export default class extends React.Component {
  3. isActive() {
  4. if (this.props.isControlled) {
  5. return this.props.isActive;
  6. } else {
  7. if (this.props.path) {
  8. return document.location.pathname.indexOf(this.props.path) === 0;
  9. } else {
  10. return false;
  11. }
  12. }
  13. }
  14. getClassName() {
  15. if (this.isActive()) {
  16. return (this.props.className || '') + ' '+ (this.props.activeClassName || 'active');
  17. } else {
  18. return this.props.className || '';
  19. }
  20. }
  21. render() {
  22. // jshint ignore:start
  23. return <li className={this.getClassName()}>
  24. {this.props.children}
  25. </li>;
  26. // jshint ignore:end
  27. }
  28. }