Git Product home page Git Product logo

ember-side-menu's Introduction

Ember-side-menu

Build Status Ember Observer Score npm version

Mobile friendly Ember menu component using CSS transitions. More effects and SVG path animations coming soon.

menu

Demo

Check out the live demo here

Ember Compability

This addon is compatible with and tested against Ember 2.x and higher.

Installation

ember install ember-side-menu

Import ember-side-menu styles in your application's app.scss file.

@import "ember-side-menu";

Usage

Side Menu

{{#side-menu}} component is a main container of your menu. Place it on some top level of your DOM document for example in application.hbs file.

{{#side-menu}}
  <header class="navbar navbar-default">
    <div class="navbar-header">
    ...
    </div>
  </header>
  <ul class="nav">
    <li class="header">Events</li>
    <li>
      {{#side-menu-link-to "new"}}
        {{inline-svg "plus" class="icon"}}
        New Event
      {{/side-menu-link-to}}
    </li>
    <li class="divider"></li>
    ...
    <li>
      <a href="https://cowbell-labs.com/" target="_blank">
        {{inline-svg "cowbell" class="icon cowbell"}}
        Cowbell Labs
      </a>
    </li>
  </ul>
{{/side-menu}}
{{content-backdrop}}
<div class="page-content">
  {{partial "shared/navbar"}}

  <main>
    <div class="container">
      {{outlet}}
    </div>
  </main>

  {{outlet "footer"}}
</div>

Parameters

  • id - (string), menu Id, use when using multiple menus, default: "default"
  • side - (string), which side of screen your menu takes. Possible values: ["left", "right"], default: "left"
  • width - (string), target width of open menu. CSS width - example values: ["40px", "40%", ...], default: null (default width set in CSS stylesheet to 70%)
  • initialTapAreaWidth - (integer, in px) - area width on left/right screen edge when menu swipe opening is initiated, default: 30
  • slightlyOpenWidth - (integer, in px) - width of slightly open menu. Menu is opened slightly on tap event within initialTapAreaWidth to the edge, default: 20
  • slightlyOpenAfter - (integer, in ms) - time delay after which menu is slighlty opened if it is still closed, default: 300

Content Backdrop

If you want to add backdrop to the rest of the layout while menu opening, then just place {{content-backdrop}} component after {{#side-menu}} component.

{{#side-menu}}
...
{{/side-menu}}
{{content-backdrop}}

Parameters

  • menuId - (string), id of controlled menu, default: "default"

Side Menu Toggle

Like a button component to toggle menu.

You can use default toggle button consist with some toggle bars

{{side-menu-toggle}}

You can use your own design block.

{{#side-menu-toggle}}
  <span class="glyphicon glyphicon-menu-hamburger"></span>
{{/side-menu-toggle}}

You can create a custom one by extending the main component.

import SideMenuToggle from "ember-side-menu/components/side-menu-toggle";

export default SideMenuToggle.extend({
    tagName: "button",
    classNames: ["navbar-btn", "btn", "btn-link", "pull-left"],
});

Parameters

  • side - (string), which side of screen your menu toggle takes. Possible values: ["left", "right"], default: "left"
  • menuId - (string), id of controlled menu, default: "default"

Side Menu Link To

Works like a standard {{link-to}} helper, but also closes the menu.

{{#side-menu-link-to "new"}}
  New Event
{{/side-menu-link-to}

Parameters

  • menuId - (string), id of menu which should be closed when clicking, default: "default"

Using multiple side menus

There is a possiblity to declare more instances of side menu components, and control them separately. Default menu id is default and it could be omitted, if you want to use more than one instance of side-menu you should not forget about setting relevant menuId for connected menu components.

{{#side-menu side="left" id="leftMenu"}}
  Left Menu
{{/side-menu}}
{{#side-menu side="right" id="rightMenu"}}
  Right Menu
{{/side-menu}}

{{side-menu-toggle menuId="leftMenu"}}
{{side-menu-toggle menuId="rightMenu"}}

{{content-backdrop menuId="leftMenu"}}
{{content-backdrop menuId="rightMenu"}}

Side Menu Service

There is an available sideMenu service to control the menu.

export default Ember.Route.extend({
  sideMenu: Ember.inject.service(),

  actions: {
    openSideMenu() {
      this.get("sideMenu").open();
    },
  },
});

Methods

  • open(menuId='default')
  • close(menuId='default')
  • toggle(menuId='default')

Properties

For backward compability there is a possiblity to control or check default menu properties directly on service object.

  • isOpen (boolean)
  • isClosed (boolean)
  • isSlightlyOpen (boolean)
  • progress (number) 0-100

When using mutliple menus or changing default menuId then menu's state is held in menus object.

For example to get isOpen property for menu with id sampleMenu we can use this.get("sideMenu.menus.sampleMenu.isOpen".

License

MIT

ember-side-menu's People

Contributors

ember-tomster avatar jkeen avatar kliput avatar tarrask avatar tsubik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ember-side-menu's Issues

ember-side-menu breaks fastboot render

We don't have access to jQuery inside of Fastboot.

 TypeError: $ is not a function
    at [object Object].disableScroll (/Users/adambaker/Development/project/projectname/dist/fastboot/vendor.js:100110:29)

which leads me to

var $rootNode = $(get(this, "rootNodeSelector"));

https://ember-fastboot.com/docs/addon-author-guide

There are a few different ways to solve this, but one is to move the definition of the observer into the didInsertElement

Ember deprecations

I am receiving this deprecation alerts when the component is instantiated.

screenshot from 2016-07-22 13 36 12

Strange behavior

When I click and hold the backdrop and slide just a little, the content inside the menu slides out of frame but the parent side menu container is still there. It seems to happen only if I click and hold close to the edge of the side menu as opposed to further out from it on a larger viewport.

I got around this by making the main component rendered in the side menu have position: fixed, but I'm wondering what could be causing the underlying issue?

image

Any idea what could cause this? I have a component nested inside my side menu and that's it

Can this be decoupled from Bootstrap better?

Is it enough to remove the ul and li style from the scss, because I use Semantic UI for the rest of the page that I'm using your side menu on. Is the addon easily framework agnostic? I know many people use Bootstrap, but many don't, and there aren't as many options out there for menu systems that give you the function without also forcing a style framework.

Scrollable menu content

In our app, we are using ember-side-menu and it contains a scrollable content area which is absolutely positioned with overflow-y: scroll (we have a header bar above it which we dont want to scroll). This works well in mouse-based environments, but scrolling within the ember-side-menu content seems to be completely disabled on touch devices.

It appears that the cause of this is specifically line 140 in addon/components/side-menu.js, where event.preventDefault(); is called within the touchMove event listener. When this line is removed, scrolling works fine on touch devices, and it doesn't seem to negatively affect the functionality of the menu itself.

Is this behavior of disabling scrolling within the menu intentional, and if so, why? And/or is there any other way to enable scrolling without having to remove the event.preventDefault();?

Possible Missing Instructions?

Using

  • Ember 2.6.2

The steps I followed:

  1. ember install ember-side-menu
  2. Added this to my application template
    {{#side-menu width="300px" side="right"}}
        <nav class="sm-item-list">
            <a href="">
                <i class="fa fa-fw fa-star-o"></i>
                <span>Favorites</span>
            </a>
            <a href="">
                <i class="fa fa-fw fa-bell-o"></i>
                <span>Alerts</span>
            </a>
            <a href="">
                <i class="fa fa-fw fa-envelope-o"></i>
                <span>Messages</span></a>
            <a href="">
                <i class="fa fa-fw fa-comment-o"></i>
                <span>Comments</span></a>
            <a href="">
                <i class="fa fa-fw fa-bar-chart-o"></i>
                <span>Analytics</span></a>
            <a href="">
                <i class="fa fa-fw fa-newspaper-o"></i>
                <span>Reading List</span>
            </a>
        </nav>
    {{/side-menu}}
    {{#side-menu-toggle}}
        <span class="glyphicon glyphicon-menu-hamburger"></span>
    {{/side-menu-toggle}}
    {{content-backdrop}}

Here's the result I get
screen shot 2016-07-19 at 9 24 58 am

Feature: multiple side menus

The ability to have different side-menus, with different toggles, would be great. While I made my own modifications to it on my app to do this, it is not generalized.

Sliding user experience not "as used to" on iPhone

Hi! We use ember-side-menu in our video editor application and cordova app. Thanks for sharing!

On IPhone 6s (my test device), iOS 9.3 the slide to open and slide to close action needs dragging across half of the menu width until the threshold is reached.

I noticed, that changedTouches on touchEnd contains the same pageX as the start event most times. But the current pageX is given as originalEvent.pageX in iOS.
=> velocityX = 0 most times => threshold passed 50%? complete : abort

This feels a little bit jerky. So i tried to improve it. It is not tested in the field yet, only on three devices and chrome. Maybe i post an update later. The current solution is to change _completeMenuTransition to this:

    _completeMenuTransition(event) {
        const progress = get(this, "progress");
        const touchStartEvent = get(this, "touchStartEvent");
        const side = get(this, "side");
        const velocityX = this._calculateVelocityX(
            touchStartEvent.originalEvent.touches[0].pageX,
            touchStartEvent.originalEvent.timeStamp,
            typeof event.originalEvent.pageX !== "undefined"? event.originalEvent.pageX : event.originalEvent.changedTouches[0].pageX,
            event.originalEvent.timeStamp
        );
        const minClosingVelocity = 0.000001;
        const isSwipingLeft = velocityX > minClosingVelocity;
        const isSwipingRight = velocityX < -minClosingVelocity;

        const isClosingMovement = (side === "left" && isSwipingLeft) ||
            (side === "right" && isSwipingRight);
        const isOpeningMovement = (side === "left" && isSwipingRight) ||
            (side === "right" && isSwipingLeft);

        if (isClosingMovement) {
            get(this, "sideMenu").close();
        } else if (isOpeningMovement) {
            get(this, "sideMenu").open();
        }
    },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.