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(sidebar): added third level navigation support for sidebar and c… #1347

Closed
wants to merge 2 commits into from
Closed
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
44 changes: 44 additions & 0 deletions pages/src/collection-grid/collection-grid.less
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@

&-column {
grid-template-columns: 1fr 1fr;

@media @xs {
grid-template-columns: 1fr;
}
}

&-column &-item {
Expand Down Expand Up @@ -133,5 +137,45 @@
}
.arrows-icon.right {
transform: rotate(-45deg);
transition: transform .4s ease-in-out;
}

&-accordion-item {
margin: 0;
border: 1px solid #c8d6f0;
border-radius: .75rem;
transition: border-color .25s ease-in-out;

&:hover {
border-color: @primary-blue;
}

.collection-grid-item {
border: none;
background-color: transparent;
}

& > .collection-grid-item {
border-bottom: 1px solid transparent;
transition: border-bottom-color .4s ease-in-out, border-radius 0s .4s;

.arrows-icon.right {
display: block;
}

&:hover {
border-color: transparent;
}

&[active] {
border-bottom-color: #c8d6f0;
border-radius: .75rem .75rem 0 0;
transition: border-bottom-color .4s ease-in-out, border-radius 0s;

.arrows-icon.right {
transform: rotate(45deg);
}
}
}
}
}
35 changes: 27 additions & 8 deletions pages/src/navigation/sidebar/sidebar-seccondary-nav.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,46 @@ esl-d-sidebar {
.sidebar-nav-secondary {
width: 100%;
}
.sidebar-nav-secondary-list {
padding: 2px 0;
.sidebar-nav-nested-list {
padding-top: 2px;
}
.sidebar-nav-secondary-item {
display: block;
.sidebar-nav-secondary-item-heading,
.sidebar-nav-third-item-heading {
display: flex;
position: relative;
padding: 10px 35px 10px 70px;

&.active {
color: @nav-dark-selected;
background: linear-gradient(to right, fade(@nav-dark-selected, 25%), fade(@nav-dark-selected, 0%));
}
}
.sidebar-nav-secondary-item-heading {
@media @sm {
padding-left: 81px;
}
@media @md-xl {
padding-left: 66px;
}
}
.sidebar-nav-third-item-heading {
padding-left: 90px;

@media @sm {
padding-left: 101px;
}
}
.sidebar-nav-secondary-item-trigger {
flex: 1 0 auto;

&.active {
color: @nav-dark-selected;
background: linear-gradient(to right, fade(@nav-dark-selected, 25%), fade(@nav-dark-selected, 0%));
&[active] {
&.sidebar-nav-item-arrow::after {
transform: rotate(180deg);
}
}
}
.sidebar-nav-secondary-link {
.sidebar-nav-item-nested-link,
.sidebar-nav-secondary-item-trigger {
display: block;
font-size: 1rem;
font-weight: 400;
Expand Down
35 changes: 27 additions & 8 deletions pages/src/navigation/sidebar/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ESLDemoSidebar extends ESLToggleable {
@prop() public closeOnOutsideAction = true;

@prop() public submenus: string = '.sidebar-nav-secondary';
@prop() public secondarySubmenus: string = '.sidebar-nav-third';
@prop() public activeMenuAttr: string = 'data-open';

@boolAttr({name: 'animation'}) protected _animation: boolean;
Expand All @@ -24,6 +25,18 @@ export class ESLDemoSidebar extends ESLToggleable {
return Array.from(this.querySelectorAll(this.submenus));
}

public get $secondarySubmenus(): ESLToggleable[] {
return Array.from(this.querySelectorAll(this.secondarySubmenus));
}

protected get isDesktop(): boolean {
return ESLMediaQuery.for('@+MD').matches;
}

protected get isStoredOpen(): boolean {
return !localStorage.getItem('sidebar-collapsed');
}

@ready
protected connectedCallback(): void {
super.connectedCallback();
Expand All @@ -34,17 +47,23 @@ export class ESLDemoSidebar extends ESLToggleable {
}

protected setInitialState(): void {
const isDesktop = ESLMediaQuery.for('@+MD').matches;
const isStoredOpen = !localStorage.getItem('sidebar-collapsed');
this.toggle(isDesktop && isStoredOpen, {force: true, initiator: 'init', immediate: true});
const initialParams = {force: true, initiator: 'init', immediate: true};

if (this.isDesktop) {
this.toggle(this.isStoredOpen, initialParams);
} else {
this.show(initialParams);
this.hide(initialParams);
}
}

public collapseAll(): void {
this.$submenus.forEach((menu) => menu.hide({activator: this}));
}

public expandActive(noAnimate: boolean = false): void {
this.$submenus
const submenus = noAnimate ? this.$submenus.concat(this.$secondarySubmenus) : this.$submenus;
submenus
.filter((menu) => menu.hasAttribute('data-open'))
.forEach((menu) => menu.show({noAnimate, activator: this}));
}
Expand All @@ -63,6 +82,7 @@ export class ESLDemoSidebar extends ESLToggleable {
this.storeState();
}
}

protected onHide(params: SidebarActionParams): void {
this._animation = !params.immediate;
super.onHide(params);
Expand All @@ -76,14 +96,13 @@ export class ESLDemoSidebar extends ESLToggleable {
event: 'change',
target: ESLMediaQuery.for('@+MD')
})
protected onBreakpointChange({matches: isDesktop}: MediaQueryListEvent): void {
const isStoredOpen = !localStorage.getItem('sidebar-collapsed');
this.toggle(isDesktop && isStoredOpen, {force: true, initiator: 'bpchange', immediate: !isDesktop});
protected onBreakpointChange(): void {
this.toggle(this.isDesktop && this.isStoredOpen, {force: true, initiator: 'bpchange', immediate: !this.isDesktop});
}

@listen({inherit: true})
protected _onOutsideAction(e: Event): void {
if (ESLMediaQuery.for('@+MD').matches) return;
if (this.isDesktop) return;
super._onOutsideAction(e);
}
}
14 changes: 14 additions & 0 deletions pages/views/_includes/badge.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% macro applyBadge(tags, isDraftCollection = false, location = '') %}
{% set isDraft = [].concat(tags).includes('draft') %}
{% set isNew = [].concat(tags).includes('new') %}
{% set isBeta = [].concat(tags).includes('beta') %}
{% if isNew %}
<sup class="badge badge-sup badge-success {% if location === 'sidebar' %}badge-sidebar{% endif %}">new</sup>
{% endif %}
{% if isBeta %}
<sup class="badge badge-sup badge-warning {% if location === 'sidebar' %}badge-sidebar{% endif %}">beta</sup>
{% endif %}
{% if isDraft %}
<sup class="badge badge-sup badge-danger {% if location === 'sidebar' %}badge-sidebar{% endif %}" {% if isDraftCollection %}hidden{% endif %}>draft</sup>
{% endif %}
{% endmacro %}
71 changes: 50 additions & 21 deletions pages/views/_includes/navigation/sidebar-item.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% from 'badge.njk' import applyBadge with context %}

{% macro navitem(title, collection, icon, opt = {}) %}
{% set isPrimaryActive = functions.isActivePath(page.url, collection) %}
{% set items = collections[collection] | released %}
{% set isDraftCollection = collection == 'draft' %}
{% set isDraftCollection = collection === 'draft' %}

{% if items.length %}
<div class="sidebar-nav-item-heading {{ 'active' if isPrimaryActive }}">
Expand All @@ -24,31 +26,58 @@
<esl-panel id="sidebar-{{ collection }}-menu"
class="sidebar-nav-secondary {{ 'open' if isPrimaryActive }}"
{% if isPrimaryActive %}data-open{% endif %}
group="esl-nav"
fallback-duration="400">
<ul class="sidebar-nav-secondary-list">
<esl-a11y-group targets="::child(li)::find(.sidebar-nav-secondary-link)"></esl-a11y-group>
group="esl-nav">
<ul class="sidebar-nav-nested-list">
<esl-a11y-group targets="::child(li)::find(.sidebar-nav-item-nested-link)"></esl-a11y-group>
{% for item in items | sortByNameAndOrder %}
{% set isActive = page.url === item.url %}
{% set isDraft = [].concat(item.data.tags).includes('draft') %}
{% set isNew = [].concat(item.data.tags).includes('new') %}
{% set isBeta = [].concat(item.data.tags).includes('beta') %}
<li class="sidebar-nav-secondary-item {{ 'active' if isActive }} {{ 'draft' if isDraft }}"
{% set isSecondaryActive = functions.isActivePath(page.url, item.data.collection) %}
{% set isList = item.data.collection %}
<li class="sidebar-nav-secondary-item">
<div class="sidebar-nav-secondary-item-heading {{ 'active' if isActive or isSecondaryActive }}"
{% if isActive %}aria-selected="true"{% endif %}>
<a class="sidebar-nav-secondary-link"
{% if isActive %}aria-current="page"{% endif %}
href="{{ item.url | url }}">
{% if isNew %}
<sup class="badge badge-sup badge-success badge-sidebar">new</sup>
{% endif %}
{% if isBeta %}
<sup class="badge badge-sup badge-warning badge-sidebar">beta</sup>
{% if not isList %}
<a class="sidebar-nav-item-nested-link"
{% if isActive %}aria-current="page"{% endif %}
href="{{ item.url | url }}">
{{ applyBadge (item.data.tags, isDraftCollection, 'sidebar') }}
{{ item.data.name }}
</a>
{% endif %}
{% if isDraft %}
<sup class="badge badge-sup badge-danger badge-sidebar" {% if isDraftCollection %}hidden{% endif %}>draft</sup>
{% if isList %}
<esl-trigger class="sidebar-nav-secondary-item-trigger sidebar-nav-item-arrow"
target="::parent::next"
{% if isSecondaryActive and not isDraftCollection %}active{% endif %}>
{{ applyBadge (item.data.tags, isDraftCollection, 'sidebar') }}
{{ item.data.name }}
</esl-trigger>
{% endif %}
{{ item.data.name }}
</a>
</div>
{% if isList %}
{% set subItems = collections[item.data.collection] | released %}
<esl-panel id="sidebar-{{ item.data.collection }}-menu{% if isDraftCollection %}-draft{% endif %}"
class="sidebar-nav-third {{ 'open' if isSecondaryActive and not isDraftCollection }}"
{% if isSecondaryActive and not isDraftCollection %}data-open{% endif %}
group="esl-nav-secondary">
<ul class="sidebar-nav-nested-list">
<esl-a11y-group targets="::child(li)::find(.sidebar-nav-item-nested-link)"></esl-a11y-group>
{% for subItem in subItems | sortByNameAndOrder %}
{% set isThirdActive = page.url === subItem.url %}
<li class="sidebar-nav-third-item">
<div class="sidebar-nav-third-item-heading {{ 'active' if isThirdActive }}"
{% if isThirdActive %}aria-selected="true"{% endif %}>
<a class="sidebar-nav-item-nested-link"
{% if isThirdActive %}aria-current="page"{% endif %}
href="{{ subItem.url | url }}">
{{ applyBadge (subItem.data.tags, isDraftCollection, 'sidebar') }}
{{ subItem.data.name }}
</a>
</div>
</li>
{% endfor %}
</ul>
</esl-panel>
{% endif %}
</li>
{% endfor %}
</ul>
Expand Down
Loading