# Ejemplo de código de Menú horizontal. DESY. Sistema de diseño del Gobierno de Aragón. ## Componentes Índice de páginas Componentes # Menú horizontal Navegación El menú horizontal está compuesto por una serie de elementos que enlazan con cada una de las secciones principales del sitio web. Se trata de una forma sencilla de organizar el contenido y facilitar su acceso. # Menu-horizontal Mostrar parámetros ## Parámetros Nunjucks del componente: "Menu-horizontal" ```yaml params: - name: idPrefix type: string required: false description: String to prefix id for each nav item if no id is specified on each item. If not passed, fall back to using the name option instead. - name: items type: array required: true description: Array of nav items objects. params: - name: href type: string required: true description: Item link. - name: target type: string required: false description: The target where the item should link to. - name: text type: string required: true description: If `html` is set, this is not required. Text to use within each nav item. If `html` is provided, the `text` argument will be ignored. - name: html type: string required: true description: If `text` is set, this is not required. HTML to use within each nav item. If `html` is provided, the `text` argument will be ignored. - name: id type: string required: false description: Specific id attribute for the nav item. If omitted, then idPrefix option will be applied. - name: active type: boolean required: false description: If true, item will be active. - name: disabled type: boolean required: false description: If true, nav item will be disabled. - name: classes type: string required: false description: Classes to add to the item. - name: attributes type: object required: false description: HTML attributes (for example data attributes) to add to the item. - name: classes type: string required: false description: Classes to add to the nav. - name: attributes type: object required: false description: HTML attributes (for example data attributes) to add to the nav tag. ``` ### Por defecto [#](#por-defecto) Mostrar códigodel ejemplo: Por defecto #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2" }, { "href": "http://www.google.com", "text": "Opción 3" }, { "href": "http://www.google.com", "text": "Opción 4" }, { "href": "http://www.google.com", "text": "Opción 5" } ], "attributes": { "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con item deshabilitado [#](#con-item-deshabilitado) Mostrar códigodel ejemplo: Con item deshabilitado #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2" }, { "href": "http://www.google.com", "text": "Opción deshabilitada 3", "disabled": true }, { "href": "http://www.google.com", "text": "Opción 4" }, { "href": "http://www.google.com", "text": "Opción 5" } ], "attributes": { "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con item activo [#](#con-item-activo) Añade active: true a un item para mostrarlo activo inicialmente. También puedes usar con javascript la función global `activateItemMenuHorizontal(elementMenu, idItemSeleccionado)` para seleccionar un item de un menú, usando sus ids. Ej: Abre la consola del navegador y escribe `activateItemMenuHorizontal('mi-menu-horizontal', 'menu-item-2')` para desactivar el item actual y activar el segundo item de este ejemplo. Mostrar códigodel ejemplo: Con item activo #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2" }, { "href": "http://www.google.com", "text": "Opción 3" }, { "href": "http://www.google.com", "text": "Opción 4", "active": true }, { "href": "http://www.google.com", "text": "Opción 5" } ], "attributes": { "aria-label": "Menú horizontal", "id": "mi-menu-horizontal" } }) }} ``` ##### HTML ```html ``` ### Con target en enlaces [#](#con-target-en-enlaces) Mostrar códigodel ejemplo: Con target en enlaces #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "items": [ { "href": "http://www.google.com", "text": "Opción 1", "target": "_blank", "attributes": { "title": "Se abre en ventana nueva" } }, { "href": "http://www.google.com", "text": "Opción 2", "target": "_blank", "attributes": { "title": "Se abre en ventana nueva" } }, { "href": "http://www.google.com", "text": "Opción 3", "target": "_blank", "attributes": { "title": "Se abre en ventana nueva" } }, { "href": "http://www.google.com", "text": "Opción 4", "target": "_blank", "attributes": { "title": "Se abre en ventana nueva" } }, { "href": "http://www.google.com", "text": "Opción 5", "target": "_blank", "attributes": { "title": "Se abre en ventana nueva" } } ], "attributes": { "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con iconos en items [#](#con-iconos-en-items) Mostrar códigodel ejemplo: Con iconos en items #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "items": [ { "href": "#", "html": " Opción 1" }, { "href": "#", "html": " Opción 2" }, { "href": "#", "html": " Opción 3" } ], "attributes": { "id": "mi-menu-icons", "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con clases de css aplicadas: tipo enlaces [#](#con-clases-de-css-aplicadas-tipo-enlaces) Clase modificadora aplicada: `.c-menu-horizontal--links` Mostrar códigodel ejemplo: Con clases de css aplicadas: tipo enlaces #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "classes": "c-menu-horizontal--links", "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2", "active": true }, { "href": "http://www.google.com", "text": "Opción 3" }, { "href": "http://www.google.com", "text": "Opción 4", "disabled": true }, { "href": "http://www.google.com", "text": "Opción 5" } ], "attributes": { "id": "mi-menu-links", "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con clases de css aplicadas: con separadores y texto pequeño [#](#con-clases-de-css-aplicadas-con-separadores-y-texto-pequeo) Clase modificadora aplicada: `.c-menu-horizontal--links`. Clases aplicadas a cada item para cambiar el padding y añadir un borde lateral. Mostrar códigodel ejemplo: Con clases de css aplicadas: con separadores y texto pequeño #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "classes": "c-menu-horizontal--links", "items": [ { "href": "http://www.google.com", "text": "Opción 1", "classes": "lg:py-0! text-sm border-r border-r-neutral-base" }, { "href": "http://www.google.com", "text": "Opción 2", "classes": "lg:py-0! text-sm border-r border-r-neutral-base", "active": true }, { "href": "http://www.google.com", "text": "Opción 3", "classes": "lg:py-0! text-sm border-r border-r-neutral-base" }, { "href": "http://www.google.com", "text": "Opción 4", "classes": "lg:py-0! text-sm border-r border-r-neutral-base", "disabled": true }, { "href": "http://www.google.com", "text": "Opción 5", "classes": "lg:py-0! text-sm" } ], "attributes": { "id": "mi-menu-links-divider", "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con clases de css aplicadas: navigation bar [#](#con-clases-de-css-aplicadas-navigation-bar) Clase modificadora aplicada: `.c-menu-horizontal--navigation-bar` Mostrar códigodel ejemplo: Con clases de css aplicadas: navigation bar #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "classes": "c-menu-horizontal--navigation-bar", "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2", "active": true }, { "href": "http://www.google.com", "text": "Opción 3" }, { "href": "http://www.google.com", "text": "Opción 4", "disabled": true }, { "href": "http://www.google.com", "text": "Opción 5" } ], "attributes": { "id": "mi-menu-navigation-bar", "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con clases de css aplicadas: navigation bar con scroll horizontal [#](#con-clases-de-css-aplicadas-navigation-bar-con-scroll-horizontal) Clases modificadora aplicadas: `.c-menu-horizontal--navigation-bar` y `.c-menu-horizontal--scroll`. Te advertimos que esta aplicación suele dar problemas de accesibilidad y la incluimos para evitar problemas en anchuras muy pequeñas. Asegúrate que los items no desbordan en las anchuras más habituales o bien usa el ejemplo anterior. Mostrar códigodel ejemplo: Con clases de css aplicadas: navigation bar con scroll horizontal #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "classes": "c-menu-horizontal--navigation-bar c-menu-horizontal--scroll", "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2", "active": true }, { "href": "http://www.google.com", "text": "Opción 3" }, { "href": "http://www.google.com", "text": "Opción 4", "disabled": true }, { "href": "http://www.google.com", "text": "Opción 5" }, { "href": "http://www.google.com", "text": "Opción 6" }, { "href": "http://www.google.com", "text": "Opción 7" }, { "href": "http://www.google.com", "text": "Opción 8" }, { "href": "http://www.google.com", "text": "Opción 9" }, { "href": "http://www.google.com", "text": "Opción 10" }, { "href": "http://www.google.com", "text": "Opción 11" }, { "href": "http://www.google.com", "text": "Opción 12" } ], "attributes": { "id": "mi-menu-navigation-bar", "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con clases de css aplicadas: tabs en escritorio [#](#con-clases-de-css-aplicadas-tabs-en-escritorio) Clase modificadora aplicada: `.c-menu-horizontal--tabs` Mostrar códigodel ejemplo: Con clases de css aplicadas: tabs en escritorio #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "classes": "c-menu-horizontal--tabs", "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2", "active": true }, { "href": "http://www.google.com", "text": "Opción 3" }, { "href": "http://www.google.com", "text": "Opción 4", "disabled": true }, { "href": "http://www.google.com", "text": "Opción 5" } ], "attributes": { "id": "mi-menu-tabs-en-escritorio", "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con clases aplicadas: tabs en móvil [#](#con-clases-aplicadas-tabs-en-mvil) Clases modificadoras aplicadas: `.c-menu-horizontal--tabs-mobile` y `.c-menu-horizontal--scroll`. Te advertimos que esta aplicación suele dar problemas de accesibilidad y la incluimos para evitar problemas en anchuras muy pequeñas. Asegúrate que los items no desbordan en las anchuras más habituales. Mostrar códigodel ejemplo: Con clases aplicadas: tabs en móvil #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "classes": "c-menu-horizontal--tabs-mobile c-menu-horizontal--scroll", "items": [ { "href": "#", "html": "Seguimiento" }, { "href": "#", "html": "Documentos", "active": true }, { "href": "#", "html": "Notificaciones" } ], "attributes": { "id": "mi-menu-tabs-en-movil", "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con idprefix [#](#con-idprefix) Mostrar código para ver el `idPrefix` aplicado Mostrar códigodel ejemplo: Con idprefix #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "idPrefix": "site-menu-item", "items": [ { "href": "http://www.google.com", "text": "Opción 1" }, { "href": "http://www.google.com", "text": "Opción 2" }, { "href": "http://www.google.com", "text": "Opción 3" }, { "href": "http://www.google.com", "text": "Opción 4" }, { "href": "http://www.google.com", "text": "Opción 5" } ], "attributes": { "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con ids individuales [#](#con-ids-individuales) Mostrar código para ver los `id` aplicados Mostrar códigodel ejemplo: Con ids individuales #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "items": [ { "href": "http://www.google.com", "text": "Opción 1", "id": "option-A" }, { "href": "http://www.google.com", "text": "Opción 2", "id": "option-B" }, { "href": "http://www.google.com", "text": "Opción 3", "id": "option-C" }, { "href": "http://www.google.com", "text": "Opción 4", "id": "option-D" }, { "href": "http://www.google.com", "text": "Opción 5", "id": "option-E" } ], "attributes": { "aria-label": "Menú horizontal" } }) }} ``` ##### HTML ```html ``` ### Con atributos [#](#con-atributos) Muestra el código para ver cómo se aplican los atributos Mostrar códigodel ejemplo: Con atributos #### Contenido Nunjucks macro HTML ##### Nunjucks macro ```js {% from "components/menu-horizontal/_macro.menu-horizontal.njk" import componentMenuHorizontal %} {{ componentMenuHorizontal({ "attributes": { "id": "nav-id-example", "aria-label": "Menú horizontal" }, "items": [ { "href": "http://www.google.com", "text": "Opción 1", "attributes": { "data-attribute-1": "value-A", "data-attribute-2": "value-B", "data-attribute-3": "value-C" } }, { "href": "http://www.google.com", "text": "Opción 2", "attributes": { "data-attribute-1": "value-A", "data-attribute-2": "value-B", "data-attribute-3": "value-C" } }, { "href": "http://www.google.com", "text": "Opción 3", "attributes": { "data-attribute-1": "value-A", "data-attribute-2": "value-B", "data-attribute-3": "value-C" } }, { "href": "http://www.google.com", "text": "Opción 4", "attributes": { "data-attribute-1": "value-A", "data-attribute-2": "value-B", "data-attribute-3": "value-C" } }, { "href": "http://www.google.com", "text": "Opción 5", "attributes": { "data-attribute-1": "value-A", "data-attribute-2": "value-B", "data-attribute-3": "value-C" } } ] }) }} ``` ##### HTML ```html ```