-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
221 additions
and
1 deletion.
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
6 changes: 6 additions & 0 deletions
6
addon/components/validated-input/types/-themes/bootstrap/checkbox-group.js
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,6 @@ | ||
import layout from "../../../../../templates/components/validated-input/types/-themes/bootstrap/checkbox-group"; | ||
import Component from "../../checkbox-group"; | ||
|
||
export default Component.extend({ | ||
layout, | ||
}); |
6 changes: 6 additions & 0 deletions
6
addon/components/validated-input/types/-themes/uikit/checkbox-group.js
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,6 @@ | ||
import layout from "../../../../../templates/components/validated-input/types/-themes/uikit/checkbox-group"; | ||
import Component from "../../checkbox-group"; | ||
|
||
export default Component.extend({ | ||
layout, | ||
}); |
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,23 @@ | ||
import Component from "@ember/component"; | ||
import { action } from "@ember/object"; | ||
|
||
import layout from "../../../templates/components/validated-input/types/checkbox-group"; | ||
|
||
export default Component.extend({ | ||
layout, | ||
|
||
@action | ||
onUpdate(key) { | ||
const value = this.value || []; | ||
const index = value.indexOf(key); | ||
|
||
if (index > -1) { | ||
value.splice(index, 1); | ||
} else { | ||
value.push(key); | ||
} | ||
|
||
this.update(value); | ||
this.setDirty(); | ||
}, | ||
}); |
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
14 changes: 14 additions & 0 deletions
14
addon/templates/components/validated-input/types/-themes/bootstrap/checkbox-group.hbs
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,14 @@ | ||
{{#each options as |option i|}} | ||
<div class="custom-control custom-checkbox"> | ||
<input | ||
type = "checkbox" | ||
class = "custom-control-input {{if isValid "is-valid"}} {{if isInvalid "is-invalid"}}" | ||
checked = {{includes option.key value}} | ||
name = {{name}} | ||
id = "{{inputId}}-{{i}}" | ||
disabled = {{disabled}} | ||
{{on "input" (fn this.onUpdate option.key)}} | ||
> | ||
<label class="custom-control-label" for="{{inputId}}-{{i}}">{{option.label}}</label> | ||
</div> | ||
{{/each}} |
15 changes: 15 additions & 0 deletions
15
addon/templates/components/validated-input/types/-themes/uikit/checkbox-group.hbs
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,15 @@ | ||
{{#each options as |option i|}} | ||
{{#unless (eq i 0)}}<br>{{/unless}} | ||
<label class="uk-form-label {{if isValid "uk-text-success"}} {{if isInvalid "uk-text-danger"}}"> | ||
<input | ||
type = "checkbox" | ||
class = "uk-checkbox uk-margin-small-right" | ||
checked = {{includes option.key value}} | ||
name = {{name}} | ||
id = "{{inputId}}-{{i}}" | ||
disabled = {{disabled}} | ||
{{on "input" (fn this.onUpdate option.key)}} | ||
> | ||
{{option.label}} | ||
</label> | ||
{{/each}} |
14 changes: 14 additions & 0 deletions
14
addon/templates/components/validated-input/types/checkbox-group.hbs
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,14 @@ | ||
{{#each options as |option i|}} | ||
<label> | ||
<input | ||
type = "checkbox" | ||
checked = {{eq value option.key}} | ||
value = {{option.key}} | ||
name = {{name}} | ||
id = "{{inputId}}-{{i}}" | ||
disabled = {{disabled}} | ||
{{on "input" (fn this.onUpdate option.key)}} | ||
> | ||
{{option.label}} | ||
</label> | ||
{{/each}} |
1 change: 1 addition & 0 deletions
1
app/components/validated-input/types/-themes/bootstrap/checkbox-group.js
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-validated-form/components/validated-input/types/-themes/bootstrap/checkbox-group"; |
1 change: 1 addition & 0 deletions
1
app/components/validated-input/types/-themes/uikit/checkbox-group.js
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-validated-form/components/validated-input/types/-themes/uikit/checkbox-group"; |
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-validated-form/components/validated-input/types/checkbox-group"; |
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
26 changes: 26 additions & 0 deletions
26
tests/integration/components/validated-input/types/-themes/bootstrap/checkbox-group-test.js
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,26 @@ | ||
import { render } from "@ember/test-helpers"; | ||
import setupConfigTest from "dummy/tests/helpers/setup-config-test"; | ||
import { hbs } from "ember-cli-htmlbars"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { module, test } from "qunit"; | ||
|
||
module( | ||
"Integration | Component | validated-input/types/-themes/bootstrap/checkbox-group", | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupConfigTest(hooks, { theme: "bootstrap" }); | ||
|
||
test("it renders", async function (assert) { | ||
await render(hbs` | ||
{{validated-input/types/-themes/bootstrap/checkbox-group | ||
options = (array (hash key='t' label='Triangle') (hash key='s' label='Square')) | ||
update=(action (mut value)) | ||
}} | ||
`); | ||
|
||
assert.dom("div.custom-control.custom-checkbox").exists(); | ||
assert.dom("input").hasClass("custom-control-input"); | ||
assert.dom("label").hasClass("custom-control-label"); | ||
}); | ||
} | ||
); |
34 changes: 34 additions & 0 deletions
34
tests/integration/components/validated-input/types/-themes/uikit/checkbox-group-test.js
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,34 @@ | ||
import { render } from "@ember/test-helpers"; | ||
import setupConfigTest from "dummy/tests/helpers/setup-config-test"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import hbs from "htmlbars-inline-precompile"; | ||
import { module, test } from "qunit"; | ||
|
||
module( | ||
"Integration | Component | validated-input/types/-themes/uikit/checkbox-group", | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupConfigTest(hooks, { theme: "uikit" }); | ||
|
||
test("it renders", async function (assert) { | ||
this.set("options", [ | ||
{ | ||
key: "opt1", | ||
label: "Option 1", | ||
}, | ||
{ | ||
key: "opt2", | ||
label: "Option 2", | ||
}, | ||
]); | ||
|
||
await render( | ||
hbs`{{validated-input/types/-themes/uikit/checkbox-group options=options update=(action (mut value))}}` | ||
); | ||
|
||
assert.dom("label > input").exists(); | ||
assert.dom("input").hasClass("uk-checkbox"); | ||
assert.dom("label").hasClass("uk-form-label"); | ||
}); | ||
} | ||
); |
27 changes: 27 additions & 0 deletions
27
tests/integration/components/validated-input/types/checkbox-group-test.js
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,27 @@ | ||
import { render } from "@ember/test-helpers"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import hbs from "htmlbars-inline-precompile"; | ||
import { module, test } from "qunit"; | ||
|
||
module( | ||
"Integration | Component | validated-input/types/checkbox-group", | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test("it renders", async function (assert) { | ||
this.set("options", [ | ||
{ key: 1, label: 1 }, | ||
{ key: 2, label: 2 }, | ||
]); | ||
|
||
await render(hbs` | ||
{{validated-input/types/checkbox-group | ||
options=options | ||
update=(action (mut value)) | ||
}} | ||
`); | ||
|
||
assert.dom("input[type=checkbox]").exists({ count: 2 }); | ||
}); | ||
} | ||
); |