0.3.2 • Published 6 years ago

nifty-nav-2 v0.3.2

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

nifty-nav-2

Build Status Github file size npm GitHub issues license David Dependencies

A customizable JavaScript menu framework for modern browsers made easy.

Getting Started

🖥 Installation


Add Nifty Nav 2 to your project using your favorite package manager.

npm
npm install nifty-nav-2 --save
yarn
yarn add nifty-nav-2

📂 Including in your project


Styles

Import the Nifty Nav 2 css or scss, or ensure it is included in your build. The following is using scss to import from node_modules. Alternatively, you could copy niftyNav2.css from node_modules to your project.

// include nifty nav 2 styles
@import 'nifty-nav-2/dist/niftyNav2.css'

JavaScript

How you include the Nifty Nav 2 JavaScript library is up to you and the architecture of your project. Nifty Nav 2 is available as a UMD module so it can be used as a AMD, Global, Node, or ES6 module. The compiled JavaScript file found in dist/ contains the babel-polyfill to ensure proper cross browser support.

Simple

Copy the niftyNav2.js file in nifty-nav-2/dist to your project directory and include in your HTML. You do not need to include any polyfills, as they are bundled directly into dist/niftyNav2.js.

<html>
  <body>
    <!-- Your HTML Content -->
    <script src="path_to_your_assets/js/niftyNav2.js"></script>
  </body>
</html>
Using Gulp

A Gulp implementation that concatenates JS files may look something like this.

var concatFiles = [
  './node_modules/nifty-nav-2/dist/niftyNav2.js', // adds niftyNav2.js to be concatenated
  './assets/js/*.js', // grabs all js files from our assets/js folder
  '!./assets/js/*.min.js', // ignore minified files
]

// Concatenate & Minify JavaScript
gulp.task('scripts', ['lint'], function() {
  return gulp.src( concatFiles )
    .pipe(concat( 'all.js' ))
    .pipe(gulp.dest( './assets/js/' ))
    .pipe(rename('all.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest( './assets/js/' ))
});
ES6 Module
import niftyNav2 from 'nifty-nav-2';

🛠 Usage


Adding the Trigger

Place the trigger or "hamburger". You can place this wherever you want it to appear in the DOM.

<div data-nifty-target="niftyNav"></div>

Your element must have a data-nifty-target attribute with a unique name. Here, we are simply calling it niftyNav but it can be anything you wish. If changed from the default niftyNav be sure to pass that via settings when initializing.

Adding the Panel

Add the panel that will be opened on click. The ID should match the value of data-nifty-target.

<div id="niftyNav">
  <!--Panel Contents -->
</div>

Initialization

Initialize Nifty Nav 2 via JavaScript. The following is an example with settings for iconColor and panelColor.

<script>
  niftyNav2.init({
    iconColor: 'rgb(123, 249, 158)',
    panelColor: 'rgb(123, 249, 158)',
  });
</script>

⚙️ Settings

There are plenty settings that can be used to customize Nifty Nav 2.

SettingDescriptionAcceptsDefault
targetsTargets to create/use Nifty Nav 2 (from data-nifty-target)array['niftyNav']
iconIcon style to be usedstring - square, roundedsquare
iconColorColor to be applied to the iconstring#fff
showMenuTextShow or hide text next to the iconbooleanfalse
menuTextText to appear when showMenuText is truestringMenu
menuTextColorColor to be applied to menuTextstring#fff
panelOriginPlacement of where the Nifty Nav 2 panel will animate fromstring - top, left, righttop
panelTopOffsetTop offset for the panelinteger0
panelPositionCSS positioning for the panelstringabsolute
panelHeightHeight to be applied to the panelstringauto
panelWidthWidth to be applied to the panelstring100%
panelAnimationType of animation for the panelstring - slide-in, fade-in, offslide-in
panelAnimationSpeedSpeed of panel animationinteger500
panelColorColor to be applied to the background of the panelstring#2d2d2d
showMaskShow or hide the mask/overlaybooleantrue
maskAnimationSpeedSpeed at which the mask/overlay animates ininteger600
maskColorColor to be applied to the mask/overlaystringrgba(0,0,0,0.5)

🔌 API Methods

There are a few API Methods available to you if you should need them.

MethodDescriptionAcceptsDefault
onToggleAccepts a function that runs when togglePanel is firedxx
toggleIconsToggles the state of all iconsxx
toggleMaskToggles the mask when usedxx
togglePanelToggles the panel when usedpanelId which is generated from the targets optionsnone

🌎 Browser Support

Current browser support as of v0.1.0.

BrowserSupportNotes
Edge 16+
Edge <= 15
IE 11
IE 10⚠️May need CSS to adjust hamburger and menu text placement, core functionality is OK
Firefox 51+
Chrome 51+
Safari 9.1+

⚠️ Issues & Contributions

Feel free to open an issue or a pull request if you find any issues or enhancements.

📝 Changelog

The changelog can be found here.