Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat: Convert packages to TypeScript #4451

Merged
merged 74 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8bcf546
feat(infrastructure): add tsconfig, tslint, and build setup (#4241)
Jan 18, 2019
1600b54
docs: Update closure-compiler.md to reflect TypeScript conversion (#4…
kfranqueiro Jan 18, 2019
66c8d81
feat(dom): Convert JS to TypeScript (#4269)
acdvorak Jan 19, 2019
87a5e8e
feat(animation): Convert JS to TypeScript (#4271)
acdvorak Jan 23, 2019
8addf4d
Merge remote-tracking branch 'origin' into feat/typescript
acdvorak Jan 23, 2019
6b958de
feat(linear-progress): Convert JS to TypeScript (#4272)
acdvorak Jan 23, 2019
c649de5
fix: add strict true to tsconfig (#4286)
Jan 24, 2019
47a9c38
feat(ripple): convert to ts (#4300)
Jan 29, 2019
54d25c1
Merge remote-tracking branch 'origin/master' into feat/typescript
Jan 31, 2019
aeb3f87
feat(form-field): ts convert (#4327)
Jan 31, 2019
8abbb53
Merge remote-tracking branch 'origin/master' into feat/typescript
acdvorak Jan 31, 2019
13d169d
feat(switch): Convert JS to TypeScript (#4320)
mmalerba Jan 31, 2019
869e44c
refactor(animation): Replace enums with string literal type aliases (…
acdvorak Jan 31, 2019
a2ac8bc
feat(menu-surface): Convert JS to TypeScript (#4273)
acdvorak Feb 5, 2019
0f8a271
Merge remote-tracking branch 'origin/master' into feat/typescript
acdvorak Feb 5, 2019
2befa88
feat(checkbox): typescript conversion (#4319)
Feb 5, 2019
90f5f05
feat(radio): ts conversion (#4329)
Feb 6, 2019
0f354ae
feat(base): Add generic type signatures to listen/unlisten/emit (#4358)
acdvorak Feb 6, 2019
f595a99
feat(icon-button): Convert to TypeScript (#4325)
abhiomkar Feb 6, 2019
0b28992
feat(list): ts conversion (#4334)
Feb 6, 2019
dc4e92c
feat(menu): Convert JS to TypeScript (#4342)
acdvorak Feb 6, 2019
33e26d7
feat(dialog): ts conversion (#4333)
Feb 7, 2019
3279cc9
style: Make TS import and export syntax consistent (#4360)
acdvorak Feb 7, 2019
1c7335b
feat(chips): ts conversion (#4332)
Feb 7, 2019
ed7f8d7
feat(grid-list): ts conversion (#4337)
Feb 7, 2019
d4250ca
docs: update best coding practices with typescript lessons learned (#…
Feb 7, 2019
9936f01
feat(ripple): updated ripple ts rewrite to remove extraneous code/typ…
Feb 7, 2019
77e8bab
Merge remote-tracking branch 'origin/master' into feat/typescript
acdvorak Feb 7, 2019
5407ada
feat(floating-label): Convert JS to TypeScript (#4374)
acdvorak Feb 8, 2019
50eb8c7
feat(line-ripple): Convert JS to TypeScript (#4373)
acdvorak Feb 8, 2019
197f7fe
feat(notched-outline): Convert JS to TypeScript (#4375)
acdvorak Feb 8, 2019
08fb283
feat(slider): Convert JS to TypeScript (#4378)
acdvorak Feb 8, 2019
e95ff8a
feat(snackbar): Convert JS to TypeScript (#4363)
acdvorak Feb 9, 2019
b859440
chore: Remove Object.assign from TS files (#4389)
acdvorak Feb 11, 2019
e8c947c
Merge branch 'master' into feat/typescript
acdvorak Feb 11, 2019
6fce645
Merge remote-tracking branch 'origin/master' into feat/typescript
acdvorak Feb 11, 2019
9526da2
Merge branch 'feat/typescript' of github.com:material-components/mate…
acdvorak Feb 11, 2019
667aeee
feat(tab-scroller): Convert JS to TypeScript (#4392)
acdvorak Feb 12, 2019
5f50d60
feat(tab-indicator): Convert JS to TypeScript (#4391)
acdvorak Feb 12, 2019
ab9879d
feat(tab): Convert JS to TypeScript (#4393)
acdvorak Feb 12, 2019
b2fa9a5
feat(tab-bar): Convert JS to TypeScript (#4394)
acdvorak Feb 12, 2019
976352c
feat(text-field): Convert JS to TypeScript (#4377)
acdvorak Feb 13, 2019
5052ada
feat(select): Convert JS to TypeScript (#4386)
acdvorak Feb 13, 2019
f8ba48f
feat(drawer): Convert JS to TypeScript (#4390)
acdvorak Feb 14, 2019
b8b1988
feat(top-app-bar): Convert JS to TypeScript (#4397)
acdvorak Feb 14, 2019
4675c95
feat(auto-init): Convert JS to TypeScript (#4395)
acdvorak Feb 14, 2019
6136db3
feat(toolbar): Convert JS to TypeScript (#4410)
acdvorak Feb 14, 2019
db6fc6d
Merge remote-tracking branch 'origin/master' into feat/typescript
acdvorak Feb 14, 2019
6d6bff8
WIP: Fix borked merge
acdvorak Feb 14, 2019
ebefb78
feat(package): Convert JS to TypeScript (#4396)
acdvorak Feb 14, 2019
ff5ad6a
chore: Fix broken TypeScript rewrite script (#4398)
acdvorak Feb 14, 2019
96afbb1
WIP: Remove `icon-toggle` from `npm run test:dependency`
acdvorak Feb 14, 2019
36ce7b9
WIP: Fix GitHub authentication issue for screenshot tests on Travis CI
acdvorak Feb 15, 2019
03b791d
fix(chips): Reference ripple/index in types for consistency (#4417)
kfranqueiro Feb 15, 2019
409a6a6
feat(tabs): Convert JS to TypeScript (#4412)
acdvorak Feb 15, 2019
1ec12b6
chore: remove icon-toggle (#4415)
Feb 15, 2019
72e8b66
refactor: Make TS easier to wrap (#4407)
acdvorak Feb 21, 2019
c487445
WIP: Add comment
acdvorak Feb 22, 2019
f441f8f
Merge remote-tracking branch 'origin/master' into feat/typescript
acdvorak Feb 22, 2019
cabeabc
chore(package): Remove need for selection-control (#4442)
kfranqueiro Feb 22, 2019
b6b6983
chore: Fix internal tslint errors (#4440)
acdvorak Feb 22, 2019
6faaabe
chore: Fix regression in `MDCChipFoundation.getDimensions()` (#4443)
acdvorak Feb 23, 2019
2bbcfea
WIP: Fix internal tslint error
acdvorak Feb 23, 2019
c6b609c
feat(infrastructure): add esmodules support for treeshaking (#4409)
Feb 26, 2019
ad96947
style: Add explanations to `tslint:disable` comments (#4448)
acdvorak Feb 26, 2019
21b2403
WIP: Update `.ts` file paths in READMEs
acdvorak Feb 26, 2019
c54310c
WIP: Export `MDCComponentClass` in `mdc-auto-init`
acdvorak Feb 26, 2019
cbb0fe6
WIP: Change `any` to `unknown` and remove `tslint:disable` comment
acdvorak Feb 26, 2019
f3a09a1
Merge remote-tracking branch 'origin/master' into feat/typescript
acdvorak Feb 26, 2019
216d975
WIP: Revert changes to logging
acdvorak Feb 20, 2019
d349fea
style: grammar mistakes on script comments (#4452)
Feb 26, 2019
8cd8b26
WIP autoinit: MDCComponentClass -> MDCAttachable
Feb 27, 2019
60c9498
WIP Remove object-assign polyfill
Feb 27, 2019
2abfb30
WIP Revert "WIP Remove object-assign polyfill"
Feb 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(grid-list): ts conversion (#4337)
related #4225
  • Loading branch information
Matt Goo authored and acdvorak committed Feb 7, 2019
commit ed7f8d792e001ca5c8b7c916e5a8232add63bcf7
4 changes: 2 additions & 2 deletions packages/mdc-grid-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,5 @@ functions, with correct signatures:
| `getNumberOfTiles() => number` | Get the number of mdc-grid-tile elements contained within the grid list. |
| `getOffsetWidthForTileAtIndex(index: number) => number` | Get offsetWidth of `mdc-grid-tile` at specified index. |
| `setStyleForTilesElement(property: string, value: number) => void` | Set `mdc-grid-list__tiles` style property to provided value. |
| `registerResizeHandler(handler: Function) => void` | Registers a handler to be called when the surface (or its viewport) resizes. Our default implementation adds the handler as a listener to the window's `resize()` event. |
| `deregisterResizeHandler(handler: Function) => void` | Unregisters a handler to be called when the surface (or its viewport) resizes. Our default implementation removes the handler as a listener to the window's `resize()` event. |
| `registerResizeHandler(handler: EventListener) => void` | Registers a handler to be called when the surface (or its viewport) resizes. Our default implementation adds the handler as a listener to the window's `resize()` event. |
| `deregisterResizeHandler(handler: EventListener) => void` | Unregisters a handler to be called when the surface (or its viewport) resizes. Our default implementation removes the handler as a listener to the window's `resize()` event. |
35 changes: 35 additions & 0 deletions packages/mdc-grid-list/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2019 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

interface MDCGridListAdapter {
deregisterResizeHandler(handler: EventListener): void;
getNumberOfTiles(): number;
getOffsetWidth(): number;
getOffsetWidthForTileAtIndex(index: number): number;
registerResizeHandler(handler: EventListener): void;
setStyleForTilesElement(
property: Exclude<keyof CSSStyleDeclaration, ('length' | 'parentRule')>, value: string | null,
): void;
}

export {MDCGridListAdapter as default, MDCGridListAdapter};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

export const strings = {
TILES_SELECTOR: '.mdc-grid-list__tiles',
TILE_SELECTOR: '.mdc-grid-tile',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,42 @@
*/

import {MDCFoundation} from '@material/base/foundation';
import {MDCGridListAdapter} from './adapter';
import {strings} from './constants';

export default class MDCGridListFoundation extends MDCFoundation {
class MDCGridListFoundation extends MDCFoundation<MDCGridListAdapter> {
static get strings() {
return strings;
}

static get defaultAdapter() {
static get defaultAdapter(): MDCGridListAdapter {
return {
getOffsetWidth: () => /* number */ 0,
getNumberOfTiles: () => /* number */ 0,
getOffsetWidthForTileAtIndex: (/* index: number */) => /* number */ 0,
setStyleForTilesElement: (/* property: string, value: string */) => {},
registerResizeHandler: (/* handler: EventListener */) => {},
deregisterResizeHandler: (/* handler: EventListener */) => {},
deregisterResizeHandler: () => undefined,
getNumberOfTiles: () => 0,
getOffsetWidth: () => 0,
getOffsetWidthForTileAtIndex: () => 0,
registerResizeHandler: () => undefined,
setStyleForTilesElement: () => undefined,
};
}
constructor(adapter) {

private readonly resizeHandler_: EventListener;
private resizeFrame_ = 0;

constructor(adapter: MDCGridListAdapter) {
super(Object.assign(MDCGridListFoundation.defaultAdapter, adapter));
this.resizeHandler_ = () => this.alignCenter();
this.resizeFrame_ = 0;
this.resizeHandler_ = this.alignCenter.bind(this);
}

init() {
this.alignCenter();
this.adapter_.registerResizeHandler(this.resizeHandler_);
}

destroy() {
this.adapter_.deregisterResizeHandler(this.resizeHandler_);
}

alignCenter() {
if (this.resizeFrame_ !== 0) {
cancelAnimationFrame(this.resizeFrame_);
Expand All @@ -60,8 +67,9 @@ export default class MDCGridListFoundation extends MDCFoundation {
this.resizeFrame_ = 0;
});
}
alignCenter_() {
if (this.adapter_.getNumberOfTiles() == 0) {

private alignCenter_() {
if (this.adapter_.getNumberOfTiles() === 0) {
return;
}
const gridWidth = this.adapter_.getOffsetWidth();
Expand All @@ -70,3 +78,5 @@ export default class MDCGridListFoundation extends MDCFoundation {
this.adapter_.setStyleForTilesElement('width', `${tilesWidth}px`);
}
}

export {MDCGridListFoundation as default, MDCGridListFoundation};
25 changes: 14 additions & 11 deletions packages/mdc-grid-list/index.js → packages/mdc-grid-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,33 @@
*/

import {MDCComponent} from '@material/base/component';
import {MDCGridListFoundation} from './foundation';

import MDCGridListFoundation from './foundation';

export {MDCGridListFoundation};

export class MDCGridList extends MDCComponent {
static attachTo(root) {
class MDCGridList extends MDCComponent<MDCGridListFoundation> {
static attachTo(root: Element) {
return new MDCGridList(root);
}

getDefaultFoundation() {
return new MDCGridListFoundation({
getOffsetWidth: () => this.root_.offsetWidth,
deregisterResizeHandler: (handler) => window.removeEventListener('resize', handler),
getNumberOfTiles: () => {
return this.root_.querySelectorAll(MDCGridListFoundation.strings.TILE_SELECTOR).length;
},
getOffsetWidth: () => (this.root_ as HTMLElement).offsetWidth,
getOffsetWidthForTileAtIndex: (index) => {
return this.root_.querySelectorAll(MDCGridListFoundation.strings.TILE_SELECTOR)[index].offsetWidth;
const tileEl = this.root_.querySelectorAll<HTMLElement>(MDCGridListFoundation.strings.TILE_SELECTOR)[index];
return tileEl.offsetWidth;
},
registerResizeHandler: (handler) => window.addEventListener('resize', handler),
setStyleForTilesElement: (property, value) => {
this.root_.querySelector(MDCGridListFoundation.strings.TILES_SELECTOR).style[property] = value;
const tilesEl = this.root_.querySelector<HTMLElement>(MDCGridListFoundation.strings.TILES_SELECTOR);
tilesEl!.style[property] = value;
},
registerResizeHandler: (handler) => window.addEventListener('resize', handler),
deregisterResizeHandler: (handler) => window.removeEventListener('resize', handler),
});
}
}

export {MDCGridList as default, MDCGridList};
export * from './adapter';
export * from './foundation';
2 changes: 1 addition & 1 deletion scripts/webpack/js-bundle-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class JsBundleFactory {
drawer: getAbsolutePath('/packages/mdc-drawer/index.js'),
floatingLabel: getAbsolutePath('/packages/mdc-floating-label/index.js'),
formField: getAbsolutePath('/packages/mdc-form-field/index.ts'),
gridList: getAbsolutePath('/packages/mdc-grid-list/index.js'),
gridList: getAbsolutePath('/packages/mdc-grid-list/index.ts'),
iconButton: getAbsolutePath('/packages/mdc-icon-button/index.ts'),
iconToggle: getAbsolutePath('/packages/mdc-icon-toggle/index.js'),
list: getAbsolutePath('/packages/mdc-list/index.ts'),
Expand Down