2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
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: '',
|
2022-09-15 08:43:17 +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: {
|
2022-09-15 08:43:17 +00:00
|
|
|
connect: function ($el) {
|
2021-03-09 09:30:01 +00:00
|
|
|
this.dialog = new A11yDialog($el);
|
2022-07-18 14:30:37 +00:00
|
|
|
this.dialog.on('hide', () => {
|
2022-09-15 08:43:17 +00:00
|
|
|
schedule('afterRender', (_) => set(this, 'isOpen', false));
|
|
|
|
this.onclose({ target: $el });
|
2022-07-18 14:30:37 +00:00
|
|
|
});
|
|
|
|
this.dialog.on('show', () => {
|
2022-09-15 08:43:17 +00:00
|
|
|
set(this, 'isOpen', true);
|
|
|
|
this.onopen({ target: $el });
|
2022-07-18 14:30:37 +00:00
|
|
|
});
|
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
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
disconnect: function ($el) {
|
2021-03-09 09:30:01 +00:00
|
|
|
this.dialog.destroy();
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
open: function () {
|
2021-03-09 09:30:01 +00:00
|
|
|
this.dialog.show();
|
2018-10-19 15:17:02 +00:00
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
close: function () {
|
2021-03-09 09:30:01 +00:00
|
|
|
this.dialog.hide();
|
|
|
|
},
|
2018-10-19 15:17:02 +00:00
|
|
|
},
|
|
|
|
});
|