Ghost/ghost/admin/app/components/gh-menu-toggle.js
Kevin Ansfield 267ce40945 Refactor general UI state into a service
no issue
- moves general UI state control such as menu display, autonav, settings menu, etc into a `ui` service for easier use within components
- no longer required to jump through hoops passing state and actions down from application controller into components
- removes indirect "route" actions in favour of calling actions/methods directly on the `ui` service
2017-08-15 16:01:12 +01:00

43 lines
1.1 KiB
JavaScript

import Component from 'ember-component';
import computed, {reads} from 'ember-computed';
import injectService from 'ember-service/inject';
/*
This cute little component has two jobs.
On desktop, it toggles autoNav behaviour. It tracks
that state via the maximise property, and uses the
state to render the appropriate icon.
On mobile, it renders a closing icon, and clicking it
closes the mobile menu
*/
export default Component.extend({
classNames: ['gh-menu-toggle'],
mediaQueries: injectService(),
isMobile: reads('mediaQueries.isMobile'),
maximise: false,
// closure actions
desktopAction() {},
mobileAction() {},
iconClass: computed('maximise', 'isMobile', function () {
if (this.get('maximise') && !this.get('isMobile')) {
return 'icon-maximise';
} else {
return 'icon-minimise';
}
}),
click() {
if (this.get('isMobile')) {
this.mobileAction();
} else {
this.toggleProperty('maximise');
this.desktopAction();
}
}
});