Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(navigation): permet l'ajout d'icone sur les liens de navigation #913

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
31 changes: 18 additions & 13 deletions src/component/navigation/example/sample/navigation.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@
let navigation = locals.navigation || {};
const href = navigation.href || '#'

const getLink = () => {
const getLink = (icon, iconPlace) => {
const id = uniqueId('nav');
return {
type: 'link',
label: `accès direct ${id}`,
id: id,
href: href
href: href,
icon: icon,
iconPlace: iconPlace
};

}

const getSubLink = (active = false) => {
const getSubLink = (active = false, icon, iconPlace) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça me fait ticker de voir un argument par défaut en premier

Suggested change
const getSubLink = (active = false, icon, iconPlace) => {
const getSubLink = (active = false, icon = undefined, iconPlace = 'left') => {

const id = uniqueId('nav');
return {
label: `Lien de navigation ${id}`,
id: id,
href: href,
active: active
active: active,
icon: icon,
iconPlace: iconPlace
}
}

const getItems = (active = false) => {
return [
getSubLink(),
getSubLink(),
getSubLink(false, 'arrow-right-line', 'right'),
getSubLink(active),
getSubLink(),
getSubLink(),
getSubLink(),
getSubLink(false, 'arrow-left-line'),
getSubLink(),
getSubLink()
];
Expand All @@ -47,12 +50,14 @@ const getMenu = (active = false) => {
}
}

const getCategory = (active = false) => {
const getCategory = (active = false, icon, iconPlace) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const getCategory = (active = false, icon, iconPlace) => {
const getCategory = (active = false, icon = undefined, iconPlace = 'left') => {

return {
id: uniqueId('category'),
label: 'Nom de catégorie',
href: href,
items: getItems(active)
items: getItems(active),
icon: icon,
iconPlace: iconPlace
};
}

Expand All @@ -76,9 +81,9 @@ const getMega = (active = false, leader = false) => {
}}),
categories: [
getCategory(),
getCategory(),
getCategory(false, 'arrow-left-line'),
getCategory(true),
getCategory()
getCategory(false,'arrow-right-line', 'right')
]
}
}
Expand All @@ -90,10 +95,10 @@ let data = {
[
getMenu(),
getMega(),
getLink(),
getLink('arrow-left-line'),
getMenu(true),
getMega(false, true),
getLink(),
getLink('arrow-right-line', 'right'),
getMega(true, false),
getMenu()
]
Expand Down
1 change: 1 addition & 0 deletions src/component/navigation/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
////

@import '../link/index';
@import '../button/index';

@import '../../core/index';
44 changes: 15 additions & 29 deletions src/component/navigation/style/module/_default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,9 @@
// @include z-index(auto);

@include selector.current {
@include before {
@include absolute(auto, null, 0, 0, 100%, 2px);
@include margin-top(0);

@include preference.forced-colors {
background-color: highlight;
@include height(1v);
}
}
background-repeat: no-repeat;
background-position: 0 100%;
background-size: #{spacing.space(100% 0.5v)};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai l'impression que la version high contrast a été retirée sans être remise ailleurs.
Est-elle toujours bien fonctionnelle ?

}
}
}
Expand All @@ -82,6 +76,14 @@
@include min-height(auto, lg);
}

#{ns(nav__btn)} {
lab9fr marked this conversation as resolved.
Show resolved Hide resolved
@include icon(arrow-down-s-line, sm, after) {
@include margin-left(2v);
@include margin-right(0);
transition: transform 0.3s;
}
}

@include respond-from(lg) {
position: initial;
@include before(none);
Expand All @@ -95,6 +97,7 @@

&__link,
&__btn {
@include nest-btn(sm, left, null, null, false);
@include size(100%);
@include padding(3v 4v);
@include text-style(md);
Expand All @@ -108,15 +111,9 @@

@include selector.current {
position: relative;
@include before('', block) {
@include absolute(50%, null, null, 0, 2px, 6v);
@include margin-top(-3v);

@include preference.forced-colors {
background-color: highlight;
@include width(1v);
}
}
background-repeat: no-repeat;
background-position: #{spacing.space(0 3v)};
background-size: #{spacing.space(2px calc(100% - 6v))};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem ici pour le high contrast

}
}

Expand All @@ -136,17 +133,6 @@
flex-direction: row;
@include padding(4v 3v 4v 4v, lg);

@include icon(arrow-down-s-line, sm, after) {
@include margin-left(2v);
@include margin-right(0);
transition: transform 0.3s;

@include preference.reduce-motion {
transition: none;
}
}
@include icon-forced-color(buttontext, true, after);

@include respond-from(lg) {
justify-content: flex-start;
}
Expand Down
4 changes: 1 addition & 3 deletions src/component/navigation/style/scheme/_default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

@include selector.current {
@include color.text(active blue-france, (legacy: $legacy));
@include before {
@include color.background(active blue-france, (legacy: $legacy));
}
@include color.background-image(active blue-france, (legacy:$legacy));
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/component/navigation/template/ejs/link.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

* link.href (string, required) : url du lien

* link.icon (string, optional) : icone du lien

* link.iconPlace (string, optional) : emplacement de l'icone
si non défini alors que le paramètre icon est défini, bouton avec icone seule, sans libellé
valeurs :
* left : icone à gauche du libellé
* right : icone à droite du libellé

* link.blank (boolean, optional) [default: false] : si true, target '_blank'

* link.active (boolean, optional) : si true l'élément est actif
Expand All @@ -17,6 +25,23 @@

<%
let link = locals.link || {};
const classes = link.classes || [];
classes.push(prefix + '-nav__link');

if (link.icon !== undefined) classes.push(`${prefix}-icon-${link.icon}`);

if (link.iconPlace !== undefined) {
switch (link.iconPlace) {
case 'left':
classes.push(`${prefix}-link--icon-left`);
break;

case 'right':
classes.push(`${prefix}-link--icon-right`);
break;
}
}

let attrs = {
href: link.href,
id: link.id
Expand All @@ -26,4 +51,4 @@ if (link.blank) attrs = {...targetBlankData(), ...attrs};
if (link.active) attrs['aria-current'] = link.isPage ? 'page' : 'true';

%>
<a class="<%= prefix %>-nav__link" <%- includeAttrs(attrs); %> ><%- link.label %></a>
<a <%- includeClasses(classes); %> <%- includeAttrs(attrs); %> ><%- link.label %></a>