aboutsummaryrefslogtreecommitdiff
path: root/src/partials/Header.astro
blob: 5fc80104f18f340f367240d8683c4717a8fd0a61 (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
---
import t from "../i18n/es.json";
---

<header>
  <div class="header-container">
    <div class="brand">
      <!-- Brand placeholder - you can replace this with a logo or name -->
      <a href="/" class="brand-link" aria-label="Ariel Costas Home">Ariel&ZeroWidthSpace;<span class="brand-accent">Costas</span></a>
    </div>

    <div class="mobile-toggle" id="mobile-toggle" aria-expanded="false" aria-controls="nav-links" aria-label="Toggle menu">
      <span class="bar"></span>
      <span class="bar"></span>
      <span class="bar"></span>
    </div>

    <nav class="nav-links" id="nav-links" aria-label="Main navigation">
      <a href="/">{t.header.home}</a>
      <a href="/blog/">{t.header.blog}</a>
      <a href="/contact/">{t.header.contact}</a>
    </nav>
  </div>
</header>

<script>
  // Wait for the DOM to be fully loaded
  document.addEventListener('DOMContentLoaded', () => {
    const mobileToggle = document.getElementById('mobile-toggle');
    const navLinks = document.getElementById('nav-links');

    // Toggle mobile menu
    mobileToggle?.addEventListener('click', () => {
      const isExpanded = mobileToggle.getAttribute('aria-expanded') === 'true';
      mobileToggle.setAttribute('aria-expanded', !isExpanded ? 'true' : 'false');
      mobileToggle.classList.toggle('active');
      navLinks?.classList.toggle('active');
    });

    // Handle Escape key to close menu
    document.addEventListener('keydown', (e) => {
      if (e.key === 'Escape' && navLinks?.classList.contains('active')) {
        mobileToggle?.classList.remove('active');
        navLinks.classList.remove('active');
        mobileToggle?.setAttribute('aria-expanded', 'false');
        mobileToggle?.focus();
      }
    });

    // Add active class to current page link
    const currentPath = window.location.pathname;
    const navItems = document.querySelectorAll('.nav-links a');
    navItems.forEach(item => {
      const href = item.getAttribute('href') ?? '';
      if (href === currentPath || (href !== '/' && currentPath.startsWith(href))) {
        item.classList.add('active');
        item.setAttribute('aria-current', 'page');
      }
    });
  });
</script>

<style lang="scss">
  @use "../../styles/variables" as *;

  header {
    color: $accent;
    padding: 1rem 2rem;

    .header-container {
      display: flex;
      align-items: center;
      justify-content: space-between;
      max-width: 1200px;
      margin: 0 auto;
      width: 100%;
    }

    .brand {
      margin-right: auto;

      .brand-link {
        font-size: 1.8rem;
        font-weight: 700;
        font-variation-settings: "wdth" 87.5,"wght" 700,"GRAD" 150;
        text-decoration: none;
        color: $accent;

        .brand-accent {
          color: $accentDark;
        }
      }
    }

    .nav-links {
      display: flex;
      gap: 2rem;
      align-items: center;

      a {
        text-decoration: none;
        font-weight: 700;
        font-size: 1.2rem;
        text-transform: uppercase;
        transition:
          color 0.2s ease-in-out,
          border-bottom-color 0.2s ease-in-out;
        color: $accent;
        line-height: 1;
        border-bottom: 2px solid transparent;

        &:hover {
          color: $accentDark;
          border-bottom-color: currentColor;
        }

        &.active {
          color: $accentDark;
        }
      }
    }

    .mobile-toggle {
      display: none;
      flex-direction: column;
      justify-content: space-between;
      width: 2rem;
      height: 1.25rem;
      cursor: pointer;
      z-index: 10;

      .bar {
        height: 3px;
        width: 100%;
        background-color: $accent;
        border-radius: 3px;
        transition: all 0.2s ease;
      }

      &.active {
        .bar:nth-child(1) {
          transform: translateY(0.5rem) rotate(45deg);
        }

        .bar:nth-child(2) {
          opacity: 0;
        }

        .bar:nth-child(3) {
          transform: translateY(-0.5rem) rotate(-45deg);
        }
      }
    }
  }

  @media (max-width: $breakpointDesktop) {
    header {
      .nav-links {
        gap: 1.5rem;

        a {
          font-size: 1rem;
        }
      }
    }
  }

  @media (max-width: $breakpointTablet) {
    header {
      .mobile-toggle {
        display: flex;
      }

      .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        width: 80%;
        max-width: 300px;
        height: 100vh;
        background-color: $lightAlt;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2rem;
        transition: right 0.3s ease;
        box-shadow: $shadow;
        z-index: 5;

        a {
          font-size: 1.5rem;
        }

        &.active {
          right: 0;
        }
      }
    }
  }
</style>