Skip to content

Commit

Permalink
Merge pull request #1436 from openeuropa/EWPP-4085
Browse files Browse the repository at this point in the history
EWPP-4085: Add mega menu variant to navigation menu pattern.
  • Loading branch information
upchuk authored Jun 7, 2024
2 parents 1f4255d + d173505 commit a8120e8
Show file tree
Hide file tree
Showing 9 changed files with 446 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ services:
pipeline:
ecl-build:
group: prepare
image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/node:21
image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/node:18.18.2
commands:
# To build the theme using a development version of ECL set its development branch in .env.dist
# and make sure that ECL_BUILD is set to "dev".
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
- '4444'
shm_size: 2g
node:
image: node:21
image: node:18.18.2
user: "node"
working_dir: /home/node/app
environment:
Expand Down
6 changes: 6 additions & 0 deletions modules/oe_theme_helper/oe_theme_helper.module
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ function oe_theme_helper_theme($existing, $type, $theme, $path) {
'variables' => [
'site_name' => '',
'menu_items' => [],
'back' => '',
'see_all_label' => '',
'button_previous_label' => '',
'button_next_label' => '',
'max_lines' => '',
'variant' => '',
],
],
'oe_theme_helper_call_status' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
close: close,
items: menu_items,
site_name: site_name,
}, 'vertical') }}
back: back|default(''),
see_all_label: see_all_label|default(''),
button_previous_label: button_previous_label|default(''),
button_next_label: button_next_label|default(''),
max_lines: max_lines|default(),
variant: variant|default('default'),
}) }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@ecl/twig-component-link": "4.2.1",
"@ecl/twig-component-list-illustration": "4.2.1",
"@ecl/twig-component-media-container": "4.2.1",
"@ecl/twig-component-mega-menu": "4.2.1",
"@ecl/twig-component-menu": "4.2.1",
"@ecl/twig-component-navigation-list": "4.2.1",
"@ecl/twig-component-news-ticker": "4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion templates/navigation/menu--main.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
label: 'Menu'|t,
close: close,
items: links,
variant: 'vertical',
variant: variant|default('default'),
}) }}
{% endif %}
99 changes: 94 additions & 5 deletions templates/patterns/navigation_menu/navigation_menu.ui_patterns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ navigation_menu:
label: "Navigation menu"
description: "Default implementation of the main navigation menu."
variants:
vertical:
label: "Vertical"
description: "Menu items will be arranged vertically, in 4 columns."
default:
label: "Default"
description: "Default variant uses the ECL menu component."
mega_menu:
label: "Mega menu"
description: "Mega menu variant uses the ECL Mega menu component."
fields:
label:
type: "text"
Expand All @@ -30,7 +33,7 @@ navigation_menu:
see_all_label:
type: "text"
label: "See all button"
description: "Label for the \"see all\" link (mobile only)."
description: "Label for the \"see all\" link (mobile only for default variant)."
preview: "See all"
button_previous_label:
type: "text"
Expand Down Expand Up @@ -82,14 +85,53 @@ navigation_menu:
extra_attributes:
- name: "extra-attr1"
value: "extra value1"
info:
title: "About the EU law"
content: "Description text, lorem ipsum dolor sit amet, consectetur adipiscing elit."
link:
label: "Discover more"
href: "#"
children:
- href: '#'
label: 'Eu Treaties'
extra_attributes:
- name: "extra-attr2"
value: "extra value2"
is_current: TRUE
external: true
see_all_label: "View all"
see_all: true
see_all_attributes:
- name: "extra-attr3"
value: "extra value3"
children:
- href: "#"
label: 'Granchild 2.1.1'
is_current: TRUE
- href: "#"
label: 'Granchild 2.1.2'
external: true
- href: "#"
label: 'Granchild 2.1.3'
- href: "#"
label: 'Granchild 2.1.4'
- href: "#"
label: 'Granchild 2.1.5'
external: true
featured:
title: "featured column 1"
content:
'#markup': "<article class=\"ecl-navigation-list__item\">\n <picture class=\"ecl-picture ecl-navigation-list__picture\"><img class=\"ecl-navigation-list__image\" src=\"https://inno-ecl.s3.amazonaws.com/media/examples/example-image.jpg\" alt=\"Alt text for the image\" /></picture>\n <div class=\"ecl-content-block ecl-navigation-list__content-block\" data-ecl-auto-init=\"ContentBlock\" data-ecl-content-block>\n <div class=\"ecl-content-block__title\" data-ecl-title-link><a href=\"/example#qspea\" class=\"ecl-link ecl-link--standalone\">Title 1</a></div>\n <div class=\"ecl-content-block__description\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida ipsum ut lorem cursus</div>\n </div>\n </article>"
items:
- href: "#"
label: "Featured link 2.1.1"
is_current: TRUE
- href: "#"
label: "Featured link 2.1.2"
- href: "#"
label: "Featured link 2.1.3"
- href: "#"
label: "Featured link 2.1.4"
external: true
- href: '#'
label: 'Application of EU law'
- href: '#'
Expand All @@ -113,9 +155,56 @@ navigation_menu:
- href: "#"
label: "Live, work, study"
external: true
info:
title: "About the Live, work, study page"
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
children:
- href: '#'
label: 'Child 6.1'
see_all_label: "See all"
see_all: true
children:
- href: "#"
label: 'Granchild 6.1.1'
is_current: TRUE
- href: "#"
label: 'Granchild 6.1.2'
external: true
- href: "#"
label: 'Granchild 6.1.3'
- href: "#"
label: 'Granchild 6.1.4'
- href: "#"
label: 'Granchild 6.1.5'
external: true
featured:
title: "featured column 2"
content:
'#markup': "<article class=\"ecl-navigation-list__item\">\n <picture class=\"ecl-picture ecl-navigation-list__picture\"><img class=\"ecl-navigation-list__image\" src=\"https://inno-ecl.s3.amazonaws.com/media/examples/example-image.jpg\" alt=\"Alt text for the image\" /></picture>\n <div class=\"ecl-content-block ecl-navigation-list__content-block\" data-ecl-auto-init=\"ContentBlock\" data-ecl-content-block>\n <div class=\"ecl-content-block__title\" data-ecl-title-link><a href=\"/example#qspea\" class=\"ecl-link ecl-link--standalone\">Title 2</a></div>\n <div class=\"ecl-content-block__description\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida ipsum ut lorem cursus</div>\n </div>\n </article>"
items:
- href: "#"
label: "Featured link 6.1.1"
is_current: TRUE
- href: "#"
label: "Featured link 6.1.2"
- href: "#"
label: "Featured link 6.1.3"
- href: "#"
label: "Featured link 6.1.4"
external: true
- href: '#'
label: 'Child 6.2'
- href: '#'
label: 'Child 6.3'
- href: '#'
label: 'Child 6.4'
- href: '#'
label: 'Child 6.5'
- href: "#"
label: "Visit a European Union institution"
- href: "#"
label: "Jobs & traineeships in EU institutions"
- href: "#"
label: "Participate, interact, vote"
container:
'#markup': "<article class=\"ecl-navigation-list__item\">\n <picture class=\"ecl-picture ecl-navigation-list__picture\"><img class=\"ecl-navigation-list__image\" src=\"https://inno-ecl.s3.amazonaws.com/media/examples/example-image.jpg\" alt=\"Alt text for the image\" /></picture>\n <div class=\"ecl-content-block ecl-navigation-list__content-block\" data-ecl-auto-init=\"ContentBlock\" data-ecl-content-block>\n <div class=\"ecl-content-block__title\" data-ecl-title-link><a href=\"/example#qspea\" class=\"ecl-link ecl-link--standalone\">Title 3</a></div>\n <div class=\"ecl-content-block__description\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida ipsum ut lorem cursus</div>\n </div>\n </article>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{#
/**
* @file
* Mega menu variant implementation for the navigation menu pattern.
*/
#}

