-
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
13 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
doc-app/app/controllers/docs/ember-input/prefabs/button.ts
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 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++; | ||
} | ||
} |
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,27 @@ | ||
# Button | ||
|
||
A button. This is a simple wrapper around the `input` element with `type="button"`. | ||
|
||
<DocsDemo as |demo|> | ||
<demo.example @name="tpk-button.hbs"> | ||
<div class="pb-4"> | ||
<Prefabs::TpkPrefabButton @onClick={{this.incrementCounter}} @label="Button Enabled" /> | ||
<Prefabs::TpkPrefabButton @onClick={{this.incrementCounter}} @disabled=true @label="Button Disabled" /> | ||
</div> | ||
<p>count = {{this.counter}}</p> | ||
</demo.example> | ||
<demo.snippet @name="tpk-button.hbs"/> | ||
</DocsDemo> | ||
|
||
## 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 |
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
48 changes: 48 additions & 0 deletions
48
doc-app/tests/integration/components/ember-input/prefabs/tpk-button-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,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( <template> | ||
<TpkPrefabButton | ||
@label="labelButton" | ||
@onClick={{onClick}} | ||
@disabled={{disabled}} | ||
/> | ||
</template>) | ||
} | ||
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"); | ||
}); | ||
} | ||
) |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
@import url('./components/prefabs/tpk-toggle.css'); | ||
@import url('./components/prefabs/tpk-prefab-button.css'); |
7 changes: 7 additions & 0 deletions
7
packages/ember-input/src/components/prefabs/tpk-prefab-button.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,7 @@ | ||
.tpk-button-container { | ||
@apply btn btn-primary | ||
} | ||
|
||
.tpk-test { | ||
@apply btn btn-warning | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/ember-input/src/components/prefabs/tpk-prefab-button.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,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<void>; | ||
} | ||
>; | ||
Blocks: { | ||
default: []; | ||
}; | ||
Element: HTMLElement; | ||
} | ||
|
||
const TpkButtonPrefabComponent: TOC<TpkButtonPrefabSignature> = <template> | ||
<TpkButtonComponent | ||
@label={{@label}} | ||
@disabled={{@disabled}} | ||
@onClick={{@onClick}} | ||
class="tpk-button-container" | ||
data-test-tpk-prefab-button-container | ||
...attributes | ||
> | ||
{{@label}} | ||
</TpkButtonComponent> | ||
</template> | ||
|
||
export default TpkButtonPrefabComponent; |
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