mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-09 15:35:25 +02:00
Mobile layout
This commit is contained in:
parent
c43d7f0cab
commit
52dfbf37e9
4 changed files with 99 additions and 57 deletions
|
@ -1,35 +1,42 @@
|
||||||
|
|
||||||
{% set mainClass = 'docs-sidebar' %}
|
{% set mainClass = 'docs-sidebar' %}
|
||||||
|
|
||||||
<aside class="{{mainClass}}" data-module="sidebar">
|
<div data-module="sidebar" class="{{mainClass}}__wrapper">
|
||||||
{% for firstLevelPage in menu %}
|
|
||||||
<section class="docs-sidebar__section" data-id="{{firstLevelPage._id}}">
|
<div class="docs-sidebar__toggler">
|
||||||
<a
|
{{ svg('menu') }} Table of contents
|
||||||
class="docs-sidebar__section-title {{page is defined and page._id == firstLevelPage._id ? 'docs-sidebar__section-title--active' : ''}}"
|
</div>
|
||||||
href="{{firstLevelPage.uri ? '/' ~ firstLevelPage.uri : '/page/' ~ firstLevelPage._id }}"
|
|
||||||
>
|
<aside class="{{mainClass}}">
|
||||||
<span>
|
{% for firstLevelPage in menu %}
|
||||||
{{ firstLevelPage.title | striptags }}
|
<section class="docs-sidebar__section" data-id="{{firstLevelPage._id}}">
|
||||||
</span>
|
<a
|
||||||
{% if firstLevelPage.children is not empty %}
|
class="docs-sidebar__section-title {{page is defined and page._id == firstLevelPage._id ? 'docs-sidebar__section-title--active' : ''}}"
|
||||||
<button class="docs-sidebar__section-toggler">
|
href="{{firstLevelPage.uri ? '/' ~ firstLevelPage.uri : '/page/' ~ firstLevelPage._id }}"
|
||||||
{{ svg('arrow-up') }}
|
>
|
||||||
</button>
|
<span>
|
||||||
{% endif %}
|
{{ firstLevelPage.title | striptags }}
|
||||||
</a>
|
</span>
|
||||||
{% if firstLevelPage.children is not empty %}
|
{% if firstLevelPage.children is not empty %}
|
||||||
<ul class="docs-sidebar__section-list">
|
<button class="docs-sidebar__section-toggler">
|
||||||
{% for child in firstLevelPage.children %}
|
{{ svg('arrow-up') }}
|
||||||
<li class="docs-sidebar__section-list-item-wrapper">
|
</button>
|
||||||
<a
|
{% endif %}
|
||||||
class="docs-sidebar__section-list-item {{page is defined and page._id == child._id ? 'docs-sidebar__section-list-item--active' : ''}}"
|
</a>
|
||||||
href="{{ child.uri ? '/' ~ child.uri : '/page/' ~ child._id }}">
|
{% if firstLevelPage.children is not empty %}
|
||||||
<span> {{ child.title | striptags }} </span>
|
<ul class="docs-sidebar__section-list">
|
||||||
</a>
|
{% for child in firstLevelPage.children %}
|
||||||
</li>
|
<li class="docs-sidebar__section-list-item-wrapper">
|
||||||
{% endfor %}
|
<a
|
||||||
</ul>
|
class="docs-sidebar__section-list-item {{page is defined and page._id == child._id ? 'docs-sidebar__section-list-item--active' : ''}}"
|
||||||
{% endif %}
|
href="{{ child.uri ? '/' ~ child.uri : '/page/' ~ child._id }}">
|
||||||
</section>
|
<span> {{ child.title | striptags }} </span>
|
||||||
{% endfor %}
|
</a>
|
||||||
</aside>
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
{% endfor %}
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
|
|
@ -23,6 +23,9 @@ export default class Sidebar {
|
||||||
sectionList: 'docs-sidebar__section-list',
|
sectionList: 'docs-sidebar__section-list',
|
||||||
sectionListCollapsed: 'docs-sidebar__section-list--collapsed',
|
sectionListCollapsed: 'docs-sidebar__section-list--collapsed',
|
||||||
sectionListItemActive: 'docs-sidebar__section-list-item--active',
|
sectionListItemActive: 'docs-sidebar__section-list-item--active',
|
||||||
|
sidebarToggler: 'docs-sidebar__toggler',
|
||||||
|
sidebar: 'docs-sidebar',
|
||||||
|
sidebarHidden: 'docs-sidebar--hidden',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +33,7 @@ export default class Sidebar {
|
||||||
* Creates base properties
|
* Creates base properties
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.nodes = {
|
this.nodes = {};
|
||||||
section: null,
|
|
||||||
};
|
|
||||||
const storedState = window.localStorage.getItem(LOCAL_STORAGE_KEY);
|
const storedState = window.localStorage.getItem(LOCAL_STORAGE_KEY);
|
||||||
|
|
||||||
this.collapsed = storedState ? JSON.parse(storedState) : {};
|
this.collapsed = storedState ? JSON.parse(storedState) : {};
|
||||||
|
@ -50,7 +51,11 @@ export default class Sidebar {
|
||||||
const id = section.getAttribute('data-id');
|
const id = section.getAttribute('data-id');
|
||||||
const togglerEl = section.querySelector('.' + Sidebar.CSS.toggler);
|
const togglerEl = section.querySelector('.' + Sidebar.CSS.toggler);
|
||||||
|
|
||||||
togglerEl.addEventListener('click', e => this.handleTogglerClick(id, section, togglerEl, e));
|
if (!togglerEl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
togglerEl.addEventListener('click', e => this.handleSectionTogglerClick(id, section, togglerEl, e));
|
||||||
|
|
||||||
if (typeof this.collapsed[id] === 'undefined') {
|
if (typeof this.collapsed[id] === 'undefined') {
|
||||||
this.collapsed[id] = false;
|
this.collapsed[id] = false;
|
||||||
|
@ -59,6 +64,9 @@ export default class Sidebar {
|
||||||
this.setSectionCollapsed(section, togglerEl, true, false);
|
this.setSectionCollapsed(section, togglerEl, true, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.nodes.sidebar = moduleEl.querySelector('.' + Sidebar.CSS.sidebar);
|
||||||
|
this.nodes.toggler = moduleEl.querySelector('.' + Sidebar.CSS.sidebarToggler);
|
||||||
|
this.nodes.toggler.addEventListener('click', () => this.toggleSidebar());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +78,7 @@ export default class Sidebar {
|
||||||
* @param {MouseEvent} event - click event
|
* @param {MouseEvent} event - click event
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
handleTogglerClick(sectionId, sectionEl, togglerEl, event) {
|
handleSectionTogglerClick(sectionId, sectionEl, togglerEl, event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.collapsed[sectionId] = !this.collapsed[sectionId];
|
this.collapsed[sectionId] = !this.collapsed[sectionId];
|
||||||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(this.collapsed));
|
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(this.collapsed));
|
||||||
|
@ -112,4 +120,13 @@ export default class Sidebar {
|
||||||
sectionTitle.classList.toggle(Sidebar.CSS.sectionTitleActive, collapsed);
|
sectionTitle.classList.toggle(Sidebar.CSS.sectionTitleActive, collapsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles sidebar visibility
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
toggleSidebar() {
|
||||||
|
this.nodes.sidebar.classList.toggle(Sidebar.CSS.sidebarHidden);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
.docs-sidebar {
|
.docs-sidebar {
|
||||||
width: 344px;
|
border-bottom: 1px solid var(--color-line-gray);
|
||||||
border-right: 1px solid var(--color-line-gray);
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 30px 22px;
|
padding: 30px 22px;
|
||||||
height: calc(100vh - var(--layout-height-header));
|
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: var(--layout-height-header);
|
top: var(--layout-height-header);
|
||||||
|
|
||||||
|
@media (--desktop) {
|
||||||
|
height: calc(100vh - var(--layout-height-header));
|
||||||
|
border-right: 1px solid var(--color-line-gray);
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__wrapper {
|
||||||
|
width: 100vw;
|
||||||
|
|
||||||
|
@media (--desktop) {
|
||||||
|
width: 344px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&__section {
|
&__section {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
@ -105,4 +117,24 @@
|
||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__toggler {
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--color-text-second);
|
||||||
|
padding: 20px 15px;
|
||||||
|
border-bottom: 1px solid var(--color-line-gray);
|
||||||
|
|
||||||
|
@media (--desktop) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,21 +1,8 @@
|
||||||
.docs {
|
.docs {
|
||||||
display: flex;
|
|
||||||
min-height: calc(100vh - var(--layout-height-header));
|
min-height: calc(100vh - var(--layout-height-header));
|
||||||
|
|
||||||
@media (--mobile) {
|
@media (--desktop) {
|
||||||
flex-wrap: wrap;
|
display: flex;
|
||||||
}
|
|
||||||
|
|
||||||
&__aside {
|
|
||||||
width: var(--layout-width-aside);
|
|
||||||
|
|
||||||
@media (--mobile) {
|
|
||||||
width: 100%;
|
|
||||||
flex-basis: 100%;
|
|
||||||
padding: 20px var(--layout-padding-horizontal) !important;
|
|
||||||
margin: 0 calc(-1 * var(--layout-padding-horizontal));
|
|
||||||
border-bottom: 1px solid var(--color-line-gray);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__content {
|
&__content {
|
||||||
|
@ -34,12 +21,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__aside,
|
|
||||||
&__content {
|
&__content {
|
||||||
padding: var(--layout-padding-vertical) var(--layout-padding-horizontal);
|
padding: var(--layout-padding-vertical) var(--layout-padding-horizontal);
|
||||||
|
|
||||||
@media (--mobile) {
|
@media (--mobile) {
|
||||||
padding: 20px 0;
|
padding: 20px var(--layout-padding-horizontal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue