Skip to content

Instantly share code, notes, and snippets.

@lennyburdette
Created July 8, 2016 02:10
Show Gist options
  • Select an option

  • Save lennyburdette/22827956e581828dbb0fe87e5939a89c to your computer and use it in GitHub Desktop.

Select an option

Save lennyburdette/22827956e581828dbb0fe87e5939a89c to your computer and use it in GitHub Desktop.
Modal Service
import Ember from 'ember';
export default Ember.Component.extend({
modal: Ember.inject.service(),
actions: {
close() {
this.get('modal').close();
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
modal: Ember.inject.service(),
actions: {
next() {
this.get('modal').open('my-other-modal');
},
close() {
this.close();
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
close() {
this.close();
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
modal: Ember.inject.service(),
appName: 'Ember Twiddle',
actions: {
openModal() {
this.get('modal').open('my-modal');
}
}
});
import Ember from 'ember';
export default Ember.Service.extend({
componentName: null,
open(name) {
this.set('componentName', name);
},
close() {
this.set('componentName', null);
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.modal-scrim {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.3);
display: flex;
justify-content: center;
align-items: center;
}
.modal-body {
background: #fff;
padding: 20px;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<button {{action "openModal"}}>Open Modal</button>
{{outlet}}
<br>
<br>
{{modal-owner}}
{{#if modal.componentName}}
<div class="modal-scrim">
<div class="modal-body">
{{component modal.componentName close=(action "close")}}
</div>
</div>
{{/if}}
modal content
<button {{action "next"}}>Next</button>
<button {{action "close"}}>Close</button>
more modal content
<button {{action "close"}}>Close</button>
{
"version": "0.10.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment