-
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.
chore(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`.
- Loading branch information
Showing
7 changed files
with
91 additions
and
101 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 |
---|---|---|
@@ -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