@spectrum-web-components/toast 0.10.5 → 0.10.8
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.
- package/package.json +7 -7
- package/sp-toast.d.ts +6 -0
- package/sp-toast.js +14 -0
- package/sp-toast.js.map +1 -0
- package/src/Toast.d.ts +44 -0
- package/src/Toast.js +209 -0
- package/src/Toast.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +13 -0
- package/src/index.js.map +1 -0
- package/src/spectrum-toast.css.d.ts +2 -0
- package/src/spectrum-toast.css.js +101 -0
- package/src/spectrum-toast.css.js.map +1 -0
- package/src/toast.css.d.ts +2 -0
- package/src/toast.css.js +101 -0
- package/src/toast.css.js.map +1 -0
- package/stories/toast.stories.js +64 -0
- package/stories/toast.stories.js.map +1 -0
- package/test/benchmark/test-basic.js +18 -0
- package/test/benchmark/test-basic.js.map +1 -0
- package/test/toast.test-vrt.js +15 -0
- package/test/toast.test-vrt.js.map +1 -0
- package/test/toast.test.js +201 -0
- package/test/toast.test.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/toast",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
"lit-html"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@spectrum-web-components/base": "^0.5.
|
|
48
|
-
"@spectrum-web-components/button": "^0.17.
|
|
49
|
-
"@spectrum-web-components/icon": "^0.11.
|
|
50
|
-
"@spectrum-web-components/icons-workflow": "^0.8.
|
|
47
|
+
"@spectrum-web-components/base": "^0.5.5",
|
|
48
|
+
"@spectrum-web-components/button": "^0.17.3",
|
|
49
|
+
"@spectrum-web-components/icon": "^0.11.6",
|
|
50
|
+
"@spectrum-web-components/icons-workflow": "^0.8.6",
|
|
51
51
|
"tslib": "^2.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@spectrum-css/toast": "^7.0.
|
|
54
|
+
"@spectrum-css/toast": "^7.0.6"
|
|
55
55
|
},
|
|
56
56
|
"types": "./src/index.d.ts",
|
|
57
57
|
"customElements": "custom-elements.json",
|
|
58
58
|
"sideEffects": [
|
|
59
59
|
"./sp-*.js"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "bdff893e2b95aba7737c58d01c6ac68861cb8b2e"
|
|
62
62
|
}
|
package/sp-toast.d.ts
ADDED
package/sp-toast.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { Toast } from './src/Toast.js';
|
|
13
|
+
customElements.define('sp-toast', Toast);
|
|
14
|
+
//# sourceMappingURL=sp-toast.js.map
|
package/sp-toast.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sp-toast.js","sourceRoot":"","sources":["sp-toast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { Toast } from './src/Toast.js';\n\ncustomElements.define('sp-toast', Toast);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-toast': Toast;\n }\n}\n"]}
|
package/src/Toast.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import '@spectrum-web-components/button/sp-close-button.js';
|
|
3
|
+
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
|
|
4
|
+
import '@spectrum-web-components/icons-workflow/icons/sp-icon-info.js';
|
|
5
|
+
import '@spectrum-web-components/icons-workflow/icons/sp-icon-checkmark-circle.js';
|
|
6
|
+
export declare const toastVariants: ToastVariants[];
|
|
7
|
+
export declare type ToastVariants = 'negative' | 'positive' | 'info' | 'error' | 'warning' | '';
|
|
8
|
+
/**
|
|
9
|
+
* @element sp-toast
|
|
10
|
+
*
|
|
11
|
+
* @slot - The toast content
|
|
12
|
+
* @slot action - button element surfacing an action in the Toast
|
|
13
|
+
*
|
|
14
|
+
* @fires close - Announces that the Toast has been closed by the user or by its timeout.
|
|
15
|
+
*/
|
|
16
|
+
export declare class Toast extends SpectrumElement {
|
|
17
|
+
static get styles(): CSSResultArray;
|
|
18
|
+
open: boolean;
|
|
19
|
+
set timeout(timeout: number | null);
|
|
20
|
+
get timeout(): number | null;
|
|
21
|
+
_timeout: number | null;
|
|
22
|
+
/**
|
|
23
|
+
* The variant applies specific styling when set to `negative`, `positive`, `info`, `error`, or `warning`.
|
|
24
|
+
* `variant` attribute is removed when not matching one of the above.
|
|
25
|
+
*
|
|
26
|
+
* @param {String} variant
|
|
27
|
+
*/
|
|
28
|
+
set variant(variant: ToastVariants);
|
|
29
|
+
get variant(): ToastVariants;
|
|
30
|
+
private _variant;
|
|
31
|
+
private renderIcon;
|
|
32
|
+
private countdownStart;
|
|
33
|
+
private nextCount;
|
|
34
|
+
private doCountdown;
|
|
35
|
+
private countdown;
|
|
36
|
+
private holdCountdown;
|
|
37
|
+
private resumeCountdown;
|
|
38
|
+
private startCountdown;
|
|
39
|
+
private stopCountdown;
|
|
40
|
+
private shouldClose;
|
|
41
|
+
close(): void;
|
|
42
|
+
protected render(): TemplateResult;
|
|
43
|
+
protected updated(changes: PropertyValues): void;
|
|
44
|
+
}
|
package/src/Toast.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { html, SpectrumElement, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import '@spectrum-web-components/button/sp-close-button.js';
|
|
16
|
+
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
|
|
17
|
+
import '@spectrum-web-components/icons-workflow/icons/sp-icon-info.js';
|
|
18
|
+
import '@spectrum-web-components/icons-workflow/icons/sp-icon-checkmark-circle.js';
|
|
19
|
+
import toastStyles from './toast.css.js';
|
|
20
|
+
export const toastVariants = [
|
|
21
|
+
'negative',
|
|
22
|
+
'positive',
|
|
23
|
+
'info',
|
|
24
|
+
'error',
|
|
25
|
+
'warning',
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* @element sp-toast
|
|
29
|
+
*
|
|
30
|
+
* @slot - The toast content
|
|
31
|
+
* @slot action - button element surfacing an action in the Toast
|
|
32
|
+
*
|
|
33
|
+
* @fires close - Announces that the Toast has been closed by the user or by its timeout.
|
|
34
|
+
*/
|
|
35
|
+
export class Toast extends SpectrumElement {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
this.open = false;
|
|
39
|
+
this._timeout = null;
|
|
40
|
+
this._variant = '';
|
|
41
|
+
this.countdownStart = 0;
|
|
42
|
+
this.nextCount = -1;
|
|
43
|
+
this.doCountdown = (time) => {
|
|
44
|
+
if (!this.countdownStart) {
|
|
45
|
+
this.countdownStart = performance.now();
|
|
46
|
+
}
|
|
47
|
+
if (time - this.countdownStart > this._timeout) {
|
|
48
|
+
this.shouldClose();
|
|
49
|
+
this.countdownStart = 0;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.countdown();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
this.countdown = () => {
|
|
56
|
+
cancelAnimationFrame(this.nextCount);
|
|
57
|
+
this.nextCount = requestAnimationFrame(this.doCountdown);
|
|
58
|
+
};
|
|
59
|
+
this.holdCountdown = () => {
|
|
60
|
+
this.stopCountdown();
|
|
61
|
+
this.addEventListener('focusout', this.resumeCountdown);
|
|
62
|
+
};
|
|
63
|
+
this.resumeCountdown = () => {
|
|
64
|
+
this.removeEventListener('focusout', this.holdCountdown);
|
|
65
|
+
this.countdown();
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
static get styles() {
|
|
69
|
+
return [toastStyles];
|
|
70
|
+
}
|
|
71
|
+
set timeout(timeout) {
|
|
72
|
+
const hasTimeout = typeof timeout !== null && timeout > 0;
|
|
73
|
+
const newTimeout = hasTimeout
|
|
74
|
+
? Math.max(6000, timeout)
|
|
75
|
+
: null;
|
|
76
|
+
const oldValue = this.timeout;
|
|
77
|
+
if (newTimeout && this.countdownStart) {
|
|
78
|
+
this.countdownStart = performance.now();
|
|
79
|
+
}
|
|
80
|
+
this._timeout = newTimeout;
|
|
81
|
+
this.requestUpdate('timeout', oldValue);
|
|
82
|
+
}
|
|
83
|
+
get timeout() {
|
|
84
|
+
return this._timeout;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The variant applies specific styling when set to `negative`, `positive`, `info`, `error`, or `warning`.
|
|
88
|
+
* `variant` attribute is removed when not matching one of the above.
|
|
89
|
+
*
|
|
90
|
+
* @param {String} variant
|
|
91
|
+
*/
|
|
92
|
+
set variant(variant) {
|
|
93
|
+
if (variant === this.variant) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const oldValue = this.variant;
|
|
97
|
+
if (toastVariants.includes(variant)) {
|
|
98
|
+
this.setAttribute('variant', variant);
|
|
99
|
+
this._variant = variant;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.removeAttribute('variant');
|
|
103
|
+
this._variant = '';
|
|
104
|
+
}
|
|
105
|
+
this.requestUpdate('variant', oldValue);
|
|
106
|
+
}
|
|
107
|
+
get variant() {
|
|
108
|
+
return this._variant;
|
|
109
|
+
}
|
|
110
|
+
renderIcon(variant) {
|
|
111
|
+
switch (variant) {
|
|
112
|
+
case 'info':
|
|
113
|
+
return html `
|
|
114
|
+
<sp-icon-info
|
|
115
|
+
label="Information"
|
|
116
|
+
class="type"
|
|
117
|
+
></sp-icon-info>
|
|
118
|
+
`;
|
|
119
|
+
case 'negative':
|
|
120
|
+
case 'error': // deprecated
|
|
121
|
+
case 'warning': // deprecated
|
|
122
|
+
return html `
|
|
123
|
+
<sp-icon-alert label="Error" class="type"></sp-icon-alert>
|
|
124
|
+
`;
|
|
125
|
+
case 'positive':
|
|
126
|
+
case 'success': // deprecated
|
|
127
|
+
return html `
|
|
128
|
+
<sp-icon-checkmark-circle
|
|
129
|
+
label="Success"
|
|
130
|
+
class="type"
|
|
131
|
+
></sp-icon-checkmark-circle>
|
|
132
|
+
`;
|
|
133
|
+
default:
|
|
134
|
+
return html ``;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
startCountdown() {
|
|
138
|
+
this.countdown();
|
|
139
|
+
this.addEventListener('focusin', this.holdCountdown);
|
|
140
|
+
}
|
|
141
|
+
stopCountdown() {
|
|
142
|
+
cancelAnimationFrame(this.nextCount);
|
|
143
|
+
this.countdownStart = 0;
|
|
144
|
+
}
|
|
145
|
+
shouldClose() {
|
|
146
|
+
const applyDefault = this.dispatchEvent(new CustomEvent('close', {
|
|
147
|
+
composed: true,
|
|
148
|
+
bubbles: true,
|
|
149
|
+
cancelable: true,
|
|
150
|
+
}));
|
|
151
|
+
if (applyDefault) {
|
|
152
|
+
this.close();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
close() {
|
|
156
|
+
this.open = false;
|
|
157
|
+
}
|
|
158
|
+
render() {
|
|
159
|
+
return html `
|
|
160
|
+
${this.renderIcon(this.variant)}
|
|
161
|
+
<div class="body" role="alert">
|
|
162
|
+
<div class="content">
|
|
163
|
+
<slot></slot>
|
|
164
|
+
</div>
|
|
165
|
+
<slot name="action"></slot>
|
|
166
|
+
</div>
|
|
167
|
+
<div class="buttons">
|
|
168
|
+
<sp-close-button
|
|
169
|
+
@click=${this.shouldClose}
|
|
170
|
+
label="Close"
|
|
171
|
+
variant="white"
|
|
172
|
+
></sp-close-button>
|
|
173
|
+
</div>
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
updated(changes) {
|
|
177
|
+
super.updated(changes);
|
|
178
|
+
if (changes.has('open')) {
|
|
179
|
+
if (this.open) {
|
|
180
|
+
if (this.timeout) {
|
|
181
|
+
this.startCountdown();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
if (this.timeout) {
|
|
186
|
+
this.stopCountdown();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (changes.has('timeout')) {
|
|
191
|
+
if (this.timeout !== null && this.open) {
|
|
192
|
+
this.startCountdown();
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
this.stopCountdown();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
__decorate([
|
|
201
|
+
property({ type: Boolean, reflect: true })
|
|
202
|
+
], Toast.prototype, "open", void 0);
|
|
203
|
+
__decorate([
|
|
204
|
+
property({ type: Number })
|
|
205
|
+
], Toast.prototype, "timeout", null);
|
|
206
|
+
__decorate([
|
|
207
|
+
property({ type: String })
|
|
208
|
+
], Toast.prototype, "variant", null);
|
|
209
|
+
//# sourceMappingURL=Toast.js.map
|
package/src/Toast.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.js","sourceRoot":"","sources":["Toast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EAEJ,eAAe,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,oDAAoD,CAAC;AAC5D,OAAO,gEAAgE,CAAC;AACxE,OAAO,+DAA+D,CAAC;AACvE,OAAO,2EAA2E,CAAC;AAEnF,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC,MAAM,CAAC,MAAM,aAAa,GAAoB;IAC1C,UAAU;IACV,UAAU;IACV,MAAM;IACN,OAAO;IACP,SAAS;CACZ,CAAC;AAUF;;;;;;;GAOG;AAEH,MAAM,OAAO,KAAM,SAAQ,eAAe;IAA1C;;QAMW,SAAI,GAAG,KAAK,CAAC;QAoBb,aAAQ,GAAkB,IAAI,CAAC;QA4B9B,aAAQ,GAAkB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G,CAAC,SAAS,CAAC,EAAE;YACxB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;gBACpC,IAAI,CAAC,cAAc,EAAE,CAAC;aACzB;iBAAM;gBACH,IAAI,CAAC,aAAa,EAAE,CAAC;aACxB;SACJ;IACL,CAAC;CACJ;AA/KG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;mCACvB;AAGpB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oCAY1B;AAeD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oCAc1B","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport '@spectrum-web-components/button/sp-close-button.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-info.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-checkmark-circle.js';\n\nimport toastStyles from './toast.css.js';\n\nexport const toastVariants: ToastVariants[] = [\n 'negative',\n 'positive',\n 'info',\n 'error',\n 'warning',\n];\n\nexport type ToastVariants =\n | 'negative'\n | 'positive'\n | 'info'\n | 'error'\n | 'warning'\n | '';\n\n/**\n * @element sp-toast\n *\n * @slot - The toast content\n * @slot action - button element surfacing an action in the Toast\n *\n * @fires close - Announces that the Toast has been closed by the user or by its timeout.\n */\n\nexport class Toast extends SpectrumElement {\n public static get styles(): CSSResultArray {\n return [toastStyles];\n }\n\n @property({ type: Boolean, reflect: true })\n public open = false;\n\n @property({ type: Number })\n public set timeout(timeout: number | null) {\n const hasTimeout = typeof timeout !== null && (timeout as number) > 0;\n const newTimeout = hasTimeout\n ? Math.max(6000, timeout as number)\n : null;\n const oldValue = this.timeout;\n if (newTimeout && this.countdownStart) {\n this.countdownStart = performance.now();\n }\n this._timeout = newTimeout;\n this.requestUpdate('timeout', oldValue);\n }\n\n public get timeout(): number | null {\n return this._timeout;\n }\n\n public _timeout: number | null = null;\n\n /**\n * The variant applies specific styling when set to `negative`, `positive`, `info`, `error`, or `warning`.\n * `variant` attribute is removed when not matching one of the above.\n *\n * @param {String} variant\n */\n @property({ type: String })\n public set variant(variant: ToastVariants) {\n if (variant === this.variant) {\n return;\n }\n const oldValue = this.variant;\n if (toastVariants.includes(variant)) {\n this.setAttribute('variant', variant);\n this._variant = variant;\n } else {\n this.removeAttribute('variant');\n this._variant = '';\n }\n this.requestUpdate('variant', oldValue);\n }\n\n public get variant(): ToastVariants {\n return this._variant;\n }\n\n private _variant: ToastVariants = '';\n\n private renderIcon(variant: string): TemplateResult {\n switch (variant) {\n case 'info':\n return html`\n <sp-icon-info\n label=\"Information\"\n class=\"type\"\n ></sp-icon-info>\n `;\n case 'negative':\n case 'error': // deprecated\n case 'warning': // deprecated\n return html`\n <sp-icon-alert label=\"Error\" class=\"type\"></sp-icon-alert>\n `;\n case 'positive':\n case 'success': // deprecated\n return html`\n <sp-icon-checkmark-circle\n label=\"Success\"\n class=\"type\"\n ></sp-icon-checkmark-circle>\n `;\n default:\n return html``;\n }\n }\n\n private countdownStart = 0;\n private nextCount = -1;\n\n private doCountdown = (time: number): void => {\n if (!this.countdownStart) {\n this.countdownStart = performance.now();\n }\n if (time - this.countdownStart > (this._timeout as number)) {\n this.shouldClose();\n this.countdownStart = 0;\n } else {\n this.countdown();\n }\n };\n\n private countdown = (): void => {\n cancelAnimationFrame(this.nextCount);\n this.nextCount = requestAnimationFrame(this.doCountdown);\n };\n\n private holdCountdown = (): void => {\n this.stopCountdown();\n this.addEventListener('focusout', this.resumeCountdown);\n };\n\n private resumeCountdown = (): void => {\n this.removeEventListener('focusout', this.holdCountdown);\n this.countdown();\n };\n\n private startCountdown(): void {\n this.countdown();\n this.addEventListener('focusin', this.holdCountdown);\n }\n\n private stopCountdown(): void {\n cancelAnimationFrame(this.nextCount);\n this.countdownStart = 0;\n }\n\n private shouldClose(): void {\n const applyDefault = this.dispatchEvent(\n new CustomEvent('close', {\n composed: true,\n bubbles: true,\n cancelable: true,\n })\n );\n if (applyDefault) {\n this.close();\n }\n }\n\n public close(): void {\n this.open = false;\n }\n\n protected render(): TemplateResult {\n return html`\n ${this.renderIcon(this.variant)}\n <div class=\"body\" role=\"alert\">\n <div class=\"content\">\n <slot></slot>\n </div>\n <slot name=\"action\"></slot>\n </div>\n <div class=\"buttons\">\n <sp-close-button\n @click=${this.shouldClose}\n label=\"Close\"\n variant=\"white\"\n ></sp-close-button>\n </div>\n `;\n }\n\n protected updated(changes: PropertyValues): void {\n super.updated(changes);\n if (changes.has('open')) {\n if (this.open) {\n if (this.timeout) {\n this.startCountdown();\n }\n } else {\n if (this.timeout) {\n this.stopCountdown();\n }\n }\n }\n if (changes.has('timeout')) {\n if (this.timeout !== null && this.open) {\n this.startCountdown();\n } else {\n this.stopCountdown();\n }\n }\n }\n}\n"]}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Toast.js';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export * from './Toast.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,cAAc,YAAY,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nexport * from './Toast.js';\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { css } from '@spectrum-web-components/base';
|
|
13
|
+
const styles = css `
|
|
14
|
+
:host{--spectrum-toast-icon-padding-y:var(
|
|
15
|
+
--spectrum-global-dimension-size-85
|
|
16
|
+
);--spectrum-toast-neutral-content-padding-top:var(
|
|
17
|
+
--spectrum-global-dimension-size-65
|
|
18
|
+
);--spectrum-toast-content-padding-bottom:var(
|
|
19
|
+
--spectrum-global-dimension-size-65
|
|
20
|
+
);--spectrum-toast-button-margin-right:var(
|
|
21
|
+
--spectrum-global-dimension-size-130
|
|
22
|
+
)}:host([dir=ltr]){padding-right:var(
|
|
23
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
24
|
+
)}:host([dir=rtl]){padding-left:var(
|
|
25
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
26
|
+
)}:host([dir=ltr]){padding-left:var(
|
|
27
|
+
--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)
|
|
28
|
+
)}:host([dir=rtl]){padding-right:var(
|
|
29
|
+
--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)
|
|
30
|
+
)}:host{-webkit-font-smoothing:antialiased;align-items:stretch;border-radius:var(
|
|
31
|
+
--spectrum-toast-neutral-border-radius,var(--spectrum-alias-border-radius-regular)
|
|
32
|
+
);box-sizing:border-box;display:inline-flex;flex-direction:row;font-size:var(
|
|
33
|
+
--spectrum-toast-neutral-text-size,var(--spectrum-global-dimension-font-size-100)
|
|
34
|
+
);font-weight:var(
|
|
35
|
+
--spectrum-toast-neutral-text-font-weight,var(--spectrum-alias-body-text-font-weight)
|
|
36
|
+
);padding-bottom:var(
|
|
37
|
+
--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)
|
|
38
|
+
);padding-top:var(
|
|
39
|
+
--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)
|
|
40
|
+
)}:host([dir=ltr]) .type{margin-right:var(
|
|
41
|
+
--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)
|
|
42
|
+
)}:host([dir=rtl]) .type{margin-left:var(
|
|
43
|
+
--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)
|
|
44
|
+
)}:host([dir=ltr]) .type{margin-left:0}:host([dir=rtl]) .type{margin-right:0}.type{flex-grow:0;flex-shrink:0;margin-bottom:var(--spectrum-toast-icon-padding-y);margin-top:var(--spectrum-toast-icon-padding-y)}:host([dir=ltr]) .content{padding-right:var(
|
|
45
|
+
--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)
|
|
46
|
+
)}:host([dir=rtl]) .content{padding-left:var(
|
|
47
|
+
--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)
|
|
48
|
+
)}:host([dir=ltr]) .content{padding-left:0}:host([dir=rtl]) .content{padding-right:0}:host([dir=ltr]) .content{text-align:left}:host([dir=rtl]) .content{text-align:right}.content{box-sizing:border-box;display:inline-block;flex:1 1 auto;font-size:var(
|
|
49
|
+
--spectrum-toast-info-text-size,var(--spectrum-global-dimension-font-size-100)
|
|
50
|
+
);font-weight:var(
|
|
51
|
+
--spectrum-toast-info-text-font-weight,var(--spectrum-alias-body-text-font-weight)
|
|
52
|
+
);line-height:var(
|
|
53
|
+
--spectrum-toast-info-text-line-height,var(--spectrum-alias-component-text-line-height)
|
|
54
|
+
);padding-bottom:var(--spectrum-toast-content-padding-bottom);padding-top:var(
|
|
55
|
+
--spectrum-toast-neutral-content-padding-top,var(--spectrum-global-dimension-size-65)
|
|
56
|
+
)}.buttons{align-items:flex-start;display:flex;flex:0 0 auto}:host([dir=ltr]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=ltr]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=ltr]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=ltr]) .buttons slot[name=action]+::slotted([slot=action]){margin-left:var(
|
|
57
|
+
--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)
|
|
58
|
+
)}:host([dir=rtl]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=rtl]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=rtl]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=rtl]) .buttons slot[name=action]+::slotted([slot=action]){margin-right:var(
|
|
59
|
+
--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)
|
|
60
|
+
)}.body{align-self:center;flex:1 1 auto}:host([dir=ltr]) .body ::slotted([slot=action]){float:right}:host([dir=rtl]) .body ::slotted([slot=action]){float:left}:host([dir=ltr]) .body ::slotted([slot=action]){margin-right:var(
|
|
61
|
+
--spectrum-toast-button-margin-right
|
|
62
|
+
)}:host([dir=rtl]) .body ::slotted([slot=action]){margin-left:var(
|
|
63
|
+
--spectrum-toast-button-margin-right
|
|
64
|
+
)}:host([dir=ltr]) .body+.buttons{padding-left:var(
|
|
65
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
66
|
+
)}:host([dir=rtl]) .body+.buttons{padding-right:var(
|
|
67
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
68
|
+
)}:host([dir=ltr]) .body+.buttons{border-left-width:1px}:host([dir=rtl]) .body+.buttons{border-right-width:1px}:host([dir=ltr]) .body+.buttons{border-left-style:solid}:host([dir=rtl]) .body+.buttons{border-right-style:solid}:host{background-color:var(
|
|
69
|
+
--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)
|
|
70
|
+
);color:var(
|
|
71
|
+
--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)
|
|
72
|
+
)}.content{color:var(
|
|
73
|
+
--spectrum-toast-neutral-text-color,var(--spectrum-global-color-static-white)
|
|
74
|
+
)}.type{color:#fff}:host([dir=ltr]) .buttons{border-left-color:hsla(0,0%,100%,.2)}:host([dir=rtl]) .buttons{border-right-color:hsla(0,0%,100%,.2)}:host([variant=error]),:host([variant=negative]){background-color:var(
|
|
75
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
76
|
+
);color:var(
|
|
77
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
78
|
+
)}:host([variant=error]) .closeButton.focus-visible:not(:active),:host([variant=negative]) .closeButton.focus-visible:not(:active){color:var(
|
|
79
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
80
|
+
)}:host([variant=error]) .closeButton:focus-visible:not(:active),:host([variant=negative]) .closeButton:focus-visible:not(:active){color:var(
|
|
81
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
82
|
+
)}:host([variant=info]){background-color:var(
|
|
83
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
84
|
+
);color:var(
|
|
85
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
86
|
+
)}:host([variant=info]) .closeButton.focus-visible:not(:active){color:var(
|
|
87
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
88
|
+
)}:host([variant=info]) .closeButton:focus-visible:not(:active){color:var(
|
|
89
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
90
|
+
)}:host([variant=positive]),:host([variant=success]){background-color:var(
|
|
91
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
92
|
+
);color:var(
|
|
93
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
94
|
+
)}:host([variant=positive]) .closeButton.focus-visible:not(:active),:host([variant=success]) .closeButton.focus-visible:not(:active){color:var(
|
|
95
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
96
|
+
)}:host([variant=positive]) .closeButton:focus-visible:not(:active),:host([variant=success]) .closeButton:focus-visible:not(:active){color:var(
|
|
97
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
98
|
+
)}
|
|
99
|
+
`;
|
|
100
|
+
export default styles;
|
|
101
|
+
//# sourceMappingURL=spectrum-toast.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spectrum-toast.css.js","sourceRoot":"","sources":["spectrum-toast.css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFjB,CAAC;AACF,eAAe,MAAM,CAAC","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{--spectrum-toast-icon-padding-y:var(\n--spectrum-global-dimension-size-85\n);--spectrum-toast-neutral-content-padding-top:var(\n--spectrum-global-dimension-size-65\n);--spectrum-toast-content-padding-bottom:var(\n--spectrum-global-dimension-size-65\n);--spectrum-toast-button-margin-right:var(\n--spectrum-global-dimension-size-130\n)}:host([dir=ltr]){padding-right:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=rtl]){padding-left:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=ltr]){padding-left:var(\n--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)\n)}:host([dir=rtl]){padding-right:var(\n--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)\n)}:host{-webkit-font-smoothing:antialiased;align-items:stretch;border-radius:var(\n--spectrum-toast-neutral-border-radius,var(--spectrum-alias-border-radius-regular)\n);box-sizing:border-box;display:inline-flex;flex-direction:row;font-size:var(\n--spectrum-toast-neutral-text-size,var(--spectrum-global-dimension-font-size-100)\n);font-weight:var(\n--spectrum-toast-neutral-text-font-weight,var(--spectrum-alias-body-text-font-weight)\n);padding-bottom:var(\n--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)\n);padding-top:var(\n--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)\n)}:host([dir=ltr]) .type{margin-right:var(\n--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)\n)}:host([dir=rtl]) .type{margin-left:var(\n--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)\n)}:host([dir=ltr]) .type{margin-left:0}:host([dir=rtl]) .type{margin-right:0}.type{flex-grow:0;flex-shrink:0;margin-bottom:var(--spectrum-toast-icon-padding-y);margin-top:var(--spectrum-toast-icon-padding-y)}:host([dir=ltr]) .content{padding-right:var(\n--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)\n)}:host([dir=rtl]) .content{padding-left:var(\n--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)\n)}:host([dir=ltr]) .content{padding-left:0}:host([dir=rtl]) .content{padding-right:0}:host([dir=ltr]) .content{text-align:left}:host([dir=rtl]) .content{text-align:right}.content{box-sizing:border-box;display:inline-block;flex:1 1 auto;font-size:var(\n--spectrum-toast-info-text-size,var(--spectrum-global-dimension-font-size-100)\n);font-weight:var(\n--spectrum-toast-info-text-font-weight,var(--spectrum-alias-body-text-font-weight)\n);line-height:var(\n--spectrum-toast-info-text-line-height,var(--spectrum-alias-component-text-line-height)\n);padding-bottom:var(--spectrum-toast-content-padding-bottom);padding-top:var(\n--spectrum-toast-neutral-content-padding-top,var(--spectrum-global-dimension-size-65)\n)}.buttons{align-items:flex-start;display:flex;flex:0 0 auto}:host([dir=ltr]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=ltr]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=ltr]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=ltr]) .buttons slot[name=action]+::slotted([slot=action]){margin-left:var(\n--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)\n)}:host([dir=rtl]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=rtl]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=rtl]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=rtl]) .buttons slot[name=action]+::slotted([slot=action]){margin-right:var(\n--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)\n)}.body{align-self:center;flex:1 1 auto}:host([dir=ltr]) .body ::slotted([slot=action]){float:right}:host([dir=rtl]) .body ::slotted([slot=action]){float:left}:host([dir=ltr]) .body ::slotted([slot=action]){margin-right:var(\n--spectrum-toast-button-margin-right\n)}:host([dir=rtl]) .body ::slotted([slot=action]){margin-left:var(\n--spectrum-toast-button-margin-right\n)}:host([dir=ltr]) .body+.buttons{padding-left:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=rtl]) .body+.buttons{padding-right:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=ltr]) .body+.buttons{border-left-width:1px}:host([dir=rtl]) .body+.buttons{border-right-width:1px}:host([dir=ltr]) .body+.buttons{border-left-style:solid}:host([dir=rtl]) .body+.buttons{border-right-style:solid}:host{background-color:var(\n--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)\n);color:var(\n--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)\n)}.content{color:var(\n--spectrum-toast-neutral-text-color,var(--spectrum-global-color-static-white)\n)}.type{color:#fff}:host([dir=ltr]) .buttons{border-left-color:hsla(0,0%,100%,.2)}:host([dir=rtl]) .buttons{border-right-color:hsla(0,0%,100%,.2)}:host([variant=error]),:host([variant=negative]){background-color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n);color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n)}:host([variant=error]) .closeButton.focus-visible:not(:active),:host([variant=negative]) .closeButton.focus-visible:not(:active){color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n)}:host([variant=error]) .closeButton:focus-visible:not(:active),:host([variant=negative]) .closeButton:focus-visible:not(:active){color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n)}:host([variant=info]){background-color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n);color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n)}:host([variant=info]) .closeButton.focus-visible:not(:active){color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n)}:host([variant=info]) .closeButton:focus-visible:not(:active){color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n)}:host([variant=positive]),:host([variant=success]){background-color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n);color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n)}:host([variant=positive]) .closeButton.focus-visible:not(:active),:host([variant=success]) .closeButton.focus-visible:not(:active){color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n)}:host([variant=positive]) .closeButton:focus-visible:not(:active),:host([variant=success]) .closeButton:focus-visible:not(:active){color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n)}\n`;\nexport default styles;"]}
|
package/src/toast.css.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { css } from '@spectrum-web-components/base';
|
|
13
|
+
const styles = css `
|
|
14
|
+
:host{--spectrum-toast-icon-padding-y:var(
|
|
15
|
+
--spectrum-global-dimension-size-85
|
|
16
|
+
);--spectrum-toast-neutral-content-padding-top:var(
|
|
17
|
+
--spectrum-global-dimension-size-65
|
|
18
|
+
);--spectrum-toast-content-padding-bottom:var(
|
|
19
|
+
--spectrum-global-dimension-size-65
|
|
20
|
+
);--spectrum-toast-button-margin-right:var(
|
|
21
|
+
--spectrum-global-dimension-size-130
|
|
22
|
+
)}:host([dir=ltr]){padding-right:var(
|
|
23
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
24
|
+
)}:host([dir=rtl]){padding-left:var(
|
|
25
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
26
|
+
)}:host([dir=ltr]){padding-left:var(
|
|
27
|
+
--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)
|
|
28
|
+
)}:host([dir=rtl]){padding-right:var(
|
|
29
|
+
--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)
|
|
30
|
+
)}:host{-webkit-font-smoothing:antialiased;align-items:stretch;border-radius:var(
|
|
31
|
+
--spectrum-toast-neutral-border-radius,var(--spectrum-alias-border-radius-regular)
|
|
32
|
+
);box-sizing:border-box;display:inline-flex;flex-direction:row;font-size:var(
|
|
33
|
+
--spectrum-toast-neutral-text-size,var(--spectrum-global-dimension-font-size-100)
|
|
34
|
+
);font-weight:var(
|
|
35
|
+
--spectrum-toast-neutral-text-font-weight,var(--spectrum-alias-body-text-font-weight)
|
|
36
|
+
);padding-bottom:var(
|
|
37
|
+
--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)
|
|
38
|
+
);padding-top:var(
|
|
39
|
+
--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)
|
|
40
|
+
)}:host([dir=ltr]) .type{margin-right:var(
|
|
41
|
+
--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)
|
|
42
|
+
)}:host([dir=rtl]) .type{margin-left:var(
|
|
43
|
+
--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)
|
|
44
|
+
)}:host([dir=ltr]) .type{margin-left:0}:host([dir=rtl]) .type{margin-right:0}.type{flex-grow:0;flex-shrink:0;margin-bottom:var(--spectrum-toast-icon-padding-y);margin-top:var(--spectrum-toast-icon-padding-y)}:host([dir=ltr]) .content{padding-right:var(
|
|
45
|
+
--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)
|
|
46
|
+
)}:host([dir=rtl]) .content{padding-left:var(
|
|
47
|
+
--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)
|
|
48
|
+
)}:host([dir=ltr]) .content{padding-left:0}:host([dir=rtl]) .content{padding-right:0}:host([dir=ltr]) .content{text-align:left}:host([dir=rtl]) .content{text-align:right}.content{box-sizing:border-box;display:inline-block;flex:1 1 auto;font-size:var(
|
|
49
|
+
--spectrum-toast-info-text-size,var(--spectrum-global-dimension-font-size-100)
|
|
50
|
+
);font-weight:var(
|
|
51
|
+
--spectrum-toast-info-text-font-weight,var(--spectrum-alias-body-text-font-weight)
|
|
52
|
+
);line-height:var(
|
|
53
|
+
--spectrum-toast-info-text-line-height,var(--spectrum-alias-component-text-line-height)
|
|
54
|
+
);padding-bottom:var(--spectrum-toast-content-padding-bottom);padding-top:var(
|
|
55
|
+
--spectrum-toast-neutral-content-padding-top,var(--spectrum-global-dimension-size-65)
|
|
56
|
+
)}.buttons{align-items:flex-start;display:flex;flex:0 0 auto}:host([dir=ltr]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=ltr]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=ltr]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=ltr]) .buttons slot[name=action]+::slotted([slot=action]){margin-left:var(
|
|
57
|
+
--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)
|
|
58
|
+
)}:host([dir=rtl]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=rtl]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=rtl]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=rtl]) .buttons slot[name=action]+::slotted([slot=action]){margin-right:var(
|
|
59
|
+
--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)
|
|
60
|
+
)}.body{align-self:center;flex:1 1 auto}:host([dir=ltr]) .body ::slotted([slot=action]){float:right}:host([dir=rtl]) .body ::slotted([slot=action]){float:left}:host([dir=ltr]) .body ::slotted([slot=action]){margin-right:var(
|
|
61
|
+
--spectrum-toast-button-margin-right
|
|
62
|
+
)}:host([dir=rtl]) .body ::slotted([slot=action]){margin-left:var(
|
|
63
|
+
--spectrum-toast-button-margin-right
|
|
64
|
+
)}:host([dir=ltr]) .body+.buttons{padding-left:var(
|
|
65
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
66
|
+
)}:host([dir=rtl]) .body+.buttons{padding-right:var(
|
|
67
|
+
--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)
|
|
68
|
+
)}:host([dir=ltr]) .body+.buttons{border-left-width:1px}:host([dir=rtl]) .body+.buttons{border-right-width:1px}:host([dir=ltr]) .body+.buttons{border-left-style:solid}:host([dir=rtl]) .body+.buttons{border-right-style:solid}:host{background-color:var(
|
|
69
|
+
--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)
|
|
70
|
+
);color:var(
|
|
71
|
+
--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)
|
|
72
|
+
)}.content{color:var(
|
|
73
|
+
--spectrum-toast-neutral-text-color,var(--spectrum-global-color-static-white)
|
|
74
|
+
)}.type{color:#fff}:host([dir=ltr]) .buttons{border-left-color:hsla(0,0%,100%,.2)}:host([dir=rtl]) .buttons{border-right-color:hsla(0,0%,100%,.2)}:host([variant=error]),:host([variant=negative]){background-color:var(
|
|
75
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
76
|
+
);color:var(
|
|
77
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
78
|
+
)}:host([variant=error]) .closeButton.focus-visible:not(:active),:host([variant=negative]) .closeButton.focus-visible:not(:active){color:var(
|
|
79
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
80
|
+
)}:host([variant=error]) .closeButton:focus-visible:not(:active),:host([variant=negative]) .closeButton:focus-visible:not(:active){color:var(
|
|
81
|
+
--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)
|
|
82
|
+
)}:host([variant=info]){background-color:var(
|
|
83
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
84
|
+
);color:var(
|
|
85
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
86
|
+
)}:host([variant=info]) .closeButton.focus-visible:not(:active){color:var(
|
|
87
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
88
|
+
)}:host([variant=info]) .closeButton:focus-visible:not(:active){color:var(
|
|
89
|
+
--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)
|
|
90
|
+
)}:host([variant=positive]),:host([variant=success]){background-color:var(
|
|
91
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
92
|
+
);color:var(
|
|
93
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
94
|
+
)}:host([variant=positive]) .closeButton.focus-visible:not(:active),:host([variant=success]) .closeButton.focus-visible:not(:active){color:var(
|
|
95
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
96
|
+
)}:host([variant=positive]) .closeButton:focus-visible:not(:active),:host([variant=success]) .closeButton:focus-visible:not(:active){color:var(
|
|
97
|
+
--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)
|
|
98
|
+
)}.content{line-height:1.5}:host(:not([open])){display:none}
|
|
99
|
+
`;
|
|
100
|
+
export default styles;
|
|
101
|
+
//# sourceMappingURL=toast.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.css.js","sourceRoot":"","sources":["toast.css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFjB,CAAC;AACF,eAAe,MAAM,CAAC","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{--spectrum-toast-icon-padding-y:var(\n--spectrum-global-dimension-size-85\n);--spectrum-toast-neutral-content-padding-top:var(\n--spectrum-global-dimension-size-65\n);--spectrum-toast-content-padding-bottom:var(\n--spectrum-global-dimension-size-65\n);--spectrum-toast-button-margin-right:var(\n--spectrum-global-dimension-size-130\n)}:host([dir=ltr]){padding-right:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=rtl]){padding-left:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=ltr]){padding-left:var(\n--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)\n)}:host([dir=rtl]){padding-right:var(\n--spectrum-toast-neutral-padding-left,var(--spectrum-global-dimension-size-200)\n)}:host{-webkit-font-smoothing:antialiased;align-items:stretch;border-radius:var(\n--spectrum-toast-neutral-border-radius,var(--spectrum-alias-border-radius-regular)\n);box-sizing:border-box;display:inline-flex;flex-direction:row;font-size:var(\n--spectrum-toast-neutral-text-size,var(--spectrum-global-dimension-font-size-100)\n);font-weight:var(\n--spectrum-toast-neutral-text-font-weight,var(--spectrum-alias-body-text-font-weight)\n);padding-bottom:var(\n--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)\n);padding-top:var(\n--spectrum-toast-neutral-padding-y,var(--spectrum-global-dimension-size-100)\n)}:host([dir=ltr]) .type{margin-right:var(\n--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)\n)}:host([dir=rtl]) .type{margin-left:var(\n--spectrum-toast-neutral-icon-padding-right,var(--spectrum-global-dimension-size-150)\n)}:host([dir=ltr]) .type{margin-left:0}:host([dir=rtl]) .type{margin-right:0}.type{flex-grow:0;flex-shrink:0;margin-bottom:var(--spectrum-toast-icon-padding-y);margin-top:var(--spectrum-toast-icon-padding-y)}:host([dir=ltr]) .content{padding-right:var(\n--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)\n)}:host([dir=rtl]) .content{padding-left:var(\n--spectrum-toast-neutral-content-padding-right,var(--spectrum-global-dimension-size-200)\n)}:host([dir=ltr]) .content{padding-left:0}:host([dir=rtl]) .content{padding-right:0}:host([dir=ltr]) .content{text-align:left}:host([dir=rtl]) .content{text-align:right}.content{box-sizing:border-box;display:inline-block;flex:1 1 auto;font-size:var(\n--spectrum-toast-info-text-size,var(--spectrum-global-dimension-font-size-100)\n);font-weight:var(\n--spectrum-toast-info-text-font-weight,var(--spectrum-alias-body-text-font-weight)\n);line-height:var(\n--spectrum-toast-info-text-line-height,var(--spectrum-alias-component-text-line-height)\n);padding-bottom:var(--spectrum-toast-content-padding-bottom);padding-top:var(\n--spectrum-toast-neutral-content-padding-top,var(--spectrum-global-dimension-size-65)\n)}.buttons{align-items:flex-start;display:flex;flex:0 0 auto}:host([dir=ltr]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=ltr]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=ltr]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=ltr]) .buttons slot[name=action]+::slotted([slot=action]){margin-left:var(\n--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)\n)}:host([dir=rtl]) .buttons .spectrum-ClearButton+.spectrum-ClearButton,:host([dir=rtl]) .buttons .spectrum-ClearButton+::slotted([slot=action]),:host([dir=rtl]) .buttons slot[name=action]+.spectrum-ClearButton,:host([dir=rtl]) .buttons slot[name=action]+::slotted([slot=action]){margin-right:var(\n--spectrum-toast-neutral-button-gap-x,var(--spectrum-global-dimension-size-100)\n)}.body{align-self:center;flex:1 1 auto}:host([dir=ltr]) .body ::slotted([slot=action]){float:right}:host([dir=rtl]) .body ::slotted([slot=action]){float:left}:host([dir=ltr]) .body ::slotted([slot=action]){margin-right:var(\n--spectrum-toast-button-margin-right\n)}:host([dir=rtl]) .body ::slotted([slot=action]){margin-left:var(\n--spectrum-toast-button-margin-right\n)}:host([dir=ltr]) .body+.buttons{padding-left:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=rtl]) .body+.buttons{padding-right:var(\n--spectrum-toast-neutral-padding-right,var(--spectrum-global-dimension-size-100)\n)}:host([dir=ltr]) .body+.buttons{border-left-width:1px}:host([dir=rtl]) .body+.buttons{border-right-width:1px}:host([dir=ltr]) .body+.buttons{border-left-style:solid}:host([dir=rtl]) .body+.buttons{border-right-style:solid}:host{background-color:var(\n--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)\n);color:var(\n--spectrum-toast-neutral-background-color,var(--spectrum-semantic-neutral-background-color-default)\n)}.content{color:var(\n--spectrum-toast-neutral-text-color,var(--spectrum-global-color-static-white)\n)}.type{color:#fff}:host([dir=ltr]) .buttons{border-left-color:hsla(0,0%,100%,.2)}:host([dir=rtl]) .buttons{border-right-color:hsla(0,0%,100%,.2)}:host([variant=error]),:host([variant=negative]){background-color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n);color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n)}:host([variant=error]) .closeButton.focus-visible:not(:active),:host([variant=negative]) .closeButton.focus-visible:not(:active){color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n)}:host([variant=error]) .closeButton:focus-visible:not(:active),:host([variant=negative]) .closeButton:focus-visible:not(:active){color:var(\n--spectrum-toast-negative-background-color,var(--spectrum-semantic-negative-background-color)\n)}:host([variant=info]){background-color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n);color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n)}:host([variant=info]) .closeButton.focus-visible:not(:active){color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n)}:host([variant=info]) .closeButton:focus-visible:not(:active){color:var(\n--spectrum-toast-info-background-color,var(--spectrum-semantic-informative-background-color)\n)}:host([variant=positive]),:host([variant=success]){background-color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n);color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n)}:host([variant=positive]) .closeButton.focus-visible:not(:active),:host([variant=success]) .closeButton.focus-visible:not(:active){color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n)}:host([variant=positive]) .closeButton:focus-visible:not(:active),:host([variant=success]) .closeButton:focus-visible:not(:active){color:var(\n--spectrum-toast-positive-background-color,var(--spectrum-semantic-positive-background-color)\n)}.content{line-height:1.5}:host(:not([open])){display:none}\n`;\nexport default styles;"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { html } from '@spectrum-web-components/base';
|
|
13
|
+
import '../sp-toast.js';
|
|
14
|
+
import '@spectrum-web-components/button/sp-button.js';
|
|
15
|
+
const toast = ({ variant = '', open = true, content = '', }) => html `
|
|
16
|
+
<sp-toast
|
|
17
|
+
variant=${variant}
|
|
18
|
+
?open=${open}
|
|
19
|
+
>
|
|
20
|
+
${content}
|
|
21
|
+
<sp-button slot="action" variant="overBackground" quiet>Undo</sp-button>
|
|
22
|
+
</sp-toast>
|
|
23
|
+
`;
|
|
24
|
+
export default {
|
|
25
|
+
component: 'sp-toast',
|
|
26
|
+
title: 'Toast',
|
|
27
|
+
args: {
|
|
28
|
+
content: 'This is a toast message.',
|
|
29
|
+
open: true,
|
|
30
|
+
},
|
|
31
|
+
argTypes: {
|
|
32
|
+
content: {
|
|
33
|
+
name: 'content',
|
|
34
|
+
type: { name: 'string', required: false },
|
|
35
|
+
table: {
|
|
36
|
+
type: { summary: 'string' },
|
|
37
|
+
defaultValue: { summary: '' },
|
|
38
|
+
},
|
|
39
|
+
control: 'text',
|
|
40
|
+
},
|
|
41
|
+
open: {
|
|
42
|
+
name: 'open',
|
|
43
|
+
type: { name: 'boolean', required: false },
|
|
44
|
+
description: 'Whether the toast is open.',
|
|
45
|
+
table: {
|
|
46
|
+
type: { summary: 'boolean' },
|
|
47
|
+
defaultValue: { summary: false },
|
|
48
|
+
},
|
|
49
|
+
control: {
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export const Default = ({ variant, open, content, }) => {
|
|
56
|
+
return toast({ variant, open, content });
|
|
57
|
+
};
|
|
58
|
+
const variantDemo = ({ variant, open, content, }) => {
|
|
59
|
+
return toast({ variant, open, content });
|
|
60
|
+
};
|
|
61
|
+
export const Positive = (args) => variantDemo(Object.assign(Object.assign({}, args), { variant: 'positive' }));
|
|
62
|
+
export const Negative = (args) => variantDemo(Object.assign(Object.assign({}, args), { variant: 'negative' }));
|
|
63
|
+
export const Info = (args) => variantDemo(Object.assign(Object.assign({}, args), { variant: 'info' }));
|
|
64
|
+
//# sourceMappingURL=toast.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.stories.js","sourceRoot":"","sources":["toast.stories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,IAAI,EAAkB,MAAM,+BAA+B,CAAC;AAErE,OAAO,gBAAgB,CAAC;AACxB,OAAO,8CAA8C,CAAC;AAEtD,MAAM,KAAK,GAAG,CAAC,EACX,OAAO,GAAG,EAAE,EACZ,IAAI,GAAG,IAAI,EACX,OAAO,GAAG,EAAE,GACf,EAAkB,EAAE,CAAC,IAAI,CAAA;;kBAER,OAMK;gBACP,IA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CAAM,IAAI,KAAE,OAAO,EAAE,UAAU,IAAG,CAAC;AAElD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAgB,EAAkB,EAAE,CACzD,WAAW,iCAAM,IAAI,KAAE,OAAO,EAAE,UAAU,IAAG,CAAC;AAElD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,IAAgB,EAAkB,EAAE,CACrD,WAAW,iCAAM,IAAI,KAAE,OAAO,EAAE,MAAM,IAAG,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { html, TemplateResult } from '@spectrum-web-components/base';\n\nimport '../sp-toast.js';\nimport '@spectrum-web-components/button/sp-button.js';\n\nconst toast = ({\n variant = '',\n open = true,\n content = '',\n}): TemplateResult => html`\n <sp-toast\n variant=${variant as\n | ''\n | 'negative'\n | 'positive'\n | 'info'\n | 'error'\n | 'warning'}\n ?open=${open}\n >\n ${content}\n <sp-button slot=\"action\" variant=\"overBackground\" quiet>Undo</sp-button>\n </sp-toast>\n`;\n\nexport default {\n component: 'sp-toast',\n title: 'Toast',\n args: {\n content: 'This is a toast message.',\n open: true,\n },\n argTypes: {\n content: {\n name: 'content',\n type: { name: 'string', required: false },\n table: {\n type: { summary: 'string' },\n defaultValue: { summary: '' },\n },\n control: 'text',\n },\n open: {\n name: 'open',\n type: { name: 'boolean', required: false },\n description: 'Whether the toast is open.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n },\n};\n\ninterface Properties {\n variant: '' | 'negative' | 'positive' | 'info' | 'error' | 'warning';\n open: boolean;\n content: string;\n onClose: (event: Event) => void;\n}\n\nexport const Default = ({\n variant,\n open,\n content,\n}: Properties): TemplateResult => {\n return toast({ variant, open, content });\n};\n\nconst variantDemo = ({\n variant,\n open,\n content,\n}: Properties): TemplateResult => {\n return toast({ variant, open, content });\n};\n\nexport const Positive = (args: Properties): TemplateResult =>\n variantDemo({ ...args, variant: 'positive' });\n\nexport const Negative = (args: Properties): TemplateResult =>\n variantDemo({ ...args, variant: 'negative' });\n\nexport const Info = (args: Properties): TemplateResult =>\n variantDemo({ ...args, variant: 'info' });\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import '@spectrum-web-components/toast/sp-toast.js';
|
|
13
|
+
import { html } from 'lit';
|
|
14
|
+
import { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';
|
|
15
|
+
measureFixtureCreation(html `
|
|
16
|
+
<sp-toast>Tip me!</sp-toast>
|
|
17
|
+
`);
|
|
18
|
+
//# sourceMappingURL=test-basic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-basic.js","sourceRoot":"","sources":["test-basic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,4CAA4C,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,sBAAsB,CAAC,IAAI,CAAA;;CAE1B,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/toast/sp-toast.js';\nimport { html } from 'lit';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-toast>Tip me!</sp-toast>\n`);\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import * as stories from '../stories/toast.stories.js';
|
|
13
|
+
import { regressVisuals } from '../../../test/visual/test.js';
|
|
14
|
+
regressVisuals('ToastStories', stories);
|
|
15
|
+
//# sourceMappingURL=toast.test-vrt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.test-vrt.js","sourceRoot":"","sources":["toast.test-vrt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,cAAc,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/toast.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\n\nregressVisuals('ToastStories', stories);\n"]}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import '../sp-toast.js';
|
|
13
|
+
import { toastVariants } from '../';
|
|
14
|
+
import { elementUpdated, expect, fixture, html, nextFrame, waitUntil, } from '@open-wc/testing';
|
|
15
|
+
import { waitForPredicate } from '../../../test/testing-helpers.js';
|
|
16
|
+
import { spy } from 'sinon';
|
|
17
|
+
describe('Toast', () => {
|
|
18
|
+
it('loads', async () => {
|
|
19
|
+
const el = await fixture(html `
|
|
20
|
+
<sp-toast open>Help text.</sp-toast>
|
|
21
|
+
`);
|
|
22
|
+
await elementUpdated(el);
|
|
23
|
+
await expect(el).to.be.accessible();
|
|
24
|
+
});
|
|
25
|
+
toastVariants.map((variant) => {
|
|
26
|
+
it(`loads - [variant="${variant}"]`, async () => {
|
|
27
|
+
const el = await fixture(html `
|
|
28
|
+
<sp-toast variant=${variant} open>
|
|
29
|
+
This toast is of the \`${variant}\` variant.
|
|
30
|
+
</sp-toast>
|
|
31
|
+
`);
|
|
32
|
+
await elementUpdated(el);
|
|
33
|
+
await expect(el).to.be.accessible();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it('loads - timeout', async () => {
|
|
37
|
+
const el = await fixture(html `
|
|
38
|
+
<sp-toast timeout="100">Help text.</sp-toast>
|
|
39
|
+
`);
|
|
40
|
+
await elementUpdated(el);
|
|
41
|
+
expect(el.open).to.be.false;
|
|
42
|
+
el._timeout = 100;
|
|
43
|
+
el.open = true;
|
|
44
|
+
await elementUpdated(el);
|
|
45
|
+
await waitForPredicate(() => el.open === false);
|
|
46
|
+
expect(el.open).to.be.false;
|
|
47
|
+
});
|
|
48
|
+
it('`timeout` updates `countdownStart`', async () => {
|
|
49
|
+
const el = await fixture(html `
|
|
50
|
+
<sp-toast timeout="100">Help text.</sp-toast>
|
|
51
|
+
`);
|
|
52
|
+
await elementUpdated(el);
|
|
53
|
+
expect(el.open).to.be.false;
|
|
54
|
+
const testableEl = el;
|
|
55
|
+
testableEl._timeout = 100;
|
|
56
|
+
el.open = true;
|
|
57
|
+
await elementUpdated(el);
|
|
58
|
+
const firstStart = testableEl.countdownStart;
|
|
59
|
+
await nextFrame();
|
|
60
|
+
await nextFrame();
|
|
61
|
+
await nextFrame();
|
|
62
|
+
el.timeout = 400;
|
|
63
|
+
await elementUpdated(el);
|
|
64
|
+
const secondStart = testableEl.countdownStart;
|
|
65
|
+
expect(secondStart).to.not.equal(firstStart);
|
|
66
|
+
await nextFrame();
|
|
67
|
+
await nextFrame();
|
|
68
|
+
el.timeout = 0;
|
|
69
|
+
await elementUpdated(el);
|
|
70
|
+
const thirdStart = testableEl.countdownStart;
|
|
71
|
+
expect(thirdStart).to.equal(0);
|
|
72
|
+
});
|
|
73
|
+
it('stops timeout on `focusin`', async () => {
|
|
74
|
+
const el = await fixture(html `
|
|
75
|
+
<sp-toast timeout="100">Help text.</sp-toast>
|
|
76
|
+
`);
|
|
77
|
+
await elementUpdated(el);
|
|
78
|
+
const testableEl = el;
|
|
79
|
+
expect(el.open, 'not open to start').to.be.false;
|
|
80
|
+
el.open = true;
|
|
81
|
+
await elementUpdated(el);
|
|
82
|
+
await nextFrame();
|
|
83
|
+
expect(testableEl.countdownStart, 'initially not 0').to.not.equal(0);
|
|
84
|
+
testableEl._timeout = 100;
|
|
85
|
+
el.dispatchEvent(new FocusEvent('focusin'));
|
|
86
|
+
await elementUpdated(el);
|
|
87
|
+
expect(testableEl.countdownStart, '0 after focusin').to.equal(0);
|
|
88
|
+
el.dispatchEvent(new FocusEvent('focusout'));
|
|
89
|
+
await elementUpdated(el);
|
|
90
|
+
await nextFrame();
|
|
91
|
+
expect(testableEl.countdownStart, 'not 0 after focusout').to.not.equal(0);
|
|
92
|
+
await waitUntil(() => el.open === false, 'closes');
|
|
93
|
+
expect(el.open, 'not open to end').to.be.false;
|
|
94
|
+
});
|
|
95
|
+
it('closes', async () => {
|
|
96
|
+
const el = await fixture(html `
|
|
97
|
+
<sp-toast open>Help text.</sp-toast>
|
|
98
|
+
`);
|
|
99
|
+
await elementUpdated(el);
|
|
100
|
+
expect(el.open).to.be.true;
|
|
101
|
+
const renderRoot = el.shadowRoot ? el.shadowRoot : el;
|
|
102
|
+
const closeButton = renderRoot.querySelector('sp-close-button');
|
|
103
|
+
closeButton.click();
|
|
104
|
+
await elementUpdated(el);
|
|
105
|
+
expect(el.open).to.be.false;
|
|
106
|
+
});
|
|
107
|
+
it('`close` can be prevented', async () => {
|
|
108
|
+
const handleClose = (event) => event.preventDefault();
|
|
109
|
+
const el = await fixture(html `
|
|
110
|
+
<sp-toast open timeout="100" @close=${handleClose}>
|
|
111
|
+
Help text.
|
|
112
|
+
</sp-toast>
|
|
113
|
+
`);
|
|
114
|
+
await elementUpdated(el);
|
|
115
|
+
expect(el.open).to.be.true;
|
|
116
|
+
const renderRoot = el.shadowRoot ? el.shadowRoot : el;
|
|
117
|
+
const closeButton = renderRoot.querySelector('sp-close-button');
|
|
118
|
+
closeButton.click();
|
|
119
|
+
await elementUpdated(el);
|
|
120
|
+
expect(el.open).to.be.true;
|
|
121
|
+
});
|
|
122
|
+
it('can be a controlled element', async () => {
|
|
123
|
+
const closeSpy = spy();
|
|
124
|
+
const handleClose = (event) => {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
closeSpy();
|
|
127
|
+
};
|
|
128
|
+
const el = await fixture(html `
|
|
129
|
+
<sp-toast open timeout="100" @close=${handleClose}>
|
|
130
|
+
Help text.
|
|
131
|
+
</sp-toast>
|
|
132
|
+
`);
|
|
133
|
+
await elementUpdated(el);
|
|
134
|
+
expect(el.open).to.be.true;
|
|
135
|
+
expect(closeSpy.callCount).to.equal(0);
|
|
136
|
+
const renderRoot = el.shadowRoot ? el.shadowRoot : el;
|
|
137
|
+
const closeButton = renderRoot.querySelector('sp-close-button');
|
|
138
|
+
closeButton.click();
|
|
139
|
+
await elementUpdated(el);
|
|
140
|
+
expect(el.open).to.be.true;
|
|
141
|
+
expect(closeSpy.callCount).to.equal(1);
|
|
142
|
+
el.open = false;
|
|
143
|
+
await elementUpdated(el);
|
|
144
|
+
expect(el.open).to.be.false;
|
|
145
|
+
expect(closeSpy.callCount).to.equal(1);
|
|
146
|
+
});
|
|
147
|
+
it('validates variants', async () => {
|
|
148
|
+
const el = await fixture(html `
|
|
149
|
+
<sp-toast variant="invalid" open>
|
|
150
|
+
This toast validates variants.
|
|
151
|
+
</sp-toast>
|
|
152
|
+
`);
|
|
153
|
+
await elementUpdated(el);
|
|
154
|
+
expect(el.variant).to.equal('');
|
|
155
|
+
el.variant = toastVariants[0];
|
|
156
|
+
await elementUpdated(el);
|
|
157
|
+
expect(el.variant).to.equal(toastVariants[0]);
|
|
158
|
+
el.variant = toastVariants[0];
|
|
159
|
+
await elementUpdated(el);
|
|
160
|
+
expect(el.variant).to.equal(toastVariants[0]);
|
|
161
|
+
});
|
|
162
|
+
it('maintains [variant] when disconnected/connected', async () => {
|
|
163
|
+
const el = await fixture(html `
|
|
164
|
+
<sp-toast variant="positive" open>
|
|
165
|
+
This toast maintains variants.
|
|
166
|
+
</sp-toast>
|
|
167
|
+
`);
|
|
168
|
+
await elementUpdated(el);
|
|
169
|
+
expect(el.variant).to.equal('positive');
|
|
170
|
+
const parent = el.parentElement;
|
|
171
|
+
el.remove();
|
|
172
|
+
expect(el.variant).to.equal('positive');
|
|
173
|
+
parent.append(el);
|
|
174
|
+
expect(el.variant).to.equal('positive');
|
|
175
|
+
});
|
|
176
|
+
it('reopens', async () => {
|
|
177
|
+
const closeSpy = spy();
|
|
178
|
+
const el = await fixture(html `
|
|
179
|
+
<sp-toast
|
|
180
|
+
variant="positive"
|
|
181
|
+
open
|
|
182
|
+
@close=${() => {
|
|
183
|
+
closeSpy();
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
This toast maintains variants.
|
|
187
|
+
</sp-toast>
|
|
188
|
+
`);
|
|
189
|
+
await elementUpdated(el);
|
|
190
|
+
expect(el.open).to.be.true;
|
|
191
|
+
const closeButton = el.shadowRoot.querySelector('sp-close-button');
|
|
192
|
+
closeButton.click();
|
|
193
|
+
await elementUpdated(el);
|
|
194
|
+
expect(el.open).to.be.false;
|
|
195
|
+
el.open = true;
|
|
196
|
+
await elementUpdated(el);
|
|
197
|
+
expect(el.open).to.be.true;
|
|
198
|
+
expect(closeSpy.callCount).to.equal(1);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=toast.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.test.js","sourceRoot":"","sources":["toast.test.ts"],"names":[],"m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AAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '../sp-toast.js';\nimport { Toast, toastVariants } from '../';\nimport {\n elementUpdated,\n expect,\n fixture,\n html,\n nextFrame,\n waitUntil,\n} from '@open-wc/testing';\nimport { CloseButton } from '@spectrum-web-components/button';\nimport { waitForPredicate } from '../../../test/testing-helpers.js';\nimport { spy } from 'sinon';\n\ninterface TestableToast {\n _timeout: number;\n countdownStart: number;\n}\n\ndescribe('Toast', () => {\n it('loads', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast open>Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n toastVariants.map((variant) => {\n it(`loads - [variant=\"${variant}\"]`, async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast variant=${variant} open>\n This toast is of the \\`${variant}\\` variant.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n });\n it('loads - timeout', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast timeout=\"100\">Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n\n (el as unknown as TestableToast)._timeout = 100;\n el.open = true;\n await elementUpdated(el);\n\n await waitForPredicate(() => el.open === false);\n expect(el.open).to.be.false;\n });\n it('`timeout` updates `countdownStart`', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast timeout=\"100\">Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n\n const testableEl = el as unknown as TestableToast;\n testableEl._timeout = 100;\n el.open = true;\n await elementUpdated(el);\n\n const firstStart = testableEl.countdownStart;\n\n await nextFrame();\n await nextFrame();\n await nextFrame();\n\n el.timeout = 400;\n\n await elementUpdated(el);\n const secondStart = testableEl.countdownStart;\n\n expect(secondStart).to.not.equal(firstStart);\n\n await nextFrame();\n await nextFrame();\n\n el.timeout = 0;\n\n await elementUpdated(el);\n const thirdStart = testableEl.countdownStart;\n\n expect(thirdStart).to.equal(0);\n });\n it('stops timeout on `focusin`', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast timeout=\"100\">Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n\n const testableEl = el as unknown as TestableToast;\n expect(el.open, 'not open to start').to.be.false;\n\n el.open = true;\n await elementUpdated(el);\n await nextFrame();\n\n expect(testableEl.countdownStart, 'initially not 0').to.not.equal(0);\n\n testableEl._timeout = 100;\n\n el.dispatchEvent(new FocusEvent('focusin'));\n\n await elementUpdated(el);\n expect(testableEl.countdownStart, '0 after focusin').to.equal(0);\n el.dispatchEvent(new FocusEvent('focusout'));\n\n await elementUpdated(el);\n await nextFrame();\n expect(testableEl.countdownStart, 'not 0 after focusout').to.not.equal(\n 0\n );\n\n await waitUntil(() => el.open === false, 'closes');\n expect(el.open, 'not open to end').to.be.false;\n });\n it('closes', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast open>Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n\n const renderRoot = el.shadowRoot ? el.shadowRoot : el;\n const closeButton = renderRoot.querySelector(\n 'sp-close-button'\n ) as CloseButton;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n });\n it('`close` can be prevented', async () => {\n const handleClose = (event: CustomEvent): void =>\n event.preventDefault();\n const el = await fixture<Toast>(\n html`\n <sp-toast open timeout=\"100\" @close=${handleClose}>\n Help text.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n\n const renderRoot = el.shadowRoot ? el.shadowRoot : el;\n const closeButton = renderRoot.querySelector(\n 'sp-close-button'\n ) as CloseButton;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n });\n it('can be a controlled element', async () => {\n const closeSpy = spy();\n const handleClose = (event: CustomEvent): void => {\n event.preventDefault();\n closeSpy();\n };\n const el = await fixture<Toast>(\n html`\n <sp-toast open timeout=\"100\" @close=${handleClose}>\n Help text.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n expect(closeSpy.callCount).to.equal(0);\n\n const renderRoot = el.shadowRoot ? el.shadowRoot : el;\n const closeButton = renderRoot.querySelector(\n 'sp-close-button'\n ) as CloseButton;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n expect(closeSpy.callCount).to.equal(1);\n\n el.open = false;\n await elementUpdated(el);\n expect(el.open).to.be.false;\n expect(closeSpy.callCount).to.equal(1);\n });\n it('validates variants', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast variant=\"invalid\" open>\n This toast validates variants.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.variant).to.equal('');\n\n el.variant = toastVariants[0];\n\n await elementUpdated(el);\n expect(el.variant).to.equal(toastVariants[0]);\n\n el.variant = toastVariants[0];\n\n await elementUpdated(el);\n expect(el.variant).to.equal(toastVariants[0]);\n });\n it('maintains [variant] when disconnected/connected', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast variant=\"positive\" open>\n This toast maintains variants.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.variant).to.equal('positive');\n const parent = el.parentElement as HTMLElement;\n\n el.remove();\n\n expect(el.variant).to.equal('positive');\n\n parent.append(el);\n\n expect(el.variant).to.equal('positive');\n });\n it('reopens', async () => {\n const closeSpy = spy();\n const el = await fixture<Toast>(\n html`\n <sp-toast\n variant=\"positive\"\n open\n @close=${() => {\n closeSpy();\n }}\n >\n This toast maintains variants.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n\n const closeButton = el.shadowRoot.querySelector(\n 'sp-close-button'\n ) as HTMLElement;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n\n el.open = true;\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n expect(closeSpy.callCount).to.equal(1);\n });\n});\n"]}
|