@vaadin/confirm-dialog 24.2.0-beta3 → 24.2.0-beta4

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.
@@ -1,125 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { Constructor } from '@open-wc/dedupe-mixin';
7
-
8
- /*
9
- * Fired when the `opened` property changes.
10
- */
11
- export type ConfirmDialogOpenedChangedEvent = CustomEvent<{ value: boolean }>;
12
-
13
- export interface ConfirmDialogCustomEventMap {
14
- 'opened-changed': ConfirmDialogOpenedChangedEvent;
15
-
16
- confirm: Event;
17
-
18
- cancel: Event;
19
-
20
- reject: Event;
21
- }
22
-
23
- export type ConfirmDialogEventMap = ConfirmDialogCustomEventMap & HTMLElementEventMap;
24
-
25
- export declare function ConfirmDialogMixin<T extends Constructor<HTMLElement>>(
26
- base: T,
27
- ): Constructor<ConfirmDialogMixinClass> & T;
28
-
29
- export declare class ConfirmDialogMixinClass {
30
- /**
31
- * Sets the `aria-describedby` attribute of the overlay element.
32
- *
33
- * By default, all elements inside the message area are linked
34
- * through the `aria-describedby` attribute. However, there are
35
- * cases where this can confuse screen reader users (e.g. the dialog
36
- * may present a password confirmation form). For these cases,
37
- * it's better to associate only the elements that will help describe
38
- * the confirmation dialog through this API.
39
- * @attr {string} accessible-description-ref
40
- */
41
- accessibleDescriptionRef: string | null | undefined;
42
-
43
- /**
44
- * True if the overlay is currently displayed.
45
- */
46
- opened: boolean;
47
-
48
- /**
49
- * Set the confirmation dialog title.
50
- */
51
- header: string;
52
-
53
- /**
54
- * Set the message or confirmation question.
55
- */
56
- message: string | null | undefined;
57
-
58
- /**
59
- * Text displayed on confirm-button.
60
- * This only affects the default button, custom slotted buttons will not be altered.
61
- * @attr {string} confirm-text
62
- */
63
- confirmText: string;
64
-
65
- /**
66
- * Theme for a confirm-button.
67
- * This only affects the default button, custom slotted buttons will not be altered.
68
- * @attr {string} confirm-theme
69
- */
70
- confirmTheme: string;
71
-
72
- /**
73
- * Set to true to disable closing dialog on Escape press
74
- * @attr {boolean} no-close-on-esc
75
- */
76
- noCloseOnEsc: boolean;
77
-
78
- /**
79
- * Whether to show reject button or not.
80
- * @attr {boolean} reject-button-visible
81
- */
82
- rejectButtonVisible: boolean;
83
-
84
- /**
85
- * Text displayed on reject-button.
86
- * This only affects the default button, custom slotted buttons will not be altered.
87
- * @attr {string} reject-text
88
- */
89
- rejectText: string;
90
-
91
- /**
92
- * Theme for a reject-button.
93
- * This only affects the default button, custom slotted buttons will not be altered.
94
- * @attr {string} reject-theme
95
- */
96
- rejectTheme: string;
97
-
98
- /**
99
- * Whether to show cancel button or not.
100
- * @attr {boolean} cancel-button-visible
101
- */
102
- cancelButtonVisible: boolean;
103
-
104
- /**
105
- * Text displayed on cancel-button.
106
- * This only affects the default button, custom slotted buttons will not be altered.
107
- * @attr {string} cancel-text
108
- */
109
- cancelText: string;
110
-
111
- /**
112
- * Theme for a cancel-button.
113
- * This only affects the default button, custom slotted buttons will not be altered.
114
- * @attr {string} cancel-theme
115
- */
116
- cancelTheme: string;
117
-
118
- /**
119
- * A space-delimited list of CSS class names
120
- * to set on the underlying overlay element.
121
- *
122
- * @attr {string} overlay-class
123
- */
124
- overlayClass: string;
125
- }
@@ -1,451 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2018 - 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { setAriaIDReference } from '@vaadin/a11y-base/src/aria-id-reference.js';
7
- import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
8
- import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js';
9
-
10
- /**
11
- * @polymerMixin
12
- */
13
- export const ConfirmDialogMixin = (superClass) =>
14
- class ConfirmDialogMixinClass extends superClass {
15
- static get properties() {
16
- return {
17
- /**
18
- * Sets the `aria-describedby` attribute of the overlay element.
19
- *
20
- * By default, all elements inside the message area are linked
21
- * through the `aria-describedby` attribute. However, there are
22
- * cases where this can confuse screen reader users (e.g. the dialog
23
- * may present a password confirmation form). For these cases,
24
- * it's better to associate only the elements that will help describe
25
- * the confirmation dialog through this API.
26
- */
27
- accessibleDescriptionRef: {
28
- type: String,
29
- },
30
-
31
- /**
32
- * True if the overlay is currently displayed.
33
- * @type {boolean}
34
- */
35
- opened: {
36
- type: Boolean,
37
- value: false,
38
- notify: true,
39
- },
40
-
41
- /**
42
- * Set the confirmation dialog title.
43
- * @type {string}
44
- */
45
- header: {
46
- type: String,
47
- value: '',
48
- },
49
-
50
- /**
51
- * Set the message or confirmation question.
52
- */
53
- message: {
54
- type: String,
55
- value: '',
56
- },
57
-
58
- /**
59
- * Text displayed on confirm-button.
60
- * This only affects the default button, custom slotted buttons will not be altered.
61
- * @attr {string} confirm-text
62
- * @type {string}
63
- */
64
- confirmText: {
65
- type: String,
66
- value: 'Confirm',
67
- },
68
-
69
- /**
70
- * Theme for a confirm-button.
71
- * This only affects the default button, custom slotted buttons will not be altered.
72
- * @attr {string} confirm-theme
73
- * @type {string}
74
- */
75
- confirmTheme: {
76
- type: String,
77
- value: 'primary',
78
- },
79
-
80
- /**
81
- * Set to true to disable closing dialog on Escape press
82
- * @attr {boolean} no-close-on-esc
83
- * @type {boolean}
84
- */
85
- noCloseOnEsc: {
86
- type: Boolean,
87
- value: false,
88
- },
89
-
90
- /**
91
- * Whether to show reject button or not.
92
- * @attr {boolean} reject-button-visible
93
- * @type {boolean}
94
- */
95
- rejectButtonVisible: {
96
- type: Boolean,
97
- reflectToAttribute: true,
98
- value: false,
99
- },
100
-
101
- /**
102
- * Text displayed on reject-button.
103
- * This only affects the default button, custom slotted buttons will not be altered.
104
- * @attr {string} reject-text
105
- * @type {string}
106
- */
107
- rejectText: {
108
- type: String,
109
- value: 'Reject',
110
- },
111
-
112
- /**
113
- * Theme for a reject-button.
114
- * This only affects the default button, custom slotted buttons will not be altered.
115
- * @attr {string} reject-theme
116
- * @type {string}
117
- */
118
- rejectTheme: {
119
- type: String,
120
- value: 'error tertiary',
121
- },
122
-
123
- /**
124
- * Whether to show cancel button or not.
125
- * @attr {boolean} cancel-button-visible
126
- * @type {boolean}
127
- */
128
- cancelButtonVisible: {
129
- type: Boolean,
130
- reflectToAttribute: true,
131
- value: false,
132
- },
133
-
134
- /**
135
- * Text displayed on cancel-button.
136
- * This only affects the default button, custom slotted buttons will not be altered.
137
- * @attr {string} cancel-text
138
- * @type {string}
139
- */
140
- cancelText: {
141
- type: String,
142
- value: 'Cancel',
143
- },
144
-
145
- /**
146
- * Theme for a cancel-button.
147
- * This only affects the default button, custom slotted buttons will not be altered.
148
- * @attr {string} cancel-theme
149
- * @type {string}
150
- */
151
- cancelTheme: {
152
- type: String,
153
- value: 'tertiary',
154
- },
155
-
156
- /**
157
- * A space-delimited list of CSS class names
158
- * to set on the underlying overlay element.
159
- *
160
- * @attr {string} overlay-class
161
- */
162
- overlayClass: {
163
- type: String,
164
- },
165
-
166
- /**
167
- * A reference to the "Cancel" button which will be teleported to the overlay.
168
- * @private
169
- */
170
- _cancelButton: {
171
- type: Object,
172
- },
173
-
174
- /**
175
- * A reference to the "Confirm" button which will be teleported to the overlay.
176
- * @private
177
- */
178
- _confirmButton: {
179
- type: Object,
180
- },
181
-
182
- /**
183
- * A reference to the "header" node which will be teleported to the overlay.
184
- * @private
185
- */
186
- _headerNode: {
187
- type: Object,
188
- },
189
-
190
- /**
191
- * A list of message nodes which will be placed in the overlay default slot.
192
- * @private
193
- */
194
- _messageNodes: {
195
- type: Array,
196
- value: () => [],
197
- },
198
-
199
- /**
200
- * A reference to the overlay element.
201
- * @private
202
- */
203
- _overlayElement: {
204
- type: Object,
205
- sync: true,
206
- },
207
-
208
- /**
209
- * A reference to the "Reject" button which will be teleported to the overlay.
210
- * @private
211
- */
212
- _rejectButton: {
213
- type: Object,
214
- },
215
-
216
- /**
217
- * Height to be set on the overlay content.
218
- * @protected
219
- */
220
- _contentHeight: {
221
- type: String,
222
- },
223
-
224
- /**
225
- * Width to be set on the overlay content.
226
- * @protected
227
- */
228
- _contentWidth: {
229
- type: String,
230
- },
231
- };
232
- }
233
-
234
- static get observers() {
235
- return [
236
- '__updateConfirmButton(_confirmButton, confirmText, confirmTheme)',
237
- '__updateCancelButton(_cancelButton, cancelText, cancelTheme, cancelButtonVisible)',
238
- '__updateHeaderNode(_headerNode, header)',
239
- '__updateMessageNodes(_messageNodes, message)',
240
- '__updateRejectButton(_rejectButton, rejectText, rejectTheme, rejectButtonVisible)',
241
- '__accessibleDescriptionRefChanged(_overlayElement, _messageNodes, accessibleDescriptionRef)',
242
- ];
243
- }
244
-
245
- constructor() {
246
- super();
247
-
248
- this.__cancel = this.__cancel.bind(this);
249
- this.__confirm = this.__confirm.bind(this);
250
- this.__reject = this.__reject.bind(this);
251
- }
252
-
253
- get __slottedNodes() {
254
- return [this._headerNode, ...this._messageNodes, this._cancelButton, this._confirmButton, this._rejectButton];
255
- }
256
-
257
- /** @protected */
258
- ready() {
259
- super.ready();
260
-
261
- this._headerController = new SlotController(this, 'header', 'h3', {
262
- initializer: (node) => {
263
- this._headerNode = node;
264
- },
265
- });
266
- this.addController(this._headerController);
267
-
268
- this._messageController = new SlotController(this, '', 'div', {
269
- // Allow providing multiple custom nodes in the default slot
270
- multiple: true,
271
- observe: false,
272
- initializer: (node) => {
273
- const wrapper = document.createElement('div');
274
- wrapper.style.display = 'contents';
275
- const wrapperId = `confirm-dialog-message-${generateUniqueId()}`;
276
- wrapper.id = wrapperId;
277
- this.appendChild(wrapper);
278
- wrapper.appendChild(node);
279
- this._messageNodes = [...this._messageNodes, wrapper];
280
- },
281
- });
282
- this.addController(this._messageController);
283
-
284
- // NOTE: order in which buttons are added should match the order of slots in template
285
- this._cancelController = new SlotController(this, 'cancel-button', 'vaadin-button', {
286
- initializer: (button) => {
287
- this.__setupSlottedButton('cancel', button);
288
- },
289
- });
290
- this.addController(this._cancelController);
291
-
292
- this._rejectController = new SlotController(this, 'reject-button', 'vaadin-button', {
293
- initializer: (button) => {
294
- this.__setupSlottedButton('reject', button);
295
- },
296
- });
297
- this.addController(this._rejectController);
298
-
299
- this._confirmController = new SlotController(this, 'confirm-button', 'vaadin-button', {
300
- initializer: (button) => {
301
- this.__setupSlottedButton('confirm', button);
302
- },
303
- });
304
- this.addController(this._confirmController);
305
- }
306
-
307
- /** @protected */
308
- _initOverlay(overlay) {
309
- overlay.addEventListener('vaadin-overlay-escape-press', this._escPressed.bind(this));
310
- overlay.addEventListener('vaadin-overlay-open', () => this.__onDialogOpened());
311
- overlay.addEventListener('vaadin-overlay-closed', () => this.__onDialogClosed());
312
- overlay.setAttribute('role', 'alertdialog');
313
- }
314
-
315
- /** @private */
316
- __onDialogOpened() {
317
- const overlay = this._overlayElement;
318
-
319
- // Teleport slotted nodes to the overlay element.
320
- this.__slottedNodes.forEach((node) => {
321
- overlay.appendChild(node);
322
- });
323
-
324
- const confirmButton = overlay.querySelector('[slot="confirm-button"]');
325
- if (confirmButton) {
326
- confirmButton.focus();
327
- }
328
- }
329
-
330
- /** @private */
331
- __onDialogClosed() {
332
- // Move nodes from the overlay back to the host.
333
- this.__slottedNodes.forEach((node) => {
334
- this.appendChild(node);
335
- });
336
- }
337
-
338
- /** @private */
339
- __accessibleDescriptionRefChanged(overlay, messageNodes, accessibleDescriptionRef) {
340
- if (!overlay || !messageNodes) {
341
- return;
342
- }
343
-
344
- if (accessibleDescriptionRef !== undefined) {
345
- setAriaIDReference(overlay, 'aria-describedby', {
346
- newId: accessibleDescriptionRef,
347
- oldId: this.__oldAccessibleDescriptionRef,
348
- fromUser: true,
349
- });
350
- } else {
351
- messageNodes.forEach((node) => {
352
- setAriaIDReference(overlay, 'aria-describedby', { newId: node.id });
353
- });
354
- }
355
-
356
- this.__oldAccessibleDescriptionRef = accessibleDescriptionRef;
357
- }
358
-
359
- /** @private */
360
- __setupSlottedButton(type, button) {
361
- const property = `_${type}Button`;
362
- const listener = `__${type}`;
363
-
364
- if (this[property] && this[property] !== button) {
365
- this[property].remove();
366
- }
367
-
368
- button.addEventListener('click', this[listener]);
369
- this[property] = button;
370
- }
371
-
372
- /** @private */
373
- __updateCancelButton(button, cancelText, cancelTheme, showCancel) {
374
- if (button) {
375
- if (button === this._cancelController.defaultNode) {
376
- button.textContent = cancelText;
377
- button.setAttribute('theme', cancelTheme);
378
- }
379
- button.toggleAttribute('hidden', !showCancel);
380
- }
381
- }
382
-
383
- /** @private */
384
- __updateConfirmButton(button, confirmText, confirmTheme) {
385
- if (button && button === this._confirmController.defaultNode) {
386
- button.textContent = confirmText;
387
- button.setAttribute('theme', confirmTheme);
388
- }
389
- }
390
-
391
- /** @private */
392
- __updateHeaderNode(headerNode, header) {
393
- // Only update text content for the default header node.
394
- if (headerNode && headerNode === this._headerController.defaultNode) {
395
- headerNode.textContent = header;
396
- }
397
- }
398
-
399
- /** @private */
400
- __updateMessageNodes(nodes, message) {
401
- if (nodes && nodes.length > 0) {
402
- const defaultWrapperNode = nodes.find(
403
- (node) => this._messageController.defaultNode && node === this._messageController.defaultNode.parentElement,
404
- );
405
- if (defaultWrapperNode) {
406
- defaultWrapperNode.firstChild.textContent = message;
407
- }
408
- }
409
- }
410
-
411
- /** @private */
412
- __updateRejectButton(button, rejectText, rejectTheme, showReject) {
413
- if (button) {
414
- if (button === this._rejectController.defaultNode) {
415
- button.textContent = rejectText;
416
- button.setAttribute('theme', rejectTheme);
417
- }
418
- button.toggleAttribute('hidden', !showReject);
419
- }
420
- }
421
-
422
- /** @private */
423
- _escPressed(event) {
424
- if (!event.defaultPrevented) {
425
- this.__cancel();
426
- }
427
- }
428
-
429
- /** @private */
430
- __confirm() {
431
- this.dispatchEvent(new CustomEvent('confirm'));
432
- this.opened = false;
433
- }
434
-
435
- /** @private */
436
- __cancel() {
437
- this.dispatchEvent(new CustomEvent('cancel'));
438
- this.opened = false;
439
- }
440
-
441
- /** @private */
442
- __reject() {
443
- this.dispatchEvent(new CustomEvent('reject'));
444
- this.opened = false;
445
- }
446
-
447
- /** @private */
448
- _getAriaLabel(header) {
449
- return header || 'confirmation';
450
- }
451
- };
@@ -1,8 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2018 - 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { CSSResult } from 'lit';
7
-
8
- export const confirmDialogOverlay: CSSResult;
@@ -1,27 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2018 - 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { css } from 'lit';
7
-
8
- export const confirmDialogOverlay = css`
9
- :host {
10
- --_vaadin-confirm-dialog-content-width: auto;
11
- --_vaadin-confirm-dialog-content-height: auto;
12
- }
13
-
14
- [part='overlay'] {
15
- width: var(--_vaadin-confirm-dialog-content-width);
16
- height: var(--_vaadin-confirm-dialog-content-height);
17
- }
18
-
19
- ::slotted([slot='header']) {
20
- pointer-events: auto;
21
- }
22
-
23
- /* Make buttons clickable */
24
- [part='footer'] > * {
25
- pointer-events: all;
26
- }
27
- `;