@pure-ds/core 0.3.0
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/CSS-INTELLISENSE-LIMITATION.md +98 -0
- package/CSS-INTELLISENSE-QUICK-REF.md +238 -0
- package/INTELLISENSE.md +384 -0
- package/LICENSE +15 -0
- package/custom-elements-manifest.config.js +30 -0
- package/custom-elements.json +2003 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/packages/pds-configurator/src/figma-export.d.ts +13 -0
- package/dist/types/packages/pds-configurator/src/figma-export.d.ts.map +1 -0
- package/dist/types/packages/pds-configurator/src/pds-config-form.d.ts +2 -0
- package/dist/types/packages/pds-configurator/src/pds-config-form.d.ts.map +1 -0
- package/dist/types/packages/pds-configurator/src/pds-configurator.d.ts +2 -0
- package/dist/types/packages/pds-configurator/src/pds-configurator.d.ts.map +1 -0
- package/dist/types/packages/pds-configurator/src/pds-demo.d.ts +2 -0
- package/dist/types/packages/pds-configurator/src/pds-demo.d.ts.map +1 -0
- package/dist/types/pds.config.d.ts +13 -0
- package/dist/types/pds.config.d.ts.map +1 -0
- package/dist/types/pds.d.ts +408 -0
- package/dist/types/public/assets/js/app.d.ts +2 -0
- package/dist/types/public/assets/js/app.d.ts.map +1 -0
- package/dist/types/public/assets/js/pds.d.ts +23 -0
- package/dist/types/public/assets/js/pds.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-calendar.d.ts +23 -0
- package/dist/types/public/assets/pds/components/pds-calendar.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-drawer.d.ts +2 -0
- package/dist/types/public/assets/pds/components/pds-drawer.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-icon.d.ts +53 -0
- package/dist/types/public/assets/pds/components/pds-icon.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-jsonform.d.ts +104 -0
- package/dist/types/public/assets/pds/components/pds-jsonform.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-richtext.d.ts +121 -0
- package/dist/types/public/assets/pds/components/pds-richtext.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-scrollrow.d.ts +61 -0
- package/dist/types/public/assets/pds/components/pds-scrollrow.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-splitpanel.d.ts +1 -0
- package/dist/types/public/assets/pds/components/pds-splitpanel.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-tabstrip.d.ts +39 -0
- package/dist/types/public/assets/pds/components/pds-tabstrip.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-toaster.d.ts +111 -0
- package/dist/types/public/assets/pds/components/pds-toaster.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-upload.d.ts +83 -0
- package/dist/types/public/assets/pds/components/pds-upload.d.ts.map +1 -0
- package/dist/types/src/js/app.d.ts +2 -0
- package/dist/types/src/js/app.d.ts.map +1 -0
- package/dist/types/src/js/common/ask.d.ts +22 -0
- package/dist/types/src/js/common/ask.d.ts.map +1 -0
- package/dist/types/src/js/common/common.d.ts +3 -0
- package/dist/types/src/js/common/common.d.ts.map +1 -0
- package/dist/types/src/js/common/font-loader.d.ts +24 -0
- package/dist/types/src/js/common/font-loader.d.ts.map +1 -0
- package/dist/types/src/js/common/msg.d.ts +3 -0
- package/dist/types/src/js/common/msg.d.ts.map +1 -0
- package/dist/types/src/js/lit.d.ts +25 -0
- package/dist/types/src/js/lit.d.ts.map +1 -0
- package/dist/types/src/js/pds-configurator/figma-export.d.ts +13 -0
- package/dist/types/src/js/pds-configurator/figma-export.d.ts.map +1 -0
- package/dist/types/src/js/pds-configurator/pds-config-form.d.ts +2 -0
- package/dist/types/src/js/pds-configurator/pds-config-form.d.ts.map +1 -0
- package/dist/types/src/js/pds-configurator/pds-configurator.d.ts +2 -0
- package/dist/types/src/js/pds-configurator/pds-configurator.d.ts.map +1 -0
- package/dist/types/src/js/pds-configurator/pds-demo.d.ts +2 -0
- package/dist/types/src/js/pds-configurator/pds-demo.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-config.d.ts +758 -0
- package/dist/types/src/js/pds-core/pds-config.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-enhancer-metadata.d.ts +6 -0
- package/dist/types/src/js/pds-core/pds-enhancer-metadata.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-enhancers.d.ts +14 -0
- package/dist/types/src/js/pds-core/pds-enhancers.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-enums.d.ts +87 -0
- package/dist/types/src/js/pds-core/pds-enums.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-generator.d.ts +741 -0
- package/dist/types/src/js/pds-core/pds-generator.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-ontology.d.ts +48 -0
- package/dist/types/src/js/pds-core/pds-ontology.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-paths.d.ts +37 -0
- package/dist/types/src/js/pds-core/pds-paths.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-query.d.ts +102 -0
- package/dist/types/src/js/pds-core/pds-query.d.ts.map +1 -0
- package/dist/types/src/js/pds-core/pds-registry.d.ts +40 -0
- package/dist/types/src/js/pds-core/pds-registry.d.ts.map +1 -0
- package/dist/types/src/js/pds.d.ts +109 -0
- package/dist/types/src/js/pds.d.ts.map +1 -0
- package/dist/types/src/pds-core/pds-api.d.ts +31 -0
- package/dist/types/src/pds-core/pds-api.d.ts.map +1 -0
- package/package.json +104 -0
- package/packages/pds-cli/README.md +15 -0
- package/packages/pds-cli/bin/generate-css-data.js +565 -0
- package/packages/pds-cli/bin/generate-manifest.js +352 -0
- package/packages/pds-cli/bin/pds-build-icons.js +152 -0
- package/packages/pds-cli/bin/pds-dx.js +114 -0
- package/packages/pds-cli/bin/pds-static.js +556 -0
- package/packages/pds-cli/bin/pds.js +127 -0
- package/packages/pds-cli/bin/postinstall.js +380 -0
- package/packages/pds-cli/bin/sync-assets.js +252 -0
- package/packages/pds-cli/lib/asset-roots.js +47 -0
- package/packages/pds-cli/lib/fs-writer.js +75 -0
- package/pds.css-data.json +5 -0
- package/pds.html-data.json +5 -0
- package/public/assets/js/app.js +5719 -0
- package/public/assets/js/lit.js +131 -0
- package/public/assets/js/pds.js +3423 -0
- package/public/assets/pds/components/pds-calendar.js +837 -0
- package/public/assets/pds/components/pds-drawer.js +857 -0
- package/public/assets/pds/components/pds-icon.js +338 -0
- package/public/assets/pds/components/pds-jsonform.js +1775 -0
- package/public/assets/pds/components/pds-richtext.js +1035 -0
- package/public/assets/pds/components/pds-scrollrow.js +331 -0
- package/public/assets/pds/components/pds-splitpanel.js +401 -0
- package/public/assets/pds/components/pds-tabstrip.js +251 -0
- package/public/assets/pds/components/pds-toaster.js +446 -0
- package/public/assets/pds/components/pds-upload.js +657 -0
- package/public/assets/pds/custom-elements.json +2003 -0
- package/public/assets/pds/icons/pds-icons.svg +498 -0
- package/public/assets/pds/pds-css-complete.json +1861 -0
- package/public/assets/pds/pds.css-data.json +2152 -0
- package/public/assets/pds/vscode-custom-data.json +824 -0
- package/readme.md +1870 -0
- package/src/js/pds-core/pds-config.js +1162 -0
- package/src/js/pds-core/pds-enhancer-metadata.js +75 -0
- package/src/js/pds-core/pds-enhancers.js +357 -0
- package/src/js/pds-core/pds-enums.js +86 -0
- package/src/js/pds-core/pds-generator.js +5317 -0
- package/src/js/pds-core/pds-ontology.js +256 -0
- package/src/js/pds-core/pds-paths.js +109 -0
- package/src/js/pds-core/pds-query.js +571 -0
- package/src/js/pds-core/pds-registry.js +129 -0
- package/src/js/pds-core/pds.d.ts +129 -0
- package/src/js/pds.d.ts +408 -0
- package/src/js/pds.js +1579 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @element pds-toaster
|
|
3
|
+
* @fires pds:toast - Global event for creating toasts
|
|
4
|
+
*
|
|
5
|
+
* @slot - Toast messages are dynamically added to the shadow DOM
|
|
6
|
+
*
|
|
7
|
+
* @cssprop --z-notification - Z-index for toast positioning (default: 9999)
|
|
8
|
+
* @cssprop --transition-normal - Animation duration for toasts
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <pds-toaster></pds-toaster>
|
|
12
|
+
*
|
|
13
|
+
* // Show toast via API
|
|
14
|
+
* toaster.toast('Hello!', { type: 'success' });
|
|
15
|
+
*
|
|
16
|
+
* // Show toast via event
|
|
17
|
+
* PDS.dispatchEvent(new CustomEvent('pds:toast', {
|
|
18
|
+
* detail: { message: 'Hello!', type: 'success' }
|
|
19
|
+
* }));
|
|
20
|
+
*/
|
|
21
|
+
export class AppToaster extends HTMLElement {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.toasts = [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Prepare styles and begin listening for global `pds:toast` events.
|
|
29
|
+
* @returns {Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
async connectedCallback() {
|
|
32
|
+
// Attach shadow DOM
|
|
33
|
+
this.attachShadow({ mode: "open" });
|
|
34
|
+
|
|
35
|
+
// Listen for global toast events
|
|
36
|
+
this._handleToastEvent = (e) => {
|
|
37
|
+
const { message, type, duration, closable, persistent } = e.detail;
|
|
38
|
+
this.toast(message, { type, duration, closable, persistent });
|
|
39
|
+
};
|
|
40
|
+
PDS.addEventListener('pds:toast', this._handleToastEvent);
|
|
41
|
+
|
|
42
|
+
// Component-specific styles (toaster layer for animations/positioning)
|
|
43
|
+
const componentStyles = PDS.createStylesheet(/*css*/ `
|
|
44
|
+
@layer toaster {
|
|
45
|
+
:host {
|
|
46
|
+
position: fixed;
|
|
47
|
+
top: var(--spacing-4);
|
|
48
|
+
right: var(--spacing-4);
|
|
49
|
+
z-index: var(--z-notification, 9999);
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
gap: var(--spacing-3);
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
max-width: 400px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Toast animations and transitions */
|
|
58
|
+
aside.toast {
|
|
59
|
+
transform: translateX(100%);
|
|
60
|
+
opacity: 0;
|
|
61
|
+
margin-bottom: var(--spacing-3);
|
|
62
|
+
position: relative;
|
|
63
|
+
pointer-events: auto;
|
|
64
|
+
max-height: 500px;
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
box-shadow: var(--shadow-lg);
|
|
67
|
+
transition: transform var(--transition-normal, 0.3s) cubic-bezier(0.175, 0.885, 0.32, 1.275),
|
|
68
|
+
opacity var(--transition-normal, 0.3s) ease-out,
|
|
69
|
+
margin-bottom var(--transition-normal, 0.3s) ease-out,
|
|
70
|
+
max-height var(--transition-normal, 0.3s) ease-out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
aside.toast.show {
|
|
74
|
+
transform: translateX(0);
|
|
75
|
+
opacity: 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Toast dismiss animation */
|
|
79
|
+
aside.toast.dismissing {
|
|
80
|
+
margin-bottom: 0;
|
|
81
|
+
max-height: 0;
|
|
82
|
+
opacity: 0;
|
|
83
|
+
transform: translateX(100%);
|
|
84
|
+
transition: transform var(--transition-normal, 0.3s) ease-out,
|
|
85
|
+
opacity var(--transition-normal, 0.3s) ease-out,
|
|
86
|
+
margin-bottom var(--transition-normal, 0.3s) ease-out,
|
|
87
|
+
max-height var(--transition-normal, 0.3s) ease-out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Toast progress bar */
|
|
91
|
+
aside.toast .toast-progress {
|
|
92
|
+
position: absolute;
|
|
93
|
+
bottom: 0;
|
|
94
|
+
left: 0;
|
|
95
|
+
height: 2px;
|
|
96
|
+
opacity: 0.7;
|
|
97
|
+
transition: width linear;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
aside.toast.alert-info .toast-progress {
|
|
101
|
+
background: var(--color-info-600);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
aside.toast.alert-success .toast-progress {
|
|
105
|
+
background: var(--color-success-600);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
aside.toast.alert-warning .toast-progress {
|
|
109
|
+
background: var(--color-warning-600);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
aside.toast.alert-danger .toast-progress,
|
|
113
|
+
aside.toast.alert-error .toast-progress {
|
|
114
|
+
background: var(--color-danger-600);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Toast shrink animation */
|
|
118
|
+
@keyframes toast-shrink {
|
|
119
|
+
from { width: 100%; }
|
|
120
|
+
to { width: 0%; }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
aside.toast p {
|
|
124
|
+
white-space: pre-line;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* Mobile responsive toast positioning */
|
|
128
|
+
@_media (max-width: 640px) {
|
|
129
|
+
:host {
|
|
130
|
+
top: auto;
|
|
131
|
+
bottom: var(--spacing-4);
|
|
132
|
+
left: var(--spacing-4);
|
|
133
|
+
right: var(--spacing-4);
|
|
134
|
+
max-width: none;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
aside.toast {
|
|
138
|
+
transform: translateY(100%);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
aside.toast.show {
|
|
142
|
+
transform: translateY(0);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
`);
|
|
147
|
+
|
|
148
|
+
// Adopt primitives (buttons), components (.alert classes), and toaster-specific styles
|
|
149
|
+
await PDS.adoptLayers(
|
|
150
|
+
this.shadowRoot,
|
|
151
|
+
["primitives", "components"],
|
|
152
|
+
[componentStyles]
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Remove toast event listeners when disconnected.
|
|
158
|
+
*/
|
|
159
|
+
disconnectedCallback() {
|
|
160
|
+
// Clean up event listener
|
|
161
|
+
if (this._handleToastEvent) {
|
|
162
|
+
PDS.removeEventListener('pds:toast', this._handleToastEvent);
|
|
163
|
+
this._handleToastEvent = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Display a toast notification
|
|
169
|
+
* @method toast
|
|
170
|
+
* @public
|
|
171
|
+
* @param {string} message - The message to display
|
|
172
|
+
* @param {Object} [options] - Toast configuration
|
|
173
|
+
* @param {"information"|"success"|"warning"|"error"} [options.type="information"] - Toast type
|
|
174
|
+
* @param {number} [options.duration] - Duration in ms (auto-calculated if not provided)
|
|
175
|
+
* @param {boolean} [options.closable=true] - Whether toast can be closed manually
|
|
176
|
+
* @param {boolean} [options.persistent=false] - If true, toast doesn't auto-dismiss
|
|
177
|
+
* @returns {string} Toast ID
|
|
178
|
+
*/
|
|
179
|
+
toast(message, options = {}) {
|
|
180
|
+
const defaults = {
|
|
181
|
+
type: "information", // information, success, warning, error
|
|
182
|
+
duration: null, // auto-calculated based on reading time
|
|
183
|
+
closable: true,
|
|
184
|
+
persistent: false, // if true, doesn't auto-dismiss
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const config = { ...defaults, ...options };
|
|
188
|
+
|
|
189
|
+
// Calculate reading time (average 200 words per minute)
|
|
190
|
+
const wordCount = message.split(/\s+/).length;
|
|
191
|
+
const baseReadingTime = Math.max(2000, (wordCount / 200) * 60 * 1000); // minimum 2 seconds
|
|
192
|
+
|
|
193
|
+
// Extend time for errors (people need more time to process error messages)
|
|
194
|
+
const multiplier = config.type === "error" ? 1.5 : 1;
|
|
195
|
+
const duration = config.duration || baseReadingTime * multiplier;
|
|
196
|
+
|
|
197
|
+
return this.#showToast(message, config, duration);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/*
|
|
201
|
+
* Internal helper used by shorthand methods to render a toast.
|
|
202
|
+
*/
|
|
203
|
+
#showToast(message, config, duration) {
|
|
204
|
+
// Generate unique ID for this toast
|
|
205
|
+
const toastId = `toast-${Date.now()}-${Math.random()
|
|
206
|
+
.toString(36)
|
|
207
|
+
.substr(2, 9)}`;
|
|
208
|
+
|
|
209
|
+
// Create toast element
|
|
210
|
+
const toastElement = this.createToastElement(
|
|
211
|
+
toastId,
|
|
212
|
+
message,
|
|
213
|
+
config.type,
|
|
214
|
+
config.closable,
|
|
215
|
+
duration,
|
|
216
|
+
config.persistent
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// Add to DOM
|
|
220
|
+
this.shadowRoot.appendChild(toastElement);
|
|
221
|
+
|
|
222
|
+
// Force reflow to ensure initial state is painted
|
|
223
|
+
void toastElement.offsetHeight;
|
|
224
|
+
|
|
225
|
+
// Trigger animation on next frame
|
|
226
|
+
requestAnimationFrame(() => {
|
|
227
|
+
toastElement.classList.add("show");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// Auto-dismiss if not persistent
|
|
231
|
+
if (!config.persistent) {
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
this.dismissToast(toastId);
|
|
234
|
+
}, duration);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return toastId;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Build a DOM node representing a single toast notification.
|
|
242
|
+
* @param {string} id
|
|
243
|
+
* @param {string} message
|
|
244
|
+
* @param {"information"|"success"|"warning"|"error"} type
|
|
245
|
+
* @param {boolean} closable
|
|
246
|
+
* @param {number} duration
|
|
247
|
+
* @param {boolean} persistent
|
|
248
|
+
* @returns {HTMLElement}
|
|
249
|
+
*/
|
|
250
|
+
createToastElement(id, message, type, closable, duration, persistent) {
|
|
251
|
+
const toast = document.createElement("aside");
|
|
252
|
+
toast.className = `toast alert ${this.#getAlertClass(type)}`;
|
|
253
|
+
toast.setAttribute("data-toast-id", id);
|
|
254
|
+
toast.setAttribute("role", "status");
|
|
255
|
+
toast.setAttribute("aria-live", "polite");
|
|
256
|
+
|
|
257
|
+
const icon = document.createElement("pds-icon");
|
|
258
|
+
icon.className = "alert-icon";
|
|
259
|
+
icon.setAttribute("icon", this.#getToastIcon(type));
|
|
260
|
+
icon.setAttribute("size", "lg");
|
|
261
|
+
|
|
262
|
+
const content = document.createElement("div");
|
|
263
|
+
|
|
264
|
+
const title = document.createElement("div");
|
|
265
|
+
title.className = "alert-title";
|
|
266
|
+
title.textContent = this.#getToastTitle(type);
|
|
267
|
+
|
|
268
|
+
const text = document.createElement("p");
|
|
269
|
+
text.style.margin = "0";
|
|
270
|
+
text.textContent = message;
|
|
271
|
+
|
|
272
|
+
content.appendChild(title);
|
|
273
|
+
content.appendChild(text);
|
|
274
|
+
|
|
275
|
+
toast.appendChild(icon);
|
|
276
|
+
toast.appendChild(content);
|
|
277
|
+
|
|
278
|
+
if (closable) {
|
|
279
|
+
const closeBtn = document.createElement("button");
|
|
280
|
+
closeBtn.className = "alert-close";
|
|
281
|
+
closeBtn.setAttribute("aria-label", "Close");
|
|
282
|
+
closeBtn.textContent = "×";
|
|
283
|
+
closeBtn.onclick = () => this.dismissToast(id);
|
|
284
|
+
toast.appendChild(closeBtn);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!persistent) {
|
|
288
|
+
const progress = document.createElement("div");
|
|
289
|
+
progress.className = "toast-progress";
|
|
290
|
+
progress.style.width = "100%";
|
|
291
|
+
progress.style.animation = `toast-shrink ${duration}ms linear`;
|
|
292
|
+
toast.appendChild(progress);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return toast;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Dismiss a toast by ID
|
|
300
|
+
* @method dismissToast
|
|
301
|
+
* @public
|
|
302
|
+
* @param {string} toastId - The ID of the toast to dismiss
|
|
303
|
+
*/
|
|
304
|
+
dismissToast(toastId) {
|
|
305
|
+
const toastElement = this.shadowRoot.querySelector(
|
|
306
|
+
`[data-toast-id="${toastId}"]`
|
|
307
|
+
);
|
|
308
|
+
if (!toastElement) return;
|
|
309
|
+
|
|
310
|
+
// Remove show class and add dismissing class for smooth collapse
|
|
311
|
+
toastElement.classList.remove("show");
|
|
312
|
+
toastElement.classList.add("dismissing");
|
|
313
|
+
|
|
314
|
+
// Remove from DOM after animation completes
|
|
315
|
+
setTimeout(() => {
|
|
316
|
+
if (toastElement.parentNode === this.shadowRoot) {
|
|
317
|
+
this.shadowRoot.removeChild(toastElement);
|
|
318
|
+
}
|
|
319
|
+
}, 300);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Close all active toasts.
|
|
324
|
+
*/
|
|
325
|
+
dismissAll() {
|
|
326
|
+
const toastElements = this.shadowRoot.querySelectorAll(".toast");
|
|
327
|
+
toastElements.forEach((toast) => {
|
|
328
|
+
toast.classList.remove("show");
|
|
329
|
+
toast.classList.add("dismissing");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// Clear all toasts after animation completes
|
|
333
|
+
setTimeout(() => {
|
|
334
|
+
while (this.shadowRoot.firstChild) {
|
|
335
|
+
this.shadowRoot.removeChild(this.shadowRoot.firstChild);
|
|
336
|
+
}
|
|
337
|
+
}, 300);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/*
|
|
341
|
+
* Programmatically close the toast associated with a button click.
|
|
342
|
+
*/
|
|
343
|
+
#handleCloseClick(toastId) {
|
|
344
|
+
this.dismissToast(toastId);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/*
|
|
348
|
+
* Placeholder hook for responding to animation lifecycle in the future.
|
|
349
|
+
*/
|
|
350
|
+
#handleAnimationEnd(toastId) {
|
|
351
|
+
// Placeholder for potential future use
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Map toast type to an icon identifier.
|
|
356
|
+
*/
|
|
357
|
+
#getToastIcon(type) {
|
|
358
|
+
const icons = {
|
|
359
|
+
information: "info",
|
|
360
|
+
success: "check-circle",
|
|
361
|
+
warning: "warning",
|
|
362
|
+
error: "x-circle",
|
|
363
|
+
};
|
|
364
|
+
return icons[type] || icons.information;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Map toast type to a semantic title label.
|
|
369
|
+
* @param {"information"|"success"|"warning"|"error"} type
|
|
370
|
+
* @returns {string}
|
|
371
|
+
*/
|
|
372
|
+
#getToastTitle(type) {
|
|
373
|
+
const titles = {
|
|
374
|
+
information: "Information",
|
|
375
|
+
success: "Success!",
|
|
376
|
+
warning: "Warning",
|
|
377
|
+
error: "Error",
|
|
378
|
+
};
|
|
379
|
+
return titles[type] || titles.information;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Resolve toast type to an alert utility class name.
|
|
384
|
+
* @param {"information"|"success"|"warning"|"error"} type
|
|
385
|
+
* @returns {string}
|
|
386
|
+
*/
|
|
387
|
+
#getAlertClass(type) {
|
|
388
|
+
const classMap = {
|
|
389
|
+
information: "alert-info",
|
|
390
|
+
success: "alert-success",
|
|
391
|
+
warning: "alert-warning",
|
|
392
|
+
error: "alert-danger",
|
|
393
|
+
};
|
|
394
|
+
return classMap[type] || "alert-info";
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Display a success toast
|
|
399
|
+
* @method toastSuccess
|
|
400
|
+
* @public
|
|
401
|
+
* @param {string} message - The message to display
|
|
402
|
+
* @param {Object} [options] - Toast configuration options
|
|
403
|
+
* @returns {string} Toast ID
|
|
404
|
+
*/
|
|
405
|
+
toastSuccess(message, options = {}) {
|
|
406
|
+
return this.toast(message, { ...options, type: "success" });
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Display a warning toast
|
|
411
|
+
* @method toastWarning
|
|
412
|
+
* @public
|
|
413
|
+
* @param {string} message - The message to display
|
|
414
|
+
* @param {Object} [options] - Toast configuration options
|
|
415
|
+
* @returns {string} Toast ID
|
|
416
|
+
*/
|
|
417
|
+
toastWarning(message, options = {}) {
|
|
418
|
+
return this.toast(message, { ...options, type: "warning" });
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Display an error toast
|
|
423
|
+
* @method toastError
|
|
424
|
+
* @public
|
|
425
|
+
* @param {string} message - The message to display
|
|
426
|
+
* @param {Object} [options] - Toast configuration options
|
|
427
|
+
* @returns {string} Toast ID
|
|
428
|
+
*/
|
|
429
|
+
toastError(message, options = {}) {
|
|
430
|
+
return this.toast(message, { ...options, type: "error" });
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Display an information toast
|
|
435
|
+
* @method toastInfo
|
|
436
|
+
* @public
|
|
437
|
+
* @param {string} message - The message to display
|
|
438
|
+
* @param {Object} [options] - Toast configuration options
|
|
439
|
+
* @returns {string} Toast ID
|
|
440
|
+
*/
|
|
441
|
+
toastInfo(message, options = {}) {
|
|
442
|
+
return this.toast(message, { ...options, type: "information" });
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
customElements.define("pds-toaster", AppToaster);
|