2020-07-09 13:30:17 +00:00
|
|
|
import Component from '@ember/component';
|
2022-07-18 14:30:37 +00:00
|
|
|
import { set } from '@ember/object';
|
2020-06-17 13:26:50 +00:00
|
|
|
import Slotted from 'block-slots';
|
2021-03-09 09:30:01 +00:00
|
|
|
import A11yDialog from 'a11y-dialog';
|
2022-07-18 14:30:37 +00:00
|
|
|
import { schedule } from '@ember/runloop';
|
2020-07-09 13:30:17 +00:00
|
|
|
|
|
|
|
export default Component.extend(Slotted, {
|
|
|
|
tagName: '',
|
2018-10-19 15:17:02 +00:00
|
|
|
onclose: function() {},
|
|
|
|
onopen: function() {},
|
2022-07-18 14:30:37 +00:00
|
|
|
isOpen: false,
|
2020-06-17 13:26:50 +00:00
|
|
|
actions: {
|
2021-03-09 09:30:01 +00:00
|
|
|
connect: function($el) {
|
|
|
|
this.dialog = new A11yDialog($el);
|
2022-07-18 14:30:37 +00:00
|
|
|
this.dialog.on('hide', () => {
|
|
|
|
schedule('afterRender', _ => set(this, 'isOpen', false));
|
|
|
|
this.onclose({ target: $el })
|
|
|
|
});
|
|
|
|
this.dialog.on('show', () => {
|
|
|
|
set(this, 'isOpen', true)
|
|
|
|
this.onopen({ target: $el })
|
|
|
|
});
|
2021-12-21 06:40:55 +00:00
|
|
|
if (this.open) {
|
2022-07-18 14:30:37 +00:00
|
|
|
this.actions.open.apply(this, []);
|
2021-12-21 06:40:55 +00:00
|
|
|
}
|
2020-06-17 13:26:50 +00:00
|
|
|
},
|
2021-03-09 09:30:01 +00:00
|
|
|
disconnect: function($el) {
|
|
|
|
this.dialog.destroy();
|
|
|
|
},
|
|
|
|
open: function() {
|
|
|
|
this.dialog.show();
|
2018-10-19 15:17:02 +00:00
|
|
|
},
|
|
|
|
close: function() {
|
2021-03-09 09:30:01 +00:00
|
|
|
this.dialog.hide();
|
|
|
|
},
|
2018-10-19 15:17:02 +00:00
|
|
|
},
|
|
|
|
});
|