-
Notifications
You must be signed in to change notification settings - Fork 27k
chore(material): migrate most components to TypeScript. #2160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Language: JavaScript | ||
| BasedOnStyle: Google | ||
| ColumnLimit: 100 | ||
|
|
||
| TabWidth: 2 | ||
| ContinuationIndentWidth: 4 | ||
| MaxEmptyLinesToKeep : 2 | ||
|
|
||
| AllowShortBlocksOnASingleLine: false | ||
| AllowShortIfStatementsOnASingleLine: false | ||
| AllowShortLoopsOnASingleLine: false | ||
| AllowShortFunctionsOnASingleLine: Empty | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| import {Directive, onAllChangesDone} from 'angular2/src/core/annotations_impl/annotations'; | ||
| import {Attribute} from 'angular2/src/core/annotations_impl/di'; | ||
| import {Parent} from 'angular2/src/core/annotations_impl/visibility'; | ||
| import {Directive, onAllChangesDone, Attribute, Parent} from 'angular2/angular2'; | ||
|
|
||
| import {ObservableWrapper, EventEmitter} from 'angular2/src/facade/async'; | ||
|
|
||
|
|
@@ -9,12 +7,57 @@ import {ObservableWrapper, EventEmitter} from 'angular2/src/facade/async'; | |
| // TODO(jelbourn): max-length counter | ||
| // TODO(jelbourn): placeholder property | ||
|
|
||
| @Directive({ | ||
| selector: 'md-input-container', | ||
| lifecycle: [onAllChangesDone], | ||
| hostProperties: | ||
| {'inputHasValue': 'class.md-input-has-value', 'inputHasFocus': 'class.md-input-focused'} | ||
| }) | ||
| export class MdInputContainer { | ||
| // The MdInput or MdTextarea inside of this container. | ||
| _input: MdInput; | ||
|
|
||
| // Whether the input inside of this container has a non-empty value. | ||
| inputHasValue: boolean; | ||
|
|
||
| // Whether the input inside of this container has focus. | ||
| inputHasFocus: boolean; | ||
|
|
||
| constructor(@Attribute('id') id: string) { | ||
| this._input = null; | ||
| this.inputHasValue = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move the init value to the declaration ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather make minimal changes in this PR to get things working and worry about idiomatic TS later.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense. I was also asking to know if we have defined a best practice for those.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we've really talked about it yet. Would be a good thing to do soon. |
||
| this.inputHasFocus = false; | ||
| } | ||
|
|
||
| onAllChangesDone() { | ||
| // Enforce that this directive actually contains a text input. | ||
| if (this._input == null) { | ||
| throw 'No <input> or <textarea> found inside of <md-input-container>'; | ||
| } | ||
| } | ||
|
|
||
| /** Registers the child MdInput or MdTextarea. */ | ||
| registerInput(input) { | ||
| if (this._input != null) { | ||
| throw 'Only one text input is allowed per <md-input-container>.'; | ||
| } | ||
|
|
||
| this._input = input; | ||
| this.inputHasValue = input.value != ''; | ||
|
|
||
| // Listen to input changes and focus events so that we can apply the appropriate CSS | ||
| // classes based on the input state. | ||
| ObservableWrapper.subscribe(input.mdChange, value => { this.inputHasValue = value != ''; }); | ||
|
|
||
| ObservableWrapper.subscribe(input.mdFocusChange, hasFocus => {this.inputHasFocus = hasFocus}); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Directive({ | ||
| selector: 'md-input-container input', | ||
| events: ['mdChange', 'mdFocusChange'], | ||
| hostProperties: { | ||
| 'yes': 'class.md-input' | ||
| }, | ||
| hostProperties: {'yes': 'class.md-input'}, | ||
| hostListeners: { | ||
| 'input': 'updateValue($event)', | ||
| 'focus': 'setHasFocus(true)', | ||
|
|
@@ -30,9 +73,8 @@ export class MdInput { | |
| mdChange: EventEmitter; | ||
| mdFocusChange: EventEmitter; | ||
|
|
||
| constructor( | ||
| @Attribute('value') value: String, | ||
| @Parent() container: MdInputContainer) { | ||
| constructor(@Attribute('value') value: string, @Parent() container: MdInputContainer, | ||
| @Attribute('id') id: string) { | ||
| // TODO(jelbourn): Remove this when #1402 is done. | ||
| this.yes = true; | ||
|
|
||
|
|
@@ -53,6 +95,7 @@ export class MdInput { | |
| } | ||
| } | ||
|
|
||
| /* | ||
| @Directive({ | ||
| selector: 'md-input-container textarea', | ||
| events: ['mdChange', 'mdFocusChange'], | ||
|
|
@@ -67,60 +110,10 @@ export class MdInput { | |
| }) | ||
| export class MdTextarea extends MdInput { | ||
| constructor( | ||
| @Attribute('value') value: String, | ||
| @Parent() container: MdInputContainer) { | ||
| super(value, container); | ||
| } | ||
| } | ||
|
|
||
| @Directive({ | ||
| selector: 'md-input-container', | ||
| lifecycle: [onAllChangesDone], | ||
| hostProperties: { | ||
| 'inputHasValue': 'class.md-input-has-value', | ||
| 'inputHasFocus': 'class.md-input-focused' | ||
| } | ||
| }) | ||
| export class MdInputContainer { | ||
| // The MdInput or MdTextarea inside of this container. | ||
| _input: MdInput; | ||
|
|
||
| // Whether the input inside of this container has a non-empty value. | ||
| inputHasValue: boolean; | ||
|
|
||
| // Whether the input inside of this container has focus. | ||
| inputHasFocus: boolean; | ||
|
|
||
| constructor() { | ||
| this._input = null; | ||
| this.inputHasValue = false; | ||
| this.inputHasFocus = false; | ||
| } | ||
|
|
||
| onAllChangesDone() { | ||
| // Enforce that this directive actually contains a text input. | ||
| if (this._input == null) { | ||
| throw 'No <input> or <textarea> found inside of <md-input-container>'; | ||
| } | ||
| } | ||
|
|
||
| /** Registers the child MdInput or MdTextarea. */ | ||
| registerInput(input) { | ||
| if (this._input != null) { | ||
| throw 'Only one text input is allowed per <md-input-container>.'; | ||
| } | ||
|
|
||
| this._input = input; | ||
| this.inputHasValue = input.value != ''; | ||
|
|
||
| // Listen to input changes and focus events so that we can apply the appropriate CSS | ||
| // classes based on the input state. | ||
| ObservableWrapper.subscribe(input.mdChange, value => { | ||
| this.inputHasValue = value != ''; | ||
| }); | ||
|
|
||
| ObservableWrapper.subscribe(input.mdFocusChange, hasFocus => { | ||
| this.inputHasFocus = hasFocus | ||
| }); | ||
| @Attribute('value') value: string, | ||
| @Parent() container: MdInputContainer, | ||
| @Attribute('id') id: string) { | ||
| super(value, container, id); | ||
| } | ||
| } | ||
| */ | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import {Component, View} from 'angular2/angular2'; | ||
|
|
||
| @Component({selector: 'md-progress-circular'}) | ||
| @View({templateUrl: 'angular2_material/src/components/progress-circular/progress_circular.html'}) | ||
| export class MdProgressCircular { | ||
| constructor() {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer these as well. Maybe we should consider applying to all of Angular. The delta would be pretty big but maybe worth it? @mprobst ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm large apathetic to this. I generally like anything that saves vertical
space (in particular for object literals, and there in particular in
named-arguments style calls). But I don't feel too strongly about it, I
just want automated formatting that works well.