ivamluz / ng-material-floating-button

Material design floating menu with action buttons implemented as an Angularjs directive.

Home Page:http://nobitagit.github.io/ng-material-floating-button/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ng-material-floating-button

Material design floating action button implemented as an Angularjs directive.

Made to be semantic, fast and easy to customize. Shamelessly inspired by action buttons from Google Inbox, Evernote and Path.

##Demo## Head over to the project homepage to see it in action.

Other versions

  • Vanilla html (original, upstream version of the component)

##How to use## Download the whole repo directly here on Github or clone it, then (optionally) run npm install to have access to the configured Grunt tasks.

Docs are still in the works (and coming soon), for the time being look in the src folder for usage examples and head to the original component docs to see how to customise the styles of the menu.

###Basic setup### Download the whole repo or clone it, then reference the directive css file (here is mfb/src/mfb.css)in your <head>:

<link href="../path/to/css/mfb.css" rel="stylesheet"/>

Place a reference to the directive before the closing <body> tag or anywhere after your angular script tag.

<link href="../mfb/src/mfb-directive.js" rel="stylesheet"/>

Make sure you reference the Mfb module as a dependecy to your app or module like so:

var app = angular.module('your-app', ['ng-mfb']);

Finally, place the correct html structure in your template. As a first example, assuming your example is using Ionicons as icon font:

<nav mfb-menu position="br" effect="zoomin" label="hover here" 
     active-icon="ion-edit" resting-icon="ion-plus-round"
     toggling-method="click">
  <a mfb-button icon="paper-airplane" label="menu item"></a>
</nav>

This example shows the two basic components of the directive, a unique mfb-menu element which serves as a wrapper to a variable number of child buttons, defined by the mfb-button attribute. This above code will output a basic button menu on the bottom right corner of the screen with a single menu item. Hardly amazing, so let's see how to customise it.

###Element attributes### A number of attributes can be passed to the elements from the template in order to customise both behavior and appearance.

####<mfb-menu> element#### This can be defined as an attribute or an element. So this is valid:

<ul mfb-menu></ul>

...and this is valid too:

<mfb-menu></mfb-menu>

#####Position#### Defines in which corner of the screen the component should be displayed.

value explanation
tl top-left corner
tr top-right corner
br bottom-right corner
bl bottom-left corner

Example:

<ul mfb-menu position="br">
  <!-- this will be displayed on the bottom-right corner of the screen -->
</ul>

#####Toggling method#### Defines how the user will open the menu. Two values are possible:

value explanation
hover hover to open the menu
click click or tap to open the menu

Example:

<ul mfb-menu toggling-method="click">
  <!-- click on the button to open the menu -->
</ul>

NOTE: Using hover will prevent user browsing on modbile/touch devices to properly interact with the menu. The directive provides a fallback for this case.

If you want the menu to work on hover but need support for touch devices you first need to include Modernizr to detect touch support. If you are alreay using it in your project just make sure that the touch detection is enabled.

If you're not using Modernizr already, just include the tiny (<3KB) provided modernizr.touch.js script (look in the mfb/src/lib/ folder) in your <head> or get the latest version of this very script right from here. Note that this is a custom build and will only detect for touch support, it's not the full library.

#####Menu state#### You can optionally include the desired starting state of the menu (open or closed). If this attribute is not specified a closed state is assumed.

You can also programmatically open/close the menu leveraging this attribute at any time after compilation, without any clicking required by the user.

value explanation
open menu is... open (surprise, surprise)
closed menu is...(hold tight) ... closed

#####Effect#### Defines the effect that is performed when the menu opens up to show its child buttons.

value explanation
zoomin test it here
slidein test it here
fountain test it here

Example:

<ul mfb-menu effect="zoomin">
</ul>

#####Label#### The text that is displayed when hovering the main button. Example:

<ul mfb-menu label="your text here">
</ul>

#####Active-icon#### The icon that will be displayed by default on the main button. Example:

<ul mfb-menu active-icon="ion-edit">
</ul>

#####Resting-icon#### The icon that will be displayed on the main button when hovering/interacting with the menu. Example:

<ul mfb-menu resting-icon="ion-plus-round">
</ul>

####<mfb-button> element#### This element represents the child button(s) of the menu and can only "live" inside a wrapper <mfb-menu> element. Like its parent, it can be defined both as an attribute and as an element. So this is valid:

<a mfb-button></a>

...and this is valid too:

<mfb-button></mfb-button>

#####Icon#### Pass the class of the icon font character that is associated to the menu item: Example:

<a mfb-button icon="ion-paperclip"></a>

#####Label#### The text that is displayed when hovering the button. Example:

<a mfb-button label="About us"></a>

#####Custom attributes##### Due to the nature of the component you'll probably want to associate some actions or use other angular directives such as ng-repeat on the buttons. As these attributes will be copied over to the generated html structure you can simply attach them to the <mfb-element>. A couple of examples, here using ui-router:

<!-- if using ui-router, associate an on-click event to the anchor-->
<a mfb-button ui-sref="yourState"></a>

And here leveraging a basic ng-repeat with buttons defined via js:

// in your controller...
$scope.buttons = [{
  label: 'a link text',
  icon: 'ion-paper-airplane'
},{
  label: 'another link',
  icon: 'ion-plus'
},{
  label: 'a third link',
  icon: 'ion-paperclip'
};
<!-- in your template -->
<!-- this will output 3 buttons with different icon, label and so on-->
<a mfb-button label="{{button.label}}" icon="{{button.icon}}" ng-repeat="button in buttons"></a>

###More customisations### The component have plenty more customisations available and they are all handled by the CSS. The CSS and its SCSS source files are found in the mfb/ folder (which is actually a subtree that pulls from this repo), while a customisation file is provided (mfb/_customisation.scss) to override the defaults without editing the source files.

For a thorough overview of what and how to customise the look of the component through css make sure you read these docs, especially if you plan to keep your copy in sync with this repo by pulling in changes in the future.

##Unit tests## To run the tests you need Jasmine and Karma runner. They can be run from the console with either grunt karma or karma start test/karma.conf.js commands.

##Contributing and issues## Contributions are very welcome, as well as opening issues if you find any bugs. If an issue is not specifically related to the Angularjs version (i.e. it's a layout/css bug) please open it on the original component repo, if possible.

##Todos##

  • add "click to open" functionality and option
  • add the directive to bower

##Credits## Demo icons courtesy of Ionicons

About

Material design floating menu with action buttons implemented as an Angularjs directive.

http://nobitagit.github.io/ng-material-floating-button/

License:MIT License


Languages

Language:CSS 53.4%Language:HTML 26.3%Language:JavaScript 20.3%