Skip to content

Feat menu active #100

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

Merged
merged 3 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions src/_includes/menu/menu-item.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,58 @@
<li class="menu-item" data-accordion data-class-active="menu-item--active">
{% assign currentPage = page.path | downcase | split: "/" %}
{% assign currentPath = include.root_section.section_title | downcase | slugify %}

<li class="menu-item {% if currentPage[0] == currentPath %}menu-item--active{% endif %}" data-accordion data-class-active="menu-item--active">
{% if include.root_section.path %}
<a class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" href="{{ site.baseurl }}{{ item.path }}">
<div class="menu-item__icon flex__column">
{% include icons/menu/icon-{{ include.root_section.section_title | slugify }}.svg %}
</div>
<a class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" href="{{ site.baseurl }}{{ include.root_section.path }}">
<span class="menu-item__icon flex__column">
{% include icons/menu/icon-{{ currentPath }}.svg %}
</span>

<div class="flex__column">{{ include.root_section.section_title }}</div>
<span class="flex__column">{{ include.root_section.section_title }}</span>
</a>
{% else %}
<div class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" data-ref="accordion[trigger]">
<div class="menu-item__icon flex__column">
{% include icons/menu/icon-{{ include.root_section.section_title | slugify }}.svg %}
</div>
<button class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" data-ref="accordion[trigger]">
<span class="menu-item__icon flex__column">
{% include icons/menu/icon-{{ currentPath }}.svg %}
</span>

<div class="flex__column">{{ include.root_section.section_title }}</div>
</div>
<span class="flex__column">{{ include.root_section.section_title }}</span>
</button>
{% endif %}

{% if include.root_section.section %}
<ul class="menu-item__body" data-ref="accordion[body]">
{% for item in root_section.section %}
<li class="menu-item" data-accordion data-class-active="menu-item--active">
{% assign currentPage = page.path | downcase | replace: "/index.md" "" | replace: ".md" "" %}
{% assign currentPath = item.path | downcase | replace_first: "/" "" %}

{% assign currentSectionPage = page.path | downcase | split: "/" %}
{% assign currentSectionPath = item.slug | downcase %}
{% capture currentSectionSlug %}{{ currentSectionPage[0] | downcase }}/{{ currentSectionPage[1] | downcase }}{% endcapture %}

<li class="menu-item {% if currentPage == currentPath or currentSectionSlug == currentSectionPath %}menu-item--active{% endif %}" data-accordion data-class-active="menu-item--active">
{% if item.path %}
<a class="menu-item__link flex" href="{{ site.baseurl }}{{ item.path }}">{{ item.title }}</a>
<a class="menu-item__link {% if currentPage == currentPath or currentSectionSlug == currentSectionPath %}menu-item__link--indicator-large{% endif %} flex" href="{{ site.baseurl }}{{ item.path }}">{{ item.title }}</a>
{% endif %}

{% if item.section_title %}
<div class="menu-item__link flex flex--middle flex--justify" data-ref="accordion[trigger]">
<div class="flex__column">
<button class="menu-item__link flex flex--middle flex--justify" data-ref="accordion[trigger]">
<span class="flex__column">
{{ item.section_title }}
</div>
</span>

<div class="menu-item__chevron flex__column flex__column--shrink">
{% include icons/symbols/chevron-down.svg %}
</div>
</div>
</span>
</button>

<ul class="menu-item__body menu-item__body--nested" data-ref="accordion[body]">
{% for subsection in item.section %}
<li>
<a class="menu-item__link flex" href="{{ site.baseurl }}{{ subsection.path }}">{{ subsection.title }}</a>
{% assign currentPage = page.path | downcase | replace: "/index.md" "" | replace: ".md" "" %}
{% assign currentPath = subsection.path | downcase | replace_first: "/" "" %}

<li class="menu-item {% if currentPage == currentPath %}menu-item--active menu-item--indicator{% endif %}">
<a class="menu-item__link {% if currentPage == currentPath %}menu-item__link--indicator{% endif %} flex" href="{{ site.baseurl }}{{ subsection.path }}">{{ subsection.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/_includes/menu/menu-primary.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<nav class="menu">
<ul class="menu__list list list--unstyle">
<a class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" href="{{ site.baseurl }}">
<a class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" href="{{ site.baseurl }}/">
<div class="menu-item__icon flex__column">
{% include icons/menu/icon-home.svg %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/_includes/menu/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% endfor %}

<li class="menu-item">
<a class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" href="{{ site.baseurl }}help">
<a class="menu-item__link menu-item__link--highlight menu-item__link--icon flex flex--middle" href="{{ site.baseurl }}/help/">
<div class="menu-item__icon flex__column">
{% include icons/menu/icon-help.svg %}
</div>
Expand Down
33 changes: 33 additions & 0 deletions src/_sass/components/_menu-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
}

&__link {
width: 100%;
text-align: left;
color: color(gray);
line-height: 1.25;
outline: 0;

&:hover {
color: color(primary);
Expand All @@ -65,6 +68,36 @@
margin-right: 18px;
}
}

&--indicator {
position: relative;

&:before {
content: "";
display: block;
position: absolute;
top: 0;
left: -18px;
height: 100%;
width: 2px;
background-color: color(primary);
}
}

&--indicator-large {
position: relative;

&:before {
content: "";
display: block;
position: absolute;
top: 0;
left: -26px;
height: 100%;
width: 2px;
background-color: color(primary);
}
}
}

&__chevron {
Expand Down
2 changes: 2 additions & 0 deletions src/_sass/pages/_docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
position: relative;
z-index: 0;
padding-top: 25px;
padding-bottom: 25px;

&::before {
content: "";
Expand Down Expand Up @@ -35,6 +36,7 @@

&__sidebar {
padding-top: 19px;
padding-bottom: 25px;

& > * + * {
margin-top: 74px;
Expand Down