Repository: nobitagit/react-material-floating-button
Branch: master
Commit: e735370b70f0
Files: 36
Total size: 58.6 KB
Directory structure:
gitextract_ymj1386v/
├── .editorconfig
├── .eslintrc
├── .gitignore
├── .jshintrc
├── .npmignore
├── .travis.yml
├── Gruntfile.js
├── LICENSE
├── README.md
├── demo/
│ ├── index.css
│ ├── index.html
│ └── index.js
├── gulpfile.js
├── index.js
├── mfb/
│ ├── .gitignore
│ ├── .npmignore
│ ├── Gruntfile.js
│ ├── LICENSE
│ ├── README.md
│ ├── package.json
│ ├── src/
│ │ ├── _/
│ │ │ ├── _fountain.scss
│ │ │ ├── _slidein-spring.scss
│ │ │ ├── _slidein.scss
│ │ │ └── _zoomin.scss
│ │ ├── index.css
│ │ ├── index.html
│ │ ├── lib/
│ │ │ └── modernizr.touch.js
│ │ └── mfb.js
│ └── test/
│ └── unit.js
├── package.json
└── src/
├── child-button.js
├── main-button.js
├── menu.js
└── utils/
├── children-validator.js
├── get-children.js
└── get-classes.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
# top-most EditorConfig file
root = true
[*]
indent_style = space
end_of_line = lf
trim_trailing_whitespace = true
[*.js]
indent_style = space
indent_size = 2
[package.json]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
================================================
FILE: .eslintrc
================================================
{
"ecmaFeatures": {
"jsx": true
},
"rules": {
"semi": [2, "always"],
"quotes": [2, "single"],
"strict": [2, "global"],
"no-underscore-dangle": 0
},
"env": {
"es6": true,
"browser": true,
"node": true
}
}
================================================
FILE: .gitignore
================================================
.DS_Store
node_modules
bower_components
.sass-cache/
.grunt
dist
npm-debug.log
build/
gh-pages_temp/
demo/bundle.js
mfb.css*
mfb.scss
================================================
FILE: .jshintrc
================================================
{
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"latedef": true,
"onevar": true,
"noarg": true,
"node": true,
"trailing": true,
"undef": true,
"unused": true,
"jasmine" : true,
"indent": 2 ,
"globals": {
"define" : true
}
}
================================================
FILE: .npmignore
================================================
index.css
index.html
showcase.html
.sass-cache/
.jshintrc
.gitignore
.grunt
test/
mfb/test/
demo/
build/
bower_components
.sass-cache/
.grunt
dist
npm-debug.log
build/
gh-pages_temp/
================================================
FILE: .travis.yml
================================================
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
================================================
FILE: Gruntfile.js
================================================
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
css: {
files: '**/*.scss',
tasks: ['sass:base']
},
js: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
tasks: ['jshint:all']
}
},
sass: {
base: {
files: {
'src/styles/style.css': 'src/styles/style.scss'
}
}
},
clean: {
check: ['.grunt/grunt-gh-pages/gh-pages/check'],
live: 'gh-pages_temp'
},
jshint: {
options: {
jshintrc : true
},
all: ['Gruntfile.js', 'build/mfb-menu.js']
},
useminPrepare: {
html: 'gh-pages_tem/index.html',
options: {
//dest: 'gh-pages_tem/index.html'
}
},
usemin: {
html: ['gh-pages_temp/index.html']
},
copy: {
live: {
files: [{
src: ['demo/index.html', 'demo/index.css', 'demo/bundle.js'],
dest: 'gh-pages_temp',
expand: true, flatten: true
},{
src: ['mfb/src/*.css', 'mfb/src/*.css.map', 'mfb/src/lib/**/*.js'],
dest: 'gh-pages_temp',
expand: true, flatten: true
}]
}
},
'gh-pages': {
options: {
base: 'gh-pages_temp/',
},
'live': {
src: ['*']
},
'check': {
options: {
push: false
},
src: ['*']
}
}
});
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-usemin');
// Publish this to live site
grunt.registerTask('live', [
'clean:live',
'useminPrepare',
'copy:live',
'usemin',
'gh-pages:live'
]);
// Live site dry run
grunt.registerTask('livecheck', [
'clean:check',
'useminPrepare',
'copy:live',
'usemin',
'clean:check','gh-pages:check'
]);
grunt.registerTask('watch-css', ['watch:css']);
grunt.registerTask('watch-js', ['watch:js']);
grunt.registerTask('default', []);
};
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# React Material Floating Button
Material design floating action button implemented as a React component.
Made to be fast and easy to customize.
~~Shamelessly~~ inspired by action buttons from Google Inbox, Evernote and Path.
Clone/download the repo from Github or just use npm:
```
npm install react-mfb --save
```
Docs are still to come (but hopefully will be there soon).
In the meantime if you want to play with it check the project homepage source code for hints on how to use the component.
## Demo
See the [project page](http://nobitagit.github.io/react-material-floating-button/) or just look at this awesome gif:
**Other versions**
- [Vanilla html](https://github.com/nobitagit/material-floating-button) (original, upstream version of the component)
- [Angular directive](https://github.com/nobitagit/ng-material-floating-button)
Demo icons courtesy of [Ionicons](http://ionicons.com)
================================================
FILE: demo/index.css
================================================
html, body{
height: 100%;
min-height: 100%;
}
html{
background: #E9EBEC;
font-family: 'Raleway', sans-serif;
font-weight: 200;
}
body{
display: -webkit-flex;
-webkit-align-items: center;
-webkit-justify-content: center;
display: flex;
align-items: center;
justify-content: center;
}
h1{
margin: 0.2em 0;
color: rgba(40, 33, 33, .7);
color: rgba(124, 98, 152, 1);
font-weight: 400;
}
header{
background: #00C8BE;
padding: 0.3em 1em;
position: relative;
z-index: 20;
}
.viewCode header{
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
}
.showcode{
background: rgb(232, 216, 49);
color: rgba(124, 98, 152, 1);
width: 40px;
height: 40px;
text-align: center;
position: absolute;
right: 1em;
bottom: 0;
margin-bottom: -15px;
border-radius: 100%;
font-size: 16px;
cursor: pointer;
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
transition: all .3s;
}
.viewCode .showcode{
-webkit-transform: rotateX(-180deg);
transform: rotateX(-180deg);
box-shadow: 0px -2px 5px 0 rgba(0, 0, 0, 0.26);
}
.icon-nocode, .icon-yepcode{
transition: opacity .3s;
position: absolute;
left: 0;
display: block;
width: 100%;
line-height: 40px;
}
.icon-nocode{
opacity: 0;
}
.viewCode .icon-nocode{
opacity: 1;
}
.viewCode .icon-yepcode{
opacity: 0;
}
.panel{
width: 90%;
position: relative;
max-width: 650px;
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
background: #F5F5F5;
border-radius: 3px;
overflow: hidden;
}
article{
min-height: 180px;
padding: 1em;
font-weight: 200;
line-height: 1.5em;
position: relative;
}
footer{
padding: 0.3em 1em 1em;
}
footer a, footer a:active, footer a:visited{
color: inherit;
}
.code{
position: absolute;
top: 0;
top: 0;
left: 0;
right: 0;
height: 100%;
overflow: scroll;
background: rgba(124, 98, 152, 0.94);
color: rgba(245, 247, 247, 0.92);
padding: 0em 1em;
transition: all .4s;
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
.code p:first-child{
margin-top: 2em;
}
.code a{
color: rgba(232, 216, 49, 0.9);
}
.viewCode .code{
-webkit-transform: translateY(0);
transform: translateY(0);
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.36);
}
.actions{
font-weight: 300;
text-transform: uppercase;
font-size: 0.8em;
padding: 1em;
border: none;
background: none;
transition: color .2s;
cursor: pointer;
}
.actions:hover{
color: rgb(30, 30, 171);
background: #F5F5F5;
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
}
code, pre {
background: rgba(255,255,255,0.1);
color: rgba(232, 216, 49, 0.9);
font-family: "Source Code Pro", Monaco, Menlo, Consolas, "Courier New",monospace;
padding: 0.5em;
border-radius: 3px;
margin: 1em 0;
}
code{
display: inline;
vertical-align: middle;
margin: 0;
}
pre{
display: block;
}
.striked{
text-decoration: line-through;
}
.mfb-component--tl{
animation: fromTop 1s 1;
-webkit-animation: fromTop 1s 1;
}
.mfb-component--tr{
animation: fromTop 1.3s 1;
-webkit-animation: fromTop 1.3s 1;
}
.mfb-component--br{
animation: fromBottom 1.6s 1;
-webkit-animation: fromBottom 1.6s 1;
}
.mfb-component--bl{
animation: fromBottom 1.9s 1;
-webkit-animation: fromBottom 1.9s 1;
}
@keyframes fromBottom {
0% {
transform: translateY(250px);
}
100% {
transform: translateY(0);
}
}
@keyframes fromTop {
0% {
transform: translateY(-250px);
}
100% {
transform: translateY(0);
}
}
@-webkit-keyframes fromBottom {
0% {
transform: translateY(250px);
}
100% {
transform: translateY(0);
}
}
@-webkit-keyframes fromTop {
0% {
transform: translateY(-250px);
}
100% {
transform: translateY(0);
}
}
================================================
FILE: demo/index.html
================================================
React Material Floating Button - by Nobita
React Material Floating Button
Material floating action button implemented as a React component. Also available in vanilla html and Angularjs directive. Shamelessly Openly inspired by Google Inbox, Evernote and Path.
To add Material Floating Buttons to any project just download or clone the repo from Github. Click on the yellow button here above for a code preview or choose an effect from the dropdown below and interact with any button on the corners of the screen.
To add Material Floating Buttons to any project just download the files from here below or clone the repo from Github.
Run npm install and after referencing the styles in your header drop the MFB markup in your HTML like so:
var component = React.createElement(MfbMenu, yourOpts);
React.render( component, document.getElementById('someId') );
The yourOpts object passed as a second param to the createElement function provide the configuration for the component such as position, labels, icons, links and callbacks. All the other styles and configurations are just css.
The best way to customise the styles is to build them directly from the source as the scss file is filled with customizable variables. From there choose your favorite colors and sizes and then compile the css.
================================================
FILE: demo/index.js
================================================
'use strict';
var React = require('react');
var ReactDOM = require('react-dom');
var Menu = require('../').Menu;
var MainButton = require('../').MainButton;
var ChildButton = require('../').ChildButton;
var panel = document.getElementById('panel'),
showcode = document.getElementById('showcode'),
selectFx = document.getElementById('selections-fx'),
selectPos = document.getElementById('selections-pos'),
selectMethod = document.getElementById('selections-method');
// demo defaults
var effect = 'zoomin',
pos = 'br',
method = 'hover';
function renderMenu(){
var component = (
);
ReactDOM.render(component, document.getElementById('menu'));
}
renderMenu();
function switchEffect(){
effect = this.options[this.selectedIndex].value;
renderMenu();
}
function switchPosition(){
pos = this.options[this.selectedIndex].value;
renderMenu();
}
function switchMethod(){
method = this.options[this.selectedIndex].value;
renderMenu();
}
function toggleCode() {
panel.classList.toggle('viewCode');
}
showcode.addEventListener('click', toggleCode);
selectFx.addEventListener('change', switchEffect);
selectPos.addEventListener('change', switchPosition);
selectMethod.addEventListener('change', switchMethod);
================================================
FILE: gulpfile.js
================================================
'use strict';
var gulp = require('gulp');
var babel = require('gulp-babel');
gulp.task('js', function(){
return gulp.src('./src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('build'));
});
gulp.task('css', function(){
return gulp.src(['./mfb/src/mfb.css', './mfb/src/mfb.css.map', './mfb/src/mfb.scss'])
.pipe(gulp.dest('./'));
});
gulp.task('default', ['js', 'css']);
================================================
FILE: index.js
================================================
'use strict';
module.exports = {
Menu: require('./build/menu'),
MainButton: require('./build/main-button'),
ChildButton: require('./build/child-button')
};
================================================
FILE: mfb/.gitignore
================================================
.DS_Store
node_modules
.sass-cache/
.grunt
================================================
FILE: mfb/.npmignore
================================================
test/
index.css
index.html
showcase.html
.sass-cache/
.jshintrc
.gitignore
.grunt
================================================
FILE: mfb/Gruntfile.js
================================================
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
css: {
files: '**/*.scss',
tasks: ['sass:base', 'cssmin']
}
},
sass: {
base: {
files: {
'src/mfb.css': 'src/mfb.scss'
}
}
},
clean: {
check: ['.grunt/grunt-gh-pages/gh-pages/check'],
live: ['.grunt/grunt-gh-pages/gh-pages/live']
},
cssmin: {
main: {
files: [{
expand: true,
cwd: 'src',
src: ['mfb.css', '!*.min.css'],
dest: 'src',
ext: '.min.css'
}]
}
},
uglify: {
main: {
files: {
'src/mfb.min.js': ['src/mfb.js']
}
}
},
livePages: [
'index.html',
'index.css',
'*.css',
'**/*.map',
'mfb.js',
'lib/modernizr.touch.js'],
'gh-pages': {
options: {
base: 'src',
},
'live': {
src: ['<%= livePages %>']
},
'check': {
options: {
push: false
},
src: ['<%= livePages %>']
}
}
});
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
// Publish this to live site
grunt.registerTask('live', ['clean:live','gh-pages:live']);
// Live site dry run: test locally before pushing.
// In .grunt look for the folder 'check'
grunt.registerTask('livecheck', ['clean:check','gh-pages:check']);
grunt.registerTask('build', [
'sass',
'cssmin',
'uglify'
]);
grunt.registerTask('watch-css', ['watch:css']);
grunt.registerTask('default', []);
};
================================================
FILE: mfb/LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: mfb/README.md
================================================
Material Floating Button
========================
Material design floating button action implementation.
Made to be semantic, fast and easy to customize.
~~Shamelessly~~ inspired by action buttons from Google Inbox, Evernote and Path.
See a demo [here](http://nobitagit.github.io/material-floating-button/) to see it in action or just take a look at this awesome gif:
Test all the available effects to date in the [demo](http://nobitagit.github.io/material-floating-button/).
##Other versions##
Also available as:
- [Angular directive](https://github.com/nobitagit/ng-material-floating-button)
- [React Component](https://github.com/nobitagit/react-material-floating-button)
##How to use##
###Basic usage###
Clone/download the repo from Github or just use npm:
```
npm install mfb --save
```
(Optionally) run `npm install` to have access to the configured Grunt tasks if you use them, then reference the basic css styles in your `` like so:
```html
```
Use the appropriate html structure (better explained later), for example:
```html
```
Everything should already work fine.
You may or may not want to include the provided `mfb.js` script depending on the need to support click/touch.
```html
```
For a breakdown on why and when you need to include the script please refer to [Toggling options and touch devices support](#toggling-opts).
###Customising the component###
####HTML####
The basic structure of the component is the following (the customisable classes/attributes are in curly braces):
```html
```
####SCSS/CSS####
Although you can use the provided css as is, it's highly likely that you will want to customise the looks and behavior of the component by changing its underlying css. A number of variables is provided for your convenience in the SASS file.
The best way to tweak them is leave the `src/mfb.scss` source as is, import it in your own style sheet and define your custom variables before the `@import` statement right there. For example:
```scss
// your .scss working file
$main-color: #4991EF;
@import "path/to/src/mfb.scss";
```
This will leave the core files unchanged from the source. You will then be able to keep this repo as upstream and pull in any future changes without having to worry about overwriting your changes.
Here below is a breakdown of all the variables currently available, along with their defaults.
#####Basic#####
Variable name | Default value | Explanation
--- | --- | ---
$main-color | #E40A5D | main/primary color of the component
$bright-text | rgba(255, 255, 255, 0.8) | color of icons and text
$number-of-child-buttons | 4 | how many child buttons the component supports
#####Effects#####
**n.b.** - set to true to include the effect styles in the compiled .css file. To actually activate the desired effect you need to reference the corresponding class in the markup (see [here](#html))
Variable name | Default value
--- | ---
$effects-zoomin | true
$effects-slidein | true
$effects-slidein-spring | true
$effects-fountain | true
As a suggestion, try to only include the animation you're using in production in order to have a much lighter css.
#####Speeds#####
Variable name | Default value | Explanation
--- | --- | ---
$delay-staggering-inflate | 0.1s | each child button can appear with a slight, more natural delay (set to 0 for no-delay)
$slide-speed | 0.5s | the child buttons animate at this speed
$label-hover-off | 0.5s | the child buttons labels fade *in* at this speed
$label-hover-on | 0.3s | the child buttons labels fade *out* at this speed
#####Sizes#####
Variable name | Default value | Explanation
--- | --- | ---
$main_button_size | 25px | the distance of the main button from the closest corners of the screen
$labels-font-size | 13px |font-size for all labels
$labels-padding-vertical | 4px | top & bottom padding for the labels
$labels-padding-horizontal | 10px | left & right padding for the labels
You can compile the final css on your own or use the provided, pre-configured Grunt tasks for it. After installing all dependencies (by running `npm install` from the terminal) type `grunt sass` (on time compilation) or `grunt watch-css` (live reload triggered after the scss files are changed).
####Toggling options and touch devices support####
The menu can be customised to be activated either on hover or on click/tap. To assign the desired toggling method the component provides some attributes to add this functionality in a declarative way right from the markup.
#####Hover toggling#####
If you're only interested in desktop support and want the menu to be activated on hover you won't need to include any scripts as that animation is CSS-based and included in the stylesheet provided. Just set the `data-mfb-toggle` attribute to `hover` like so:
```html
```
#####Click toggling#####
To add click and touch support (and to support the open/close animation programmatically, more on this later) include the `mfb.js` file and reference it in the page. Finally set the `data-mfb-toggle` attribute to `click`, along with the initial state you want the menu to appear at load time, using the `data-mfb-state` attribute. An example:
```html
```
If you want the menu to appear open at load time, do this instead:
```html
```
#####Hover toggling along with touch support#####
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 provided `modernizr.touch.js` script (look in the `src/lib/` folder) in your `` or get the latest version of this very script right from [here](http://modernizr.com/download/#-touch-teststyles-prefixes). Note that this is a custom build and will only detect for touch support, it's not the full library.
Then include the `mfb.js` file, ideally at the bottom of your page.
Once the scripts are in place just set up a normal button with hover toggling like so:
```html
```
The script will take care of changing the behavior when the page is viewed from a touch enabled device.
#####Opening/closing the menu programmatically#####
If you need to close the menu after a certain event (or open it without user interaction) you can easily do so just by setting its state to `closed` or `open`. Once you have selected the menu in your desired way just close it like so:
```js
menu.setAttribute('data-mfb-state', 'closed');
```
Or open it with:
```js
menu.setAttribute('data-mfb-state', 'open');
```
##Contributions?##
Yes please!
If you submit a PR please add the relative documentation in this README (if needed) and don't forget to add you name and/or email to the contributors list in the package.json file.
##Credits##
- Andrey Sitnik's [Easings.net](http://easings.net/) for visualizing animations.
- Demo icons courtesy of [Ionicons](ionicons.com).
- All the [contributors](https://github.com/nobitagit/material-floating-button/graphs/contributors) to this project.
##Todos##
- [x] provide minified script and stylesheet
- [ ] replace `@extend`s as much as possible from the SCSS to optimize output
- [ ] more animations
- [ ] add to bower
- [ ] provide more variables/get rid of currently hard-coded values
================================================
FILE: mfb/package.json
================================================
{
"name": "mfb",
"version": "0.12.0",
"description": "html component for a material menu à la Path and Google Inbox",
"main": "index.html",
"repository": "https://github.com/nobitagit/material-floating-button",
"keywords": [
"component",
"material",
"design",
"menu",
"css"
],
"bugs": "https://github.com/nobitagit/material-floating-button/issues",
"author": "Nobita",
"contributors": [
{
"name": "Maxence Winandy",
"email": "maxence.winandy@gmail.com"
},
{
"name": "Christian Flach",
"email": "cmfcmf.flach@gmail.com"
}
],
"license": "MIT",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-cssmin": "^0.12.2",
"grunt-contrib-sass": "^0.8.1",
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-gh-pages": "^0.9.1"
}
}
================================================
FILE: mfb/src/_/_fountain.scss
================================================
@mixin effects-fountain{
/**
* FOUNTAIN
* When hovering the main button the child buttons
* jump into view from outside the viewport
*/
.mfb-component--tl.mfb-fountain,
.mfb-component--tr.mfb-fountain{
.mfb-component__list{
li{
-webkit-transform: scale(0);
transform: scale(0);
}
@for $i from 1 through $number-of-child-buttons {
$distance: -1 * $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(0);
transform: translateY($distance) scale(0);
transition: all $slide-speed;
// this is the delay at which the buttons start disappearing
transition-delay: ( $number-of-child-buttons - $i ) * 0.05s;
}
}
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
@for $i from 1 through $number-of-child-buttons {
$distance: $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(1);
transform: translateY($distance) scale(1);
// this is the delay at which the buttons appear
transition-delay: $i * 0.05s;
}
}
}
}
}
.mfb-component--bl.mfb-fountain,
.mfb-component--br.mfb-fountain{
.mfb-component__list{
li{
-webkit-transform: scale(0);
transform: scale(0);
}
@for $i from 1 through $number-of-child-buttons {
$distance: $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(0);
transform: translateY($distance) scale(0);
transition: all $slide-speed;
// this is the delay at which the buttons start disappearing
transition-delay: ( $number-of-child-buttons - $i ) * 0.05s;
}
}
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
@for $i from 1 through $number-of-child-buttons {
$distance: -1 * $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(1);
transform: translateY($distance) scale(1);
// this is the delay at which the buttons appear
transition-delay: $i * 0.05s;
}
}
}
}
}
}
================================================
FILE: mfb/src/_/_slidein-spring.scss
================================================
@mixin effects-slidein-spring{
/**
* SLIDE IN SPRING
* When hovering the main button, the child buttons slide out from beneath
* the main button while transitioning from transparent to opaque.
*
*/
.mfb-component--tl.mfb-slidein-spring,
.mfb-component--tr.mfb-slidein-spring{
.mfb-component__list li{
opacity: 0;
transition: all $slide-speed cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
li{
opacity: 1;
}
@for $i from 1 through $number-of-child-buttons {
$distance: $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY( $distance );
transform: translateY( $distance ); }
}
}
}
}
.mfb-component--bl.mfb-slidein-spring,
.mfb-component--br.mfb-slidein-spring{
.mfb-component__list li{
opacity: 0;
transition: all $slide-speed cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
li{
opacity: 1;
}
@for $i from 1 through $number-of-child-buttons {
$distance: -1 * $button-space * $i;
li:nth-child( #{$i} ) { -webkit-transform: translateY( $distance );
transform: translateY( $distance ); }
}
}
}
}
}
================================================
FILE: mfb/src/_/_slidein.scss
================================================
@mixin effects-slidein{
/**
* SLIDE IN + FADE
* When hovering the main button, the child buttons slide out from beneath
* the main button while transitioning from transparent to opaque.
*
*/
.mfb-component--tl.mfb-slidein,
.mfb-component--tr.mfb-slidein{
.mfb-component__list li{
opacity: 0;
transition: all $slide-speed;
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
li{
opacity: 1;
}
@for $i from 1 through $number-of-child-buttons {
$distance: $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY( $distance );
transform: translateY( $distance ); }
}
}
}
}
.mfb-component--bl.mfb-slidein,
.mfb-component--br.mfb-slidein{
.mfb-component__list li{
opacity: 0;
transition: all $slide-speed;
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
li{
opacity: 1;
}
@for $i from 1 through $number-of-child-buttons {
$distance: -1 * $button-space * $i;
li:nth-child( #{$i} ) { -webkit-transform: translateY( $distance );
transform: translateY( $distance ); }
}
}
}
}
}
================================================
FILE: mfb/src/_/_zoomin.scss
================================================
@mixin effects-zoomin{
/**
* ZOOM-IN
* When hovering the main button, the child buttons grow
* from zero to normal size.
*
*/
.mfb-component--tl.mfb-zoomin,
.mfb-component--tr.mfb-zoomin{
.mfb-component__list{
li{
-webkit-transform: scale(0);
transform: scale(0);
}
@for $i from 1 through $number-of-child-buttons {
$distance: $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(0);
transform: translateY($distance) scale(0);
transition: all $slide-speed;
// this is the delay at which the buttons *disappear*
transition-delay: ( $number-of-child-buttons - $i ) * 0.05s;
}
}
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
@for $i from 1 through $number-of-child-buttons {
$distance: $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(1);
transform: translateY($distance) scale(1);
// this is the delay at which the buttons *appear*
transition-delay: $i * 0.05s;
}
}
}
}
}
.mfb-component--bl.mfb-zoomin,
.mfb-component--br.mfb-zoomin{
.mfb-component__list{
li{
-webkit-transform: scale(0);
transform: scale(0);
}
@for $i from 1 through $number-of-child-buttons {
$distance: -1 * $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(0);
transform: translateY($distance) scale(0);
transition: all $slide-speed;
// this is the delay at which the buttons start disappearing
transition-delay: ( $number-of-child-buttons - $i ) * 0.05s;
}
}
}
&[data-mfb-toggle="hover"]:hover,
&[data-mfb-state="open"]{
.mfb-component__list{
@for $i from 1 through $number-of-child-buttons {
$distance: -1 * $button-space * $i;
li:nth-child( #{$i} ) {
-webkit-transform: translateY($distance) scale(1);
transform: translateY($distance) scale(1);
// this is the delay at which the buttons appear
transition-delay: $i * 0.05s;
}
}
}
}
}
}
================================================
FILE: mfb/src/index.css
================================================
html, body{
height: 100%;
min-height: 100%;
}
html{
background: #E9EBEC;
font-family: 'Raleway', sans-serif;
font-weight: 200;
-ms-touch-action: manipulation;
touch-action: manipulation;
}
body{
display: -webkit-flex;
-webkit-align-items: center;
-webkit-justify-content: center;
display: flex;
align-items: center;
justify-content: center;
}
h1{
margin: 0.2em 0;
color: rgba(40, 33, 33, .7);
color: rgba(124, 98, 152, 1);
font-weight: 400;
}
header{
background: #00C8BE;
padding: 0.3em 1em;
position: relative;
z-index: 20;
}
.viewCode header{
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
}
.showcode{
background: rgb(232, 216, 49);
color: rgba(124, 98, 152, 1);
width: 40px;
height: 40px;
text-align: center;
position: absolute;
right: 1em;
bottom: 0;
margin-bottom: -15px;
border-radius: 100%;
font-size: 16px;
cursor: pointer;
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
transition: all .3s;
}
.viewCode .showcode{
-webkit-transform: rotateX(-180deg);
transform: rotateX(-180deg);
box-shadow: 0px -2px 5px 0 rgba(0, 0, 0, 0.26);
}
.icon-nocode, .icon-yepcode{
transition: opacity .3s;
position: absolute;
left: 0;
display: block;
width: 100%;
line-height: 40px;
}
.icon-nocode{
opacity: 0;
}
.viewCode .icon-nocode{
opacity: 1;
}
.viewCode .icon-yepcode{
opacity: 0;
}
.panel{
width: 90%;
position: relative;
max-width: 650px;
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
background: #F5F5F5;
border-radius: 3px;
overflow: hidden;
}
article{
min-height: 180px;
padding: 1em;
font-weight: 200;
line-height: 1.5em;
position: relative;
}
footer{
padding: 0.3em 1em 1em;
}
footer a, footer a:active, footer a:visited{
color: inherit;
}
.code{
position: absolute;
top: 0;
top: 0;
left: 0;
right: 0;
height: 100%;
overflow: scroll;
background: rgba(124, 98, 152, 0.94);
color: rgba(245, 247, 247, 0.92);
padding: 0em 1em;
transition: all .4s;
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
.code p:first-child{
margin-top: 2em;
}
.code a{
color: rgba(232, 216, 49, 0.9);
}
.viewCode .code{
-webkit-transform: translateY(0);
transform: translateY(0);
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.36);
}
.actions{
font-weight: 300;
text-transform: uppercase;
font-size: 0.8em;
padding: 1em;
border: none;
background: none;
transition: color .2s;
cursor: pointer;
}
.actions:hover{
color: rgb(30, 30, 171);
background: #F5F5F5;
box-shadow: 0px 2px 5px 0 rgba(0, 0, 0, 0.26);
}
code, pre {
background: rgba(255,255,255,0.1);
color: rgba(232, 216, 49, 0.9);
font-family: "Source Code Pro", Monaco, Menlo, Consolas, "Courier New",monospace;
padding: 0.5em;
border-radius: 3px;
margin: 1em 0;
}
code{
display: inline;
vertical-align: middle;
margin: 0;
}
pre{
display: block;
}
.striked{
text-decoration: line-through;
}
.mfb-component--tl{
animation: fromTop 1s 1;
-webkit-animation: fromTop 1s 1;
}
.mfb-component--tr{
animation: fromTop 1.3s 1;
-webkit-animation: fromTop 1.3s 1;
}
.mfb-component--br{
animation: fromBottom 1.6s 1;
-webkit-animation: fromBottom 1.6s 1;
}
.mfb-component--bl{
animation: fromBottom 1.9s 1;
-webkit-animation: fromBottom 1.9s 1;
}
@keyframes fromBottom {
0% {
transform: translateY(250px);
}
100% {
transform: translateY(0);
}
}
@keyframes fromTop {
0% {
transform: translateY(-250px);
}
100% {
transform: translateY(0);
}
}
@-webkit-keyframes fromBottom {
0% {
transform: translateY(250px);
}
100% {
transform: translateY(0);
}
}
@-webkit-keyframes fromTop {
0% {
transform: translateY(-250px);
}
100% {
transform: translateY(0);
}
}
================================================
FILE: mfb/src/index.html
================================================
Material floating button. The index.
Material Floating Buttons
Customizable, semantic Material button implementation. Shamelessly Openly inspired by Google Inbox, Evernote and Path.
To add Material Floating Buttons to any project just download or clone the repo from Github.
Try it yourself by selecting a style here below, or click on the yellow button here above for a code preview and refer to the docs more info.
To add Material Floating Buttons to any project just download the files from here below or clone the repo from Github.
The two classes of the main <ul> tag define the position of the component and its associated animation. The rest of the code always stays the same regardless of position and animation chosen. Refer to the docs or to the showcase for a thorough explanation.
The best way to integrate MFB in existing projects is to build the styles directly from the source. The scss file is filled with customizable variables. From there choose your favorite colors and sizes and then compile the css.
If you use Grunt and have cloned the repo just run grunt build or grunt watch to have automatic compilation.
================================================
FILE: mfb/src/lib/modernizr.touch.js
================================================
/* Modernizr 2.8.3 (Custom Build) | MIT & BSD
* Build: http://modernizr.com/download/#-touch-teststyles-prefixes
*/
;window.Modernizr=function(a,b,c){function v(a){i.cssText=a}function w(a,b){return v(l.join(a+";")+(b||""))}function x(a,b){return typeof a===b}function y(a,b){return!!~(""+a).indexOf(b)}function z(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:x(f,"function")?f.bind(d||b):f}return!1}var d="2.8.3",e={},f=b.documentElement,g="modernizr",h=b.createElement(g),i=h.style,j,k={}.toString,l=" -webkit- -moz- -o- -ms- ".split(" "),m={},n={},o={},p=[],q=p.slice,r,s=function(a,c,d,e){var h,i,j,k,l=b.createElement("div"),m=b.body,n=m||b.createElement("body");if(parseInt(d,10))while(d--)j=b.createElement("div"),j.id=e?e[d]:g+(d+1),l.appendChild(j);return h=["",'"].join(""),l.id=g,(m?l:n).innerHTML+=h,n.appendChild(l),m||(n.style.background="",n.style.overflow="hidden",k=f.style.overflow,f.style.overflow="hidden",f.appendChild(n)),i=c(l,a),m?l.parentNode.removeChild(l):(n.parentNode.removeChild(n),f.style.overflow=k),!!i},t={}.hasOwnProperty,u;!x(t,"undefined")&&!x(t.call,"undefined")?u=function(a,b){return t.call(a,b)}:u=function(a,b){return b in a&&x(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=q.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(q.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(q.call(arguments)))};return e}),m.touch=function(){var c;return"ontouchstart"in a||a.DocumentTouch&&b instanceof DocumentTouch?c=!0:s(["@media (",l.join("touch-enabled),("),g,")","{#modernizr{top:9px;position:absolute}}"].join(""),function(a){c=a.offsetTop===9}),c};for(var A in m)u(m,A)&&(r=A.toLowerCase(),e[r]=m[A](),p.push((e[r]?"":"no-")+r));return e.addTest=function(a,b){if(typeof a=="object")for(var d in a)u(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof enableClasses!="undefined"&&enableClasses&&(f.className+=" "+(b?"":"no-")+a),e[a]=b}return e},v(""),h=j=null,e._version=d,e._prefixes=l,e.testStyles=s,e}(this,this.document);
================================================
FILE: mfb/src/mfb.js
================================================
/**
* Material floating button
* By: Nobita
* Repo and docs: https://github.com/nobitagit/material-floating-button
*
* License: MIT
*/
;(function ( window, document, undefined ) {
'use strict';
/**
* Some defaults
*/
var clickOpt = 'click',
hoverOpt = 'hover',
toggleMethod = 'data-mfb-toggle',
menuState = 'data-mfb-state',
isOpen = 'open',
isClosed = 'closed',
mainButtonClass = 'mfb-component__button--main';
/**
* Internal references
*/
var elemsToClick,
elemsToHover,
mainButton,
target,
currentState;
/**
* For every menu we need to get the main button and attach the appropriate evt.
*/
function attachEvt( elems, evt ){
for( var i = 0, len = elems.length; i < len; i++ ){
mainButton = elems[i].querySelector('.' + mainButtonClass);
mainButton.addEventListener( evt , toggleButton, false);
}
}
/**
* Remove the hover option, set a click toggle and a default,
* initial state of 'closed' to menu that's been targeted.
*/
function replaceAttrs( elems ){
for( var i = 0, len = elems.length; i < len; i++ ){
elems[i].setAttribute( toggleMethod, clickOpt );
elems[i].setAttribute( menuState, isClosed );
}
}
function getElemsByToggleMethod( selector ){
return document.querySelectorAll('[' + toggleMethod + '="' + selector + '"]');
}
/**
* The open/close action is performed by toggling an attribute
* on the menu main element.
*
* First, check if the target is the menu itself. If it's a child
* keep walking up the tree until we found the main element
* where we can toggle the state.
*/
function toggleButton( evt ){
target = evt.target;
while ( target && !target.getAttribute( toggleMethod ) ){
target = target.parentNode;
if(!target) { return; }
}
currentState = target.getAttribute( menuState ) === isOpen ? isClosed : isOpen;
target.setAttribute(menuState, currentState);
}
/**
* On touch enabled devices we assume that no hover state is possible.
* So, we get the menu with hover action configured and we set it up
* in order to make it usable with tap/click.
**/
if ( window.Modernizr && Modernizr.touch ){
elemsToHover = getElemsByToggleMethod( hoverOpt );
replaceAttrs( elemsToHover );
}
elemsToClick = getElemsByToggleMethod( clickOpt );
attachEvt( elemsToClick, 'click' );
})( window, document );
================================================
FILE: mfb/test/unit.js
================================================
/**
* Currently there are no scripts along with this repo so no need to test anything.
*
**/
================================================
FILE: package.json
================================================
{
"name": "react-mfb",
"version": "0.6.0",
"description": "React component for a material menu à la Google Inbox and Evernote",
"author": "Nobita",
"contributors": [],
"license": "MIT",
"repository": "nobitagit/react-material-floating-button",
"engines": {
"node": ">= 0.10"
},
"main": "index.js",
"files": [
"LICENSE",
"index.js",
"mfb.css",
"mfb.css.map",
"mfb.scss",
"build"
],
"scripts": {
"build": "gulp",
"bro": "npm run build && browserify -t reactify demo/index.js -o demo/bundle.js",
"prepublish": "gulp"
},
"dependencies": {
"classnames": "^1.2.0",
"prop-types": "^15.5.10",
"react-dom": "^15.3.1"
},
"peerDependencies": {
"react": "^15.3.1"
},
"devDependencies": {
"browserify": "^9.0.3",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-sass": "^0.8.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-gh-pages": "^0.9.1",
"grunt-usemin": "^3.0.0",
"gulp": "^3.8.11",
"gulp-babel": "^4.0.0",
"reactify": "^1.0.0"
},
"keywords": [
"component",
"css",
"design",
"facebook",
"material",
"react",
"react-component",
"reactjs"
]
}
================================================
FILE: src/child-button.js
================================================
'use strict';
var React = require('react');
var classnames = require('classnames');
class ChildButton extends React.Component {
constructor(props) {
super(props);
this.handleOnClick = this.handleOnClick.bind(this);
}
handleOnClick() {
if (this.props.disabled === true) {
return;
}
if (this.props.onClick) {
this.props.onClick();
}
}
render() {
var iconClass = classnames('mfb-component__child-icon', this.props.icon);
var className = classnames('mfb-component__button--child',
this.props.className,
{"mfb-component__button--disabled": this.props.disabled});
return (
);
}
}
module.exports = ChildButton;
================================================
FILE: src/main-button.js
================================================
'use strict';
var React = require('react');
var classnames = require('classnames');
class MainButton extends React.Component {
constructor(props) {
super(props);
}
render() {
var iconResting = classnames('mfb-component__main-icon--resting', this.props.iconResting);
var iconActive = classnames('mfb-component__main-icon--active', this.props.iconActive);
var mainClass = classnames('mfb-component__button--main', this.props.className);
if (this.props.label) {
return (
);
} else {
return (
);
}
}
}
MainButton.defaultProps = {
href: '#',
onClick: function(){},
iconResting: '',
iconActive: '',
label: null
};
module.exports = MainButton;
================================================
FILE: src/menu.js
================================================
'use strict';
var React = require('react');
var PropTypes = require("prop-types");
var getClasses = require('./utils/get-classes');
var getChildren = require('./utils/get-children');
var childrenValidator = require('./utils/children-validator');
class Menu extends React.Component {
constructor(props) {
super(props);
this.state = {
isOpen: false
};
this.toggleMenu = this.toggleMenu.bind(this);
}
toggleMenu(evt) {
evt.preventDefault();
if (this.props.method === 'hover') {
return;
}
// flip the state from open to close and viceversa
this.setState({
isOpen: !this.state.isOpen
});
}
render() {
var classes = getClasses(this.props);
var buttons = getChildren(this.props.children);
var main = buttons.main && React.cloneElement(buttons.main, {
onClick: this.toggleMenu
});
return (
{main}
{buttons.child}
);
}
}
Menu.propTypes = {
effect: PropTypes.oneOf(['zoomin', 'slidein', 'slidein-spring', 'fountain']).isRequired,
position: PropTypes.oneOf(['tl', 'tr', 'bl', 'br']).isRequired,
children: childrenValidator
};
module.exports = Menu;
================================================
FILE: src/utils/children-validator.js
================================================
'use strict';
var Children = require('react').Children;
var MainButton = require('../main-button');
var ChildButton = require('../child-button');
function childrenValidator(props, propName, componentName){
var children = props[propName];
var mainButtonCount = 0;
var childButtonCount = 0;
var otherCount = 0;
var msg;
Children.forEach(children, function(child){
if(child.type === MainButton){
return mainButtonCount++;
}
if(child.type === ChildButton){
return childButtonCount++;
}
otherCount++;
});
if(mainButtonCount === 0){
msg = 'Prop `children` must contain a MainButton component in `' + componentName + '`.';
return new Error(msg);
}
if(mainButtonCount > 1){
msg = 'Prop `children` must contain only 1 MainButton component in `' +
componentName + '`, but ' + mainButtonCount + ' exist.';
return new Error(msg);
}
if(otherCount){
msg = 'Prop `children` contains elements other than MainButton and ChildButton ' +
'components in `' + componentName + '`.';
return new Error(msg);
}
}
module.exports = childrenValidator;
================================================
FILE: src/utils/get-children.js
================================================
'use strict';
var Children = require('react').Children;
var MainButton = require('../main-button');
function getChildren(children){
var buttons = {
main: null,
child: []
};
Children.forEach(children, function(child){
if(child.type === MainButton){
buttons.main = child;
return;
}
buttons.child.push(child);
});
return buttons;
}
module.exports = getChildren;
================================================
FILE: src/utils/get-classes.js
================================================
'use strict';
var classnames = require('classnames');
function getClasses(props){
return classnames({
'mfb-zoomin': props.effect === 'zoomin',
'mfb-slidein': props.effect === 'slidein',
'mfb-slidein-spring': props.effect === 'slidein-spring',
'mfb-fountain': props.effect === 'fountain',
'mfb-component--tl': props.position === 'tl',
'mfb-component--tr': props.position === 'tr',
'mfb-component--bl': props.position === 'bl',
'mfb-component--br': props.position === 'br'
}, props.className);
}
module.exports = getClasses;