// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @module elements-sk/error-toast-sk
* @description <h2><code>error-toast-sk</code></h2>
*
* <p>
* Listens for 'error-sk' events that bubble up to the document and displays them.
* These are normally generated by errorMessage.
* </p>
*
* <p>
* The 'error-sk' event should have 'detail' of the form:
* </p>
*
* <pre>
* {
* message: "The error message to display goes here.",
* duration: Integer, the number of ms to display or 0 for indefinitely.
* Defaults to 10000 (10s)
* }
* </pre>
*
* @example
*
* <footer>
* <error-toast-sk></error-toast-sk>
* </footer>
*/
import { define } from '../define';
import '../toast-sk';
export class ErrorToastSk extends HTMLElement {
constructor() {
super(...arguments);
this.toast = null;
this.span = null;
}
connectedCallback() {
this.innerHTML = '<toast-sk><span></span><button title="Close">✗</button></toast-sk>';
this.toast = this.firstElementChild;
this.span = this.toast.firstElementChild;
document.addEventListener('error-sk', this);
this.querySelector('button').addEventListener('click', (e) => this.clickHandler());
}
disconnectedCallback() {
document.removeEventListener('error-sk', this);
}
clickHandler() {
this.toast.hide();
}
handleEvent(e) {
this.toast.duration = e.detail.duration;
this.span.textContent = e.detail.message;
this.toast.show();
}
}
define('error-toast-sk', ErrorToastSk);
//# sourceMappingURL=error-toast-sk.js.map