-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.astro
More file actions
99 lines (84 loc) · 2.36 KB
/
Header.astro
File metadata and controls
99 lines (84 loc) · 2.36 KB
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
---
import '../styles/global.css'
import SearchBar from '../components/SearchBar.astro'
import IconHome from '../assets/icon/home.svg'
import IconUser from '../assets/icon/user-circle.svg'
import IconAdminPanel from '../assets/icon/device-desktop-analytics.svg'
import { SITE_NAME } from '../config.js'
const { canSearch = false } = Astro.props || {}
---
<header class="show">
<a href="index.html" title="Home">
<IconHome />
<h1>{SITE_NAME}</h1>
</a>
{canSearch && <SearchBar placeholder="Search for recipes..." />}
<nav>
<ul>
<li title="Admin Panel">
<a href="admin.html"><IconAdminPanel /></a>
</li>
<li title="Account">
<a href="authentication.html"><IconUser /></a>
</li>
</ul>
</nav>
</header>
<style>
header {
background-color: var(--color-primary);
display: flex;
justify-content: space-between;
position: fixed;
gap: var(--spacing-medium);
transition: transform 0.5s ease-in-out;
white-space: nowrap;
width: 100%;
z-index: 1;
}
header.hide {
transform: translateY(-100%);
}
header.show {
transform: translateY(0);
}
header > a {
display: flex;
gap: var(--spacing-small);
}
ul {
display: flex;
gap: var(--spacing-medium);
list-style: none;
}
header > *:first-child,
header > *:last-child {
margin: 0 var(--spacing-medium);
}
@media screen and (width<=1000px) {
header {
align-items: center;
flex-direction: column;
gap: 0;
}
header > *:first-child,
header > *:last-child {
margin: 0;
}
svg {
width: calc(1.5 * var(--spacing-medium));
height: calc(1.5 * var(--spacing-medium));
}
}
</style>
<script type="module" is:inline>
const header = document.querySelector('header')
let lastScroll = 0
window.addEventListener('scroll', () => {
const current = window.scrollY
const scrollingDown = current > lastScroll
header.classList.toggle('hide', scrollingDown && current > 0)
header.classList.toggle('show', !scrollingDown || current <= 0)
lastScroll = Math.max(current, 0)
})
</script>