Skip to content

Commit 0c53ae1

Browse files
authored
refactor: extract dialog size properties into separate mixin (#9735)
1 parent a2dad47 commit 0c53ae1

File tree

7 files changed

+84
-36
lines changed

7 files changed

+84
-36
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
1010
import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
1111
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
1212
import { DialogBaseMixin } from '@vaadin/dialog/src/vaadin-dialog-base-mixin.js';
13+
import { DialogSizeMixin } from '@vaadin/dialog/src/vaadin-dialog-size-mixin.js';
1314
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
1415
import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
1516
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -94,7 +95,9 @@ defineCustomElement(ConfirmDialogOverlay);
9495
* An element used internally by `<vaadin-confirm-dialog>`. Not intended to be used separately.
9596
* @private
9697
*/
97-
class ConfirmDialogDialog extends DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(PolylitMixin(LitElement)))) {
98+
class ConfirmDialogDialog extends DialogSizeMixin(
99+
DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(PolylitMixin(LitElement)))),
100+
) {
98101
static get is() {
99102
return 'vaadin-confirm-dialog-dialog';
100103
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,4 @@ export declare class DialogBaseMixinClass {
5858
* overlay from stretching all the way to the left of the viewport).
5959
*/
6060
left: string;
61-
62-
/**
63-
* Set the width of the overlay.
64-
* If a unitless number is provided, pixels are assumed.
65-
*/
66-
width: string | null;
67-
68-
/**
69-
* Set the height of the overlay.
70-
* If a unitless number is provided, pixels are assumed.
71-
*/
72-
height: string | null;
7361
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,6 @@ export const DialogBaseMixin = (superClass) =>
7575
type: String,
7676
},
7777

78-
/**
79-
* Set the width of the overlay.
80-
* If a unitless number is provided, pixels are assumed.
81-
*/
82-
width: {
83-
type: String,
84-
},
85-
86-
/**
87-
* Set the height of the overlay.
88-
* If a unitless number is provided, pixels are assumed.
89-
*/
90-
height: {
91-
type: String,
92-
},
93-
9478
/**
9579
* The `role` attribute value to be set on the overlay. Defaults to "dialog".
9680
*
@@ -104,7 +88,7 @@ export const DialogBaseMixin = (superClass) =>
10488
}
10589

10690
static get observers() {
107-
return ['__positionChanged(top, left)', '__sizeChanged(width, height)'];
91+
return ['__positionChanged(top, left)'];
10892
}
10993

11094
/** @protected */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2025 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+
export declare function DialogSizeMixin<T extends Constructor<HTMLElement>>(
9+
base: T,
10+
): Constructor<DialogSizeMixinClass> & T;
11+
12+
export declare class DialogSizeMixinClass {
13+
/**
14+
* Set the width of the overlay.
15+
* If a unitless number is provided, pixels are assumed.
16+
*/
17+
width: string | null;
18+
19+
/**
20+
* Set the height of the overlay.
21+
* If a unitless number is provided, pixels are assumed.
22+
*/
23+
height: string | null;
24+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
7+
/**
8+
* @polymerMixin
9+
*/
10+
export const DialogSizeMixin = (superClass) =>
11+
class DialogSizeMixinClass extends superClass {
12+
static get properties() {
13+
return {
14+
/**
15+
* Set the width of the overlay.
16+
* If a unitless number is provided, pixels are assumed.
17+
*/
18+
width: {
19+
type: String,
20+
},
21+
22+
/**
23+
* Set the height of the overlay.
24+
* If a unitless number is provided, pixels are assumed.
25+
*/
26+
height: {
27+
type: String,
28+
},
29+
};
30+
}
31+
32+
static get observers() {
33+
return ['__sizeChanged(width, height)'];
34+
}
35+
36+
/** @private */
37+
__sizeChanged(width, height) {
38+
requestAnimationFrame(() => this.$.overlay.setBounds({ width, height }, false));
39+
}
40+
};

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DialogBaseMixin } from './vaadin-dialog-base-mixin.js';
1010
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';
13+
import { DialogSizeMixin } from './vaadin-dialog-size-mixin.js';
1314

1415
export { DialogOverlay, DialogOverlayBounds } from './vaadin-dialog-overlay.js';
1516

@@ -124,9 +125,11 @@ export type DialogEventMap = DialogCustomEventMap & HTMLElementEventMap;
124125
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
125126
* @fires {CustomEvent} closed - Fired when the dialog is closed.
126127
*/
127-
declare class Dialog extends DialogDraggableMixin(
128-
DialogResizableMixin(
129-
DialogRendererMixin(DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(HTMLElement))))),
128+
declare class Dialog extends DialogSizeMixin(
129+
DialogDraggableMixin(
130+
DialogResizableMixin(
131+
DialogRendererMixin(DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(HTMLElement))))),
132+
),
130133
),
131134
) {
132135
/**

packages/dialog/src/vaadin-dialog.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DialogBaseMixin } from './vaadin-dialog-base-mixin.js';
1515
import { DialogDraggableMixin } from './vaadin-dialog-draggable-mixin.js';
1616
import { DialogRendererMixin } from './vaadin-dialog-renderer-mixin.js';
1717
import { DialogResizableMixin } from './vaadin-dialog-resizable-mixin.js';
18+
import { DialogSizeMixin } from './vaadin-dialog-size-mixin.js';
1819

1920
export { DialogOverlay } from './vaadin-dialog-overlay.js';
2021

@@ -89,11 +90,16 @@ export { DialogOverlay } from './vaadin-dialog-overlay.js';
8990
* @mixes DialogDraggableMixin
9091
* @mixes DialogRendererMixin
9192
* @mixes DialogResizableMixin
93+
* @mixes DialogSizeMixin
9294
* @mixes OverlayClassMixin
9395
*/
94-
class Dialog extends DialogDraggableMixin(
95-
DialogResizableMixin(
96-
DialogRendererMixin(DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolylitMixin(LitElement)))))),
96+
class Dialog extends DialogSizeMixin(
97+
DialogDraggableMixin(
98+
DialogResizableMixin(
99+
DialogRendererMixin(
100+
DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolylitMixin(LitElement))))),
101+
),
102+
),
97103
),
98104
) {
99105
static get is() {

0 commit comments

Comments
 (0)