Skip to content

Commit

Permalink
feat(modal): change to a composable component (#307)
Browse files Browse the repository at this point in the history
Changes the uk-modal component to be composable with header, body and
footer.

BREAKING CHANGE: This removes the default stying of "uk-modal-body", to
migrate to this patch and keep the stying it will have to be changed from:
```hbs
{{#uk-modal}}
  Lorem ipsum
{{/uk-modal}}
```
to:
```hbs
{{#uk-modal as |modal|}}
  {{#modal.body}}
    Lorem ipsum
  {{/modal.body}}
{{/uk-modal}}
```
The footer can be migrated as follows:
```hbs
{{#uk-modal}}
  <p class="uk-text-right">
    Footer content
  </p>
{{/uk-modal}}
```
to:
```hbs
{{#uk-modal as |modal|}}
  {{#modal.footer class="uk-text-right"}}
    Footer content
  {{/modal.footer}}
{{/uk-modal}}
```
  • Loading branch information
Yelinz authored and Jonas Metzener committed Dec 2, 2019
1 parent 50b9235 commit 3ee42d0
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 22 deletions.
2 changes: 2 additions & 0 deletions addon/components/uk-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const noop = () => {};
export default Component.extend({
layout,

modalClass: "",
dialogClass: "",
btnClose: true,
escClose: true,
bgClose: true,
Expand Down
10 changes: 10 additions & 0 deletions addon/components/uk-modal/body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Component from "@ember/component";
import layout from "../../templates/components/uk-modal/body";

export default Component.extend({
layout,

tagName: "div",

classNames: ["uk-modal-body"]
});
10 changes: 10 additions & 0 deletions addon/components/uk-modal/footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Component from "@ember/component";
import layout from "../../templates/components/uk-modal/footer";

export default Component.extend({
layout,

tagName: "div",

classNames: ["uk-modal-footer"]
});
10 changes: 10 additions & 0 deletions addon/components/uk-modal/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Component from "@ember/component";
import layout from "../../templates/components/uk-modal/header";

export default Component.extend({
layout,

tagName: "div",

classNames: ["uk-modal-header"]
});
16 changes: 9 additions & 7 deletions addon/templates/components/uk-modal.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{#-in-element containerElement}}
<div id={{this.modalId}}>
<div class="uk-modal-dialog">
{{#if @btnClose}}<button class="uk-modal-close-default" type="button" uk-close></button>{{/if}}
<div class="uk-modal-body">
{{yield}}
</div>
<div id={{this.modalId}} class={{@modalClass}}>
<div class="uk-modal-dialog {{@dialogClass}}">
{{#if this.btnClose}}<button class="uk-modal-close-default" type="button" uk-close></button>{{/if}}
{{yield (hash
header = (component "uk-modal/header")
body = (component "uk-modal/body")
footer = (component "uk-modal/footer")
)}}
</div>
</div>
{{/-in-element}}
{{/-in-element}}
1 change: 1 addition & 0 deletions addon/templates/components/uk-modal/body.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
1 change: 1 addition & 0 deletions addon/templates/components/uk-modal/footer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
1 change: 1 addition & 0 deletions addon/templates/components/uk-modal/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
1 change: 0 additions & 1 deletion addon/templates/components/uk-modal/modal.hbs

This file was deleted.

1 change: 1 addition & 0 deletions app/components/uk-modal/body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "ember-uikit/components/uk-modal/body";
1 change: 1 addition & 0 deletions app/components/uk-modal/footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "ember-uikit/components/uk-modal/footer";
1 change: 1 addition & 0 deletions app/components/uk-modal/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "ember-uikit/components/uk-modal/header";
1 change: 1 addition & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const getChannelURL = require("ember-source-channel-url");

module.exports = async function() {
return {
useYarn: true,
scenarios: [
{
name: "ember-lts-3.8",
Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/app/controllers/docs/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import Controller from "@ember/controller";

export default Controller.extend({
visible: false,
btnClose: true,
closable: true,
modalClass: "",
dialogClass: "",

actions: {
submit() {
Expand Down
16 changes: 10 additions & 6 deletions tests/dummy/app/snippets/modal.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{{#uk-modal visible=visible on-hide=(action (mut visible) false)}}
<h2 class="uk-modal-title">Attention</h2>
<p>Do you really want to proceed?</p>
<p class="uk-text-right">
{{#uk-modal visible=visible on-hide=(action (mut visible) false) as |modal|}}
{{#modal.header}}
<h2 class="uk-modal-title">Attention</h2>
{{/modal.header}}
{{#modal.body}}
<p>Do you really want to proceed?</p>
{{/modal.body}}
{{#modal.footer class="uk-text-right"}}
{{uk-button color="primary" label="Ok" on-click=(action "submit")}}
</p>
{{/modal.footer}}
{{/uk-modal}}

{{uk-button label="Open modal" on-click=(action (mut visible) true)}}
{{uk-button label="Open modal" on-click=(action (mut visible) true)}}
40 changes: 36 additions & 4 deletions tests/dummy/app/templates/docs/components/modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
<div class="uk-padding uk-box-shadow-medium uk-margin">
{{#uk-modal
visible=visible
btnClose=btnClose
modalClass=modalClass
dialogClass=dialogClass
on-show=(action (mut visible) true)
on-hide=(action (mut visible) false)
as |modal|
}}
<h2 class="uk-modal-title">Test</h2>
<p>Lorem Ipsum</p>
<p class="uk-text-right">

{{#modal.header}}
<h2 class="uk-modal-title">Test</h2>
{{/modal.header}}
{{#modal.body uk-modal-overflow-auto}}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
{{/modal.body}}
{{#modal.footer class="uk-text-right"}}
{{uk-button color="primary" label="Submit" on-click=(action "submit")}}
</p>
{{/modal.footer}}
{{/uk-modal}}

{{uk-button label="Open modal" on-click=(action (mut visible true))}}
Expand Down Expand Up @@ -47,6 +56,29 @@
{{input type="checkbox" class="uk-checkbox" checked=visible}}
</td>
</tr>
<tr>
<td><code>btnClose</code></td>
<td><code>Boolean</code></td>
<td><code>true</code></td>
<td>Whether a button to close the modal should show up in the top right corner or not</td>
<td>
{{input type="checkbox" class="uk-checkbox" checked=btnClose}}
</td>
</tr>
<tr>
<td><code>modalClass</code></td>
<td><code>String</code></td>
<td><code>""</code></td>
<td>Add CSS classes to the modal.</td>
<td>{{input class="uk-input" value=modalClass}}</td>
</tr>
<tr>
<td><code>dialogClass</code></td>
<td><code>String</code></td>
<td><code>""</code></td>
<td>Add CSS classes to the dialog.</td>
<td>{{input class="uk-input" value=dialogClass}}</td>
</tr>
<tr>
<td><code>escClose</code></td>
<td><code>Boolean</code></td>
Expand Down
20 changes: 16 additions & 4 deletions tests/integration/components/uk-modal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ module("Integration | Component | uk-modal", function(hooks) {
assert.expect(1);

await render(hbs`
{{#uk-modal}}
<h2>Test</h2>
{{#uk-modal as |modal|}}
{{#modal.header}}
<h2>Test</h2>
{{/modal.header}}
{{/uk-modal}}
`);

Expand All @@ -25,7 +27,15 @@ module("Integration | Component | uk-modal", function(hooks) {

await render(hbs`
{{#uk-modal visible=true}}
<h2>Test</h2>
{{#modal.header}}
<h2>Test</h2>
{{/modal.header}}
{{#modal.body}}
<p>Lorem ipsum</p>
{{/modal.body}}
{{#modal.footer class="uk-text-right"}}
<button></button>
{{/modal.footer}}
{{/uk-modal}}
`);

Expand All @@ -41,7 +51,9 @@ module("Integration | Component | uk-modal", function(hooks) {

await render(hbs`
{{#uk-modal visible=true on-hide=hide}}
<h2>Test</h2>
{{#modal.header}}
<h2>Test</h2>
{{/modal.header}}
{{/uk-modal}}
`);

Expand Down
26 changes: 26 additions & 0 deletions tests/integration/components/uk-modal/body-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "ember-qunit";
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";

module("Integration | Component | uk-modal/body", function(hooks) {
setupRenderingTest(hooks);

test("it renders", async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`{{uk-modal/body}}`);

assert.equal(this.element.textContent.trim(), "");

// Template block usage:
await render(hbs`
{{#uk-modal/body}}
template block text
{{/uk-modal/body}}
`);

assert.equal(this.element.textContent.trim(), "template block text");
});
});
26 changes: 26 additions & 0 deletions tests/integration/components/uk-modal/footer-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "ember-qunit";
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";

module("Integration | Component | uk-modal/header", function(hooks) {
setupRenderingTest(hooks);

test("it renders", async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`{{uk-modal/footer}}`);

assert.equal(this.element.textContent.trim(), "");

// Template block usage:
await render(hbs`
{{#uk-modal/footer}}
template block text
{{/uk-modal/footer}}
`);

assert.equal(this.element.textContent.trim(), "template block text");
});
});
26 changes: 26 additions & 0 deletions tests/integration/components/uk-modal/header-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "ember-qunit";
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";

module("Integration | Component | uk-modal/footer", function(hooks) {
setupRenderingTest(hooks);

test("it renders", async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`{{uk-modal/header}}`);

assert.equal(this.element.textContent.trim(), "");

// Template block usage:
await render(hbs`
{{#uk-modal/header}}
template block text
{{/uk-modal/header}}
`);

assert.equal(this.element.textContent.trim(), "template block text");
});
});

0 comments on commit 3ee42d0

Please sign in to comment.