Nav.svelte 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <script lang="typescript">
  2. import { faBars } from "@fortawesome/free-solid-svg-icons";
  3. import Icon from "svelte-awesome/components/Icon.svelte";
  4. interface RouteDefinition {
  5. route: string;
  6. moderatorOnly: boolean;
  7. name: string;
  8. }
  9. export let routes!: RouteDefinition[];
  10. export let isModerator!: boolean;
  11. export let currentPath!: string;
  12. const bars = (faBars as unknown) as undefined;
  13. let showMenu = false;
  14. </script>
  15. <style>
  16. nav {
  17. @apply fixed w-screen z-10;
  18. }
  19. .nav-bar {
  20. @apply shadow-lg flex flex-col;
  21. background-color: #0a0d13;
  22. &.main {
  23. background-color: #07090d;
  24. }
  25. &.mobile-menu {
  26. @apply flex-row;
  27. }
  28. a {
  29. @apply text-white px-5 py-3;
  30. &:hover {
  31. @apply bg-gray-800 cursor-pointer;
  32. }
  33. &.active {
  34. @apply bg-gray-800;
  35. }
  36. }
  37. }
  38. .hide-menu {
  39. display: none;
  40. }
  41. .divider {
  42. @apply mx-0 my-2;
  43. }
  44. :global {
  45. svg.menu-icon {
  46. vertical-align: sub;
  47. }
  48. }
  49. @screen sm {
  50. .nav-bar.main {
  51. @apply px-4 h-12 flex-row items-center;
  52. background-color: #0a0d13;
  53. }
  54. .divider {
  55. @apply mx-auto my-0;
  56. }
  57. .nav-bar.mobile-menu {
  58. @apply hidden;
  59. }
  60. .hide-menu {
  61. display: flex;
  62. }
  63. }
  64. </style>
  65. <nav>
  66. <div class="nav-bar mobile-menu">
  67. <a href="/" class="mx-0" on:click|preventDefault={() => showMenu = !showMenu}><Icon data={bars} scale={1.2} class="menu-icon" /></a>
  68. </div>
  69. <div class="nav-bar main" class:hide-menu={!showMenu}>
  70. {#each routes as route (route.route)}
  71. {#if !route.moderatorOnly || (route.moderatorOnly && isModerator)}
  72. <a
  73. href="/{route.route}"
  74. class:active={route.route == currentPath} on:click={() => showMenu = false}>{route.name}</a>
  75. {/if}
  76. {/each}
  77. <span class="divider" />
  78. <a href="/logout">Log out</a>
  79. </div>
  80. </nav>