@digital-realty/ix-toast 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +78 -0
  3. package/demo/ToastDemo.js +46 -0
  4. package/demo/ToasterDemo.js +175 -0
  5. package/demo/index.html +38 -0
  6. package/dist/src/IxMessageToast.d.ts +14 -0
  7. package/dist/src/IxMessageToast.js +124 -0
  8. package/dist/src/IxMessageToast.js.map +1 -0
  9. package/dist/src/IxToast.d.ts +24 -0
  10. package/dist/src/IxToast.js +145 -0
  11. package/dist/src/IxToast.js.map +1 -0
  12. package/dist/src/IxToaster.d.ts +16 -0
  13. package/dist/src/IxToaster.js +83 -0
  14. package/dist/src/IxToaster.js.map +1 -0
  15. package/dist/src/IxToasters.d.ts +24 -0
  16. package/dist/src/IxToasters.js +199 -0
  17. package/dist/src/IxToasters.js.map +1 -0
  18. package/dist/src/index.d.ts +3 -0
  19. package/dist/src/index.js +4 -0
  20. package/dist/src/index.js.map +1 -0
  21. package/dist/src/ix-message-toast.d.ts +1 -0
  22. package/dist/src/ix-message-toast.js +3 -0
  23. package/dist/src/ix-message-toast.js.map +1 -0
  24. package/dist/src/ix-toast.d.ts +1 -0
  25. package/dist/src/ix-toast.js +3 -0
  26. package/dist/src/ix-toast.js.map +1 -0
  27. package/dist/src/ix-toaster.d.ts +1 -0
  28. package/dist/src/ix-toaster.js +3 -0
  29. package/dist/src/ix-toaster.js.map +1 -0
  30. package/dist/src/ix-toasters.d.ts +1 -0
  31. package/dist/src/ix-toasters.js +3 -0
  32. package/dist/src/ix-toasters.js.map +1 -0
  33. package/dist/src/utils.d.ts +38 -0
  34. package/dist/src/utils.js +41 -0
  35. package/dist/src/utils.js.map +1 -0
  36. package/dist/test/ix-toast.test.d.ts +1 -0
  37. package/dist/test/ix-toast.test.js +77 -0
  38. package/dist/test/ix-toast.test.js.map +1 -0
  39. package/dist/tsconfig.tsbuildinfo +1 -0
  40. package/package.json +94 -0
  41. package/src/IxMessageToast.ts +117 -0
  42. package/src/IxToast.ts +143 -0
  43. package/src/IxToaster.ts +87 -0
  44. package/src/IxToasters.ts +247 -0
  45. package/src/index.ts +3 -0
  46. package/src/ix-message-toast.ts +3 -0
  47. package/src/ix-toast.ts +3 -0
  48. package/src/ix-toaster.ts +3 -0
  49. package/src/ix-toasters.ts +3 -0
  50. package/src/utils.ts +85 -0
  51. package/test/ix-toast.test.ts +97 -0
  52. package/tsconfig.json +21 -0
  53. package/web-dev-server.config.mjs +27 -0
  54. package/web-test-runner.config.mjs +41 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ix-toast
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # \<ix-toast>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i ix-toast
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import '@digital-realty/ix-toast/ix-toasters.js';
16
+ </script>
17
+
18
+ <ix-toasters></ix-toasters>
19
+
20
+ This will setup an event listener to add a toaster with toast. See the demo for a working example.
21
+ ```
22
+
23
+ ## Linting and formatting
24
+
25
+ To scan the project for linting and formatting errors, run
26
+
27
+ ```bash
28
+ npm run lint
29
+ ```
30
+
31
+ To automatically fix linting and formatting errors, run
32
+
33
+ ```bash
34
+ npm run format
35
+ ```
36
+
37
+ ## Testing with Web Test Runner
38
+
39
+ To execute a single test run:
40
+
41
+ ```bash
42
+ npm run test
43
+ ```
44
+
45
+ To run the tests in interactive watch mode run:
46
+
47
+ ```bash
48
+ npm run test:watch
49
+ ```
50
+
51
+ ## Demoing with Storybook
52
+
53
+ To run a local instance of Storybook for your component, run
54
+
55
+ ```bash
56
+ npm run storybook
57
+ ```
58
+
59
+ To build a production version of Storybook, run
60
+
61
+ ```bash
62
+ npm run storybook:build
63
+ ```
64
+
65
+
66
+ ## Tooling configs
67
+
68
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
69
+
70
+ If you customize the configuration a lot, you can consider moving them to individual files.
71
+
72
+ ## Local Demo with `web-dev-server`
73
+
74
+ ```bash
75
+ npm start
76
+ ```
77
+
78
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,46 @@
1
+ import { html, css, LitElement } from 'lit';
2
+
3
+ class ToastDemo extends LitElement {
4
+ static styles = css`
5
+ .bg-green-500 {
6
+ background-color: rgb(34 197 94);
7
+ }
8
+
9
+ .p-2 {
10
+ padding: 0.5rem;
11
+ }
12
+
13
+ .m-2 {
14
+ margin: 0.5rem;
15
+ }
16
+ `;
17
+
18
+ static properties = {
19
+ id: {type: String},
20
+ forceClose: {type: Boolean}
21
+ };
22
+
23
+ closeToast() {
24
+ this.dispatchEvent(new CustomEvent('remove-toast', {
25
+ detail: {
26
+ ids: this.id,
27
+ forceClose: this.forceClose
28
+ },
29
+ bubbles: true,
30
+ composed: true
31
+ }));
32
+ };
33
+
34
+ render() {
35
+ return html`
36
+ <div class="bg-green-500 p-2 m-2">
37
+ <button @click=${()=>this.closeToast()}>close</button>
38
+ <slot></slot>
39
+ </div>
40
+ `
41
+ };
42
+
43
+ }
44
+
45
+ window.customElements.define('toast-demo', ToastDemo);
46
+
@@ -0,0 +1,175 @@
1
+ import { render, html, css, LitElement } from 'lit';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import './ToastDemo.js';
4
+ import '../dist/src/ix-toasters.js';
5
+ import '../dist/src/ix-message-toast.js';
6
+
7
+
8
+ class ToasterDemo extends LitElement {
9
+ static styles = css`
10
+ .bg-green-500 {
11
+ background-color: rgb(34 197 94);
12
+ }
13
+
14
+ .p-2 {
15
+ padding: 0.5rem;
16
+ }
17
+
18
+ .m-2 {
19
+ margin: 0.5rem;
20
+ }
21
+ `;
22
+
23
+ static properties = {
24
+ _uuid: {state: true},
25
+ _popupNo: {state:true}
26
+ };
27
+
28
+
29
+ constructor() {
30
+ super();
31
+ this._uuid = uuidv4();
32
+ this._popupNo = 1;
33
+ }
34
+
35
+
36
+ handleSubmit(e) {
37
+ e.preventDefault();
38
+ const formData = new FormData(e.target);
39
+ // formData.forEach((value, key) => console.log(`${key}: ${value}`));
40
+ const event = new CustomEvent("add-toast", { detail: {
41
+ id: formData.get('id'),
42
+ content: html`<toast-demo ?forceClose=${formData.get('forceClose') === 'on' ? true : false} .id=${formData.get('id')}>${formData.get('content')}</toast-demo>`,
43
+ autoClose: parseInt(formData.get('autoClose')),
44
+ durationOut: formData.get('durationOut'),
45
+ vertical: formData.get('vertical'),
46
+ horizontal: formData.get('horizontal'),
47
+ animated: formData.get('animated') === 'on' ? true : false,
48
+ above: formData.get('above') === 'on' ? true : false,
49
+ } });
50
+ window.dispatchEvent(event);
51
+ this._uuid = uuidv4();
52
+ this._popupNo += 1;
53
+ return formData;
54
+ }
55
+
56
+ createToast = ({id, content, autoClose, durationOut, vertical, horizontal, animated, above}) => {
57
+ window.dispatchEvent(
58
+ new CustomEvent("add-toast", { detail: {
59
+ id,
60
+ content,
61
+ autoClose,
62
+ durationOut,
63
+ vertical,
64
+ horizontal,
65
+ animated,
66
+ above,
67
+ } })
68
+ );
69
+ }
70
+
71
+ createMessageToast = ({id, content, autoClose, durationOut, vertical, horizontal, animated, above}) => {
72
+ window.dispatchEvent(
73
+ new CustomEvent("add-toast", { detail: {
74
+ id,
75
+ content: html`
76
+ <ix-message-toast toastId=${id}>
77
+ <div slot="heading">A heading</div>
78
+ Hello world success
79
+ </ix-message-toast>`,
80
+ autoClose,
81
+ durationOut,
82
+ vertical,
83
+ horizontal,
84
+ animated,
85
+ above,
86
+ } })
87
+ );
88
+ }
89
+
90
+
91
+ render() {
92
+ return html`
93
+ <ix-toasters>
94
+ </ix-toasters>
95
+ <form @submit=${this.handleSubmit}>
96
+ <div>
97
+ <label>
98
+ Id
99
+ <input name="id" value="${this._uuid}" />
100
+ </label>
101
+ </div>
102
+ <div>
103
+ <label>
104
+ Horizontal
105
+ <select name="horizontal">
106
+ <option value="right">right</option>
107
+ <option value="left">left</option>
108
+ <option value="center">center</option>
109
+ </select>
110
+ </label>
111
+ </div>
112
+ <div>
113
+ <label>
114
+ Vertical
115
+ <select name="vertical">
116
+ <option value="bottom">bottom</option>
117
+ <option value="top">top</option>
118
+ <option value="middle">middle</option>
119
+ </select>
120
+ </label>
121
+ </div>
122
+ <div>
123
+ <label>
124
+ Auto close (ms)
125
+ <input type="number" value="0" name="autoClose">
126
+ </label>
127
+ </div>
128
+ <div>
129
+ <label>
130
+ Duration out (ms)
131
+ <input type="number" value="333" name="durationOut">
132
+ </label>
133
+ </div>
134
+ <div>
135
+ <label>
136
+ Force close
137
+ <input type="checkbox" name="forceClose" />
138
+ </label>
139
+ </div>
140
+ <div>
141
+ <label>
142
+ Content
143
+ <input name="content" value="Hello World ${this._popupNo}" />
144
+ </label>
145
+ </div>
146
+ <div><label>
147
+ Animated
148
+ <input type="checkbox" name="animated" checked />
149
+ </label>
150
+ </div>
151
+ <div><label>
152
+ Above
153
+ <input type="checkbox" name="above" />
154
+ </label>
155
+ </div>
156
+ <button type="submit">Make toast</button>
157
+ </form>
158
+ <ix-message-toast>
159
+ <div slot="heading">A heading</div>
160
+ Hello world success</ix-message-toast>
161
+ <ix-message-toast type="warning">
162
+ <div slot="heading">A heading</div>
163
+ Hello world warning</ix-message-toast>
164
+ <ix-message-toast type="error">
165
+ <div slot="heading">A heading</div>
166
+ Hello world error</ix-message-toast>
167
+ <button type="button" @click=${() => this.createToast({content: html`hello world`})}>Make simple toast</button>
168
+ <button type="button" @click=${() => this.createMessageToast({id: uuidv4()})}>Make message toast</button>
169
+ `
170
+ };
171
+
172
+ }
173
+
174
+ window.customElements.define('toaster-demo', ToasterDemo);
175
+
@@ -0,0 +1,38 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
6
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
7
+ <link
8
+ rel="stylesheet"
9
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200"
10
+ />
11
+ <link
12
+ rel="stylesheet"
13
+ href="https://fonts.googleapis.com/css2?family=Red+Hat+Display:wght@400;700&display=swap"
14
+ />
15
+ <link rel="stylesheet" href="https://unpkg.com/@digital-realty/theme@1.0.7/dist/css/tw-reset-output.css" />
16
+ <link rel="stylesheet" href="https://unpkg.com/@digital-realty/theme@1.0.7/dist/css/baseTheme.css" />
17
+ <style>
18
+ body {
19
+ background: #fafafa;
20
+ }
21
+ </style>
22
+ </head>
23
+ <body>
24
+ <div id="demo"></div>
25
+
26
+ <script type="module">
27
+ import { render, html } from 'lit';
28
+ import './ToasterDemo.js';
29
+
30
+ render(
31
+ html`
32
+ <toaster-demo></toaster-demo>
33
+ `,
34
+ document.querySelector('#demo')
35
+ );
36
+ </script>
37
+ </body>
38
+ </html>
@@ -0,0 +1,14 @@
1
+ import { LitElement } from 'lit';
2
+ import { TMessageToast } from './utils.js';
3
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
4
+ export declare class IxMessageToast extends LitElement {
5
+ toastId: string;
6
+ type: TMessageToast;
7
+ hasClose: boolean;
8
+ forceClose: boolean;
9
+ private _hasHeading;
10
+ private _handleSlotChange;
11
+ static styles: import("lit").CSSResult;
12
+ closeToast(): void;
13
+ render(): import("lit").TemplateResult<1>;
14
+ }
@@ -0,0 +1,124 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement, css, nothing } from 'lit';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { property, state } from 'lit/decorators.js';
5
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
6
+ export class IxMessageToast extends LitElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.toastId = 'message-toast';
10
+ this.type = 'success';
11
+ this.hasClose = true;
12
+ this.forceClose = false;
13
+ this._hasHeading = false;
14
+ }
15
+ _handleSlotChange() {
16
+ this._hasHeading = true;
17
+ }
18
+ closeToast() {
19
+ this.dispatchEvent(new CustomEvent('remove-toast', {
20
+ detail: {
21
+ ids: this.toastId,
22
+ forceClose: this.forceClose,
23
+ },
24
+ bubbles: true,
25
+ composed: true,
26
+ }));
27
+ }
28
+ render() {
29
+ return html `
30
+ <div class="message ${this.type}">
31
+ ${this.hasClose
32
+ ? html `
33
+ <ix-icon-button
34
+ class="close"
35
+ @click=${() => this.closeToast()}
36
+ icon="close"
37
+ ></ix-icon-button>
38
+ `
39
+ : nothing}
40
+ <div class="${classMap({ heading: this._hasHeading })}">
41
+ <slot name="heading" @slotchange=${this._handleSlotChange}></slot>
42
+ </div>
43
+ <slot></slot>
44
+ </div>
45
+ `;
46
+ }
47
+ }
48
+ IxMessageToast.styles = css `
49
+ .message {
50
+ --_spacing: var(--ix-message-toast-spacing, 12px);
51
+ --_neg-spacing: calc(-1 * var(--_spacing));
52
+ --_half-spacing: calc(var(--_spacing) / 2);
53
+ border-radius: var(--ix-message-toast-radius, 6px);
54
+ filter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.07))
55
+ drop-shadow(0 2px 2px rgb(0 0 0 / 0.06));
56
+ margin: var(--_spacing);
57
+ padding: var(--_spacing);
58
+ }
59
+
60
+ .heading {
61
+ margin: 0 var(--_neg-spacing);
62
+ margin-bottom: var(--_spacing);
63
+ padding: 0 var(--_spacing);
64
+ padding-bottom: var(--_half-spacing);
65
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
66
+ }
67
+
68
+ .close {
69
+ margin: var(--_neg-spacing) var(--_neg-spacing) 0 0;
70
+ float: right;
71
+ }
72
+
73
+ .success {
74
+ background-color: var(
75
+ --ix-message-toast-sucess-bg,
76
+ var(--md-sys-color-success, #4caf50)
77
+ );
78
+ color: var(--ix-message-toast-success-color, #fff);
79
+ --md-sys-color-on-surface-variant: var(
80
+ --ix-message-toast-success-color,
81
+ #fff
82
+ );
83
+ }
84
+
85
+ .error {
86
+ background-color: var(
87
+ --ix-message-toast-error-bg,
88
+ var(--md-sys-color-error, #db0028)
89
+ );
90
+ color: var(--ix-message-toast-error-color, #fff);
91
+ --md-sys-color-on-surface-variant: var(
92
+ --ix-message-toast-error-color,
93
+ #fff
94
+ );
95
+ }
96
+
97
+ .warning {
98
+ background-color: var(
99
+ --ix-message-toast-warning-bg,
100
+ var(--md-sys-color-warning, rgba(255, 152, 0, 1))
101
+ );
102
+ color: var(--ix-message-toast-error-color, #000);
103
+ --md-sys-color-on-surface-variant: var(
104
+ --ix-message-toast-warning-color,
105
+ #000
106
+ );
107
+ }
108
+ `;
109
+ __decorate([
110
+ property({ type: String })
111
+ ], IxMessageToast.prototype, "toastId", void 0);
112
+ __decorate([
113
+ property({ type: String })
114
+ ], IxMessageToast.prototype, "type", void 0);
115
+ __decorate([
116
+ property({ type: Boolean })
117
+ ], IxMessageToast.prototype, "hasClose", void 0);
118
+ __decorate([
119
+ property({ type: Boolean })
120
+ ], IxMessageToast.prototype, "forceClose", void 0);
121
+ __decorate([
122
+ state()
123
+ ], IxMessageToast.prototype, "_hasHeading", void 0);
124
+ //# sourceMappingURL=IxMessageToast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IxMessageToast.js","sourceRoot":"","sources":["../../src/IxMessageToast.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,kDAAkD,CAAC;AAE1D,MAAM,OAAO,cAAe,SAAQ,UAAU;IAA9C;;QAC8B,YAAO,GAAW,eAAe,CAAC;QAElC,SAAI,GAAkB,SAAS,CAAC;QAE/B,aAAQ,GAAY,IAAI,CAAC;QAEzB,eAAU,GAAY,KAAK,CAAC;QAGjD,gBAAW,GAAY,KAAK,CAAC;IAoGvC,CAAC;IAlGS,iBAAiB;QACvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAgED,UAAU;QACR,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,cAAc,EAAE;YAC9B,MAAM,EAAE;gBACN,GAAG,EAAE,IAAI,CAAC,OAAO;gBACjB,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B;YACD,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;4BACa,IAAI,CAAC,IAAI;UAC3B,IAAI,CAAC,QAAQ;YACb,CAAC,CAAC,IAAI,CAAA;;;yBAGS,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE;;;aAGnC;YACH,CAAC,CAAC,OAAO;sBACG,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;6CAChB,IAAI,CAAC,iBAAiB;;;;KAI9D,CAAC;IACJ,CAAC;;AA7FM,qBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DlB,CAAC;AA3E0B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAmC;AAElC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAiC;AAE/B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gDAA0B;AAEzB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;kDAA6B;AAGzD;IADC,KAAK,EAAE;mDAC6B","sourcesContent":["import { html, LitElement, css, nothing } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { property, state } from 'lit/decorators.js';\nimport { TMessageToast } from './utils.js';\nimport '@digital-realty/ix-icon-button/ix-icon-button.js';\n\nexport class IxMessageToast extends LitElement {\n @property({ type: String }) toastId: string = 'message-toast';\n\n @property({ type: String }) type: TMessageToast = 'success';\n\n @property({ type: Boolean }) hasClose: boolean = true;\n\n @property({ type: Boolean }) forceClose: boolean = false;\n\n @state()\n private _hasHeading: boolean = false;\n\n private _handleSlotChange() {\n this._hasHeading = true;\n }\n\n static styles = css`\n .message {\n --_spacing: var(--ix-message-toast-spacing, 12px);\n --_neg-spacing: calc(-1 * var(--_spacing));\n --_half-spacing: calc(var(--_spacing) / 2);\n border-radius: var(--ix-message-toast-radius, 6px);\n filter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.07))\n drop-shadow(0 2px 2px rgb(0 0 0 / 0.06));\n margin: var(--_spacing);\n padding: var(--_spacing);\n }\n\n .heading {\n margin: 0 var(--_neg-spacing);\n margin-bottom: var(--_spacing);\n padding: 0 var(--_spacing);\n padding-bottom: var(--_half-spacing);\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n }\n\n .close {\n margin: var(--_neg-spacing) var(--_neg-spacing) 0 0;\n float: right;\n }\n\n .success {\n background-color: var(\n --ix-message-toast-sucess-bg,\n var(--md-sys-color-success, #4caf50)\n );\n color: var(--ix-message-toast-success-color, #fff);\n --md-sys-color-on-surface-variant: var(\n --ix-message-toast-success-color,\n #fff\n );\n }\n\n .error {\n background-color: var(\n --ix-message-toast-error-bg,\n var(--md-sys-color-error, #db0028)\n );\n color: var(--ix-message-toast-error-color, #fff);\n --md-sys-color-on-surface-variant: var(\n --ix-message-toast-error-color,\n #fff\n );\n }\n\n .warning {\n background-color: var(\n --ix-message-toast-warning-bg,\n var(--md-sys-color-warning, rgba(255, 152, 0, 1))\n );\n color: var(--ix-message-toast-error-color, #000);\n --md-sys-color-on-surface-variant: var(\n --ix-message-toast-warning-color,\n #000\n );\n }\n `;\n\n closeToast() {\n this.dispatchEvent(\n new CustomEvent('remove-toast', {\n detail: {\n ids: this.toastId,\n forceClose: this.forceClose,\n },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n return html`\n <div class=\"message ${this.type}\">\n ${this.hasClose\n ? html`\n <ix-icon-button\n class=\"close\"\n @click=${() => this.closeToast()}\n icon=\"close\"\n ></ix-icon-button>\n `\n : nothing}\n <div class=\"${classMap({ heading: this._hasHeading })}\">\n <slot name=\"heading\" @slotchange=${this._handleSlotChange}></slot>\n </div>\n <slot></slot>\n </div>\n `;\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { LitElement } from 'lit';
2
+ import { AnimateController } from '@lit-labs/motion';
3
+ export declare class IxToast extends LitElement {
4
+ animated: Boolean;
5
+ uuid: string;
6
+ toastId: string;
7
+ toasterId: string;
8
+ autoClose: number;
9
+ shown: boolean;
10
+ durationOut: number;
11
+ private _timeout;
12
+ static styles: import("lit").CSSResult[];
13
+ private _setAutoClose;
14
+ private _animationCompleted;
15
+ private _dispatchEvent;
16
+ private _mouseover;
17
+ private _mouseout;
18
+ controller: AnimateController;
19
+ connectedCallback(): void;
20
+ disconnectedCallback(): void;
21
+ closeToast(forceClose: boolean): void;
22
+ removeToast(forceClose?: boolean): void;
23
+ render(): import("lit").TemplateResult<1>;
24
+ }
@@ -0,0 +1,145 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement, css } from 'lit';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { animate, AnimateController } from '@lit-labs/motion';
5
+ import { property, state } from 'lit/decorators.js';
6
+ import { v4 as uuidv4 } from 'uuid';
7
+ export class IxToast extends LitElement {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.animated = false;
11
+ this.uuid = uuidv4();
12
+ this.toastId = uuidv4();
13
+ this.toasterId = '';
14
+ this.autoClose = 0;
15
+ this.shown = true;
16
+ this.durationOut = 333;
17
+ this.controller = new AnimateController(this, {
18
+ onComplete: () => this._animationCompleted(),
19
+ });
20
+ }
21
+ _setAutoClose() {
22
+ if (this.autoClose > 0) {
23
+ this._timeout = setTimeout(() => {
24
+ this.removeToast();
25
+ }, this.autoClose);
26
+ }
27
+ }
28
+ _animationCompleted() {
29
+ if (!this.shown) {
30
+ this._dispatchEvent('toast-closed', 'toast closed');
31
+ }
32
+ }
33
+ _dispatchEvent(name, message) {
34
+ this.dispatchEvent(new CustomEvent(name, {
35
+ detail: {
36
+ message,
37
+ id: this.toastId,
38
+ uuid: this.uuid,
39
+ toasterId: this.toasterId,
40
+ },
41
+ bubbles: true,
42
+ composed: true,
43
+ }));
44
+ }
45
+ _mouseover() {
46
+ if (this.autoClose > 0) {
47
+ this.shown = true;
48
+ clearTimeout(this._timeout);
49
+ if (this.controller.isAnimating) {
50
+ this.controller.finish();
51
+ }
52
+ }
53
+ }
54
+ _mouseout() {
55
+ this._setAutoClose();
56
+ }
57
+ connectedCallback() {
58
+ super.connectedCallback();
59
+ this._setAutoClose();
60
+ }
61
+ disconnectedCallback() {
62
+ super.disconnectedCallback();
63
+ if (this._timeout) {
64
+ clearTimeout(this._timeout);
65
+ }
66
+ }
67
+ closeToast(forceClose) {
68
+ if (this.animated) {
69
+ this.shown = false;
70
+ }
71
+ if (!this.animated || forceClose) {
72
+ this._dispatchEvent('toast-closed', 'toast closed');
73
+ }
74
+ }
75
+ removeToast(forceClose = false) {
76
+ this.dispatchEvent(new CustomEvent('remove-toast', {
77
+ detail: {
78
+ ids: this.toastId,
79
+ uuid: this.uuid,
80
+ forceClose,
81
+ },
82
+ bubbles: true,
83
+ composed: true,
84
+ }));
85
+ }
86
+ render() {
87
+ return html `
88
+ <div
89
+ @mouseout=${this._mouseout}
90
+ @mouseover=${this._mouseover}
91
+ @focus=${this._mouseover}
92
+ @blur=${this._mouseout}
93
+ >
94
+ <div
95
+ class="toast ${classMap({
96
+ shown: this.shown,
97
+ })}"
98
+ ${animate({
99
+ keyframeOptions: {
100
+ duration: this.durationOut,
101
+ },
102
+ disabled: !this.animated,
103
+ })}
104
+ >
105
+ <slot></slot>
106
+ </div>
107
+ </div>
108
+ `;
109
+ }
110
+ }
111
+ IxToast.styles = [
112
+ css `
113
+ .toast {
114
+ opacity: 0;
115
+ }
116
+ .shown {
117
+ opacity: 1;
118
+ }
119
+ `,
120
+ ];
121
+ __decorate([
122
+ property({ type: Boolean })
123
+ ], IxToast.prototype, "animated", void 0);
124
+ __decorate([
125
+ property({ type: String })
126
+ ], IxToast.prototype, "uuid", void 0);
127
+ __decorate([
128
+ property({ type: String, attribute: 'data-id' })
129
+ ], IxToast.prototype, "toastId", void 0);
130
+ __decorate([
131
+ property({ type: String })
132
+ ], IxToast.prototype, "toasterId", void 0);
133
+ __decorate([
134
+ property({ type: Number })
135
+ ], IxToast.prototype, "autoClose", void 0);
136
+ __decorate([
137
+ property({ type: Boolean })
138
+ ], IxToast.prototype, "shown", void 0);
139
+ __decorate([
140
+ property({ type: Number })
141
+ ], IxToast.prototype, "durationOut", void 0);
142
+ __decorate([
143
+ state()
144
+ ], IxToast.prototype, "_timeout", void 0);
145
+ //# sourceMappingURL=IxToast.js.map