Skip to content

Commit

Permalink
Merge pull request #34 from rustnl/submenu
Browse files Browse the repository at this point in the history
Subitems in main menu
  • Loading branch information
erikjee authored Jan 21, 2025
2 parents 0c5a693 + 977c23b commit 30b39fa
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 61 deletions.
3 changes: 0 additions & 3 deletions src/components/page/footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import Menu from "./menu.astro";
<div class="menu">
<a href="/">RustWeek 2025</a>
</div>
<div class="menu">
<Menu location="footer" />
</div>
<div class="menu">
<a href="/resources/sponsorship-prospectus-rustweek-2025.pdf">Sponsorships</a>
<a href="/unconf">Unconf</a>
Expand Down
46 changes: 42 additions & 4 deletions src/components/page/header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ const { withLogo = false, withoutMenu = false }: Props = Astro.props;
}

toggle?.addEventListener("click", toggleMenu);

const header = document.querySelector(".header") as HTMLElement;
const hero = document.querySelector('.hero') as HTMLElement;

function scrollHanlde(event: Event) {
const heroHeight = hero.offsetHeight;
const headerHeight = header.offsetHeight;
const treshold = heroHeight - headerHeight;
const scroll = window.scrollY;

if (scroll > treshold) {
header?.classList.add('scrolled');
} else {
header?.classList.remove('scrolled');
}
}

document.addEventListener('scroll', scrollHanlde);
</script>

