-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modal): convert modal logic to modifier
Moving the modal logic to a modifier has the advantage of not needing the ember and mutation observers and the dependency on `@ember/render-modifiers`. Consuming apps that needed to enable the `default-async-observers` for modals to work should be able to disable it now.
- Loading branch information
Showing
8 changed files
with
92 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { registerDestructor } from "@ember/destroyable"; | ||
import Modifier from "ember-modifier"; | ||
import UIkit from "uikit"; | ||
|
||
export default class UkModalModifier extends Modifier { | ||
#modal; | ||
#events; | ||
|
||
constructor(owner, args) { | ||
super(owner, args); | ||
|
||
registerDestructor(this, () => { | ||
this.#events.forEach(([event, handler]) => { | ||
UIkit.util.off(this.#modal.$el, event, handler); | ||
}); | ||
|
||
this.#modal.$destroy(); | ||
}); | ||
} | ||
|
||
modify(element, positional, named) { | ||
if (!this.#modal) { | ||
this.initialize(element, positional, named); | ||
} | ||
|
||
if (named.visible) { | ||
this.#modal.show(); | ||
} else { | ||
this.#modal.hide(); | ||
} | ||
} | ||
|
||
initialize(element, positional, named) { | ||
this.#events = [ | ||
["hide", named.onHide], | ||
["hidden", named.onHidden], | ||
["show", named.onShow], | ||
["shown", named.onShown], | ||
]; | ||
|
||
this.#modal = UIkit.modal(element, { | ||
escClose: named.escClose ?? true, | ||
bgClose: named.bgClose ?? true, | ||
stack: named.stack ?? false, | ||
container: named.container, | ||
clsPage: named.clsPage ?? "uk-modal-page", | ||
clsPanel: named.clsPanel ?? "uk-modal-dialog", | ||
selClose: | ||
named.selClose ?? | ||
".uk-modal-close,.uk-modal-close-default,.uk-modal-close-outside,.uk-modal-close-full", | ||
}); | ||
|
||
this.#events.forEach(([event, handler]) => { | ||
UIkit.util.on(this.#modal.$el, event, handler); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-uikit/modifiers/uk-modal"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"application-template-wrapper": false, | ||
"default-async-observers": true, | ||
"default-async-observers": false, | ||
"jquery-integration": false, | ||
"template-only-glimmer-components": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { module, test } from "qunit"; | ||
|
||
module("Integration | Modifier | uk-modal", function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test("it renders", async function (assert) { | ||
// the functionality of the uk-modal modifier is fully tested in the tests | ||
// for the uk-modal component | ||
assert.ok(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters