Skip to content

Instantly share code, notes, and snippets.

@camskene
Created August 13, 2017 08:12
Show Gist options
  • Save camskene/366749526a071d4be54ed13f3bdc89bf to your computer and use it in GitHub Desktop.
Save camskene/366749526a071d4be54ed13f3bdc89bf to your computer and use it in GitHub Desktop.
liquid-wormhole
import Ember from 'ember';
export default Ember.Component.extend({
tagName: '',
});
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'button',
});
import Ember from 'ember';
export default Ember.Component.extend({
isExpanded: false,
classNames: ['my-component'],
actions: {
toggle() {
this.toggleProperty('isExpanded');
if (!this.get('isExpanded')) {
return;
}
this._setupClickHandler();
},
},
willDestroyElement() {
this._super(...arguments);
this._teardownClickHandler();
},
_setupClickHandler() {
$(document).on(`click.${this.elementId}`, (e) => {
if (!e.target.closest(`#${this.elementId}`) && !e.target.closest('.my-component-body')) {
this.set('isExpanded', false);
this._teardownClickHandler();
}
});
},
_teardownClickHandler() {
$(document).off(`click.${this.elementId}`);
},
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
body {
margin: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.my-component-body {
width: 300px;
padding: 15px 20px;
color: #fff;
font-weight: 700;
background-color: #2980b9;
border: 2px solid rgba(0,0,0,.1);
border-radius: 7px;
text-align: center;
margin: calc(50vh - 29px) auto 0;
box-shadow: 0 2px rgba(0,0,0,.15);
}
{{#my-component as |c|}}
{{c.trigger}}
{{#c.body}}
Foo
{{/c.body}}
{{/my-component}}
<hr>
{{#my-component as |c|}}
{{c.trigger}}
{{#c.body}}
Bar
{{/c.body}}
{{/my-component}}
<hr>
{{#my-component as |c|}}
{{c.trigger}}
{{#c.body}}
Baz
{{/c.body}}
{{/my-component}}
{{#if isExpanded}}
{{#liquid-wormhole class='my-component-body'}}
{{yield}}
{{/liquid-wormhole}}
{{/if}}
{{if isExpanded 'Collapse' 'Expand'}}
{{yield (hash
trigger=(component 'my-component-trigger' isExpanded=isExpanded click=(action 'toggle'))
body=(component 'my-component-body' isExpanded=isExpanded)
)}}
export default function() {
this.transition(
this.hasClass('my-component-body'),
this.toValue(true),
this.use('to-right'),
this.reverse('to-right'),
);
}
{
"version": "0.12.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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"liquid-wormhole": "v2.0.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment