• Stars
    star
    279
  • Rank 147,967 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An off-canvas sidebar component with a collection of animations and styles using CSS transitions

ember-burger-menu

CI npm version

An off-canvas sidebar component with a collection of animations and styles using CSS transitions

Features

  • Easy to use & setup off-canvas menu
  • Mix and match from many menu & menu item animations
  • Swipe gesture support with changeable thresholds
  • Easily create your own animations

Compatibility

  • Ember.js v3.24 or above
  • Ember CLI v3.24 or above
  • Node.js v12 or above

Installation

ember install ember-burger-menu

Sass

Installing ember-burger-menu should also install ember-cli-sass and automatically create a scss file under app/styles/app.scss with

// app/styles/app.scss

@import 'ember-burger-menu';

Overriding Variables

Using sass, you can override default variables and easily change the default behavior of ember-burger-menu. See variables.scss for a list of variables you can change.

// app/styles/app.scss

// Burger Menu Overrides
$bm-transition-duration: 0.3s;
$bm-overlay-background: rgba(0, 0, 0, 0.7);

// Import all the styles!
@import 'ember-burger-menu';

Import Only What You Need

Using sass, you can import only the styles you need for the animations you use.

// Core Styles
@import 'ember-burger-menu/variables';
@import 'ember-burger-menu/structure';

// Animations
@import 'ember-burger-menu/animations/push';
@import 'ember-burger-menu/animations/menu-item/stack';

Helpful Links

Looking for help?

If it is a bug please open an issue on GitHub.

Animations

Menu Animations

  • slide
  • reveal
  • push
  • fall-down
  • open-door
  • push-rotate
  • rotate-out
  • scale-up
  • scale-down
  • scale-rotate
  • slide-reverse
  • squeeze

Menu Item Animations

  • push
  • stack

Usage

This addon utilizes contextual components to be able to correctly control and animate necessary elements.

