diff --git a/doc-app/app/controllers/docs/ember-input/prefabs/button.ts b/doc-app/app/controllers/docs/ember-input/prefabs/button.ts new file mode 100644 index 00000000..cb640c9b --- /dev/null +++ b/doc-app/app/controllers/docs/ember-input/prefabs/button.ts @@ -0,0 +1,12 @@ +import Controller from '@ember/controller'; +import { action } from '@ember/object'; +import { tracked } from 'tracked-built-ins'; + +export default class DocsTpkPrefabButtonController extends Controller { + @tracked counter = 0; + + @action + async incrementCounter() { + this.counter++; + } +} \ No newline at end of file diff --git a/doc-app/app/router.ts b/doc-app/app/router.ts index 7afa0b95..58f96ea6 100644 --- a/doc-app/app/router.ts +++ b/doc-app/app/router.ts @@ -22,6 +22,7 @@ Router.map(function (this: RouterDSL) { this.route('ember-input', function () { this.route('installation'); this.route('prefabs', function () { + this.route('button') this.route('toggle'); }); this.route('input'); diff --git a/doc-app/app/templates/docs.hbs b/doc-app/app/templates/docs.hbs index 42e0e0c5..8eb81c25 100644 --- a/doc-app/app/templates/docs.hbs +++ b/doc-app/app/templates/docs.hbs @@ -122,6 +122,7 @@ {{! input section }} + diff --git a/doc-app/app/templates/docs/ember-input/prefabs/button.md b/doc-app/app/templates/docs/ember-input/prefabs/button.md new file mode 100644 index 00000000..29bc2b40 --- /dev/null +++ b/doc-app/app/templates/docs/ember-input/prefabs/button.md @@ -0,0 +1,27 @@ +# Button + +A button. This is a simple wrapper around the `input` element with `type="button"`. + + + +
+ + +
+

count = {{this.counter}}

+
+ +
+ +## Mandatory properties + +- `@label`: The label for the button field. +- `@onClick`: The action to be called when the button clicked. + +## Optional properties + +- `@disabled`: Whether the button field is disabled. + +## Important + +- `class`: To create a custom class you must do it in a CSS file to override the button class \ No newline at end of file diff --git a/doc-app/app/templates/docs/ember-input/prefabs/toggle.md b/doc-app/app/templates/docs/ember-input/prefabs/toggle.md index 556e4b4a..9e7f0d83 100644 --- a/doc-app/app/templates/docs/ember-input/prefabs/toggle.md +++ b/doc-app/app/templates/docs/ember-input/prefabs/toggle.md @@ -3,10 +3,10 @@ A toggle switch. This is a simple wrapper around the `input` element with `type="checkbox"`. - + - + diff --git a/doc-app/tests/integration/components/ember-input/prefabs/tpk-button-test.gts b/doc-app/tests/integration/components/ember-input/prefabs/tpk-button-test.gts new file mode 100644 index 00000000..c0d6f5f4 --- /dev/null +++ b/doc-app/tests/integration/components/ember-input/prefabs/tpk-button-test.gts @@ -0,0 +1,48 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { setupIntl } from 'ember-intl/test-support'; +import { click, render } from '@ember/test-helpers'; +import TpkPrefabButton from '@triptyk/ember-input/components/prefabs/tpk-prefab-button'; + +module( + 'Integration | Component | Prefabs | tpk-button', + function (hooks) { + setupRenderingTest(hooks); + setupIntl(hooks, 'fr-fr'); + + let message = "before click" + + async function renderComponent(onClick: () => void, disabled: boolean = false) { + await render( ) + } + const onClick=()=> { + message = "after click" + } + + test('Render toggle with default structure', async function (assert) { + + await renderComponent(onClick); + assert.dom('[data-test-tpk-prefab-button-container]').exists(); + assert.dom('[data-test-tpk-prefab-button-container]').hasText('labelButton'); + }); + + test('Button is disabled', async function (assert) { + await renderComponent(onClick, true); + assert.dom('[data-test-tpk-prefab-button-container]').hasAttribute('disabled'); + + }); + + test('onClick is called', async function (assert) { + await renderComponent(onClick); + assert.strictEqual(message, "before click"); + await click('[data-test-tpk-prefab-button-container]'); + assert.strictEqual(message, "after click"); + }); + } +) \ No newline at end of file diff --git a/packages/ember-input/package.json b/packages/ember-input/package.json index 0fa3af83..07a405b2 100644 --- a/packages/ember-input/package.json +++ b/packages/ember-input/package.json @@ -121,6 +121,7 @@ "main": "addon-main.cjs", "app-js": { "./components/base.js": "./dist/_app_/components/base.js", + "./components/prefabs/tpk-prefab-button.js": "./dist/_app_/components/prefabs/tpk-prefab-button.js", "./components/prefabs/tpk-toggle.js": "./dist/_app_/components/prefabs/tpk-toggle.js", "./components/tpk-button.js": "./dist/_app_/components/tpk-button.js", "./components/tpk-checkbox-input.js": "./dist/_app_/components/tpk-checkbox-input.js", diff --git a/packages/ember-input/src/app.css b/packages/ember-input/src/app.css index 29a02980..c7fd9ff0 100644 --- a/packages/ember-input/src/app.css +++ b/packages/ember-input/src/app.css @@ -1 +1,2 @@ @import url('./components/prefabs/tpk-toggle.css'); +@import url('./components/prefabs/tpk-prefab-button.css'); diff --git a/packages/ember-input/src/components/prefabs/tpk-prefab-button.css b/packages/ember-input/src/components/prefabs/tpk-prefab-button.css new file mode 100644 index 00000000..744dbf24 --- /dev/null +++ b/packages/ember-input/src/components/prefabs/tpk-prefab-button.css @@ -0,0 +1,7 @@ +.tpk-button-container { + @apply btn btn-primary +} + +.tpk-test { + @apply btn btn-warning +} \ No newline at end of file diff --git a/packages/ember-input/src/components/prefabs/tpk-prefab-button.gts b/packages/ember-input/src/components/prefabs/tpk-prefab-button.gts new file mode 100644 index 00000000..abc13a04 --- /dev/null +++ b/packages/ember-input/src/components/prefabs/tpk-prefab-button.gts @@ -0,0 +1,34 @@ +import type { MergeDeep } from "type-fest"; +import type { BaseUIComponentArgs } from "../base"; +import TpkButtonComponent from "../tpk-button.gts"; +import type { TOC } from "@ember/component/template-only"; + +export type TpkButtonPrefabSignature = { + Args: MergeDeep< + BaseUIComponentArgs['Args'], + { + disabled?: boolean; + label: string; + onClick: (e: Event) => void | Promise; + } + >; + Blocks: { + default: []; + }; + Element: HTMLElement; +} + +const TpkButtonPrefabComponent: TOC = + +export default TpkButtonPrefabComponent; \ No newline at end of file diff --git a/packages/ember-input/src/components/prefabs/tpk-toggle.gts b/packages/ember-input/src/components/prefabs/tpk-toggle.gts index 15bb04c7..db099813 100644 --- a/packages/ember-input/src/components/prefabs/tpk-toggle.gts +++ b/packages/ember-input/src/components/prefabs/tpk-toggle.gts @@ -3,7 +3,7 @@ import type { BaseUIComponentArgs } from '../base'; import TpkCheckboxComponent from '../tpk-checkbox.gts'; import type { TOC } from '@ember/component/template-only'; -export type TpkCheckboxPrefabSignature = { +export type TpkTogglePrefabSignature = { Args: MergeDeep< BaseUIComponentArgs['Args'], { @@ -18,7 +18,7 @@ export type TpkCheckboxPrefabSignature = { Element: HTMLDivElement; }; -const TpkCheckboxPrefabComponent: TOC =