Skip to content

Commit 635c139

Browse files
authored
Merge pull request #489 from appuniversum/chore/more-gts
More Glint / TS conversion
2 parents 85de57b + d5d2ce2 commit 635c139

20 files changed

+868
-481
lines changed

addon/components/au-modal.gjs addon/components/au-modal.gts

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuIcon } from '@appuniversum/ember-appuniversum';
1+
import type { TOC } from '@ember/component/template-only';
22
import { assert } from '@ember/debug';
33
import { concat, hash } from '@ember/helper';
44
import { on } from '@ember/modifier';
@@ -7,20 +7,49 @@ import Component from '@glimmer/component';
77
import { focusTrap } from 'ember-focus-trap';
88
import { CrossIcon } from './icons/cross';
99
import { cn } from '../private/helpers/class-names';
10+
import AuIcon from './au-icon';
1011

1112
// TODO: replace these with the named imports from ember-truth-helpers v4 once our dependencies support that version
1213
import not from 'ember-truth-helpers/helpers/not';
1314
import or from 'ember-truth-helpers/helpers/or';
1415

1516
const FOCUS_TRAP_ADDITIONAL_ELEMENTS = ['#ember-basic-dropdown-wormhole'];
1617

17-
export default class AuModal extends Component {
18-
constructor() {
19-
super(...arguments);
18+
export interface AuModalSignature {
19+
Args: {
20+
closable?: boolean;
21+
closeModal?: () => void;
22+
id?: string;
23+
initialFocus?: string;
24+
modalOpen?: boolean;
25+
overflow?: boolean;
26+
padding?: 'none';
27+
size?: 'large' | 'fullscreen';
28+
title?: string;
29+
};
30+
Blocks: {
31+
body: [];
32+
footer: [];
33+
title: [];
34+
default: [
35+
{
36+
Body: typeof Body;
37+
Footer: typeof Footer;
38+
},
39+
];
40+
};
41+
Element: HTMLDivElement;
42+
}
43+
44+
export default class AuModal extends Component<AuModalSignature> {
45+
destinationElement: HTMLElement;
46+
47+
constructor(owner: unknown, args: AuModalSignature['Args']) {
48+
super(owner, args);
2049

2150
this.destinationElement = document.querySelector(
2251
'[data-au-modal-container]',
23-
);
52+
) as HTMLElement;
2453

2554
assert(
2655
'au-modal: No target element was found. Please add the `<AuModalContainer />` component where appropriate.',
@@ -161,13 +190,13 @@ export default class AuModal extends Component {
161190
{{/if}}
162191
</template>
163192
}
164-
const Body = <template>
193+
const Body: TOC<{ Blocks: { default: [] } }> = <template>
165194
<div class="au-c-modal__body" data-test-modal-body>
166195
{{yield}}
167196
</div>
168197
</template>;
169198

170-
const Footer = <template>
199+
const Footer: TOC<{ Blocks: { default: [] } }> = <template>
171200
<div class="au-c-modal__footer" data-test-modal-footer>
172201
{{yield}}
173202
</div>

addon/components/au-radio-group.gjs addon/components/au-radio-group.gts

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
import { AuRadio } from '@appuniversum/ember-appuniversum';
21
import { hash } from '@ember/helper';
32
import { guidFor } from '@ember/object/internals';
43
import Component from '@glimmer/component';
4+
import type { WithBoundArgs } from '@glint/template';
5+
import AuRadio, { type AuRadioSignature } from './au-radio';
56

67
// TODO: replace these with the named imports from ember-truth-helpers v4 once our dependencies support that version
78
import or from 'ember-truth-helpers/helpers/or';
89

9-
export default class AuRadioGroup extends Component {
10+
export interface AuRadioGroupSignature {
11+
Args: {
12+
alignment?: 'inline';
13+
disabled?: AuRadioSignature['Args']['disabled'];
14+
name?: AuRadioSignature['Args']['name'];
15+
onChange?: AuRadioSignature['Args']['onChangeGroup'];
16+
selected?: AuRadioSignature['Args']['groupValue'];
17+
};
18+
Blocks: {
19+
default: [
20+
{
21+
Radio: WithBoundArgs<
22+
typeof AuRadio,
23+
'name' | 'inGroup' | 'groupValue' | 'disabled' | 'onChangeGroup'
24+
>;
25+
},
26+
];
27+
};
28+
Element: HTMLDivElement;
29+
}
30+
31+
export default class AuRadioGroup extends Component<AuRadioGroupSignature> {
1032
uniqueName = guidFor(this);
1133

1234
get alignmentClass() {

addon/components/au-radio.gjs addon/components/au-radio.gts

+24-3
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,43 @@ import { action } from '@ember/object';
66
import and from 'ember-truth-helpers/helpers/and';
77
import not from 'ember-truth-helpers/helpers/not';
88

9-
export default class AuRadio extends Component {
9+
interface PrivateArgs {
10+
groupValue?: unknown;
11+
inGroup?: boolean;
12+
onChangeGroup?: (selected: string | undefined, event: Event) => void;
13+
}
14+
15+
export interface AuRadioSignature {
16+
Args: {
17+
checked?: boolean;
18+
disabled?: boolean;
19+
name?: string;
20+
onChange?: (selected: string, event: Event) => void;
21+
value?: string;
22+
} & PrivateArgs;
23+
Blocks: {
24+
default: [];
25+
};
26+
Element: HTMLInputElement;
27+
}
28+
29+
export default class AuRadio extends Component<AuRadioSignature> {
1030
get checked() {
1131
const { inGroup, checked, groupValue, value } = this.args;
1232
return inGroup ? value === groupValue : checked;
1333
}
1434

1535
@action
16-
onChange(event) {
36+
onChange(event: Event) {
1737
const { inGroup, onChange, onChangeGroup, value } = this.args;
1838

1939
if (inGroup && typeof onChangeGroup === 'function') {
2040
onChangeGroup(value, event);
2141
} else if (typeof onChange === 'function') {
22-
onChange(event.target.value, event);
42+
onChange((event.target as AuRadioSignature['Element']).value, event);
2343
}
2444
}
45+
2546
<template>
2647
{{~!~}}
2748
<label

addon/components/au-table.gjs addon/components/au-table.gts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import Component from '@glimmer/component';
22

3-
export default class AuTable extends Component {
3+
export interface AuTableSignature {
4+
Args: {
5+
size?: 'small';
6+
};
7+
Blocks: {
8+
body: [];
9+
footer: [];
10+
header: [];
11+
title: [];
12+
};
13+
Element: HTMLTableElement;
14+
}
15+
16+
export default class AuTable extends Component<AuTableSignature> {
417
get size() {
518
if (this.args.size == 'small') return 'au-c-table--small';
619
else return '';

addon/components/au-tabs.gjs

-13
This file was deleted.

addon/components/au-tabs.gts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { TOC } from '@ember/component/template-only';
2+
3+
export interface AuTabsSignature {
4+
Args: {
5+
reversed?: boolean;
6+
};
7+
Blocks: {
8+
default: [typeof Tab];
9+
};
10+
Element: HTMLElement;
11+
}
12+
13+
const AuTabs: TOC<AuTabsSignature> = <template>
14+
<nav class="au-c-tabs {{if @reversed 'au-c-tabs--reversed'}}" ...attributes>
15+
<ul class="au-c-tabs-list">
16+
{{yield Tab}}
17+
</ul>
18+
</nav>
19+
</template>;
20+
21+
export default AuTabs;
22+
23+
interface TabSignature {
24+
Blocks: {
25+
default: [];
26+
};
27+
Element: HTMLLIElement;
28+
}
29+
30+
const Tab: TOC<TabSignature> = <template>
31+
<li class="au-c-tabs-list__item" ...attributes>
32+
{{yield}}
33+
</li>
34+
</template>;

addon/components/au-textarea.gjs addon/components/au-textarea.gts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import Component from '@glimmer/component';
22

3-
export default class AuTextarea extends Component {
3+
export interface AuTextareaSignature {
4+
Args: {
5+
disabled?: boolean;
6+
error?: boolean;
7+
warning?: boolean;
8+
width?: 'block';
9+
};
10+
Blocks: {
11+
default: [];
12+
};
13+
Element: HTMLTextAreaElement;
14+
}
15+
16+
export default class AuTextarea extends Component<AuTextareaSignature> {
417
get width() {
518
if (this.args.width == 'block') return 'au-c-textarea--block';
619
else return '';

addon/template-registry.ts

+12
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ import type AuMainContainer from '@appuniversum/ember-appuniversum/components/au
3131
import type AuMainFooter from '@appuniversum/ember-appuniversum/components/au-main-footer';
3232
import type AuMainHeader from '@appuniversum/ember-appuniversum/components/au-main-header';
3333
import type AuModalContainer from '@appuniversum/ember-appuniversum/components/au-modal-container';
34+
import type AuModal from '@appuniversum/ember-appuniversum/components/au-modal';
3435
import type AuNavigationLink from '@appuniversum/ember-appuniversum/components/au-navigation-link';
3536
import type AuPanel from '@appuniversum/ember-appuniversum/components/au-panel';
3637
import type AuPill from '@appuniversum/ember-appuniversum/components/au-pill';
38+
import type AuRadioGroup from '@appuniversum/ember-appuniversum/components/au-radio-group';
39+
import type AuRadio from '@appuniversum/ember-appuniversum/components/au-radio';
40+
import type AuTable from '@appuniversum/ember-appuniversum/components/au-table';
41+
import type AuTabs from '@appuniversum/ember-appuniversum/components/au-tabs';
42+
import type AuTextarea from '@appuniversum/ember-appuniversum/components/au-textarea';
3743
import type AuToolbar from '@appuniversum/ember-appuniversum/components/au-toolbar';
3844

3945
// Modifiers
@@ -73,9 +79,15 @@ export default interface AppuniversumRegistry {
7379
AuMainFooter: typeof AuMainFooter;
7480
AuMainHeader: typeof AuMainHeader;
7581
AuModalContainer: typeof AuModalContainer;
82+
AuModal: typeof AuModal;
7683
AuNavigationLink: typeof AuNavigationLink;
7784
AuPanel: typeof AuPanel;
7885
AuPill: typeof AuPill;
86+
AuRadioGroup: typeof AuRadioGroup;
87+
AuRadio: typeof AuRadio;
88+
AuTable: typeof AuTable;
89+
AuTabs: typeof AuTabs;
90+
AuTextarea: typeof AuTextarea;
7991
AuToolbar: typeof AuToolbar;
8092

8193
// Modifiers

0 commit comments

Comments
 (0)