@vaadin/dialog 24.2.0-alpha1 → 24.2.0-alpha10

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.
@@ -0,0 +1,181 @@
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 { css } from 'lit';
7
+
8
+ export const dialogOverlay = css`
9
+ [part='header'],
10
+ [part='header-content'],
11
+ [part='footer'] {
12
+ display: flex;
13
+ align-items: center;
14
+ flex-wrap: wrap;
15
+ flex: none;
16
+ pointer-events: none;
17
+ z-index: 1;
18
+ }
19
+
20
+ [part='header'] {
21
+ flex-wrap: nowrap;
22
+ }
23
+
24
+ ::slotted([slot='header-content']),
25
+ ::slotted([slot='title']),
26
+ ::slotted([slot='footer']) {
27
+ display: contents;
28
+ pointer-events: auto;
29
+ }
30
+
31
+ ::slotted([slot='title']) {
32
+ font: inherit !important;
33
+ overflow-wrap: anywhere;
34
+ }
35
+
36
+ [part='header-content'] {
37
+ flex: 1;
38
+ }
39
+
40
+ :host([has-title]) [part='header-content'],
41
+ [part='footer'] {
42
+ justify-content: flex-end;
43
+ }
44
+
45
+ :host(:not([has-title]):not([has-header])) [part='header'],
46
+ :host(:not([has-header])) [part='header-content'],
47
+ :host(:not([has-title])) [part='title'],
48
+ :host(:not([has-footer])) [part='footer'] {
49
+ display: none !important;
50
+ }
51
+
52
+ :host(:is([has-title], [has-header], [has-footer])) [part='content'] {
53
+ height: auto;
54
+ }
55
+
56
+ @media (min-height: 320px) {
57
+ :host(:is([has-title], [has-header], [has-footer])) .resizer-container {
58
+ overflow: hidden;
59
+ display: flex;
60
+ flex-direction: column;
61
+ }
62
+
63
+ :host(:is([has-title], [has-header], [has-footer])) [part='content'] {
64
+ flex: 1;
65
+ overflow: auto;
66
+ }
67
+ }
68
+
69
+ /*
70
+ NOTE(platosha): Make some min-width to prevent collapsing of the content
71
+ taking the parent width, e. g., <vaadin-grid> and such.
72
+ */
73
+ [part='content'] {
74
+ min-width: 12em; /* matches the default <vaadin-text-field> width */
75
+ }
76
+
77
+ :host([has-bounds-set]) [part='overlay'] {
78
+ max-width: none;
79
+ }
80
+
81
+ @media (forced-colors: active) {
82
+ [part='overlay'] {
83
+ outline: 3px solid !important;
84
+ }
85
+ }
86
+ `;
87
+
88
+ export const resizableOverlay = css`
89
+ [part='overlay'] {
90
+ position: relative;
91
+ overflow: visible;
92
+ max-height: 100%;
93
+ display: flex;
94
+ }
95
+
96
+ [part='content'] {
97
+ box-sizing: border-box;
98
+ height: 100%;
99
+ }
100
+
101
+ .resizer-container {
102
+ overflow: auto;
103
+ flex-grow: 1;
104
+ border-radius: inherit; /* prevent child elements being drawn outside part=overlay */
105
+ }
106
+
107
+ [part='overlay'][style] .resizer-container {
108
+ min-height: 100%;
109
+ width: 100%;
110
+ }
111
+
112
+ :host(:not([resizable])) .resizer {
113
+ display: none;
114
+ }
115
+
116
+ :host([resizable]) [part='title'] {
117
+ cursor: move;
118
+ -webkit-user-select: none;
119
+ user-select: none;
120
+ }
121
+
122
+ .resizer {
123
+ position: absolute;
124
+ height: 16px;
125
+ width: 16px;
126
+ }
127
+
128
+ .resizer.edge {
129
+ height: 8px;
130
+ width: 8px;
131
+ inset: -4px;
132
+ }
133
+
134
+ .resizer.edge.n {
135
+ width: auto;
136
+ bottom: auto;
137
+ cursor: ns-resize;
138
+ }
139
+
140
+ .resizer.ne {
141
+ top: -4px;
142
+ right: -4px;
143
+ cursor: nesw-resize;
144
+ }
145
+
146
+ .resizer.edge.e {
147
+ height: auto;
148
+ left: auto;
149
+ cursor: ew-resize;
150
+ }
151
+
152
+ .resizer.se {
153
+ bottom: -4px;
154
+ right: -4px;
155
+ cursor: nwse-resize;
156
+ }
157
+
158
+ .resizer.edge.s {
159
+ width: auto;
160
+ top: auto;
161
+ cursor: ns-resize;
162
+ }
163
+
164
+ .resizer.sw {
165
+ bottom: -4px;
166
+ left: -4px;
167
+ cursor: nesw-resize;
168
+ }
169
+
170
+ .resizer.edge.w {
171
+ height: auto;
172
+ right: auto;
173
+ cursor: ew-resize;
174
+ }
175
+
176
+ .resizer.nw {
177
+ top: -4px;
178
+ left: -4px;
179
+ cursor: nwse-resize;
180
+ }
181
+ `;
@@ -6,7 +6,9 @@
6
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
7
  import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
