-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
sidenav update #384
sidenav update #384
Changes from 2 commits
51e6041
c03962d
9448653
9b9be7b
7c3f9cf
9d26778
2b6db3c
6b6e0be
d61eb64
c7703ec
fca26fc
7392eeb
016f579
9c52a9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Ember from 'ember'; | ||
const { Component } = Ember; | ||
|
||
export default Component.extend({ | ||
classNames: ['flex', 'layout-row'] | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
import Ember from 'ember'; | ||
import PaperNavContainer from './paper-nav-container'; | ||
const { Component } = Ember; | ||
|
||
export default Ember.Component.extend({ | ||
tagName: 'div', | ||
export default Component.extend({ | ||
|
||
navContainer: Ember.computed(function() { | ||
return this.nearestOfType(PaperNavContainer); | ||
}), | ||
classNameBindings: ['hideClass'], | ||
|
||
actions: { | ||
toggleMenu() { | ||
this.get('navContainer').get('sideBar').send('toggleMenu'); | ||
} | ||
}, | ||
name: 'default', | ||
|
||
didInsertElement() { | ||
init() { | ||
this._super(...arguments); | ||
if (this.get('navContainer')) { | ||
let lockedOpen = this.get('navContainer').get('sideBar').get('locked-open'); | ||
let lockedOpen = this.get('navContainer').get('sideBar').get('lockedOpen'); | ||
if (lockedOpen) { | ||
this.$().attr(`hide-${lockedOpen}`, true); | ||
this.set('hideClass', `hide-${lockedOpen}`); | ||
} | ||
} | ||
}, | ||
|
||
actions: { | ||
toggleMenu() { | ||
this.get('navContainer').get('sideBar').send('toggleMenu'); | ||
} | ||
} | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,66 @@ | ||
import Ember from 'ember'; | ||
import PaperNavContainer from './paper-nav-container'; | ||
import TransitionMixin from 'ember-css-transitions/mixins/transition-mixin'; | ||
import PaperSidenavContainer from './paper-sidenav-container'; | ||
|
||
export default Ember.Component.extend({ | ||
constants: Ember.inject.service(), | ||
const { Component, inject, computed, $, run } = Ember; | ||
|
||
export default Component.extend(TransitionMixin, { | ||
tagName: 'md-sidenav', | ||
attributeBindings: ['tabindex'], | ||
classNameBindings: ['positionClass'], | ||
transitionTriggers: ['isLockedOpen:md-locked-open', 'closed:md-closed'], | ||
|
||
'locked-open': 'gt-sm', | ||
constants: inject.service(), | ||
paperSidenav: inject.service(), | ||
|
||
name: 'default', | ||
position: 'left', | ||
lockedOpen: 'gt-sm', | ||
closed: true, | ||
closeOnClick: true, | ||
tabindex: -1, | ||
|
||
navContainer: Ember.computed(function() { | ||
return this.nearestOfType(PaperNavContainer); | ||
navContainer: computed(function() { | ||
return this.nearestOfType(PaperSidenavContainer); | ||
}), | ||
|
||
attributeBindings: ['tabindex'], | ||
classNameBindings: ['isLockedOpen:md-locked-open', 'closed:md-closed'], | ||
tabindex: -1, | ||
positionClass: computed('position', function() { | ||
return `md-sidenav-${this.get('position')}`; | ||
}), | ||
|
||
_init: Ember.on('init', function() { | ||
let _self = this; | ||
init() { | ||
this.updateLockedOpen(); | ||
|
||
if (this.get('navContainer')) { | ||
this.get('navContainer').set('sideBar', this); | ||
} | ||
this._super(...arguments); | ||
|
||
this.matchMedia(); | ||
this.set('__resizeWindow', function() { | ||
_self.matchMedia(); | ||
}); | ||
}), | ||
/*if (this.get('navContainer')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftovers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true. I still need to make up my mind on the sidenav service. :/ |
||
this.get('navContainer').set('sideBar', this); | ||
}*/ | ||
|
||
_observeClosedState: Ember.observer('closed', function() { | ||
if (this.get('closed')) { | ||
Ember.$('body').css('overflow', 'inherit'); | ||
} else { | ||
Ember.$('body').css('overflow', 'hidden'); | ||
} | ||
}), | ||
this.get('paperSidenav').register(this.get('name')); | ||
}, | ||
|
||
didInsertElement() { | ||
Ember.$(window).on('resize', this.get('__resizeWindow')); | ||
this._super(...arguments); | ||
$(window).on(`resize.${this.elementId}`, run.bind(this, 'updateLockedOpen')); | ||
}, | ||
|
||
willDestroyElement() { | ||
Ember.$(window).off('resize', this.get('__resizeWindow')); | ||
this._super(...arguments); | ||
$(window).off(`resize.${this.elementId}`, run.bind(this, 'updateLockedOpen')); | ||
}, | ||
|
||
updateLockedOpen() { | ||
let mediaQuery = this.get('constants').MEDIA[this.get('lockedOpen')]; | ||
let isLockedOpen = window.matchMedia(mediaQuery).matches; | ||
this.set('isLockedOpen', isLockedOpen); | ||
if (isLockedOpen) { | ||
this.set('closed', true); | ||
} | ||
}, | ||
|
||
matchMedia() { | ||
let mediaQuery = this.get('constants').MEDIA[this.get('locked-open')]; | ||
this.set('isLockedOpen', window.matchMedia(mediaQuery).matches); | ||
if (this.get('isLockedOpen')) { | ||
click() { | ||
if (this.get('closeOnClick') && !this.get('isLockedOpen')) { | ||
this.set('closed', true); | ||
} | ||
}, | ||
|
@@ -59,17 +71,6 @@ export default Ember.Component.extend({ | |
this.toggleProperty('closed'); | ||
} | ||
} | ||
}, | ||
|
||
click() { | ||
if (!this.get('closeOnClick') || this.get('isLockedOpen')) { | ||
return; | ||
} | ||
|
||
let _self = this; | ||
Ember.run.next(function() { | ||
_self.set('closed', true); | ||
}); | ||
} | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Ember from 'ember'; | ||
const { Service, $, run, Object: EmObject, assert } = Ember; | ||
|
||
export default Service.extend({ | ||
init() { | ||
this._super(...arguments); | ||
this.set('sidenavs', EmObject.create()); | ||
}, | ||
|
||
didInsertElement() { | ||
this._super(...arguments); | ||
$(window).on('resize.sidenav-service', run.bind(this, 'updateLockedOpen')); | ||
}, | ||
|
||
willDestroyElement() { | ||
this._super(...arguments); | ||
$(window).off('resize.sidenav-service', run.bind(this, 'updateLockedOpen')); | ||
}, | ||
|
||
updateLockedOpen() { | ||
let sidenavs = this.get('sidenavs'); | ||
Object.keys(sidenavs) | ||
.map((k) => sidenavs.get(k)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've usually seen fluent code indented. Just an option. |
||
.forEach((s) => { | ||
let lockedOpen = s.get('lockedOpen'); | ||
let mediaQuery = this.get('constants').MEDIA[lockedOpen]; | ||
let match = window.matchMedia(mediaQuery).matches; | ||
s.set('isLockedOpen', match); | ||
if (match) { | ||
s.set('closed', match); | ||
} | ||
}); | ||
}, | ||
|
||
register(name, lockedOpen) { | ||
assert(`You tried to register a sidenav named '${name}' but there is already a sidenav with that name registered`, !this.get('sidenavs').get(name)); | ||
this.get('sidenavs').set(name, EmObject.create({ | ||
open: false, | ||
isLockedOpen: false, | ||
lockedOpen | ||
})); | ||
}, | ||
|
||
open(name = 'default') { | ||
assert(`You tried to open a sidenav named '${name}' but no such sidenav is registered`, this.get('sidenavs').get(name)); | ||
this.get('sidenavs').get(name).set('open', true); | ||
}, | ||
|
||
close(name = 'default') { | ||
assert(`You tried to close a sidenav named '${name}' but no such sidenav is registered`, this.get('sidenavs').get(name)); | ||
this.get('sidenavs').get(name).set('open', false); | ||
}, | ||
|
||
toggle() { | ||
assert(`You tried to toggle a sidenav named '${name}' but no such sidenav is registered`, this.get('sidenavs').get(name)); | ||
this.get('sidenavs').get(name).toggleProperty(name); | ||
} | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-paper/components/paper-sidenav-container'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-paper/services/paper-sidenav'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be a use case for lockedOpen being dynamic (i.e. changing after component creation)? I don't have one, but it would be easy to move this to didReceiveAttrs().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is on the toggle component. The toggle component is reaching the sidenav container for the
lockedOpen
. lockedOpen is never passed in to sidenav-toggle, so I don't see how we can use didReceiveAttrs?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. Difficult to bind attributes from components that are parent/child. No matter as the use case is sketchy anyhow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still need a better way to do this with the new service. shouldn't be difficult.