Sidebar.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { h } from 'preact';
  2. import Link from './components/Link';
  3. import { Link as RouterLink } from 'preact-router/match';
  4. import { useCallback, useState } from 'preact/hooks';
  5. function HamburgerIcon() {
  6. return (
  7. <svg fill="currentColor" viewBox="0 0 20 20" className="w-6 h-6">
  8. <path
  9. fill-rule="evenodd"
  10. d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z"
  11. clip-rule="evenodd"
  12. ></path>
  13. </svg>
  14. );
  15. }
  16. function CloseIcon() {
  17. return (
  18. <svg fill="currentColor" viewBox="0 0 20 20" className="w-6 h-6">
  19. <path
  20. fill-rule="evenodd"
  21. d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
  22. clip-rule="evenodd"
  23. ></path>
  24. </svg>
  25. );
  26. }
  27. function NavLink({ className = '', href, text }) {
  28. const external = href.startsWith('http');
  29. const El = external ? Link : RouterLink;
  30. const props = external ? { rel: 'noopener nofollow', target: '_blank' } : {};
  31. return (
  32. <El
  33. activeClassName="bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 dark:focus:bg-gray-600 dark:focus:text-white dark:hover:text-white dark:text-gray-200"
  34. className={`block px-4 py-2 mt-2 text-sm font-semibold text-gray-900 bg-transparent rounded-lg dark:bg-transparent dark:hover:bg-gray-600 dark:focus:bg-gray-600 dark:focus:text-white dark:hover:text-white dark:text-gray-200 hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline self-end ${className}`}
  35. href={href}
  36. {...props}
  37. >
  38. {text}
  39. </El>
  40. );
  41. }
  42. export default function Sidebar() {
  43. const [open, setOpen] = useState(false);
  44. const handleToggle = useCallback(() => {
  45. setOpen(!open);
  46. }, [open, setOpen]);
  47. return (
  48. <div className="flex flex-col w-full md:w-64 text-gray-700 bg-white dark:text-gray-200 dark:bg-gray-700 flex-shrink-0">
  49. <div className="flex-shrink-0 px-8 py-4 flex flex-row items-center justify-between">
  50. <a
  51. href="#"
  52. className="text-lg font-semibold tracking-widest text-gray-900 uppercase rounded-lg dark:text-white focus:outline-none focus:shadow-outline"
  53. >
  54. Frigate
  55. </a>
  56. <button
  57. className="rounded-lg md:hidden rounded-lg focus:outline-none focus:shadow-outline"
  58. onClick={handleToggle}
  59. >
  60. {open ? <CloseIcon /> : <HamburgerIcon />}
  61. </button>
  62. </div>
  63. <nav
  64. className={`flex-col flex-grow md:block overflow-hidden px-4 pb-4 md:pb-0 md:overflow-y-auto ${
  65. !open ? 'md:h-0 hidden' : ''
  66. }`}
  67. >
  68. <NavLink href="/" text="Cameras" />
  69. <NavLink href="/events" text="Events" />
  70. <NavLink href="/debug" text="Debug" />
  71. <hr className="border-solid border-gray-500 mt-2" />
  72. <NavLink
  73. className="self-end"
  74. href="https://github.com/blakeblackshear/frigate/blob/master/README.md"
  75. text="Documentation"
  76. />
  77. <NavLink className="self-end" href="https://github.com/blakeblackshear/frigate" text="GitHub" />
  78. </nav>
  79. </div>
  80. );
  81. }