2.0.0 • Published 1 year ago

hamburger-button v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
1 year ago

Простая кнопка-гамбургер для меню

Не включает в себя меню. Только кнопка.

Установка

npm install hamburger-button

Использование

Вставьте код кнопки в нужное место на вашей странице

<div class="hamburger" role="button"><span><span>≡</span></span></div>

Инициализация

import HamburgerButton from 'hamburger-button';

let hamburger = new HamburgerButton({
  mainClass       : 'hamburger',              // по умолчанию
  stateActiveClass: 'hamburger_state_active', // по умолчанию
  onOpen() { console.log('Открыто'); },
  onClose(){ console.log('Закрыто'); },
});

hamburger.toggle(); // Переключить состояние
hamburger.open();   // Открыть меню
hamburger.close();  // Закрыть меню

Если не используется модульный сборщик, скрипт можно подключить напрямую в страницу

<srcipt src="node_modules/hamburger-button/dist/hamburger.js"></script>

Подключите scss-миксин в ваш файл стилей и вызовите его:

import './node_modules/hamburger-button/hamburger.scss';

@include makeHamburgerButton((
    main-class: '.hamburger',
    width     : 3rem,
    height    : 3rem,
));

Javascript options

OptionDefaultDescription
mainClass'hamburger'CSS-class of block
stateActiveClass'hamburger_state_active'The class at which the button is in the open state
onOpennullCallback function that is called when you go to the open state
onClosenullCallback function that is called when you go to the close state

Javascript API

MethodDescription
toggle()Toggle state of the button
open()Toggle to open state of the button
close()Toggle to close state of the button

SCSS options

OptionDefaultDescription
main-class'.hamburger'CSS-class of block
state-active-modifier_state_activeThe BEM modifier at which the button is in the open state
backgroundtransparentBackground of the button
icon-colorcurrentColorColor of the icon
width50pxWidth of the button
height50pxHeight of the button
icon-widthhalf of widthWidth of the icon
icon-heightthird of heightHeight of the icon
icon-item-space-chunk2
icon-item-heightcalculate
icon-item-spacecalculate