{{#burger-menu as |burger|}}
  {{#burger.menu itemTagName="li" as |menu|}}
    <button {{on "click" burger.state.closeMenu}}>Close</button>

    <ul>
      {{#menu.item}}
        <LinkTo @route="features">
          Features
        </LinkTo>
      {{/menu.item}}

      {{#menu.item}}
        <LinkTo @route="about">
          About
        </LinkTo>
      {{/menu.item}}

      {{#menu.item}}
        <LinkTo @route="contact">
          Contact Us
        </LinkTo>
      {{/menu.item}}
    </ul>
  {{/burger.menu}}

  {{#burger.outlet}}
    <button {{on "click" burger.state.toggleMenu}}>Menu</button>
    {{outlet}}
  {{/burger.outlet}}
{{/burger-menu}}

Components

{{burger-menu}}

Options

  • open

    The current open state of the menu.

    Default: false

  • animation

    The menu animation. See Animations for the list of available animations.

    Default: slide

  • itemAnimation

    The menu item animation. See Item Animations for the list of available item animations.

    Default: null

  • position

    The menu's open position. Can either be left or right

    Default: left

  • width

    The menu's width (in px).

    Default: 300

  • locked

    Lock the menu in its current open / closed state.

    Default: false

  • customAnimation

    Override of the menu's styles with your own implementation. See Custom Animations for more details.

  • translucentOverlay

    Whether the outlet has a translucent overlay over it once the menu is opened.

    Default: true

  • dismissOnClick

    Whether the menu can be dismissed when clicking outside of it.

    Default: true

  • dismissOnEsc

    Whether the menu can be closed when pressing the ESC key.

    Default: true

  • gesturesEnabled

    Whether the menu can be open / closed using gestures. The only available gesture currently is swipe.

    Default: true

  • minSwipeDistance

    The minimum distance (in px) the user must swipe to register as valid.

    Default: 150

  • maxSwipeTime

    The maximum amount of time (in ms) it must take the user to swipe to be registered as valid .

    Default: 300

{{burger.outlet}}

This component is where all your content should be placed.

{{burger.menu}}

Everything rendered here will be inside the menu.

Options

  • itemTagName

    The default tagName that will be used by the {{menu.item}} component.

    Default: div

  • dismissOnItemClick

    Close the menu on click of a {{menu.item}}.

    Default: false

Actions

  • onOpen

    Triggered when the menu is opening

  • onClose

    Triggered when the menu is closing

{{menu.item}}

The individual menu item. This is required if you have specified an itemAnimation.

Options

  • dismissOnClick

    Close the menu on click.

    Default: false

The Menu State

The {{burger-menu}} component exposes multiple contextual components, but it also exposes a state object.

You can use the menu state object to modify pretty much any property.

  • open
  • width
  • position
  • animation
  • itemAnimation
  • customAnimation

The state object also exposes some actions:

  • open

    <button {{on "click" burger.state.openMenu}}>Open</button>
  • close

    <button {{on "click" burger.state.closeMenu}}>Close</button>
  • toggle

    <button {{on "click" burger.state.toggleMenu}}>Toggle</button>

Custom Animations

If you're not impressed with the in-house animations and want to create your own, all you have to do is pass the following class to the customAnimation property in the {{burger-menu}} component. If you think your animation would be a good addition to the existing collection, feel free to open a PR with it!

import Animation from 'ember-burger-menu/animations/base';

export default Animation.extend({
  // CSS class names to be able to target our menu
  animation: 'my-custom-animation',
  itemAnimation: 'my-custom-item-animation',

  container(open, width, right) {
    return {};
  },

  outlet(open, width, right) {
    return {
      transform: open ? right ? `translate3d(-${width}px, 0, 0)` : `translate3d(${width}px, 0, 0)` : ''
    };
  },

  menu(open, width, right) {
    return {};
  },

  menuItem(open, width, right, index) {
    return {
      transform: open ? '' : `translate3d(0, ${(index + 1) * 500}px, 0)`
    };
  }
});

Note: You don't need to worry about prefixing your CSS attributes as it will be done for you.

If you need to add some base CSS to your animation, you can target the menu as such:

.ember-burger-menu.bm--my-custom-animation {
  #{$bm-menu} {}
  > .bm-outlet {}

  &.is-open {
    #{$bm-menu} {}
    > .bm-outlet {}
  }
}

And the menu items as such:

.ember-burger-menu.bm-item--my-custom-item-animation {
  #{$bm-menu} {
    .bm-menu-item {}
  }

  &.is-open {
    #{$bm-menu} {
      .bm-menu-item {}
    }
  }
}

To use our new custom animation, all we have to do is pass the class to the customAnimation option in the {{burger-menu}} component.

import MyCustomAnimation from 'path/to/my-custom-animation';

export default Ember.Component.extend({
  MyCustomAnimation
});
{{#burger-menu customAnimation=MyCustomAnimation}}
  ...
{{/burger-menu}}

Contributing

See the Contributing guide for details.

More Repositories

1

ember-electron

⚑ Build, test, compile and package desktop apps with Ember and Electron
JavaScript
806
star
2

ember-cp-validations

Ember computed property based validations
JavaScript
443
star
3

ember-changeset

Ember.js flavored changesets, inspired by Ecto
JavaScript
431
star
4

ember-moment

JavaScript
399
star
5

ember-infinity

⚑ Simple, flexible Infinite Scroll for Ember CLI Apps.
JavaScript
377
star
6

ember-data-model-fragments

Ember Data addon to support nested JSON documents
JavaScript
371
star
7

ember-metrics

Send data to multiple analytics integrations without re-implementing new API
JavaScript
367
star
8

ember-cli-flash

Simple, highly configurable flash messages for ember-cli
JavaScript
355
star
9

ember-light-table

Lightweight, contextual component based table for Ember
JavaScript
312
star
10

ember-data-factory-guy

Factories and helper functions for (unit, integration, acceptance) testing + development scenarios with Ember Data
JavaScript
302
star
11

ember-sortable

Sortable UI primitives for Ember.js
JavaScript
295
star
12

ember-cli-sass

Use node-sass to preprocess your ember-cli app's files, with support for sourceMaps and include paths
JavaScript
276
star
13

ember-notify

Notification messages for your Ember.js app
JavaScript
264
star
14

ember-collection

An efficient incremental rendering component for Ember.js with support for custom layouts and large lists
JavaScript
236
star
15

ember-changeset-validations

Validations for ember-changeset
JavaScript
219
star
16

ember-file-upload

File uploads for Ember apps
TypeScript
201
star
17

emberx-select

Select component for Ember based on the native html select element.
JavaScript
200
star
18

ember-keyboard

An Ember.js addon for the painless support of keyboard events
JavaScript
177
star
19

ember-pikaday

A datepicker component for Ember CLI projects.
JavaScript
159
star
20

ember-impagination

An Ember Addon that puts the fun back in asynchronous, paginated datasets
JavaScript
122
star
21

active-model-adapter

Adapters and Serializers for Rails's ActiveModel::Serializers
TypeScript
102
star
22

ember-cli-hot-loader

An early look at what hot reloading might be like in the ember ecosystem
JavaScript
99
star
23

ember-autoresize

Autoresize for Ember Components
JavaScript
88
star
24

ember-cli-windows

🚀 Improve Ember-Cli Performance on Windows
JavaScript
79
star
25

ember-set-helper

A better `mut` helper
JavaScript
68
star
26

ember-inputmask

Ember wrapper around Inputmask.js
JavaScript
68
star
27

ember-collapsible-panel

An unopinionated, zero-dependency panel and accordion
JavaScript
57
star
28

ember-qunit-nice-errors

Because expected true, result false is not enough!
JavaScript
56
star
29

ember-cli-ifa

Ember CLI addon for injecting fingerprinted asset map file into Ember app
JavaScript
54
star
30

emberx-file-input

A tiny Ember component which does one thing and only: select files beautifully.
JavaScript
52
star
31

ember-cognito

AWS Amplify/Cognito and ember-simple-auth integration
JavaScript
32
star
32

ember-validators

A collection of EmberJS validators
JavaScript
24
star
33

ember-cli-bugsnag

Integrates Bugsnag reporting service into your Ember CLI app.
JavaScript
20
star
34

ember-stripe-elements

A simple Ember wrapper for Stripe Elements
JavaScript
18
star
35

ember-popper-modifier

An Ember modifier for working with Popper.js.
TypeScript
14
star
36

ember-launch-darkly

A modern Ember addon to wrap the Launch Darkly service
JavaScript
13
star
37

ember-require-module

Dynamically require modules
JavaScript
7
star
38

ember-indexeddb-adapter

Ember Data adapter for IndexedDB
JavaScript
4
star
39

program-guidelines

Checklist and guidelines for the Adopted Ember Addons org.
JavaScript
3
star
40

ember-cli-deploy-new-relic-sourcemap

Ember CLI Deploy plugin to deploy source maps to new relic
JavaScript
2
star