aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/LandingHeader.svelte
blob: c20c80a05159f28b557316859e4592efafac8496 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<script>
  import { goto } from "$app/navigation";
  import { scroll } from "$lib/utils";
  import { t } from "$lib/translations";
  import { page } from "$app/stores";

  import DarkToggle from "$comp/DarkToggle.svelte";
  import LocaleSelector from "$comp/LocaleSelector.svelte";

  let {
    howItWorks,
    faq,
    about,
    user
  } = $props();

  let showMobileMenu = $state(false);
  let header = $state();
  const mobileMenuButtonClick = (section) => {
    showMobileMenu = false;
    scroll(section);
  };
</script>

<header
  class="w-full lg:w-5/6 p-4 mx-auto fixed sticky z-10 top-0 bg-base-100"
  bind:this={header}
>
  <nav class="block lg:flex justify-between items-center">
    <div class="flex justify-start lg:justify-center items-center lg:space-x-5">
      <a href="/" onclick={() => scroll(header)}>
        <iconify-icon icon="coinos:logo" width="224"></iconify-icon>
      </a>
    </div>

    <!-- desktop nav -->
    <div class="hidden space-x-5 lg:flex justify-center items-center font-bold">
      {#if $page.url.pathname === "/"}
        <button class="hover:opacity-80" onclick={() => scroll(howItWorks)}
          >{$t("howItWorks.header")}</button
        >
        <button class="hover:opacity-80" onclick={() => scroll(faq)}
          >{$t("faq.header")}</button
        >
        <button class="hover:opacity-80" onclick={() => scroll(about)}
          >{$t("about.header")}</button
        >
      {/if}
      {#if user}
        <button
          class="btn !w-auto !rounded-full"
          onclick={() => goto(`/${user.username}`)}
          >Home
        </button>
        <button
          class="btn !w-auto !rounded-full"
          onclick={() => goto("/logout")}
        >
          {$t("nav.signOut")}
        </button>
      {:else}
        <button
          class="btn btn-accent !w-auto !rounded-full"
          onclick={() => goto("/register")}
          >{$t("nav.register")}
        </button>
        <button
          class="btn !w-auto !rounded-full"
          onclick={() => goto("/login")}
        >
          {$t("nav.signIn")}
        </button>
      {/if}
    </div>

    <button
      class="block lg:hidden absolute top-[34.5px] right-10 z"
      onclick={() => (showMobileMenu = !showMobileMenu)}
    >
      <iconify-icon
        icon={!showMobileMenu ? "ph:list-bold" : "ph:x-bold"}
        width="32"
></iconify-icon>
    </button>

    <div
      class="container w-full p-10 lg:hidden absolute top-0 {showMobileMenu
        ? 'right-0'
        : 'right-[-100%]'} transition-all ease-in-out duration-300 h-[100vh] w-full bg-base-100"
    >
      <div class="space-y-5 mt-24 font-bold text-xl">
        <LocaleSelector />
        <DarkToggle />
        <button onclick={() => mobileMenuButtonClick(howItWorks)} class="block"
          >{$t("howItWorks.header")}</button
        >
        <button onclick={() => mobileMenuButtonClick(faq)} class="block"
          >{$t("faq.header")}</button
        >
        <button onclick={() => mobileMenuButtonClick(about)} class="block"
          >{$t("about.header")}</button
        >
        {#if !user}
          <button class="btn btn-accent" onclick={() => goto("/register")}
            >{$t("nav.register")}
          </button>
          <button class="btn" onclick={() => goto("/login")}>
            {$t("nav.signIn")}
          </button>
        {:else}
          <button
            class="border rounded-full px-6 py-2 font-bold block"
            onclick={() => goto(`/${user.username}`)}
            >{$t("nav.account")}
          </button>
          <button
            class="bg-primary text-white border rounded-full px-6 py-2 font-bold block"
            onclick={() => goto("/logout")}
          >
            {$t("nav.signOut")}
          </button>
        {/if}
      </div>
    </div>
  </nav>
</header>

<style>
  .z {
    z-index: 100;
  }
</style>