Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Drawer component #689

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module.exports = function(grunt) {
'js/push.js',
'js/segmented-controllers.js',
'js/sliders.js',
'js/toggles.js'
'js/toggles.js',
'js/drawers.js'
],
dest: '<%= meta.distPath %>js/<%= pkg.name %>.js'
}
Expand Down
38 changes: 38 additions & 0 deletions dist/css/ratchet.css
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,44 @@ select {
border-radius: 6px;
}

.drawer {
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
padding: inherit;
background-color: transparent;
-webkit-transition: background-color .2s linear, left 0 linear .2s;
-moz-transition: background-color .2s linear, left 0 linear .2s;
transition: background-color .2s linear, left 0 linear .2s;
}

.drawer.active {
left: 0;
background-color: rgba(0, 0, 0, .3);
-webkit-transition: background-color .2s linear;
-moz-transition: background-color .2s linear;
transition: background-color .2s linear;
}

.drawer > .drawer-inner {
position: relative;
left: -100%;
width: 80%;
height: 100%;
overflow: hidden;
background: white;
box-shadow: 1px 0 2px rgba(0, 0, 0, .3);
-webkit-transition: left .2s linear;
-moz-transition: left .2s linear;
transition: left .2s linear;
}

.drawer.active > .drawer-inner {
left: 0;
}

.modal {
position: fixed;
top: 0;
Expand Down
2 changes: 1 addition & 1 deletion dist/css/ratchet.min.css

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions dist/js/ratchet.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,3 +962,51 @@
});

}());

/* ========================================================================
* Ratchet: drawer.js v2.0.2
* http://goratchet.com/components#drawer
* ========================================================================
* Copyright 2014 Connor Sears
* Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
* ======================================================================== */

!(function () {
'use strict';

var findDrawers = function (target) {
var i;
var drawers = document.querySelectorAll('a');

for (; target && target !== document; target = target.parentNode) {
for (i = drawers.length; i--;) {
if (drawers[i] === target) {
return target;
}
}
}
};

var getDrawer = function (event) {
var drawerToggle = findDrawers(event.target);
if (drawerToggle && drawerToggle.hash) {
return document.querySelector(drawerToggle.hash);
}
};

window.addEventListener('touchend', function (event) {
if (event.target.classList.contains('drawer')) {
// click directly on the drawer, but not on it's inner element
event.target.classList.remove('active');
return;
}

var drawer = getDrawer(event);
if (drawer) {
if (drawer && drawer.classList.contains('drawer')) {
drawer.classList.toggle('active');
}
event.preventDefault(); // prevents rewriting url (apps can still use hash values in url)
}
});
}());
2 changes: 1 addition & 1 deletion dist/js/ratchet.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/_includes/jump.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<a class="docs-component-item" href="#popovers" data-ignore="push">Popovers</a>
<a class="docs-component-item" href="#modals" data-ignore="push">Modals</a>
<a class="docs-component-item" href="#sliders" data-ignore="push">Sliders</a>
<a class="docs-component-item" href="#drawers" data-ignore="push">Drawers</a>
<a class="docs-component-item" href="#push" data-ignore="push">Push</a>
<a class="docs-component-item" href="#ratchicons" data-ignore="push">Ratchicons</a>
</div>
4 changes: 4 additions & 0 deletions docs/assets/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,10 @@ code {
margin: 10px;
}

#drawersInDevice #iwindow > .btn {
margin: 10px;
}

@media screen and (min-width: 768px) {
.slider .slide {
cursor: -webkit-grab;
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/css/docs.min.css

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions docs/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,37 @@ <h3 class="component-title">Sliders</h3>

</article>


<article class="component" id="drawers">
<h3 class="component-title">Drawers</h3>
<p class="component-description">Overlapping navigation drawer</p>

<div class="component-example">
<a href="#myDrawer" class="btn">Open Drawer</a>
<nav class="drawer" id="myDrawer">
<div class="drawer-inner">
<ul class="table-view">
<li class="table-view-cell">Home</li>
<li class="table-view-cell">Settings</li>
</ul>
</div>
</nav>
</div>

{% highlight html %}
<a href="#myDrawer" class="btn">Open Drawer</a>
<nav class="drawer" id="myDrawer">
<div class="drawer-inner">
<ul class="table-view">
<li class="table-view-cell">Home</li>
<li class="table-view-cell">Settings</li>
</ul>
</div>
</nav>
{% endhighlight %}

</article>

<!-- Push docs -->
<article class="component" id="push">
<h3 class="component-title">Push</h3>
Expand Down
38 changes: 38 additions & 0 deletions docs/dist/css/ratchet.css
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,44 @@ select {
border-radius: 6px;
}

.drawer {
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
padding: inherit;
background-color: transparent;
-webkit-transition: background-color .2s linear, left 0 linear .2s;
-moz-transition: background-color .2s linear, left 0 linear .2s;
transition: background-color .2s linear, left 0 linear .2s;
}

.drawer.active {
left: 0;
background-color: rgba(0, 0, 0, .3);
-webkit-transition: background-color .2s linear;
-moz-transition: background-color .2s linear;
transition: background-color .2s linear;
}

.drawer > .drawer-inner {
position: relative;
left: -100%;
width: 80%;
height: 100%;
overflow: hidden;
background: white;
box-shadow: 1px 0 2px rgba(0, 0, 0, .3);
-webkit-transition: left .2s linear;
-moz-transition: left .2s linear;
transition: left .2s linear;
}

.drawer.active > .drawer-inner {
left: 0;
}

.modal {
position: fixed;
top: 0;
Expand Down
2 changes: 1 addition & 1 deletion docs/dist/css/ratchet.min.css

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions docs/dist/js/ratchet.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,3 +962,51 @@
});

}());

