Skip to content

Commit

Permalink
Drop is= on navMenuButton, simplify nav and shell CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca committed Dec 19, 2023
1 parent c714f8c commit ef5a35a
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 54 deletions.
4 changes: 1 addition & 3 deletions src/assets/customElements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ customElements.define('pc-auto-form', autoForm);
customElements.define('pc-clipboard-button', clipboardButton);
customElements.define('pc-event-form', eventForm);
customElements.define('pc-faircalendar-filters-form', fairCalendarFiltersForm);
customElements.define('pc-nav-menu-button', navMenuButton, {
extends: 'button'
});
customElements.define('pc-nav-menu-button', navMenuButton);
customElements.define('pc-theme-toggler', themeToggler);
12 changes: 7 additions & 5 deletions src/assets/customElements/navMenuButton.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// @ts-check

export default class extends HTMLButtonElement {
export default class extends HTMLElement {
connectedCallback() {
const ariaControls = this.getAttribute('aria-controls');
const btn = /** @type {HTMLButtonElement} */ (this.querySelector('button'));

const ariaControls = btn.getAttribute('aria-controls');

if (!ariaControls) {
throw new Error('aria-controls is missing');
Expand All @@ -12,11 +14,11 @@ export default class extends HTMLButtonElement {
ariaControls
));

let open = this.getAttribute('aria-expanded') === 'true' || false;
let open = btn.getAttribute('aria-expanded') === 'true' || false;

this.addEventListener('click', () => {
btn.addEventListener('click', () => {
open = !open;
this.setAttribute('aria-expanded', open.toString());
btn.setAttribute('aria-expanded', open.toString());
linksList.hidden = !open;
});
}
Expand Down
5 changes: 5 additions & 0 deletions src/assets/styles/components/header.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pc-header {
position: sticky;
top: 0;
background-color: var(--background-default);
}
1 change: 1 addition & 0 deletions src/assets/styles/components/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import './dropdown.css';
@import './event.css';
@import './form_errors.css';
@import './header.css';
@import './icon.css';
@import './input-group.css';
@import './label.css';
Expand Down
27 changes: 18 additions & 9 deletions src/assets/styles/components/nav.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,34 @@
color: var(--text-muted);
}

[is='pc-nav-menu-button'] {
.pc-nav.pc-mobile-only {
position: absolute;
top: 100%;
left: 0;
width: 100%;
box-shadow: var(--shadow-default);
}

.pc-nav.pc-desktop-only {
display: none;
}

pc-nav-menu-button > button {
background-color: transparent;
border: none;
width: 2rem;
height: 2rem;
cursor: pointer;
}

.pc-nav ul {
list-style-type: none;
padding: 0;
margin-block: 0;
}

@media screen and (min-width: 840px) {
[is='pc-nav-menu-button'] {
pc-nav-menu-button {
display: none;
}
.pc-nav.pc-mobile-only {
display: none;
}
.pc-nav > ul {
.pc-nav.pc-desktop-only {
display: block;
}
}
Expand Down
28 changes: 5 additions & 23 deletions src/assets/styles/components/shell.css
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
.pc-shell {
/* Ensure page takes at least full height */
display: flex;
flex-direction: column;
align-self: stretch;
min-height: var(--shell-min-size, 100vh);
}

/* Main shell content grows */
.pc-shell > .pc-shell__content {
flex-grow: 1;
}

.pc-shell__content {
flex-grow: 1;
background-color: var(--background-alt-grey);
}

/* Ensure all other shell elements match the main content's size */
:where(.pc-shell, .pc-shell-mobile) > * {
.pc-shell__element {
/* Grow to match the content's size */
align-self: stretch;
}

@media screen and (max-width: 840px) {
.pc-shell-mobile {
display: flex;
flex-direction: column;
min-height: var(--shell-min-size, 100vh);
}

.pc-shell-mobile > .pc-shell__content {
flex-grow: 1;
}

.pc-shell-mobile > * {
align-self: stretch;
}
}
4 changes: 0 additions & 4 deletions src/assets/styles/utilities/placement.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
display: grid;
place-items: center;
}

.pc-relative {
position: relative;
}
17 changes: 13 additions & 4 deletions src/templates/components/header.njk
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{% import 'macros/icons.njk' as icons %}

<header class="pc-cluster pc-relative pc-shadow pc-p" style="--cluster-justify: space-between; z-index: 2; --p: calc(3 * var(--v)) calc(6 * var(--v))">
<button is="pc-nav-menu-button" aria-haspopup="true" aria-expanded="false" aria-controls="pc-nav-menu" aria-label="{{ 'nav-open'|trans }}">
{{ icons.menu() }}
</button>
<header class="pc-header pc-cluster pc-shadow pc-p" style="--cluster-justify: space-between; z-index: 2; --p: calc(3 * var(--v)) calc(6 * var(--v))">
<pc-nav-menu-button>
<button aria-haspopup="true" aria-expanded="false" aria-controls="pc-nav-mobile-menu" aria-label="{{ 'nav-open'|trans }}">
{{ icons.menu() }}
</button>
</pc-nav-menu-button>

<a href="{{ path('home') }}" class="pc-brand">
<img src="{{ asset('images/logo.png') }}" alt="{{ 'coop-name'|trans }}"/>
Expand Down Expand Up @@ -36,4 +38,11 @@
</ul>
</details>
</div>

<nav class="pc-nav pc-mobile-only">
{# 'hidden' so that it is closed by default #}
<ul id="pc-nav-mobile-menu" class="pc-raw-list" role="list" hidden>
{% include 'components/nav_links.njk' %}
</ul>
</nav>
</header>
4 changes: 2 additions & 2 deletions src/templates/components/nav_links.njk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<span class="pc-nav-dropdown" aria-hidden="true"></span>
</summary>
<ul>
<ul class="pc-raw-list" role="list">
<li>
<a href="{{ path('crm_customers_list') }}" class="pc-link-btn" {% if view_name|startswith('crm_customers_') %}aria-current="page"{% endif %}>
{{ "crm-customers-title"|trans|capitalize }}
Expand Down Expand Up @@ -50,7 +50,7 @@
<span class="pc-nav-dropdown" aria-hidden="true"></span>
</summary>
<ul>
<ul class="pc-raw-list" role="list">
<li>
<a href="{{ path('people_leaves_list') }}" class="pc-link-btn" {% if view_name|startswith('people_leaves_') %}aria-current="page"{% endif %}>
{{ 'leaves-title'|trans }}
Expand Down
8 changes: 4 additions & 4 deletions src/templates/layouts/app.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<div class="pc-shell">
{% include 'components/header.njk' %}

<div class="pc-shell__content pc-shell-mobile pc-with-sidebar-desktop" style="--sidebar-size: 35ch; --shell-min-size: 100%">
<nav class="pc-nav">
<ul id="pc-nav-menu" hidden>
<div class="pc-shell__content pc-with-sidebar-desktop" style="--sidebar-size: 35ch; --shell-min-size: 100%">
<nav class="pc-shell__element pc-nav pc-desktop-only">
<ul class="pc-raw-list" role="list">
{% include 'components/nav_links.njk' %}
</ul>
</nav>

<main class="pc-shell__content pc-p" style="--p: calc(3 * var(--w)) 0">
<main class="pc-shell__element pc-p" style="--p: calc(3 * var(--w)) 0">
{% block main %}{% endblock main %}
</main>
</div>
Expand Down

0 comments on commit ef5a35a

Please sign in to comment.