HM-27 Добавил компонет меню вместе с компонентом кнопки (#11)
* HM-27 Добавил компонет меню вместе с компонентом кнопки
This commit is contained in:
15
src/components/button-component/ButtonComponent.js
Normal file
15
src/components/button-component/ButtonComponent.js
Normal file
@ -0,0 +1,15 @@
|
||||
import Component from '../component/index';
|
||||
|
||||
class ButtonComponent extends Component {
|
||||
constructor (parentNode, text, newStyle) {
|
||||
super('#button', parentNode);
|
||||
|
||||
this.mainNode.textContent = text;
|
||||
this.mainNode.className = newStyle;
|
||||
|
||||
this.addEventListener(this.mainNode, 'click', (event) => {
|
||||
this.next('click', event);
|
||||
});
|
||||
}
|
||||
}
|
||||
export default ButtonComponent;
|
||||
0
src/components/button-component/index.js
Normal file
0
src/components/button-component/index.js
Normal file
@ -0,0 +1,16 @@
|
||||
.Buttons__container {
|
||||
margin: 0 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.NavButton {
|
||||
margin: 5px 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px){
|
||||
.Buttons__container {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
import Component from '../component/index';
|
||||
import routeService from '../../services/RouteService';
|
||||
import ButtonComponent from '../button-component/ButtonComponent';
|
||||
import Image from '../../img/logo.png';
|
||||
|
||||
import './NavButtonComponent.css';
|
||||
|
||||
class NavButtonComponent extends Component {
|
||||
constructor () {
|
||||
super('#main-menu', document.body);
|
||||
|
||||
this.buttonsContainer = this.mainNode.querySelector('.Buttons__container');
|
||||
this.logoImg = document.createElement('img');
|
||||
this.logoImg.src = Image;
|
||||
this.logoImg.alt = 'logo';
|
||||
this.logoImg.className = 'Logo';
|
||||
this.logoBox = this.mainNode.querySelector('.Logo__box');
|
||||
this.logoBox.appendChild(this.logoImg);
|
||||
}
|
||||
|
||||
render = (menu) => {
|
||||
menu.forEach((element) => {
|
||||
this.button = new ButtonComponent(this.buttonsContainer, element.title, 'btn btn-outline-primary NavButton');
|
||||
this.button.subscribe('click', () => {
|
||||
routeService.goTo(element.url);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const navMenuButtons = new NavButtonComponent();
|
||||
|
||||
export default navMenuButtons;
|
||||
14
src/components/navigation-buttons-component/constants.js
Normal file
14
src/components/navigation-buttons-component/constants.js
Normal file
@ -0,0 +1,14 @@
|
||||
export const NAV_MENU = [
|
||||
{
|
||||
title: 'Home',
|
||||
url: '/'
|
||||
},
|
||||
{
|
||||
title: 'Api',
|
||||
url: '/api'
|
||||
},
|
||||
{
|
||||
title: 'Еще что-то',
|
||||
url: '/something'
|
||||
},
|
||||
];
|
||||
3
src/components/navigation-buttons-component/index.js
Normal file
3
src/components/navigation-buttons-component/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
import NavButtonComponent from './NavButtonComponent';
|
||||
|
||||
export default NavButtonComponent;
|
||||
@ -1,3 +0,0 @@
|
||||
html, body, .PageContainer, .Page {
|
||||
height: 100%;
|
||||
}
|
||||
@ -1,5 +1,3 @@
|
||||
import RouterPagesContainer from './RouterPagesContainer';
|
||||
|
||||
const routerPagesContainer = new RouterPagesContainer();
|
||||
|
||||
export default routerPagesContainer;
|
||||
export default RouterPagesContainer;
|
||||
|
||||
Reference in New Issue
Block a user