Source

components/SideNav/SideNavLink/SideNavLink.js

  1. // NPM module imports
  2. import React from "react";
  3. import PropTypes from "prop-types";
  4. import { Link } from "react-router-dom";
  5. // Style imports
  6. import styles from "./SideNavLink.module.scss";
  7. /**
  8. * Renders the SideNavLink component
  9. * @component
  10. * @category SideNav
  11. * @author Dan Levy <danlevy124@gmail.com>
  12. */
  13. // TODO: This component should be split into a two components: (1) side nav link and (2) side nav sign out link
  14. const SideNavLink = (props) => {
  15. // The component to render
  16. let component;
  17. if (props.isSignOutLink) {
  18. // Sets component to the sign out version of SideNavLink
  19. component = (
  20. <button
  21. className={`${styles.sideNavLink} ${styles.sideNavLinkSignOut}`}
  22. type="button"
  23. onClick={props.onClick}
  24. >
  25. {/* Tab icon */}
  26. <img
  27. className={styles.sideNavLinkIcon}
  28. src={props.icon}
  29. alt={props.name + " Icon"}
  30. />
  31. {/* Tab name */}
  32. <h3
  33. className={`${styles.sideNavLinkName} ${styles.sideNavLinkNameWhiteText}`}
  34. >
  35. {props.name}
  36. </h3>
  37. </button>
  38. );
  39. } else {
  40. const currentTabStyle = props.isCurrentTab
  41. ? styles.sideNavLinkCurrentTab
  42. : "";
  43. const textColorStyle = props.isCurrentTab
  44. ? styles.sideNavLinkNameBlueText
  45. : styles.sideNavLinkNameWhiteText;
  46. // Sets component to the regular version of SideNavLink
  47. component = (
  48. <Link
  49. className={`${styles.sideNavLink} ${currentTabStyle}`}
  50. to={props.route}
  51. onClick={props.onClick}
  52. >
  53. {/* Tab icon */}
  54. <img
  55. className={styles.sideNavLinkIcon}
  56. src={props.icon}
  57. alt={props.name + " Icon"}
  58. />
  59. {/* Tab name */}
  60. <h3 className={`${styles.sideNavLinkName} ${textColorStyle}`}>
  61. {props.name}
  62. </h3>
  63. </Link>
  64. );
  65. }
  66. // Returns the JSX to render
  67. return component;
  68. };
  69. // Prop types for the SideNavLink component
  70. SideNavLink.propTypes = {
  71. /**
  72. * Indicates if the tab is the currently selected tab
  73. */
  74. isCurrentTab: PropTypes.bool,
  75. /**
  76. * The tab name
  77. */
  78. name: PropTypes.string.isRequired,
  79. /**
  80. * The tab icon
  81. */
  82. icon: PropTypes.string.isRequired,
  83. /**
  84. * Where to route if the tab is clicked on
  85. */
  86. route: PropTypes.string,
  87. /**
  88. * Click handler
  89. */
  90. onClick: PropTypes.func.isRequired,
  91. /**
  92. * Indicates if the link is a sign out link
  93. */
  94. isSignOutLink: PropTypes.bool.isRequired,
  95. };
  96. export default SideNavLink;