Skip to content

Commit

Permalink
Make hamburger menu on mobile functional, update style overrides (#17)
Browse files Browse the repository at this point in the history
* Add Bulma javascript snippet to show/hide hamburger menu

This is just copied from the docs, Bulma doesn't come with Javascript
built in so we have to add it ourselves

There are ways to get clever with hidden checkboxes and not require
Javascript here, but this is a very Javascript-oriented project, so that
would be silly

* Make layout consistent with docs

* Add labels in mobile menu

I duplicated the icons because hiding just the text in desktop mode
results in weird margins on the icon buttons, sigh.

This is just kinda part of the tradeoff of using something like Bulma,
and that's fine

* Fix missing active/focus overrides

This resulted in buttons sometimes being white which was invisible

Also, this is a lot, imo because we're fighting with an opinionated
styling system outside of its built-in customization channels.

A cleaner way to do this would be to use the customization variables
they give us, likely by upgrading to 1.0 so we don't have to deal with
generating the files ourselves, but that's a whole other project
  • Loading branch information
cincodenada authored Dec 30, 2024
1 parent a675dea commit fd24b06
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
22 changes: 22 additions & 0 deletions web/scripts/bulma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// From https://bulma.io/documentation/components/navbar/#navbarJsExample
document.addEventListener('DOMContentLoaded', () => {

// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);

// Add a click event on each of them
$navbarBurgers.forEach( el => {
el.addEventListener('click', () => {

// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);

// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle('is-active');
$target.classList.toggle('is-active');

});
});

});
31 changes: 22 additions & 9 deletions web/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,21 @@ h6 {

/* Section: Links */

a,
a:focus,
a:hover {
a, a:focus {
color: var(--link-color);
text-decoration: var(--link-decoration);
}

a:hover {
a:hover, a:active {
color: var(--link-hover-color);
text-decoration: var(--link-hover-decoration);
}

a.tags,
a.tags:hover {
a.tags:hover,
a.tags:active,
a.tags:focus
{
text-decoration: none;
}

Expand All @@ -112,7 +113,10 @@ a.button::after {
content: none;
}

.navbar a, .navbar a:focus, .navbar a:hover {
.navbar a,
.navbar a:focus,
.navbar a:hover,
.navbar a:active {
text-decoration: none;
}

Expand All @@ -122,7 +126,9 @@ a.button::after {
background-color: var(--color-Violet);
}

.button.is-primary:hover {
.button.is-primary:hover,
.button.is-primary:active,
.button.is-primary:focus {
background-color: var(--color-Aquarelle);
}

Expand All @@ -132,7 +138,9 @@ a.button::after {
border-color: transparent;
}

.button.is-alt:hover {
.button.is-alt:hover,
.button.is-alt:active,
.button.is_alt:focus {
background-color: var(--color-Cupid);
}

Expand Down Expand Up @@ -179,7 +187,12 @@ body {
font-size: 1.5rem;
}

.navbar.is-primary .navbar-brand > a.navbar-item:hover, .navbar.is-primary .navbar-end > a.navbar-item:hover {
.navbar.is-primary .navbar-brand > a.navbar-item:hover,
.navbar.is-primary .navbar-brand > a.navbar-item:active,
.navbar.is-primary .navbar-brand > a.navbar-item:focus,
.navbar.is-primary .navbar-menu a.navbar-item:hover,
.navbar.is-primary .navbar-menu a.navbar-item:active,
.navbar.is-primary .navbar-menu a.navbar-item:focus {
background-color: var(--color-Zinnia);
}

Expand Down
31 changes: 26 additions & 5 deletions web/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gingerbread</title>
<link rel="stylesheet" href="./styles/styles.css">
<script defer type="text/javascript" src="./scripts/bulma.js"></script>
</head>

<body>
Expand All @@ -27,17 +28,37 @@
<span></span>
</span>
</div>
<div class="navbar-start">
</div>
<div id="navbarMenuHeroA" class="navbar-menu">
<div class="navbar-start">
</div>
<div class="navbar-end">
<a class="navbar-item" href="help.html">
<span class="material-symbols-outlined">
help
<span class="is-hidden-touch">
<span class="material-symbols-outlined">
help
</span>
</span>
<span class="is-hidden-desktop">
<span class="icon-text">
<span class="icon material-symbols-outlined">
help
</span>
<span>Help</span>
</span>
</span>
</a>
<a class="navbar-item" href="https://github.com/wntrblm/Gingerbread" target="_blank">
<img src="./images/github.png"/>
<span class="is-hidden-touch">
<img alt="GitHub" src="./images/github.png"/>
</span>
<span class="is-hidden-desktop">
<span class="icon-text">
<span class="icon">
<img alt="GitHub" src="./images/github.png"/>
</span>
<span class="is-hidden-desktop">GitHub</span>
</span>
</span>
</a>
</div>
</div>
Expand Down

0 comments on commit fd24b06

Please sign in to comment.