Skip to content

Commit

Permalink
Merge pull request #463 from appuniversum/chore/ts-conversion
Browse files Browse the repository at this point in the history
Partial TypeScript conversion
  • Loading branch information
Windvis authored Feb 2, 2024
2 parents aeb00ba + 6eee009 commit 9ef3e00
Show file tree
Hide file tree
Showing 73 changed files with 1,736 additions and 900 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ module.exports = {
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {},
rules: {
// This works around an issue in Glint https://github.com/typed-ember/glint/issues/697
// It also makes adding state to a component easier, since no other code changes would be needed.
'ember/no-empty-glimmer-component-classes': 'off',
},
},
// node files
{
Expand Down
8 changes: 8 additions & 0 deletions .template-lintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ module.exports = {
'addon/components/au-data-table/**',
'tests/dummy/app/components/docs*/**',
],
overrides: [
{
files: ['tests/integration/**'],
rules: {
'require-input-label': 'off',
},
},
],
};
20 changes: 18 additions & 2 deletions addon/components/au-alert.gjs → addon/components/au-alert.gts
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import { AuIcon } from '@appuniversum/ember-appuniversum';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import AuIcon from './au-icon';

export default class AuAlert extends Component {
export interface AuAlertSignature {
Args: {
closable?: boolean;
icon?: string;
iconVisible?: boolean;
onClose?: () => void;
size?: 'tiny' | 'small';
skin?: 'info' | 'success' | 'warning' | 'error';
title?: string;
};
Blocks: {
default: [];
};
Element: HTMLDivElement;
}

export default class AuAlert extends Component<AuAlertSignature> {
@tracked isVisible = true;

get skin() {
Expand Down
5 changes: 0 additions & 5 deletions addon/components/au-app.gjs

This file was deleted.

16 changes: 16 additions & 0 deletions addon/components/au-app.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Component from '@glimmer/component';

export interface AuAppSignature {
Blocks: {
default: [];
};
Element: HTMLDivElement;
}

export default class AuApp extends Component<AuAppSignature> {
<template>
<div class="au-c-app" ...attributes>
{{yield}}
</div>
</template>
}
22 changes: 19 additions & 3 deletions addon/components/au-badge.gjs → addon/components/au-badge.gts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { AuIcon } from '@appuniversum/ember-appuniversum';
import Component from '@glimmer/component';
import AuIcon from './au-icon';

export interface AuBadgeSignature {
Args: {
icon?: string;
iconVisible?: boolean;
number?: number;
size?: 'small';
skin?: 'action' | 'border' | 'brand' | 'error' | 'success' | 'warning';
};
Element: HTMLSpanElement;
}

const SKIN_CLASSES = {
border: 'au-c-badge--border',
Expand All @@ -8,12 +19,17 @@ const SKIN_CLASSES = {
success: 'au-c-badge--success',
warning: 'au-c-badge--warning',
error: 'au-c-badge--error',
default: 'au-c-badge--default',
};

export default class AuBadge extends Component {
export default class AuBadge extends Component<AuBadgeSignature> {
get skin() {
if (!this.args.skin) {
return SKIN_CLASSES.default;
}

const skin = SKIN_CLASSES[this.args.skin];
return skin ? skin : 'au-c-badge--default';
return skin ? skin : SKIN_CLASSES.default;
}

get size() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import Component from '@glimmer/component';

export default class AuBodyContainer extends Component {
export interface AuBodyContainerSignature {
Args: {
scroll?: boolean;
};
Blocks: {
default: [];
};
Element: HTMLDivElement;
}

export default class AuBodyContainer extends Component<AuBodyContainerSignature> {
get scroll() {
if (this.args.scroll) return 'au-c-body-container--scroll';
else return '';
Expand Down
10 changes: 9 additions & 1 deletion addon/components/au-brand.gjs → addon/components/au-brand.gts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { guidFor } from '@ember/object/internals';
import Component from '@glimmer/component';

export default class AuBrand extends Component {
export interface AuBrandSignature {
Args: {
link?: string;
tagline?: string;
};
Element: HTMLDivElement | HTMLAnchorElement;
}

export default class AuBrand extends Component<AuBrandSignature> {
id = guidFor(this);

get tagline() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import Component from '@glimmer/component';

export default class AuButtonGroup extends Component {
export interface AuButtonGroupSignature {
Args: {
inline?: boolean;
};
Blocks: {
default: [];
};
Element: HTMLDivElement;
}

export default class AuButtonGroup extends Component<AuButtonGroupSignature> {
get inline() {
if (this.args.inline) return 'au-c-button-group--inline';
else return '';
Expand Down
55 changes: 44 additions & 11 deletions addon/components/au-button.gjs → addon/components/au-button.gts
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import { AuIcon, AuLoader } from '@appuniversum/ember-appuniversum';
import Component from '@glimmer/component';
import AuIcon from './au-icon';
import AuLoader from './au-loader';

const SKINS = [
'primary',
'secondary',
'naked',
'link',
'link-secondary',
] as const;

export interface AuButtonSignature {
Args: {
alert?: boolean;
disabled?: boolean;
hideText?: boolean;
icon?: string;
iconAlignment?: 'left' | 'right';
loading?: boolean;
loadingMessage?: string;
size?: 'large';
skin?: (typeof SKINS)[number];
width?: 'block';
wrap?: boolean;
};
Blocks: {
default: [];
};
Element: HTMLButtonElement;
}

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

const SKINS = ['primary', 'secondary', 'naked', 'link', 'link-secondary'];

export default class AuButton extends Component {
export default class AuButton extends Component<AuButtonSignature> {
get skin() {
if (SKINS.includes(this.args.skin)) return this.args.skin;
if (this.args.skin && SKINS.includes(this.args.skin)) return this.args.skin;
else return 'primary';
}

Expand Down Expand Up @@ -52,6 +75,14 @@ export default class AuButton extends Component {
else return 'Aan het laden';
}

get isIconLeft() {
return !!this.args.icon && this.iconAlignment === 'left';
}

get isIconRight() {
return !!this.args.icon && this.iconAlignment === 'right';
}

get iconAlignment() {
if (this.args.iconAlignment) return this.args.iconAlignment;
else return 'left';
Expand All @@ -78,7 +109,8 @@ export default class AuButton extends Component {
...attributes
>
{{#unless @loading}}
{{#if (and @icon (eq this.iconAlignment "left"))}}
{{#if this.isIconLeft}}
{{! @glint-expect-error: this.isIconLeft ensures that @icon is set }}
<AuIcon @icon={{@icon}} />
{{/if}}
{{/unless}}
Expand All @@ -100,7 +132,8 @@ export default class AuButton extends Component {
{{/if}}

{{#unless @loading}}
{{#if (and @icon (eq this.iconAlignment "right"))}}
{{#if this.isIconRight}}
{{! @glint-expect-error: this.isIconRight ensures that @icon is set }}
<AuIcon @icon={{@icon}} />
{{/if}}
{{/unless}}
Expand Down
Loading

0 comments on commit 9ef3e00

Please sign in to comment.