Skip to content

Commit a20b939

Browse files
authored
refactor: move dialog setBounds logic to overlay mixin (#9643)
1 parent c0e4876 commit a20b939

File tree

7 files changed

+37
-56
lines changed

7 files changed

+37
-56
lines changed

packages/confirm-dialog/src/vaadin-confirm-dialog-overlay.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,6 @@ class ConfirmDialogOverlay extends OverlayMixin(DirMixin(ThemableMixin(LumoInjec
8686
this.setAttribute('has-header', '');
8787
this.setAttribute('has-footer', '');
8888
}
89-
90-
/**
91-
* Updates the coordinates of the overlay.
92-
*/
93-
setBounds(bounds) {
94-
const overlay = this.$.overlay;
95-
const parsedBounds = { ...bounds };
96-
97-
Object.keys(parsedBounds).forEach((arg) => {
98-
// Allow setting width or height to `null`
99-
if (parsedBounds[arg] !== null && !isNaN(parsedBounds[arg])) {
100-
parsedBounds[arg] = `${parsedBounds[arg]}px`;
101-
}
102-
});
103-
104-
Object.assign(overlay.style, parsedBounds);
105-
}
10689
}
10790

10891
defineCustomElement(ConfirmDialogOverlay);

packages/dialog/src/vaadin-dialog-overlay-mixin.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ export type DialogOverlayBounds = {
1414
height: number;
1515
};
1616

17-
export type DialogOverlayBoundsParam =
18-
| DialogOverlayBounds
19-
| {
20-
top?: number | string;
21-
left?: number | string;
22-
width?: number | string;
23-
height?: number | string;
24-
};
25-
2617
export declare function DialogOverlayMixin<T extends Constructor<HTMLElement>>(
2718
base: T,
2819
): Constructor<DialogOverlayMixinClass> & Constructor<OverlayMixinClass> & T;
@@ -48,9 +39,4 @@ export declare class DialogOverlayMixinClass {
4839
* Retrieves the coordinates of the overlay.
4940
*/
5041
getBounds(): DialogOverlayBounds;
51-
52-
/**
53-
* Updates the coordinates of the overlay.
54-
*/
55-
setBounds(bounds: DialogOverlayBoundsParam, absolute: boolean): void;
5642
}

packages/dialog/src/vaadin-dialog-overlay-mixin.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,6 @@ export const DialogOverlayMixin = (superClass) =>
193193
this.__updateOverflow();
194194
}
195195

196-
/**
197-
* Updates the coordinates of the overlay.
198-
* @param {!DialogOverlayBoundsParam} bounds
199-
* @param {boolean} absolute
200-
*/
201-
setBounds(bounds, absolute = true) {
202-
const overlay = this.$.overlay;
203-
const parsedBounds = { ...bounds };
204-
205-
if (absolute && overlay.style.position !== 'absolute') {
206-
overlay.style.position = 'absolute';
207-
}
208-
209-
Object.keys(parsedBounds).forEach((arg) => {
210-
// Allow setting width or height to `null`
211-
if (parsedBounds[arg] !== null && !isNaN(parsedBounds[arg])) {
212-
parsedBounds[arg] = `${parsedBounds[arg]}px`;
213-
}
214-
});
215-
216-
Object.assign(overlay.style, parsedBounds);
217-
}
218-
219196
/**
220197
* Retrieves the coordinates of the overlay.
221198
* @return {!DialogOverlayBounds}

packages/dialog/src/vaadin-dialog-overlay.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
77
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
88
import { DialogOverlayMixin } from './vaadin-dialog-overlay-mixin.js';
99

10-
export { DialogOverlayBounds, DialogOverlayBoundsParam } from './vaadin-dialog-overlay-mixin.js';
10+
export { DialogOverlayBounds } from './vaadin-dialog-overlay-mixin.js';
1111

1212
/**
1313
* An element used internally by `<vaadin-dialog>`. Not intended to be used separately.

packages/dialog/src/vaadin-dialog.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DialogDraggableMixin } from './vaadin-dialog-draggable-mixin.js';
1111
import { DialogRendererMixin } from './vaadin-dialog-renderer-mixin.js';
1212
import { DialogResizableMixin } from './vaadin-dialog-resizable-mixin.js';
1313

14-
export { DialogOverlay, DialogOverlayBounds, DialogOverlayBoundsParam } from './vaadin-dialog-overlay.js';
14+
export { DialogOverlay, DialogOverlayBounds } from './vaadin-dialog-overlay.js';
1515

1616
export type DialogRenderer = (root: HTMLElement, dialog: Dialog) => void;
1717

packages/overlay/src/vaadin-overlay-mixin.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import type { Constructor } from '@open-wc/dedupe-mixin';
77
import type { OverlayFocusMixinClass } from './vaadin-overlay-focus-mixin.js';
88
import type { OverlayStackMixinClass } from './vaadin-overlay-stack-mixin.js';
99

10+
export type OverlayBounds = {
11+
top?: number | string;
12+
left?: number | string;
13+
width?: number | string;
14+
height?: number | string;
15+
};
16+
1017
export type OverlayRenderer = (root: HTMLElement, owner: HTMLElement, model?: object) => void;
1118

1219
export declare function OverlayMixin<T extends Constructor<HTMLElement>>(
@@ -58,6 +65,11 @@ export declare class OverlayMixinClass {
5865

5966
close(sourceEvent?: Event | null): void;
6067

68+
/**
69+
* Updates the coordinates of the overlay.
70+
*/
71+
setBounds(bounds: OverlayBounds, absolute?: boolean): void;
72+
6173
/**
6274
* Requests an update for the content of the overlay.
6375
* While performing the update, it invokes the renderer passed in the `renderer` property.

packages/overlay/src/vaadin-overlay-mixin.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,29 @@ export const OverlayMixin = (superClass) =>
182182
}
183183
}
184184

185+
/**
186+
* Updates the coordinates of the overlay.
187+
* @param {!OverlayBoundsParam} bounds
188+
* @param {boolean} absolute
189+
*/
190+
setBounds(bounds, absolute = true) {
191+
const overlay = this.$.overlay;
192+
const parsedBounds = { ...bounds };
193+
194+
if (absolute && overlay.style.position !== 'absolute') {
195+
overlay.style.position = 'absolute';
196+
}
197+
198+
Object.keys(parsedBounds).forEach((arg) => {
199+
// Allow setting width or height to `null`
200+
if (parsedBounds[arg] !== null && !isNaN(parsedBounds[arg])) {
201+
parsedBounds[arg] = `${parsedBounds[arg]}px`;
202+
}
203+
});
204+
205+
Object.assign(overlay.style, parsedBounds);
206+
}
207+
185208
/** @private */
186209
_detectIosNavbar() {
187210
/* c8 ignore next 15 */

0 commit comments

Comments
 (0)