-
Notifications
You must be signed in to change notification settings - Fork 1
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
11 changed files
with
162 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Controller from "@ember/controller"; | ||
|
||
export default class extends Controller {} |
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
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 @@ | ||
# Toggle | ||
|
||
A toggle switch. This is a simple wrapper around the `input` element with `type="checkbox"`. | ||
|
||
<DocsDemo as |demo|> | ||
<demo.example @name="tpk-checkbox.hbs"> | ||
<Prefabs::TpkToggle @checked={{true}} @label="Toggle Input" /> | ||
<Prefabs::TpkToggle @checked={{true}} @disabled={{true}} @label="Toggle Disabled" /> | ||
</demo.example> | ||
<demo.snippet @name="tpk-checkbox.hbs"/> | ||
</DocsDemo> | ||
|
68 changes: 68 additions & 0 deletions
68
doc-app/tests/integration/components/ember-input/prefabs/tpk-toggle-test.gts
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,68 @@ | ||
|
||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import { ImmerChangeset } from 'ember-immer-changeset'; | ||
import { setupIntl } from 'ember-intl/test-support'; | ||
import TpkToggle from '@triptyk/ember-input/components/prefabs/tpk-toggle'; | ||
import { a11yAudit } from 'ember-a11y-testing/test-support'; | ||
|
||
|
||
module( | ||
'Integration | Component | Prefabs | tpk-toggle', | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupIntl(hooks, 'fr-fr'); | ||
|
||
async function renderComponent({ | ||
changeset, | ||
disabled | ||
}: { | ||
changeset: ImmerChangeset, | ||
disabled?: boolean, | ||
}) { | ||
await render( | ||
<template> | ||
<TpkToggle | ||
@changeset={{changeset}} | ||
@validationField="toggle" | ||
@label="label" | ||
@disabled={{disabled}} | ||
@mandatory={{true}} | ||
@checked={{true}} | ||
/> | ||
</template>, | ||
); | ||
return changeset; | ||
} | ||
|
||
test('render toggle with default structure and with mandatory', async function (assert) { | ||
const changeset = new ImmerChangeset({ | ||
toggle: 'applati', | ||
}); | ||
await renderComponent({changeset}); | ||
assert.dom('[data-test-tpk-label]').exists(); | ||
assert.dom('[data-test-tpk-label]').exists(); | ||
}); | ||
|
||
test('@disabled disables the input', async function(assert) { | ||
const changeset = new ImmerChangeset({ | ||
toggle: 'applati', | ||
}); | ||
await renderComponent({ | ||
disabled: true, | ||
changeset | ||
}); | ||
assert.dom(`[data-test-tpk-prefab-toggle-container] input`).hasAttribute('disabled'); | ||
}); | ||
|
||
test('Accessibility', async function (assert) { | ||
assert.expect(0); | ||
const changeset = new ImmerChangeset({ | ||
toggle: 'applati', | ||
}); | ||
await renderComponent({changeset}); | ||
await a11yAudit(); | ||
}); | ||
}, | ||
); |
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 @@ | ||
@import url('./components/prefabs/tpk-toggle.css'); |
15 changes: 15 additions & 0 deletions
15
packages/ember-input/src/components/prefabs/tpk-toggle.css
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 @@ | ||
.tpk-toggle-container { | ||
@apply form-control; | ||
} | ||
|
||
.tpk-toggle-label-container { | ||
@apply label cursor-pointer; | ||
} | ||
|
||
.tpk-toggle-label { | ||
@apply label-text; | ||
} | ||
|
||
.tpk-toggle-input { | ||
@apply toggle; | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/ember-input/src/components/prefabs/tpk-toggle.gts
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,32 @@ | ||
import type { MergeDeep } from 'type-fest'; | ||
import type { BaseUIComponentArgs } from '../base'; | ||
import TpkCheckboxComponent from '../tpk-checkbox.gts'; | ||
import type { TOC } from '@ember/component/template-only'; | ||
|
||
export type TpkCheckboxPrefabSignature = { | ||
Args: MergeDeep< | ||
BaseUIComponentArgs['Args'], | ||
{ | ||
checked?: boolean; | ||
disabled?: boolean; | ||
onChange?: (isChecked: boolean, value: string, e: Event) => unknown; | ||
} | ||
>; | ||
Blocks: { | ||
default: []; | ||
}; | ||
Element: HTMLDivElement; | ||
}; | ||
|
||
const TpkCheckboxPrefabComponent: TOC<TpkCheckboxPrefabSignature> = <template> | ||
<TpkCheckboxComponent @disabled={{@disabled}} @checked={{@checked}} @label={{@label}} @onChange={{@onChange}} as |C|> | ||
<div class="tpk-toggle-container" data-test-tpk-prefab-toggle-container ...attributes> | ||
<C.Label class="tpk-toggle-label-container"> | ||
<span class="tpk-toggle-label">{{@label}}</span> | ||
<C.Input class="tpk-toggle-input" /> | ||
</C.Label> | ||
</div> | ||
</TpkCheckboxComponent> | ||
</template> | ||
|
||
export default TpkCheckboxPrefabComponent; |