/* ========================================================================
* Ratchet: drawer.js v2.0.2
* http://goratchet.com/components#drawer
* ========================================================================
* Copyright 2014 Connor Sears
* Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
* ======================================================================== */

!(function () {
'use strict';

var findDrawers = function (target) {
var i;
var drawers = document.querySelectorAll('a');

for (; target && target !== document; target = target.parentNode) {
for (i = drawers.length; i--;) {
if (drawers[i] === target) {
return target;
}
}
}
};

var getDrawer = function (event) {
var drawerToggle = findDrawers(event.target);
if (drawerToggle && drawerToggle.hash) {
return document.querySelector(drawerToggle.hash);
}
};

window.addEventListener('touchend', function (event) {
if (event.target.classList.contains('drawer')) {
// click directly on the drawer, but not on it's inner element
event.target.classList.remove('active');
return;
}

var drawer = getDrawer(event);
if (drawer) {
if (drawer && drawer.classList.contains('drawer')) {
drawer.classList.toggle('active');
}
event.preventDefault(); // prevents rewriting url (apps can still use hash values in url)
}
});
}());
2 changes: 1 addition & 1 deletion docs/dist/js/ratchet.min.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions js/drawers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* ========================================================================
* Ratchet: drawer.js v2.0.2
* http://goratchet.com/components#drawer
* ========================================================================
* Copyright 2014 Connor Sears
* Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
* ======================================================================== */

!(function () {
'use strict';

var findDrawers = function (target) {
var i;
var drawers = document.querySelectorAll('a');

for (; target && target !== document; target = target.parentNode) {
for (i = drawers.length; i--;) {
if (drawers[i] === target) {
return target;
}
}
}
};

var getDrawer = function (event) {
var drawerToggle = findDrawers(event.target);
if (drawerToggle && drawerToggle.hash) {
return document.querySelector(drawerToggle.hash);
}
};

window.addEventListener('touchend', function (event) {
if (event.target.classList.contains('drawer')) {
// click directly on the drawer, but not on it's inner element
event.target.classList.remove('active');
return;
}

var drawer = getDrawer(event);
if (drawer) {
if (drawer && drawer.classList.contains('drawer')) {
drawer.classList.toggle('active');
}
event.preventDefault(); // prevents rewriting url (apps can still use hash values in url)
}
});
}());
7 changes: 7 additions & 0 deletions sass/docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,13 @@ code {
}
}

// Drawer
#drawersInDevice {
#iwindow > .btn {
margin: 10px;
}
}

// Sliders
@media screen and (min-width: 768px) {
.slider .slide {
Expand Down
38 changes: 38 additions & 0 deletions sass/drawer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// DRAWER
// --------------------------------------------------


.drawer {
position: absolute;
padding: inherit;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0);

// wait for the drawer-inner animation to finish before hiding the backdrop
@include transition(background-color .25s linear, left 0 linear .25s);
}

.drawer.active {
left: 0;
background-color: rgba(0,0,0,.3);
@include transition(background-color .25s linear);
}

.drawer > .drawer-inner {
position: relative;
left: -100%;
width: 80%;
height: 100%;
background: white;
overflow: hidden;
@include box-shadow(1px 0 2px rgba(0,0,0,.3));
@include transition(left .25s linear);
}

.drawer.active > .drawer-inner {
left: 0;
}
1 change: 1 addition & 0 deletions sass/ratchet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import "forms.scss";
@import "segmented-controls.scss";
@import "popovers.scss";
@import "drawer.scss";

// Javascript components
@import "modals.scss";
Expand Down