Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Commit

Permalink
Better API for subnav
Browse files Browse the repository at this point in the history
  • Loading branch information
samselikoff committed Jan 28, 2016
1 parent 73c2088 commit 7634965
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
29 changes: 17 additions & 12 deletions addon/components/ted-subnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ export default Ember.Component.extend({

let $clone = this.$().clone();
$clone.removeAttr('id');
this.$().parent().prepend($clone);
$clone.removeClass('ember-view');

let $previousSibling = this.$().prev();
let $parent = this.$().parent();

Ember.run.schedule('afterRender', () => {
if (this.get('shouldAnimateOut')) {
if ($previousSibling.length) {
$previousSibling.after($clone);
} else {
$parent.prepend($clone);
}

this.animateOut($clone);
} else {
$clone.remove();
}
});

Expand All @@ -57,28 +64,26 @@ export default Ember.Component.extend({
let $mainContent = Ember.$('.Ted-subnav-wrapper__inner');
let offset = this.$().outerHeight();

$mainContent.removeClass('Ted-subnav-wrapper__inner--should-transition');
$mainContent.css('transform', `translateY(-${offset}px)`);
this.$().removeClass('Ted-subnav--should-transition');
this.$().css('max-height', 0);

Ember.run.next(() => {
$mainContent.addClass('Ted-subnav-wrapper__inner--should-transition');
$mainContent.css('transform', `translateY(0)`);
this.$().addClass('Ted-subnav--should-transition');
this.$().css('max-height', '200px');
});
},

animateOut($clone) {
// Note: this duration has to match the transition time in ted-subnav.scss
let duration = 200;
let duration = 300;
let offset = $clone.outerHeight();
let $mainContent = Ember.$('.Ted-subnav-wrapper__inner');

$mainContent.addClass('Ted-subnav-wrapper__inner--should-transition');
$mainContent.css('transform', `translateY(-${offset}px)`);
$clone.addClass('Ted-subnav--should-transition');
$clone.css('max-height', '0');

Ember.run.later(() => {
$mainContent.removeClass('Ted-subnav-wrapper__inner--should-transition');
$clone.remove();
$mainContent.css('transform', `translateY(0px)`);
}, duration);
}

Expand Down
14 changes: 12 additions & 2 deletions app/styles/ember-cli-ted-navs/ted-subnav.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
.Ted-subnav {
padding-top: 15px;
padding-bottom: 15px;
clear: both;
list-style-type: none;
border-bottom: 1px solid #ddd;
overflow: hidden;
max-height: 200px;

&__content {
padding-top: 15px;
padding-bottom: 15px;
}

&--should-transition {
// Note: this transition duration has to match the duration property in ted-subnav.js
transition: max-height 0.3s ease-in-out;
}
}

.Ted-subnav-wrapper {
Expand Down
6 changes: 1 addition & 5 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
{{/ted-nav-item}}
{{/ted-nav}}

<div class="Ted-subnav-wrapper">
<div class="Ted-subnav-wrapper__inner">
{{outlet}}
</div>
</div>
{{outlet}}
</div>

7 changes: 7 additions & 0 deletions tests/dummy/app/templates/conferences.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{{#ted-subnav}}
{{ted-subnav-item 'Do something' onClick=(action (mut someVar))}}
{{#ted-subnav-item onClick=(action (mut anotherVar))}}
<i class='fa fa-plus'></i> New transfer
{{/ted-subnav-item}}
{{/ted-subnav}}

<h1>Um, the conference</h1>

0 comments on commit 7634965

Please sign in to comment.