diff --git a/assets/icons/chevron-down.svg b/assets/icons/chevron-down.svg new file mode 100644 index 00000000..9368d7fe --- /dev/null +++ b/assets/icons/chevron-down.svg @@ -0,0 +1,12 @@ + diff --git a/assets/js/header.js b/assets/js/header.js new file mode 100644 index 00000000..1e576c6c --- /dev/null +++ b/assets/js/header.js @@ -0,0 +1,11 @@ +function header_toggle_nested_menu(element) { + if (!element) { + throw new Error("Could not find button") + } + let parent_element = element.parentElement; + if(!parent_element) { + throw new Error("Could not get parent element from button") + } + let nested_menu = parent_element.querySelector(".header-nested-menu") + nested_menu.classList.toggle('hidden'); +} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 31db44bf..a85fd39c 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -147,4 +147,10 @@ {{ end }} {{ end }} - \ No newline at end of file + + {{/* Header */}} + {{ $headerLib := resources.Get "js/header.js" }} + {{ $headerLib := $headerLib | resources.Minify }} + {{ $headerJS := $headerLib | resources.Fingerprint "sha512" }} + + diff --git a/layouts/partials/header/README.md b/layouts/partials/header/README.md new file mode 100644 index 00000000..e7845957 --- /dev/null +++ b/layouts/partials/header/README.md @@ -0,0 +1,37 @@ +# Header + +- `header-option-simple.html` renders menus without nested items +- `header-option-nested.html` renders menus with nested items +- `header-option.html` decides which template to render given the menu + +- `js/header.js` exposes a method to toggle visibility of nested menus + +- Nesting is configured using the `parent` and `identifier` properties in `menus.en.yml`. Example + +```yml +main: + - name: Product + identifier: product + weight: 1 + - name: Analytics + pageRef: analytics + weight: 1 + parent: product + - name: Engagement + pageRef: engagement + weight: 2 + parent: product + +secondary: + - name: Engineering + identifier: engineering + weight: 1 + - name: Computers + pageRef: computers + weight: 1 + parent: engineering + - name: Rockets + pageRef: rockets + weight: 2 + parent: engineering +``` diff --git a/layouts/partials/header/basic.html b/layouts/partials/header/basic.html index 3574ddc5..0a17c50e 100644 --- a/layouts/partials/header/basic.html +++ b/layouts/partials/header/basic.html @@ -22,18 +22,15 @@ -
{{ end }} - +