- Now has a hover state to match other items.
- Now spans the full sidebar with like other items.
- Also updated chapter-toggle to a chapter-contents component, following
the newer component system.
--- /dev/null
+import {slideUp, slideDown} from "../services/animations";
+
+/**
+ * @extends {Component}
+ */
+class ChapterContents {
+
+ setup() {
+ this.list = this.$refs.list;
+ this.toggle = this.$refs.toggle;
+
+ this.isOpen = this.toggle.classList.contains('open');
+ this.toggle.addEventListener('click', this.click.bind(this));
+ }
+
+ open() {
+ this.toggle.classList.add('open');
+ this.toggle.setAttribute('aria-expanded', 'true');
+ slideDown(this.list, 180);
+ this.isOpen = true;
+ }
+
+ close() {
+ this.toggle.classList.remove('open');
+ this.toggle.setAttribute('aria-expanded', 'false');
+ slideUp(this.list, 180);
+ this.isOpen = false;
+ }
+
+ click(event) {
+ event.preventDefault();
+ this.isOpen ? this.close() : this.open();
+ }
+
+}
+
+export default ChapterContents;
+++ /dev/null
-import {slideUp, slideDown} from "../services/animations";
-
-class ChapterToggle {
-
- constructor(elem) {
- this.elem = elem;
- this.isOpen = elem.classList.contains('open');
- elem.addEventListener('click', this.click.bind(this));
- }
-
- open() {
- const list = this.elem.parentNode.querySelector('.inset-list');
- this.elem.classList.add('open');
- this.elem.setAttribute('aria-expanded', 'true');
- slideDown(list, 180);
- }
-
- close() {
- const list = this.elem.parentNode.querySelector('.inset-list');
- this.elem.classList.remove('open');
- this.elem.setAttribute('aria-expanded', 'false');
- slideUp(list, 180);
- }
-
- click(event) {
- event.preventDefault();
- this.isOpen ? this.close() : this.open();
- this.isOpen = !this.isOpen;
- }
-
-}
-
-export default ChapterToggle;
import autoSuggest from "./auto-suggest.js"
import backToTop from "./back-to-top.js"
import bookSort from "./book-sort.js"
-import chapterToggle from "./chapter-toggle.js"
+import chapterContents from "./chapter-contents.js"
import codeEditor from "./code-editor.js"
import codeHighlighter from "./code-highlighter.js"
import codeTextarea from "./code-textarea.js"
"auto-suggest": autoSuggest,
"back-to-top": backToTop,
"book-sort": bookSort,
- "chapter-toggle": chapterToggle,
+ "chapter-contents": chapterContents,
"code-editor": codeEditor,
"code-highlighter": codeHighlighter,
"code-textarea": codeTextarea,
}
}
-[chapter-toggle] {
+.chapter-contents-toggle {
cursor: pointer;
margin: 0;
transition: all ease-in-out 180ms;
transform: rotate(90deg);
}
svg[data-icon="caret-right"] + * {
- margin-inline-start: $-xs;
+ margin-inline-start: $-xxs;
}
}
> .content {
flex: 1;
}
- .chapter-expansion-toggle {
+ .chapter-contents-toggle {
border-radius: 0 4px 4px 0;
padding: $-xs ($-m + $-xxs);
width: 100%;
text-align: start;
}
- .chapter-expansion-toggle:hover {
+ .chapter-contents-toggle:hover {
background-color: rgba(0, 0, 0, 0.06);
}
}
border-radius: 0 3px 3px 0;
padding-inline-end: 0;
.content {
+ width: 100%;
padding-top: $-xs;
padding-bottom: $-xs;
max-width: calc(100% - 20px);
margin-top: -.2rem;
margin-inline-start: -1rem;
}
- [chapter-toggle] {
- padding-inline-start: .7rem;
- padding-bottom: .2rem;
+ .chapter-contents-toggle {
+ display: block;
+ width: 100%;
+ text-align: left;
+ padding: $-xxs $-s ($-xxs * 2) $-s;
+ border-radius: 0 3px 3px 0;
+ line-height: 1;
+ margin-top: -$-xxs;
+ margin-bottom: -$-xxs;
+ &:hover {
+ @include lightDark(background-color, rgba(0, 0, 0, 0.06), rgba(255, 255, 255, 0.06));
+ }
}
.entity-list-item .icon {
z-index: 2;
}
}
-.chapter-child-menu {
- ul.sub-menu {
- display: none;
- padding-inline-start: 0;
- position: relative;
- margin-bottom: 0;
- }
- [chapter-toggle].open + .sub-menu {
- display: block;
- }
+.chapter-child-menu ul.sub-menu {
+ display: none;
+ padding-inline-start: 0;
+ position: relative;
+ margin-bottom: 0;
}
// Sortable Lists
}
.entity-list-item-children {
- padding: $-m;
+ padding: $-m $-l;
> div {
overflow: hidden;
padding: 0 0 $-xs 0;
-<div class="chapter-child-menu">
- <button chapter-toggle type="button" aria-expanded="{{ $isOpen ? 'true' : 'false' }}"
- class="text-muted @if($isOpen) open @endif">
+<div component="chapter-contents" class="chapter-child-menu">
+ <button type="button"
+ refs="chapter-contents@toggle"
+ aria-expanded="{{ $isOpen ? 'true' : 'false' }}"
+ class="text-muted chapter-contents-toggle @if($isOpen) open @endif">
@icon('caret-right') @icon('page') <span>{{ trans_choice('entities.x_pages', $bookChild->visible_pages->count()) }}</span>
</button>
- <ul class="sub-menu inset-list @if($isOpen) open @endif" @if($isOpen) style="display: block;" @endif role="menu">
+ <ul refs="chapter-contents@list"
+ class="chapter-contents-list sub-menu inset-list @if($isOpen) open @endif" @if($isOpen)
+ style="display: block;" @endif
+ role="menu">
@foreach($bookChild->visible_pages as $childPage)
<li class="list-item-page {{ $childPage->isA('page') && $childPage->draft ? 'draft' : '' }}" role="presentation">
@include('entities.list-item-basic', ['entity' => $childPage, 'classes' => $current->matches($childPage)? 'selected' : '' ])
@if ($chapter->visible_pages->count() > 0)
<div class="chapter chapter-expansion">
<span class="icon text-chapter">@icon('page')</span>
- <div class="content">
- <button type="button" chapter-toggle
+ <div component="chapter-contents" class="content">
+ <button type="button"
+ refs="chapter-contents@toggle"
aria-expanded="false"
- class="text-muted chapter-expansion-toggle">@icon('caret-right') <span>{{ trans_choice('entities.x_pages', $chapter->visible_pages->count()) }}</span></button>
- <div class="inset-list">
+ class="text-muted chapter-contents-toggle">@icon('caret-right') <span>{{ trans_choice('entities.x_pages', $chapter->visible_pages->count()) }}</span></button>
+ <div refs="chapter-contents@list" class="inset-list chapter-contents-list">
<div class="entity-list-item-children">
@include('entities.list', ['entities' => $chapter->visible_pages])
</div>