Skip to content

Commit 6eee009

Browse files
committed
Add Glint support to the AuDateInput component
1 parent cbe8f5c commit 6eee009

File tree

5 files changed

+88
-40
lines changed

5 files changed

+88
-40
lines changed

addon/components/au-date-input.gjs

-17
This file was deleted.

addon/components/au-date-input.gts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Component from '@glimmer/component';
2+
import AuInput, { type AuInputSignature } from './au-input';
3+
import auDateInput, {
4+
type AuDateInputModifierSignature,
5+
} from '../modifiers/au-date-input';
6+
7+
export interface AuDateInputSignature {
8+
Args: {
9+
disabled?: AuInputSignature['Args']['disabled'];
10+
error?: AuInputSignature['Args']['error'];
11+
warning?: AuInputSignature['Args']['warning'];
12+
width?: AuInputSignature['Args']['width'];
13+
value?: AuDateInputModifierSignature['Args']['Named']['value'];
14+
prefillYear?: AuDateInputModifierSignature['Args']['Named']['prefillYear'];
15+
onChange?: AuDateInputModifierSignature['Args']['Named']['onChange'];
16+
};
17+
Element: AuInputSignature['Element'];
18+
}
19+
20+
export default class AuDateInput extends Component<AuDateInputSignature> {
21+
<template>
22+
{{~!~}}
23+
<AuInput
24+
@disabled={{@disabled}}
25+
@error={{@error}}
26+
@icon="calendar"
27+
@warning={{@warning}}
28+
@width={{@width}}
29+
autocomplete="off"
30+
placeholder="DD-MM-JJJJ"
31+
{{auDateInput value=@value prefillYear=@prefillYear onChange=@onChange}}
32+
...attributes
33+
/>
34+
{{~!~}}
35+
</template>
36+
}