8
8
  import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
9
+ import { DialogBaseMixin } from './vaadin-dialog-base-mixin.js';
9
10
  import { DialogDraggableMixin } from './vaadin-dialog-draggable-mixin.js';
11
+ import { DialogRendererMixin } from './vaadin-dialog-renderer-mixin.js';
10
12
  import { DialogResizableMixin } from './vaadin-dialog-resizable-mixin.js';
11
13
 
12
14
  export { DialogOverlay, DialogOverlayBounds, DialogOverlayBoundsParam } from './vaadin-dialog-overlay.js';
@@ -101,26 +103,11 @@ export type DialogEventMap = DialogCustomEventMap & HTMLElementEventMap;
101
103
  * @fires {CustomEvent} resize - Fired when the dialog resize is finished.
102
104
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
103
105
  */
104
- declare class Dialog extends OverlayClassMixin(
105
- ThemePropertyMixin(ElementMixin(DialogDraggableMixin(DialogResizableMixin(HTMLElement)))),
106
+ declare class Dialog extends DialogDraggableMixin(
107
+ DialogResizableMixin(
108
+ DialogRendererMixin(DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(HTMLElement))))),
109
+ ),
106
110
  ) {
107
- /**
108
- * True if the overlay is currently displayed.
109
- */
110
- opened: boolean;
111
-
112
- /**
113
- * Set to true to disable closing dialog on outside click
114
- * @attr {boolean} no-close-on-outside-click
115
- */
116
- noCloseOnOutsideClick: boolean;
117
-
118
- /**
119
- * Set to true to disable closing dialog on Escape press
120
- * @attr {boolean} no-close-on-esc
121
- */
122
- noCloseOnEsc: boolean;
123
-
124
111
  /**
125
112
  * Set the `aria-label` attribute for assistive technologies like
126
113
  * screen readers. An empty string value for this property (the
@@ -128,66 +115,6 @@ declare class Dialog extends OverlayClassMixin(
128
115
  */
129
116
  ariaLabel: string;
130
117
 
131
- /**
132
- * Custom function for rendering the content of the dialog.
133
- * Receives two arguments:
134
- *
135
- * - `root` The root container DOM element. Append your content to it.
136
- * - `dialog` The reference to the `<vaadin-dialog>` element.
137
- */
138
- renderer: DialogRenderer | null | undefined;
139
-
140
- /**
141
- * String used for rendering a dialog title.
142
- *
143
- * If both `headerTitle` and `headerRenderer` are defined, the title
144
- * and the elements created by the renderer will be placed next to
145
- * each other, with the title coming first.
146
- *
147
- * When `headerTitle` is set, the attribute `has-title` is added to the overlay element.
148
- * @attr {string} header-title
149
- */
150
- headerTitle: string | null | undefined;
151
-
152
- /**
153
- * Custom function for rendering the dialog header.
154
- * Receives two arguments:
155
- *
156
- * - `root` The root container DOM element. Append your content to it.
157
- * - `dialog` The reference to the `<vaadin-dialog>` element.
158
- *
159
- * If both `headerTitle` and `headerRenderer` are defined, the title
160
- * and the elements created by the renderer will be placed next to
161
- * each other, with the title coming first.
162
- *
163
- * When `headerRenderer` is set, the attribute `has-header` is added to the overlay element.
164
- */
165
- headerRenderer: DialogRenderer | null | undefined;
166
-
167
- /**
168
- * Custom function for rendering the dialog footer.
169
- * Receives two arguments:
170
- *
171
- * - `root` The root container DOM element. Append your content to it.
172
- * - `dialog` The reference to the `<vaadin-dialog>` element.
173
- *
174
- * When `footerRenderer` is set, the attribute `has-footer` is added to the overlay element.
175
- */
176
- footerRenderer: DialogRenderer | null | undefined;
177
-
178
- /**
179
- * Set to true to remove backdrop and allow click events on background elements.
180
- */
181
- modeless: boolean;
182
-
183
- /**
184
- * While performing the update, it invokes the renderer passed in the `renderer` property,
185
- * as well as `headerRender` and `footerRenderer` properties, if these are defined.
186
- *
187
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
188
- */
189
- requestContentUpdate(): void;
190
-
191
118
  addEventListener<K extends keyof DialogEventMap>(
192
119
  type: K,
193
120
  listener: (this: Dialog, ev: DialogEventMap[K]) => void,
@@ -9,7 +9,9 @@ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
9
  import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
10
10
  import { processTemplates } from '@vaadin/component-base/src/templates.js';
11
11
  import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
12
+ import { DialogBaseMixin } from './vaadin-dialog-base-mixin.js';
12
13
  import { DialogDraggableMixin } from './vaadin-dialog-draggable-mixin.js';
14
+ import { DialogRendererMixin } from './vaadin-dialog-renderer-mixin.js';
13
15
  import { DialogResizableMixin } from './vaadin-dialog-resizable-mixin.js';
14
16
 
15
17
  export { DialogOverlay } from './vaadin-dialog-overlay.js';
@@ -78,12 +80,16 @@ export { DialogOverlay } from './vaadin-dialog-overlay.js';
78
80
  * @extends HTMLElement
79
81
  * @mixes ThemePropertyMixin
80
82
  * @mixes ElementMixin
83
+ * @mixes DialogBaseMixin
81
84
  * @mixes DialogDraggableMixin
85
+ * @mixes DialogRendererMixin
82
86
  * @mixes DialogResizableMixin
83
87
  * @mixes OverlayClassMixin
84
88
  */
85
- class Dialog extends OverlayClassMixin(
86
- ThemePropertyMixin(ElementMixin(DialogDraggableMixin(DialogResizableMixin(PolymerElement)))),
89
+ class Dialog extends DialogDraggableMixin(
90
+ DialogResizableMixin(
91
+ DialogRendererMixin(DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerElement))))),
92
+ ),
87
93
  ) {
88
94
  static get template() {
89
95
  return html`
@@ -115,36 +121,6 @@ class Dialog extends OverlayClassMixin(
115
121
 
116
122
  static get properties() {
117
123
  return {
118
- /**
119
- * True if the overlay is currently displayed.
120
- * @type {boolean}
121
- */
122
- opened: {
123
- type: Boolean,
124
- value: false,
125
- notify: true,
126
- },
127
-
128
- /**
129
- * Set to true to disable closing dialog on outside click
130
- * @attr {boolean} no-close-on-outside-click
131
- * @type {boolean}
132
- */
133
- noCloseOnOutsideClick: {
134
- type: Boolean,
135
- value: false,
136
- },
137
-
138
- /**
139
- * Set to true to disable closing dialog on Escape press
140
- * @attr {boolean} no-close-on-esc
141
- * @type {boolean}
142
- */
143
- noCloseOnEsc: {
144
- type: Boolean,
145
- value: false,
146
- },
147
-
148
124
  /**
149
125
  * Set the `aria-label` attribute for assistive technologies like
150
126
  * screen readers. An empty string value for this property (the
@@ -154,65 +130,6 @@ class Dialog extends OverlayClassMixin(
154
130
  type: String,
155
131
  value: '',
156
132
  },
157
-
158
- /**
159
- * Custom function for rendering the content of the dialog.
160
- * Receives two arguments:
161
- *
162
- * - `root` The root container DOM element. Append your content to it.
163
- * - `dialog` The reference to the `<vaadin-dialog>` element.
164
- * @type {DialogRenderer | undefined}
165
- */
166
- renderer: Function,
167
-
168
- /**
169
- * String used for rendering a dialog title.
170
- *
171
- * If both `headerTitle` and `headerRenderer` are defined, the title
172
- * and the elements created by the renderer will be placed next to
173
- * each other, with the title coming first.
174
- *
175
- * When `headerTitle` is set, the attribute `has-title` is added to the overlay element.
176
- * @attr {string} header-title
177
- */
178
- headerTitle: String,
179
-
180
- /**
181
- * Custom function for rendering the dialog header.
182
- * Receives two arguments:
183
- *
184
- * - `root` The root container DOM element. Append your content to it.
185
- * - `dialog` The reference to the `<vaadin-dialog>` element.
186
- *
187
- * If both `headerTitle` and `headerRenderer` are defined, the title
188
- * and the elements created by the renderer will be placed next to
189
- * each other, with the title coming first.
190
- *
191
- * When `headerRenderer` is set, the attribute `has-header` is added to the overlay element.
192
- * @type {DialogRenderer | undefined}
193
- */
194
- headerRenderer: Function,
195
-
196
- /**
197
- * Custom function for rendering the dialog footer.
198
- * Receives two arguments:
199
- *
200
- * - `root` The root container DOM element. Append your content to it.
201
- * - `dialog` The reference to the `<vaadin-dialog>` element.
202
- *
203
- * When `footerRenderer` is set, the attribute `has-footer` is added to the overlay element.
204
- * @type {DialogRenderer | undefined}
205
- */
206
- footerRenderer: Function,
207
-
208
- /**
209
- * Set to true to remove backdrop and allow click events on background elements.
210
- * @type {boolean}
211
- */
212
- modeless: {
213
- type: Boolean,
214
- value: false,
215
- },
216
133
  };
217
134
  }
218
135
 
@@ -228,58 +145,16 @@ class Dialog extends OverlayClassMixin(
228
145
  ready() {
229
146
  super.ready();
230
147
 
231
- const overlay = this.$.overlay;
232
- overlay.setAttribute('role', 'dialog');
233
-
234
- overlay.addEventListener('vaadin-overlay-outside-click', this._handleOutsideClick.bind(this));
235
- overlay.addEventListener('vaadin-overlay-escape-press', this._handleEscPress.bind(this));
236
-
237
- this._overlayElement = overlay;
148
+ this._overlayElement.setAttribute('role', 'dialog');
238
149
 
239
150
  processTemplates(this);
240
151
  }
241
152
 
242
- /**
243
- * Requests an update for the content of the dialog.
244
- * While performing the update, it invokes the renderer passed in the `renderer` property,
245
- * as well as `headerRender` and `footerRenderer` properties, if these are defined.
246
- *
247
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
248
- */
249
- requestContentUpdate() {
250
- if (this.$) {
251
- this.$.overlay.requestContentUpdate();
252
- }
253
- }
254
-
255
153
  /** @private */
256
154
  _rendererChanged(renderer, headerRenderer, footerRenderer) {
257
155
  this.$.overlay.setProperties({ owner: this, renderer, headerRenderer, footerRenderer });
258
156
  }
259
157
 
260
- /** @protected */
261
- connectedCallback() {
262
- super.connectedCallback();
263
- // Restore opened state if overlay was opened when disconnecting
264
- if (this.__restoreOpened) {
265
- this.opened = true;
266
- }
267
- }
268
-
269
- /** @protected */
270
- disconnectedCallback() {
271
- super.disconnectedCallback();
272
- // Automatically close the overlay when dialog is removed from DOM
273
- // Using a timeout to avoid toggling opened state, and dispatching change
274
- // events, when just moving the dialog in the DOM
275
- setTimeout(() => {
276
- if (!this.isConnected) {
277
- this.__restoreOpened = this.opened;
278
- this.opened = false;
279
- }
280
- });
281
- }
282
-
283
158
  /** @private */
284
159
  _openedChanged(opened) {
285
160
  this.$.overlay.opened = opened;
@@ -293,40 +168,6 @@ class Dialog extends OverlayClassMixin(
293
168
  this.$.overlay.removeAttribute('aria-label');
294
169
  }
295
170
  }
296
-
297
- /** @private */
298
- _onOverlayOpened(e) {
299
- if (e.detail.value === false) {
300
- this.opened = false;
301
- }
302
- }
303
-
304
- /**
305
- * Close the dialog if `noCloseOnOutsideClick` isn't set to true
306
- * @private
307
- */
308
- _handleOutsideClick(e) {
309
- if (this.noCloseOnOutsideClick) {
310
- e.preventDefault();
311
- }
312
- }
313
-
314
- /**
315
- * Close the dialog if `noCloseOnEsc` isn't set to true
316
- * @private
317
- */
318
- _handleEscPress(e) {
319
- if (this.noCloseOnEsc) {
320
- e.preventDefault();
321
- }
322
- }
323
-
324
- /** @private */
325
- _bringOverlayToFront() {
326
- if (this.modeless) {
327
- this.$.overlay.bringToFront();
328
- }
329
- }
330
171
  }
331
172
 
332
173
  customElements.define(Dialog.is, Dialog);
@@ -103,3 +103,5 @@ const dialogOverlay = css`
103
103
  `;
104
104
 
105
105
  registerStyles('vaadin-dialog-overlay', [overlay, dialogOverlay], { moduleId: 'lumo-dialog' });
106
+
107
+ export { dialogOverlay };
@@ -60,3 +60,5 @@ const dialogOverlay = css`
60
60
  registerStyles('vaadin-dialog-overlay', [overlay, dialogOverlay], {
61
61
  moduleId: 'material-dialog',
62
62
  });
63
+
64
+ export { dialogOverlay };