li.js 655 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 (
  17. (this.props.className || "") +
  18. " " +
  19. (this.props.activeClassName || "active")
  20. )
  21. } else {
  22. return this.props.className || ""
  23. }
  24. }
  25. render() {
  26. return <li className={this.getClassName()}>{this.props.children}</li>
  27. }
  28. }