Skip to content

Commit

Permalink
Merge pull request #47 from josemarluedke/docs/add-typescript-to-docs
Browse files Browse the repository at this point in the history
Add typescript to docs app
  • Loading branch information
josemarluedke committed Mar 23, 2020
2 parents 0f458cb + ee8451c commit a26dc22
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import {
NotificationOptions,
NotificationsService
} from '@frontile/notifications';

export default class Demo extends Component {
@service notifications;
@tracked options = {
interface DemoArgs {}

export default class Demo extends Component<DemoArgs> {
@service notifications!: NotificationsService;
@tracked options: NotificationOptions = {
appearance: 'info',
preserve: false,
duration: 5000,
Expand All @@ -14,40 +20,43 @@ export default class Demo extends Component {

@tracked placement = 'bottom-right';

@tracked customActions = [
@tracked customActions: NotificationOptions['customActions'] = [
{
label: 'Ok',
onClick: () => {
onClick: (): void => {
// empty
}
},
{
label: 'Undo',
onClick: () => {
onClick: (): void => {
// empty
}
},
{
label: 'Cancel',
onClick: () => {
onClick: (): void => {
// empty
}
}
];

@action setPlacement(placement) {
@action setPlacement(placement: string): void {
this.placement = placement;
}

@action setValue(key, value) {
@action setValue<T extends keyof NotificationOptions>(
key: T,
value: NotificationOptions[T]
): void {
const options = {
...this.options,
[key]: value
};
this.options = options;
}

@action addNotification() {
@action addNotification(): void {
this.notifications.add(
'Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna.',
this.options
Expand Down
18 changes: 18 additions & 0 deletions packages/docs/app/config/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DefaultConfig } from '@frontile/notifications';

/**
* Type declarations for
* import config from './config/environment'
*
* For now these need to be managed by the developer
* since different ember addons can materialize new entries.
*/
declare const config: {
environment: string;
modulePrefix: string;
podModulePrefix: string;
locationType: string;
rootURL: string;
'@frontile/notifications'?: DefaultConfig;
};
export default config;
10 changes: 9 additions & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"@frontile/notifications": "^0.1.0-alpha.4",
"@glimmer/component": "^1.0.0",
"@glimmer/tracking": "^1.0.0",
"@types/ember": "^3.1.1",
"@types/ember-qunit": "^3.4.7",
"@types/ember__test-helpers": "^0.7.9",
"@types/qunit": "^2.9.0",
"@types/rsvp": "^4.0.3",
"autoprefixer": "^9.7.4",
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^1.2.20",
Expand All @@ -45,6 +50,8 @@
"ember-cli-inject-live-reload": "^2.0.1",
"ember-cli-postcss": "^5.0.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-typescript": "^3.1.3",
"ember-cli-typescript-blueprints": "^3.0.0",
"ember-cli-uglify": "^3.0.0",
"ember-export-application-global": "^2.0.1",
"ember-load-initializers": "^2.1.1",
Expand All @@ -54,7 +61,8 @@
"ember-source": "^3.17.0",
"loader.js": "^4.7.0",
"qunit-dom": "^1.1.0",
"tailwindcss": "^1.2.0"
"tailwindcss": "^1.2.0",
"typescript": "3.7.5"
},
"engines": {
"node": ">= 10.*"
Expand Down
14 changes: 14 additions & 0 deletions packages/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"docs/tests/*": ["tests/*"],
"docs/*": ["app/*"],
"@frontile/notifications": ["../notifications/addon"],
"@frontile/notifications/*": ["../notifications/addon/*"],
"*": ["types/*"]
}
},
"include": ["app/**/*", "tests/**/*", "types/**/*"]
}
8 changes: 8 additions & 0 deletions packages/docs/types/docs/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Ember from 'ember';

declare global {
interface Array<T> extends Ember.ArrayPrototypeExtensions<T> {}
// interface Function extends Ember.FunctionPrototypeExtensions {}
}

export {};
3 changes: 3 additions & 0 deletions packages/docs/types/ember-get-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Config from 'docs/config/environment';

export default Config;
6 changes: 6 additions & 0 deletions packages/docs/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Types for compiled templates
declare module 'docs/templates/*' {
import { TemplateFactory } from 'htmlbars-inline-precompile';
const tmpl: TemplateFactory;
export default tmpl;
}

0 comments on commit a26dc22

Please sign in to comment.