<style lang="scss">
Expand All @@ -52,11 +70,26 @@ const { withLogo = false, withoutMenu = false }: Props = Astro.props;
.header {
align-items: center;
display: flex;
height: space(24);
height: space(18);
padding-inline: space(4);
position: absolute;
position: fixed;
width: 100%;
z-index: 1;
background-color: transparent;
transition-property: background-color, height;
transition-duration: 150ms;

@include wider_than(lg) {
height: space(24);
}

&.scrolled {
background-color: $color-yellow-500;

@include wider_than(lg) {
height: space(20);
}
}

.logo {
img {
Expand All @@ -66,7 +99,8 @@ const { withLogo = false, withoutMenu = false }: Props = Astro.props;

.hamburger {
margin-inline-start: auto;
padding: 0.5em 1em;
height: space(12);
padding-inline: 1rem;

@include wider_than(lg) {
display: none;
Expand All @@ -85,7 +119,7 @@ const { withLogo = false, withoutMenu = false }: Props = Astro.props;
align-items: flex-start;
background-color: $color-neutral-400;
border: 1px solid $color-red-500;
bottom: space(3);
bottom: space(0);
display: flex;
flex-direction: column;
left: space(4);
Expand All @@ -101,6 +135,9 @@ const { withLogo = false, withoutMenu = false }: Props = Astro.props;
width: calc(100% - space(8));
gap: space(3);

max-height: calc(100vh - 88px);
overflow: auto;

@include wider_than(lg) {
align-items: center;
background-color: transparent;
Expand All @@ -117,6 +154,7 @@ const { withLogo = false, withoutMenu = false }: Props = Astro.props;
translate: none;
visibility: visible;
width: auto;
overflow: visible;
}

&.open {
Expand Down
229 changes: 176 additions & 53 deletions src/components/page/menu.astro
Original file line number Diff line number Diff line change
@@ -1,79 +1,202 @@
---
import Button from "../Button.astro";
import Button from '../Button.astro';
interface Props {
location: "header" | "footer";
location: 'header' | 'footer';
}
const { location }: Props = Astro.props;
---

<div class:list={["menu", location]}>
<a
href="/#schedule"
onclick="document.querySelector('[data-menu-toggle]').click()"
>Schedule</a
>
<a
<div class:list={['menu', location]}>
<ul>
<li class="parent">
<span>Schedule</span>
<ul class="submenu">
<li class="child">
<a
href="/#schedule"
onclick="document.querySelector('[data-menu-toggle]').click()"
>Overview</a
>
</li>
<li class="child"><a href="/industry">Industry track</a></li>
</ul>
</li>
<li class="parent">
<a
href="/#cfp"
onclick="document.querySelector('[data-menu-toggle]').click()">CFP</a
>
<a href="/speakers">Speakers</a>
<a href="/industry">Industry</a>
<a
>
</li>
<li class="parent">
<a href="/speakers">Speakers</a>
</li>
<li class="parent">
<a
href="/#sponsors"
onclick="document.querySelector('[data-menu-toggle]').click()"
>Sponsors</a
>
<a href="/about">About</a>
<Button
>
</li>
<li class="parent">
<span>About</span>
<ul class="submenu">
<li class="child">
<a href="/about">About</a>
</li>
<li class="child">
<a href="mailto:[email protected]">Contact</a>
</li>
</ul>
</li>
<li class="parent">
<Button
link="https://www.eventbrite.nl/e/rust-week-2025-tickets-1001676961757?aff=oddtdtcreator"
ty="primary"
inFooter={location == "footer"}>Tickets</Button
>
inFooter={location == 'footer'}>Tickets</Button
>
</li>
</ul>
</div>

<style lang="scss">
@import "../../styles/variables.scss";
@import "../../styles/breakpoint.scss";
@import '../../styles/variables.scss';
@import '../../styles/breakpoint.scss';

.menu {
display: contents;

&.footer {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: space(2);

a {
color: #ffffff;
}
}

&.header {
> ul {
align-items: flex-start;
display: flex;
flex-direction: column;
row-gap: space(3);
width: 100%;

@include wider_than(lg) {
align-items: stretch;
flex-direction: row;
}
}

ul {
padding: 0;
}

li {
list-style: none;
margin: 0;
padding: 0;
}

a {
text-decoration: none;
}

span {
cursor: pointer;
}

.submenu {
padding-inline-start: 0.75rem;

.menu {
display: contents;
@include wider_than(lg) {
background-color: $color-background;
border: 1px solid $color-black;
bottom: 0;
color: $color-black;
opacity: var(--submenu-opacity, 0);
padding: 0;
pointer-events: var(--submenu-pointer-events, none);
position: absolute;
padding-inline-start: 0;
translate: 0 100%;
visibility: var(--submenu-visibility, hidden);
width: max-content;
}
}

.submenu a {
font-weight: 400;
display: flex;
height: space(12);
align-items: center;

@include wider_than(lg) {
height: space(12);
padding-inline: space(4);
}

&:hover {
text-decoration: underline;
}
}

.parent {
justify-content: center;
display: flex;
flex-direction: column;
font-weight: 700;
min-height: space(12);
cursor: pointer;

&.footer {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: space(2);
@include wider_than(lg) {
color: $color-background;
flex: 1;
min-height: auto;
margin: 0;
padding-inline: space(4);
position: relative;

a {
color: #ffffff;
}
&:has(.submenu):hover {
--submenu-opacity: 1;
--submenu-visibility: visible;
--submenu-pointer-events: all;
}
}

&.header {
a {
align-items: center;
color: inherit;
display: flex;
font-weight: 700;
min-height: space(12);
text-decoration: none;
width: 100%;

@include wider_than(lg) {
color: #ffffff;
width: auto;
}
}

a:last-child {
margin-block-start: space(3);

@include wider_than(lg) {
margin-block-start: 0;
}
}
&:last-child {
margin-block-start: space(3);

@include wider_than(lg) {
margin-block-start: 0;
}
}

&:hover span::after {
rotate: 180deg;
}
}

.parent span {
display: flex;
align-items: center;
gap: space(2);

&::after {
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0yMDEuNCAzNzQuNmMxMi41IDEyLjUgMzIuOCAxMi41IDQ1LjMgMGwxNjAtMTYwYzEyLjUtMTIuNSAxMi41LTMyLjggMC00NS4zcy0zMi44LTEyLjUtNDUuMyAwTDIyNCAzMDYuNyA4Ni42IDE2OS40Yy0xMi41LTEyLjUtMzIuOC0xMi41LTQ1LjMgMHMtMTIuNSAzMi44IDAgNDUuM2wxNjAgMTYweiIvPjwvc3ZnPg==');
background-position: center center;
background-repeat: no-repeat;
content: '';
height: space(4);
transition-duration: 150ms;
transition-property: rotate;
width: space(4);
}
}
}
}
</style>
2 changes: 1 addition & 1 deletion src/styles/global/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ h1, h2 {
}


.anchor {
[id] {
scroll-margin-top: space(24);
}

Expand Down

0 comments on commit 30b39fa

Please sign in to comment.