mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-10 16:05:32 +02:00
the sidebar search selected added
This commit is contained in:
parent
dbce38ad67
commit
22f4a592f2
3 changed files with 40 additions and 3 deletions
|
@ -2,7 +2,7 @@ import Page, { PageData } from '../models/page';
|
||||||
import Alias from '../models/alias';
|
import Alias from '../models/alias';
|
||||||
import PagesOrder from './pagesOrder';
|
import PagesOrder from './pagesOrder';
|
||||||
import PageOrder from '../models/pageOrder';
|
import PageOrder from '../models/pageOrder';
|
||||||
import HttpException from "../exceptions/httpException";
|
import HttpException from '../exceptions/httpException';
|
||||||
|
|
||||||
type PageDataFields = keyof PageData;
|
type PageDataFields = keyof PageData;
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,12 @@ export default class Sidebar {
|
||||||
sectionAnimated: 'docs-sidebar__section--animated',
|
sectionAnimated: 'docs-sidebar__section--animated',
|
||||||
sectionTitle: 'docs-sidebar__section-title',
|
sectionTitle: 'docs-sidebar__section-title',
|
||||||
sectionTitleActive: 'docs-sidebar__section-title--active',
|
sectionTitleActive: 'docs-sidebar__section-title--active',
|
||||||
|
sectionTitleSelected: 'docs-sidebar__section-title--selected',
|
||||||
sectionList: 'docs-sidebar__section-list',
|
sectionList: 'docs-sidebar__section-list',
|
||||||
sectionListItem: 'docs-sidebar__section-list-item',
|
sectionListItem: 'docs-sidebar__section-list-item',
|
||||||
sectionListItemWrapperHidden: 'docs-sidebar__section-list-item-wrapper--hidden',
|
sectionListItemWrapperHidden: 'docs-sidebar__section-list-item-wrapper--hidden',
|
||||||
sectionListItemActive: 'docs-sidebar__section-list-item--active',
|
sectionListItemActive: 'docs-sidebar__section-list-item--active',
|
||||||
|
sectionListItemSlelected: 'docs-sidebar__section-list-item--selected',
|
||||||
sidebarToggler: 'docs-sidebar__toggler',
|
sidebarToggler: 'docs-sidebar__toggler',
|
||||||
sidebarContent: 'docs-sidebar__content',
|
sidebarContent: 'docs-sidebar__content',
|
||||||
sidebarContentHidden: 'docs-sidebar__content--hidden',
|
sidebarContentHidden: 'docs-sidebar__content--hidden',
|
||||||
|
@ -55,6 +57,9 @@ export default class Sidebar {
|
||||||
sidebarContent: null,
|
sidebarContent: null,
|
||||||
toggler: null,
|
toggler: null,
|
||||||
search:null,
|
search:null,
|
||||||
|
searchResults: [],
|
||||||
|
selectedSearchResult: null,
|
||||||
|
selectedSearchResultIndex: null,
|
||||||
};
|
};
|
||||||
this.sidebarStorage = new Storage(LOCAL_STORAGE_KEY);
|
this.sidebarStorage = new Storage(LOCAL_STORAGE_KEY);
|
||||||
const storedState = this.sidebarStorage.get();
|
const storedState = this.sidebarStorage.get();
|
||||||
|
@ -202,18 +207,36 @@ export default class Sidebar {
|
||||||
if (this.nodes.search === document.activeElement) {
|
if (this.nodes.search === document.activeElement) {
|
||||||
if (e.code === 'ArrowUp') {
|
if (e.code === 'ArrowUp') {
|
||||||
console.log("up");
|
console.log("up");
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.code === 'ArrowDown') {
|
if (e.code === 'ArrowDown') {
|
||||||
console.log("down");
|
console.log("down");
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
e.stopImmediatePropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
search(e) {
|
search(e) {
|
||||||
const searchValue = e.target.value;
|
const searchValue = e.target.value;
|
||||||
|
|
||||||
|
if (this.nodes.selectedSearchResult) {
|
||||||
|
const { element, type } = this.nodes.selectedSearchResult;
|
||||||
|
|
||||||
|
if (element) {
|
||||||
|
if (type === 'title') {
|
||||||
|
element.classList.remove(Sidebar.CSS.sectionTitleSelected);
|
||||||
|
}
|
||||||
|
if ( type === 'item') {
|
||||||
|
element.classList.remove(Sidebar.CSS.sectionListItemSlelected);
|
||||||
|
}
|
||||||
|
this.nodes.selectedSearchResult = null;
|
||||||
|
this.nodes.selectedSearchResultIndex = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.nodes.searchResults = [];
|
||||||
this.nodes.sections.forEach(section => {
|
this.nodes.sections.forEach(section => {
|
||||||
const sectionTitle = section.querySelector('.' + Sidebar.CSS.sectionTitle);
|
const sectionTitle = section.querySelector('.' + Sidebar.CSS.sectionTitle);
|
||||||
let isTitleMatch = true;
|
let isTitleMatch = true;
|
||||||
|
@ -233,6 +256,10 @@ export default class Sidebar {
|
||||||
if (item.innerText.trim().toLowerCase()
|
if (item.innerText.trim().toLowerCase()
|
||||||
.indexOf(searchValue.toLowerCase()) !== -1) {
|
.indexOf(searchValue.toLowerCase()) !== -1) {
|
||||||
item.parentElement.classList.remove(Sidebar.CSS.sectionListItemWrapperHidden);
|
item.parentElement.classList.remove(Sidebar.CSS.sectionListItemWrapperHidden);
|
||||||
|
this.nodes.searchResults.push({
|
||||||
|
element:item,
|
||||||
|
type:'item',
|
||||||
|
});
|
||||||
isItemMatch = true;
|
isItemMatch = true;
|
||||||
} else {
|
} else {
|
||||||
item.parentElement.classList.add(Sidebar.CSS.sectionListItemWrapperHidden);
|
item.parentElement.classList.add(Sidebar.CSS.sectionListItemWrapperHidden);
|
||||||
|
@ -243,6 +270,10 @@ export default class Sidebar {
|
||||||
section.classList.add(Sidebar.CSS.sectionHidden);
|
section.classList.add(Sidebar.CSS.sectionHidden);
|
||||||
} else {
|
} else {
|
||||||
section.classList.remove(Sidebar.CSS.sectionHidden);
|
section.classList.remove(Sidebar.CSS.sectionHidden);
|
||||||
|
this.nodes.searchResults.push({
|
||||||
|
element:sectionTitle,
|
||||||
|
type:'title',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
|
|
|
@ -123,6 +123,12 @@
|
||||||
transition-property: background-color;
|
transition-property: background-color;
|
||||||
transition-duration: 0.1s;
|
transition-duration: 0.1s;
|
||||||
@apply --squircle;
|
@apply --squircle;
|
||||||
|
|
||||||
|
&--selected
|
||||||
|
{
|
||||||
|
border: 2px solid rgba(147, 166, 233, 0.5);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__section-title > span,
|
&__section-title > span,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue