HM-79. Добавлена работа формы с ручкой, валидация формы. HM-88. Добавлены пункты меню с js. HM-76. Добавлена подсветка элементов меню (#40)

This commit is contained in:
Nikolay
2020-08-01 17:32:59 +03:00
committed by GitHub
parent 281ec56288
commit 8c1daa5771
18 changed files with 252 additions and 137 deletions

View File

@ -0,0 +1,89 @@
import Component from '../component/index';
import routeService from '../../services/RouteService';
import Image from '../../img/logo.svg';
import './MainMenu.css';
import {createElement} from '../../utils/elementUtils';
import {EVENTS} from '../../consts';
export const NAV_MENU = [
{
title: 'Главная',
url: '/'
},
{
title: 'Список хранилищ',
url: '/api'
},
{
title: 'Журнал',
url: '/logs'
},
];
class MainMenu extends Component {
menuItems = [];
constructor () {
super('#main-menu', document.body);
this.buttonsContainer = this.mainNode.querySelector('.navbar-nav');
this.logoImg = document.createElement('img');
this.logoImg.src = Image;
this.logoImg.alt = 'logo';
this.logoImg.className = 'Logo mr-2';
this.logoBox = this.mainNode.querySelector('.Logo__box');
this.logoBox.appendChild(this.logoImg);
this.addSubscribe(routeService, EVENTS.ROUTE_CHANGE, (route) => {
this.menuItems.forEach(({url, link}) => {
if (route.url === url) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
});
}
render = () => {
this.menuItems = NAV_MENU.map(({url, title}) => {
const li = createElement({
tagName: 'li',
parentNode: this.buttonsContainer,
options: {
className: 'nav-item',
},
});
const link = createElement({
tagName: 'a',
parentNode: li,
options: {
className: 'nav-link',
textContent: title,
},
});
this.addEventListener(li, 'click', () => {
routeService.goTo(url);
});
return {url, link};
});
}
isHide = () => {
return this.mainNode.parentNode;
}
hideMenu = () => {
this.mainNode.remove();
}
showMenu = () => {
document.body.prepend(this.mainNode);
}
}
const navMenuButtons = new MainMenu();
export default navMenuButtons;