{# Process items as expected by ECL Mega menu. #}
{% set _items = [] %}
{% for item in items %}

{# Process children, if any. #}
{% set _children = [] %}
{% for child in item.children %}
{% set _child = {
path: child.href,
label: child.label,
see_all: child.see_all|default(false),
see_all_label: child.see_all_label|default('See all'),
see_all_attributes: child.see_all_attributes,
extra_attributes: child.extra_attributes,
} %}
{% if child.is_current is defined and child.is_current == true %}
{% set _child = _child|merge({
is_current: child.is_current,
}) %}
{% endif %}
{% if child.external is defined and child.external == true %}
{% set _child = _child|merge({
external: child.external,
icon_path: ecl_icon_path
}) %}
{% endif %}

{# Process grandchildren, if any. #}
{% set _grandchildren = [] %}
{% for grandchild in child.children %}
{% set _grandchild = {
path: grandchild.href,
label: grandchild.label,
extra_attributes: grandchild.extra_attributes,
} %}
{% if grandchild.is_current is defined and grandchild.is_current == true%}
{% set _grandchild = _grandchild|merge({
is_current: grandchild.is_current,
}) %}
{% endif %}
{% if grandchild.external is defined and grandchild.external == true %}
{% set _grandchild = _grandchild|merge({
external: grandchild.external,
icon_path: ecl_icon_path
}) %}
{% endif %}
{% set _grandchildren = _grandchildren|merge([_grandchild]) %}
{% endfor %}

{# Process featured column, if set. #}
{% set _featured = [] %}
{% if child.featured is not empty %}
{% set _featured = _featured|merge({
title: child.featured.title|default(''),
content: child.featured.content|default(''),
}) %}
{% set _featured_items = [] %}
{% for featured_item in child.featured.items %}
{% set _featured_item = {
path: featured_item.href,
label: featured_item.label,
extra_attributes: featured_item.extra_attributes,
} %}
{% if featured_item.is_current is defined and featured_item.is_current == true%}
{% set _featured_item = _featured_item|merge({
is_current: featured_item.is_current,
}) %}
{% endif %}
{% if featured_item.external is defined and featured_item.external == true %}
{% set _featured_item = _featured_item|merge({
external: featured_item.external,
icon_path: ecl_icon_path
}) %}
{% endif %}
{% set _featured_items = _featured_items|merge([_featured_item]) %}
{% endfor %}
{% set _featured = _featured|merge({
items: _featured_items,
}) %}
{% endif %}
{% set _child = _child|merge({
children: _grandchildren,
featured: _featured,
see_all: child.see_all|default(false)
}) %}
{% set _children = _children|merge([_child]) %}
{% endfor %}

{# Process item's info. #}
{% set _info = [] %}
{% if item.info is not empty %}
{% set _info = _info|merge({
'title': item.info.title,
'content': item.info.content,
}) %}
{% if item.info.link is not empty and item.info.link.href is not empty %}
{% set _info = _info|merge({
'link': {
'link': {
'label': item.info.link.label|default(item.info.link.href),
'path': item.info.link.href|default(''),
},
'icon': {
name: "arrow-left",
path: ecl_icon_path,
transform: "flip-horizontal",
size: "xs"
},
'extra_classes': "ecl-mega-menu__info-link"
},
}) %}
{% endif %}
{% endif %}

{# Process menu items. #}
{% set _item = {
path: item.href,
label: item.label,
info: _info|default([]),
children: _children,
link_aria_label: "Access item's children"|t,
extra_attributes: item.extra_attributes,
} %}
{% if _children is empty %}
{% if item.external is defined and item.external == true %}
{% set _item = _item|merge({
external: item.external,
icon_path: ecl_icon_path
}) %}
{% endif %}
{% if item.container is defined and item.container is not empty %}
{% set _item = _item|merge({
container: item.container,
}) %}
{% endif %}
{% endif %}
{% if item.is_current is defined and item.is_current == true %}
{% set _item = _item|merge({
is_current: item.is_current,
}) %}
{% endif %}
{% set _items = _items|merge([_item]) %}
{% endfor %}

{% if _items %}
{# Add extra attributes. #}
{% set extra_attributes = [
{
'name': 'aria-label',
'value': "Site navigation"|t,
}
] %}
{% include '@ecl-twig/mega-menu' with {
title: label|default('Menu'|t),
toggle: {
link: {
label: label|default('Menu'|t),
hide_label: true
},
icon: {
path: ecl_icon_path,
name: 'hamburger',
size: 'm',
}
},
close: {
label: close.label|default('Close'|t),
icon: {
path: ecl_icon_path,
name: ecl_component_library == 'ec' ? 'close' : 'close-filled',
size: ecl_component_library == 'ec' ? 'm' : 's',
},
hide_label: ecl_component_library == 'ec',
},
back_label: back|default('Back'|t),
icon_path: ecl_icon_path,
items: _items,
see_all_label: see_all_label|default('Browse all'|t),
extra_attributes: extra_attributes|default([]),
} only %}
{% endif %}

Loading

0 comments on commit a8120e8

Please sign in to comment.