addon/template-registry.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type AuCheckbox from '@appuniversum/ember-appuniversum/components/au-chec
1111
import type AuCheckboxGroup from '@appuniversum/ember-appuniversum/components/au-checkbox-group';
1212
import type AuContentHeader from '@appuniversum/ember-appuniversum/components/au-content-header';
1313
import type AuContent from '@appuniversum/ember-appuniversum/components/au-content';
14+
import type AuDateInput from '@appuniversum/ember-appuniversum/components/au-date-input';
1415
import type AuIcon from '@appuniversum/ember-appuniversum/components/au-icon';
1516
import type AuInput from '@appuniversum/ember-appuniversum/components/au-input';
1617
import type AuLinkExternal from '@appuniversum/ember-appuniversum/components/au-link-external';
@@ -35,6 +36,7 @@ export default interface AppuniversumRegistry {
3536
AuCheckboxGroup: typeof AuCheckboxGroup;
3637
AuContentHeader: typeof AuContentHeader;
3738
AuContent: typeof AuContent;
39+
AuDateInput: typeof AuDateInput;
3840
AuIcon: typeof AuIcon;
3941
AuInput: typeof AuInput;
4042
AuLinkExternal: typeof AuLinkExternal;

tests/integration/components/au-date-input-test.js tests/integration/components/au-date-input-test.gts

+43-23
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,55 @@
11
import { module, test } from 'qunit';
22
import { setupRenderingTest } from 'dummy/tests/helpers';
33
import { typeIn, fillIn, render, triggerKeyEvent } from '@ember/test-helpers';
4-
import { hbs } from 'ember-cli-htmlbars';
4+
import AuDateInput from '@appuniversum/ember-appuniversum/components/au-date-input';
5+
import { tracked } from '@glimmer/tracking';
6+
import { settled } from '@ember/test-helpers';
57

8+
class TestState {
9+
@tracked value?: string | Date;
10+
}
611
module('Integration | Component | au-date-input', function (hooks) {
712
setupRenderingTest(hooks);
813

914
test('it adds attributes to the input element', async function (assert) {
10-
await render(hbs`
11-
<AuDateInput data-test-date-input />
12-
`);
15+
await render(<template><AuDateInput data-test-date-input /></template>);
1316

1417
assert.dom('[data-test-date-input]').hasTagName('input');
1518
});
1619

1720
test('it supports disabling the date input', async function (assert) {
18-
await render(hbs`
19-
<AuDateInput @disabled={{true}} data-test-date-input />
20-
`);
21+
await render(
22+
<template>
23+
<AuDateInput @disabled={{true}} data-test-date-input />
24+
</template>,
25+
);
2126

2227
assert.dom('[data-test-date-input]').hasAttribute('disabled');
2328
});
2429

2530
test('it accepts an iso date string or date object as a value', async function (assert) {
26-
this.value = '2023-02-02';
31+
const state = new TestState();
32+
state.value = '2023-02-02';
2733

28-
await render(hbs`
29-
<AuDateInput data-test-date-input @value={{this.value}} />
30-
`);
34+
await render(
35+
<template>
36+
<AuDateInput data-test-date-input @value={{state.value}} />
37+
</template>,
38+
);
3139

3240
assert.dom('[data-test-date-input]').hasValue('02-02-2023');
3341

34-
this.set('value', new Date(2024, 5, 3));
42+
state.value = new Date(2024, 5, 3);
43+
await settled();
3544
assert.dom('[data-test-date-input]').hasValue('03-06-2024');
3645

37-
this.set('value', undefined);
46+
state.value = undefined;
47+
await settled();
3848
assert.dom('[data-test-date-input]').hasNoValue();
3949
});
4050

4151
test('it calls @onChange with the correct date', async function (assert) {
42-
this.onChange = (isoDate, date) => {
52+
const onChange = (isoDate: string | null, date: Date | null) => {
4353
assert.strictEqual(
4454
isoDate,
4555
'2023-02-02',
@@ -51,16 +61,18 @@ module('Integration | Component | au-date-input', function (hooks) {
5161
);
5262
};
5363

54-
await render(hbs`
55-
<AuDateInput data-test-date-input @onChange={{this.onChange}} />
56-
`);
64+
await render(
65+
<template>
66+
<AuDateInput data-test-date-input @onChange={{onChange}} />
67+
</template>,
68+
);
5769

5870
await fillIn('[data-test-date-input]', '0202202');
5971
await typeIn('[data-test-date-input]', '3'); // fillIn alone doesn't do the trick, but typeIn has issues when typing all the characters..
6072
});
6173

6274
test('it calls @onChange with `null` if the input is cleared', async function (assert) {
63-
this.onChange = (isoDate, date) => {
75+
const onChange = (isoDate: string | null, date: Date | null) => {
6476
assert.strictEqual(
6577
isoDate,
6678
null,
@@ -69,17 +81,25 @@ module('Integration | Component | au-date-input', function (hooks) {
6981
assert.strictEqual(date, null, 'it returns null if the input is cleared');
7082
};
7183

72-
await render(hbs`
73-
<AuDateInput data-test-date-input @value="2023-02-02" @onChange={{this.onChange}} />
74-
`);
84+
await render(
85+
<template>
86+
<AuDateInput
87+
data-test-date-input
88+
@value="2023-02-02"
89+
@onChange={{onChange}}
90+
/>
91+
</template>,
92+
);
7593

76-
let input = document.querySelector('[data-test-date-input]');
94+
const input = document.querySelector(
95+
'[data-test-date-input]',
96+
) as HTMLInputElement;
7797

7898
await clearInput(input);
7999
});
80100
});
81101

82-
async function clearInput(input) {
102+
async function clearInput(input: HTMLInputElement) {
83103
// Focus seems to be needed to make the backspace work
84104
input.focus();
85105

tests/integration/components/loose-mode-test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ module('Integration | Component | Loose mode', function (hooks) {
9292
assert.dom('[data-test-content]').exists();
9393
});
9494

95+
test('`<AuDateInput>` resolves in loose mode', async function (assert) {
96+
await render(hbs`
97+
<AuDateInput data-test-date-input />
98+
`);
99+
assert.dom('[data-test-date-input]').exists();
100+
});
101+
95102
test('`<AuIcon>` resolves in loose mode', async function (assert) {
96103
await render(hbs`<AuIcon data-test-icon @icon="test" />`);
97104

0 commit comments

Comments
 (0)