diff --git a/package.json b/package.json index efdb5a7..292601c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-toaster", - "version": "1.0.1", + "version": "2.0.0", "description": "", "main": "tp-toaster.js", "scripts": { @@ -16,6 +16,7 @@ "@tp/helpers": "^1.2.1", "@tp/tp-icon": "^1.0.1", "@tp/tp-media-query": "^1.0.0", + "@tp/tp-timeout-strip": "^1.0.0", "lit": "^2.2.0" } } diff --git a/tp-toast.js b/tp-toast.js index 2dc0c30..02e47d1 100644 --- a/tp-toast.js +++ b/tp-toast.js @@ -3,6 +3,7 @@ Copyright (c) 2023 EDV Wasmeier */ +import '@tp/tp-timeout-strip/tp-timeout-strip.js'; import { EventHelpers } from '@tp/helpers/event-helpers.js'; import { LitElement, html, css, svg } from 'lit'; @@ -11,13 +12,10 @@ class TpToast extends EventHelpers(LitElement) { return [ css` :host { - --tp-toast-info-icon-color: #fff; - --tp-toast-success-icon-color: #fff; - --tp-toast-error-icon-color: #fff; - --tp-toast-warning-icon-color: #fff; + display: inline-block; + position: relative; transition: transform 0.5s, opacity 0.3s; will-change: transform, opacity; - display: inline-block; border-radius: 2px; background: #FAFAFA; font-size: 0.8em; @@ -27,41 +25,31 @@ class TpToast extends EventHelpers(LitElement) { 0 1px 8px 0 rgba(0, 0, 0, 0.12), 0 3px 3px -2px rgba(0, 0, 0, 0.4); } + + tp-timeout-strip { + position: absolute; + bottom: 0; + left: 0; + right: 0; + pointer-events: none; + } .wrap { display: flex; flex-direction: row; + gap: 10px; } .icon { - padding: 10px; - border-right: 1px #fff; - color: #ffffff; + padding: 10px 0 10px 10px; display: flex; flex-direction: row; align-items: center; justify-content: center; } - :host([type="info"]) .icon { - background: #039BE5; - } - - :host([type="success"]) .icon { - background: #558B2F; - color: #fff; - } - - :host([type="warning"]) .icon { - background: #FFCA28; - } - - :host([type="error"]) .icon { - background: #B71C1C; - } - .content { - padding: 10px 10px 10px 10px; + padding: 10px 0; line-height: 24px; } @@ -85,18 +73,19 @@ class TpToast extends EventHelpers(LitElement) { return html`
-
- +
+
-
+
${!sticky ? html` -
- +
+
` : null}
+ `; } @@ -108,7 +97,7 @@ class TpToast extends EventHelpers(LitElement) { /** * Configures what kind of toast this is. * Comes with the variants `info`, `warning`, `error`, `success`. - * Each type comes with a pre-defined icon, but via the `icon` property a custom icon can also be used. + * Each type comes with a pre-defined icon. To use a custom icon use the `icon` property. */ type: { type: String, reflect: true }, @@ -138,23 +127,23 @@ class TpToast extends EventHelpers(LitElement) { } static get defaultDismissIcon() { - return svg``; + return svg``; } static get infoIcon() { - return svg``; + return svg``; } static get successIcon() { - return svg``; + return svg``; } static get errorIcon() { - return svg``; + return svg``; } static get warningIcon() { - return svg``; + return svg``; } connectedCallback() { @@ -183,6 +172,7 @@ class TpToast extends EventHelpers(LitElement) { */ activateDelay() { if (this.delay > 0) { + this.shadowRoot.querySelector('tp-timeout-strip').show(this.delay); this.stopDelay(); this._delayJob = setTimeout(this.dismiss, this.delay); }