├── .gitignore ├── LICENSE ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── Menu.vue │ ├── Menu │ │ ├── bubble.vue │ │ ├── elastic.vue │ │ ├── fallDown.vue │ │ ├── push.vue │ │ ├── pushRotate.vue │ │ ├── reveal.vue │ │ ├── scaleDown.vue │ │ ├── scaleRotate.vue │ │ ├── slide.vue │ │ └── stack.vue │ └── index.js └── main.js ├── vue.config.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018-present, Mohit Bajoria 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-burger-menu [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) 2 | 3 | [![npm](https://img.shields.io/npm/v/vue-burger-menu.svg?maxAge=3600)](https://www.npmjs.com/package/vue-burger-menu) 4 | 5 | [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?url=https%3A%2F%2Fvue-burger-menu.netlify.com%2F&via=mbj36&text=Checkout%20vue-burger-menu&hashtags=%23vuejs) 6 | 7 | An off-canvas sidebar Vue component with a collection of effects and styles using CSS transitions and SVG path animations. 8 | 9 | ## Demo & examples 10 | 11 | Live demo - https://vue-burger-menu.netlify.com/ 12 | 13 | To build the examples locally, run: 14 | 15 | ``` 16 | npm i 17 | npm run serve 18 | ``` 19 | 20 | ``` 21 | yarn 22 | yarn serve 23 | ``` 24 | 25 | Then open [`localhost:8080`](http://localhost:8080) in a browser 26 | 27 | ## Installation 28 | 29 | ``` 30 | npm install vue-burger-menu --save 31 | ``` 32 | 33 | ``` 34 | yarn add vue-burger-menu 35 | ``` 36 | 37 | ## Usage 38 | 39 | Items should be passed as child elements of the components 40 | 41 | ```javascript 42 | import { Slide } from 'vue-burger-menu' // import the CSS transitions you wish to use, in this case we are using `Slide` 43 | 44 | export default { 45 | components: { 46 | Slide // Register your component 47 | } 48 | } 49 | ``` 50 | 51 | In your template 52 | 53 | ``` 54 | 61 | ``` 62 | 63 | ### Animations 64 | 65 | The example above imported `slide` which renders a menu that slides in on the page when the burger icon is clicked. To use a different animation you can subsitute slide with any of the following 66 | 67 | * Slide 68 | * ScaleDown 69 | * ScaleRotate 70 | * Reveal 71 | * Push 72 | * PushRotate 73 | 74 | ATTENTION - the below animations are in WIP 75 | 76 | * FallDown 77 | * Stack 78 | * Elastic 79 | * Bubble 80 | 81 | ### Properties 82 | 83 | Some animation require certain other elements on your page 84 | 85 | * Page wrapper - an element wrapping the rest of the content on yur page, placed after the menu component 86 | 87 | ```javascript 88 | 89 | 90 |
91 | . 92 | . 93 |
94 | 95 | ``` 96 | 97 | * Outer container called `app` - an element containing everything including the menu component 98 | 99 | ```javascript 100 |
101 | 102 |
103 | . 104 | . 105 | . 106 |
107 |
108 | ``` 109 | 110 | Check this table to see which animations require these elements: 111 | 112 | Animation | `pageWrapId` | `appId` 113 | --- | :---: | :---: 114 | `Slide` | | 115 | `Push` | ✓ | ✓ 116 | `PushRotate` | ✓ | ✓ 117 | `ScaleDown` | ✓ | ✓ 118 | `ScaleRotate` | ✓ | ✓ 119 | `Reveal` | ✓ | ✓ 120 | 121 | ### Position 122 | 123 | The menu opens from left by default. To have it open from the right, use the `right` prop. It's just a boolean so you don't need to specify a value. 124 | 125 | ```javascript 126 | 127 | ``` 128 | 129 | ### Width 130 | 131 | You can specify the width of the menu with the `width` prop. The default is `300px` 132 | 133 | ```javascript 134 | 135 | ``` 136 | 137 | ### Open state 138 | 139 | You can control whether the sidebar is open or closed with the `isOpen` prop. This is useful if you need to close the menu after a user clicks on an item in it, for example, or if you want to open the menu from some other button in addition to the standard burger icon. The default value is `false` 140 | 141 | ```javascript 142 | // To render the menu open 143 | 144 | 145 | ``` 146 | ### Menu events 147 | 148 | If you want to get a notification when the menu open or close you can use the `openMenu` and `closeMenu` notifications. This way you can update your application state when the menu open or close 149 | 150 | ```javascript 151 | // To bind the open and close events 152 | 153 | 157 | ``` 158 | ### Close on Outside Click 159 | 160 | You can turn off the menu closing when an an outside click is triggered with `disableOutsideClick`. 161 | 162 | ``` javascript 163 | 164 | ``` 165 | 166 | ### Close on Escape 167 | 168 | By default, the menu will close when the Escape key is pressed. To disable this behavior, you can pass the `disableCloseOnEsc` prop. This is useful in cases where you want the menu to be open all the time, for example if you're implementing a responsive menu that behaves differently depending on the browser width. 169 | 170 | ``` javascript 171 | 172 | ``` 173 | 174 | ### Close on Navigation 175 | 176 | By default, the menu will not close when a link inside the menu is clicked. To disable this behavior, you can pass the `closeOnNavigation` prop. This is useful in cases where you want the menu to close when a navigation link is clicked as this then stops the user having to make an extra click to close the menu. 177 | 178 | ``` javascript 179 | 180 | ``` 181 | 182 | ### Overlay 183 | 184 | You can turn off the default overlay with `noOverlay`. 185 | 186 | ``` javascript 187 | 188 | ``` 189 | 190 | ### Burger Icon and Cross Icon 191 | 192 | You can disable both icons by passing burgerIcon and crossIcon to `false`. This can be useful if you want to keep the menu open and don't want the user to close the menu 193 | 194 | ```javascript 195 | 196 | ``` 197 | 198 | ### Styling 199 | 200 | Visual styles (color, font etc) need to be supplied with the help of CSS 201 | 202 | #### CSS 203 | The component has following helper class 204 | 205 | ```CSS 206 | .bm-burger-button { 207 | position: fixed; 208 | width: 36px; 209 | height: 30px; 210 | left: 36px; 211 | top: 36px; 212 | cursor: pointer; 213 | } 214 | .bm-burger-bars { 215 | background-color: #373a47; 216 | } 217 | .line-style { 218 | position: absolute; 219 | height: 20%; 220 | left: 0; 221 | right: 0; 222 | } 223 | .cross-style { 224 | position: absolute; 225 | top: 12px; 226 | right: 2px; 227 | cursor: pointer; 228 | } 229 | .bm-cross { 230 | background: #bdc3c7; 231 | } 232 | .bm-cross-button { 233 | height: 24px; 234 | width: 24px; 235 | } 236 | .bm-menu { 237 | height: 100%; /* 100% Full-height */ 238 | width: 0; /* 0 width - change this with JavaScript */ 239 | position: fixed; /* Stay in place */ 240 | z-index: 1000; /* Stay on top */ 241 | top: 0; 242 | left: 0; 243 | background-color: rgb(63, 63, 65); /* Black*/ 244 | overflow-x: hidden; /* Disable horizontal scroll */ 245 | padding-top: 60px; /* Place content 60px from the top */ 246 | transition: 0.5s; /*0.5 second transition effect to slide in the sidenav*/ 247 | } 248 | 249 | .bm-overlay { 250 | background: rgba(0, 0, 0, 0.3); 251 | } 252 | .bm-item-list { 253 | color: #b8b7ad; 254 | margin-left: 10%; 255 | font-size: 20px; 256 | } 257 | .bm-item-list > * { 258 | display: flex; 259 | text-decoration: none; 260 | padding: 0.7em; 261 | } 262 | .bm-item-list > * > span { 263 | margin-left: 10px; 264 | font-weight: 700; 265 | color: white; 266 | } 267 | ``` 268 | 269 | ## Browser Support 270 | 271 | Chrome and Firefox have full support, but Safari and IE have strange behavior for some of the menus. 272 | 273 | ## Author 274 | 275 | © [Mohit Bajoria](https://mbj36.xyz) 276 | 277 | ## License 278 | 279 | [MIT](https://github.com/mbj36/vue-burger-menu/blob/master/LICENSE) 280 | 281 | Like it ? it 282 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-burger-menu", 3 | "version": "2.0.5", 4 | "private": false, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint", 9 | "build-bundle": "vue-cli-service build --target lib --name vue-burger-menu ./src/components/index.js" 10 | }, 11 | "dependencies": { 12 | "vue": "^2.5.17" 13 | }, 14 | "author": { 15 | "name": "Mohit Bajoria", 16 | "email": "mohitbajo36@gmail.com", 17 | "url": "https://mbj36.xyz" 18 | }, 19 | "keywords": [ 20 | "vuejs", 21 | "menu", 22 | "hamburger", 23 | "sidebar" 24 | ], 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/mbj36/vue-burger-menu.git" 28 | }, 29 | "devDependencies": { 30 | "@vue/cli-plugin-babel": "^3.0.0", 31 | "@vue/cli-plugin-eslint": "^3.0.0", 32 | "@vue/cli-service": "^3.0.0", 33 | "less": "^3.8.1", 34 | "less-loader": "^4.1.0", 35 | "vue-template-compiler": "^2.5.17" 36 | }, 37 | "main": "./dist/vue-burger-menu.common.js", 38 | "license": "MIT", 39 | "eslintConfig": { 40 | "root": true, 41 | "env": { 42 | "node": true 43 | }, 44 | "extends": [ 45 | "plugin:vue/essential", 46 | "eslint:recommended" 47 | ], 48 | "rules": {}, 49 | "parserOptions": { 50 | "parser": "babel-eslint" 51 | } 52 | }, 53 | "postcss": { 54 | "plugins": { 55 | "autoprefixer": {} 56 | } 57 | }, 58 | "browserslist": [ 59 | "> 1%", 60 | "last 2 versions", 61 | "not ie <= 8" 62 | ], 63 | "files": [ 64 | "dist/vue-burger-menu.common.js", 65 | "dist/vue-burger-menu.umd.js" 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbj36/vue-burger-menu/257c8056e57be6c85d5dd3d97005c37cbddc0a29/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | vue-burger-menu 11 | 14 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 30 |
31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 55 | 56 | 112 | 113 | 371 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbj36/vue-burger-menu/257c8056e57be6c85d5dd3d97005c37cbddc0a29/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/Menu.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 205 | 206 | 278 | 279 | -------------------------------------------------------------------------------- /src/components/Menu/bubble.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 60 | -------------------------------------------------------------------------------- /src/components/Menu/elastic.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 38 | -------------------------------------------------------------------------------- /src/components/Menu/fallDown.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 71 | -------------------------------------------------------------------------------- /src/components/Menu/push.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/components/Menu/pushRotate.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/components/Menu/reveal.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/components/Menu/scaleDown.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/components/Menu/scaleRotate.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/components/Menu/slide.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/components/Menu/stack.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/components/index.js: -------------------------------------------------------------------------------- 1 | // Different CSS animations 2 | 3 | import Slide from './Menu/slide' 4 | import Bubble from './Menu/bubble' 5 | import Reveal from './Menu/reveal' 6 | import Push from './Menu/push' 7 | import Elastic from './Menu/elastic' 8 | import FallDown from './Menu/fallDown' 9 | import PushRotate from './Menu/pushRotate' 10 | import Stack from './Menu/stack' 11 | import ScaleRotate from './Menu/scaleRotate' 12 | import ScaleDown from './Menu/scaleDown' 13 | import Menu from './Menu' 14 | 15 | export default { 16 | Menu, 17 | Slide, 18 | Bubble, 19 | Reveal, 20 | Push, 21 | PushRotate, 22 | ScaleDown, 23 | ScaleRotate, 24 | Stack, 25 | FallDown, 26 | Elastic 27 | } -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App) 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | css: { 3 | extract: false 4 | }, 5 | configureWebpack: { 6 | output: { 7 | libraryExport: 'default' 8 | } 9 | } 10 | } 11 | 12 | 13 | 14 | --------------------------------------------------------------------------------