Convert gr-confirm-abandon-dialog to typescript

Change-Id: Ia91e15fb99703427de5d4751040af7a644e22f5d
This commit is contained in:
Dhruv Srivastava
2020-08-06 14:30:06 +02:00
parent 026669597b
commit 5768c46e28

View File

@@ -14,25 +14,40 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import '@polymer/iron-autogrow-textarea/iron-autogrow-textarea.js'; import '@polymer/iron-autogrow-textarea/iron-autogrow-textarea';
import '../../shared/gr-dialog/gr-dialog.js'; import '../../shared/gr-dialog/gr-dialog';
import '../../../styles/shared-styles.js'; import '../../../styles/shared-styles';
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js'; import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners';
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js'; import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin';
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-confirm-abandon-dialog_html.js'; import {htmlTemplate} from './gr-confirm-abandon-dialog_html';
import {KeyboardShortcutMixin} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.js'; import {KeyboardShortcutMixin} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
import {customElement, property} from '@polymer/decorators';
import {IronAutogrowTextareaElement} from '@polymer/iron-autogrow-textarea/iron-autogrow-textarea';
export interface GrConfirmAbandonDialog {
$: {
messageInput: IronAutogrowTextareaElement;
};
}
declare global {
interface HTMLElementTagNameMap {
'gr-confirm-abandon-dialog': GrConfirmAbandonDialog;
}
}
/** /**
* @extends PolymerElement * @extends PolymerElement
*/ */
class GrConfirmAbandonDialog extends KeyboardShortcutMixin( @customElement('gr-confirm-abandon-dialog')
GestureEventListeners( export class GrConfirmAbandonDialog extends KeyboardShortcutMixin(
LegacyElementMixin( GestureEventListeners(LegacyElementMixin(PolymerElement))
PolymerElement))) { ) {
static get template() { return htmlTemplate; } static get template() {
return htmlTemplate;
}
static get is() { return 'gr-confirm-abandon-dialog'; }
/** /**
* Fired when the confirm button is pressed. * Fired when the confirm button is pressed.
* *
@@ -45,11 +60,8 @@ class GrConfirmAbandonDialog extends KeyboardShortcutMixin(
* @event cancel * @event cancel
*/ */
static get properties() { @property({type: String})
return { message?: string;
message: String,
};
}
get keyBindings() { get keyBindings() {
return { return {
@@ -61,30 +73,34 @@ class GrConfirmAbandonDialog extends KeyboardShortcutMixin(
this.$.messageInput.textarea.focus(); this.$.messageInput.textarea.focus();
} }
_handleEnterKey(e) { _handleEnterKey() {
this._confirm(); this._confirm();
} }
_handleConfirmTap(e) { _handleConfirmTap(e: Event) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this._confirm(); this._confirm();
} }
_confirm() { _confirm() {
this.dispatchEvent(new CustomEvent('confirm', { this.dispatchEvent(
detail: {reason: this.message}, new CustomEvent('confirm', {
composed: true, bubbles: false, detail: {reason: this.message},
})); composed: true,
bubbles: false,
})
);
} }
_handleCancelTap(e) { _handleCancelTap(e: Event) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this.dispatchEvent(new CustomEvent('cancel', { this.dispatchEvent(
composed: true, bubbles: false, new CustomEvent('cancel', {
})); composed: true,
bubbles: false,
})
);
} }
} }
customElements.define(GrConfirmAbandonDialog.is, GrConfirmAbandonDialog);