Skip to content

Commit 34e9db1

Browse files
authored
feat: add missing PositionMixin type definitions (#5042)
1 parent 54f903f commit 34e9db1

4 files changed

Lines changed: 86 additions & 1 deletion

File tree

‎packages/overlay/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"polymer"
3535
],
3636
"dependencies": {
37+
"@open-wc/dedupe-mixin": "^1.3.0",
3738
"@polymer/polymer": "^3.0.0",
3839
"@vaadin/component-base": "24.0.0-alpha4",
3940
"@vaadin/vaadin-lumo-styles": "24.0.0-alpha4",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2022 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 PositionMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<PositionMixinClass> & T;
9+
10+
export declare class PositionMixinClass {
11+
/**
12+
* The element next to which this overlay should be aligned.
13+
* The position of the overlay relative to the positionTarget can be adjusted
14+
* with properties `horizontalAlign`, `verticalAlign`, `noHorizontalOverlap`
15+
* and `noVerticalOverlap`.
16+
*/
17+
positionTarget: HTMLElement;
18+
19+
/**
20+
* When `positionTarget` is set, this property defines whether to align the overlay's
21+
* left or right side to the target element by default.
22+
* Possible values are `start` and `end`.
23+
* RTL is taken into account when interpreting the value.
24+
* The overlay is automatically flipped to the opposite side when it doesn't fit into
25+
* the default side defined by this property.
26+
*
27+
* @attr {start|end} horizontal-align
28+
*/
29+
horizontalAlign: 'end' | 'start';
30+
31+
/**
32+
* When `positionTarget` is set, this property defines whether to align the overlay's
33+
* top or bottom side to the target element by default.
34+
* Possible values are `top` and `bottom`.
35+
* The overlay is automatically flipped to the opposite side when it doesn't fit into
36+
* the default side defined by this property.
37+
*
38+
* @attr {top|bottom} vertical-align
39+
*/
40+
verticalAlign: 'bottom' | 'top';
41+
42+
/**
43+
* When `positionTarget` is set, this property defines whether the overlay should overlap
44+
* the target element in the x-axis, or be positioned right next to it.
45+
*
46+
* @attr {boolean} no-horizontal-overlap
47+
*/
48+
noHorizontalOverlap: boolean;
49+
50+
/**
51+
* When `positionTarget` is set, this property defines whether the overlay should overlap
52+
* the target element in the y-axis, or be positioned right above/below it.
53+
*
54+
* @attr {boolean} no-vertical-overlap
55+
*/
56+
noVerticalOverlap: boolean;
57+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export const PositionMixin = (superClass) =>
5050
* RTL is taken into account when interpreting the value.
5151
* The overlay is automatically flipped to the opposite side when it doesn't fit into
5252
* the default side defined by this property.
53+
*
54+
* @attr {start|end} horizontal-align
5355
*/
5456
horizontalAlign: {
5557
type: String,
@@ -62,6 +64,8 @@ export const PositionMixin = (superClass) =>
6264
* Possible values are `top` and `bottom`.
6365
* The overlay is automatically flipped to the opposite side when it doesn't fit into
6466
* the default side defined by this property.
67+
*
68+
* @attr {top|bottom} vertical-align
6569
*/
6670
verticalAlign: {
6771
type: String,
@@ -71,6 +75,8 @@ export const PositionMixin = (superClass) =>
7175
/**
7276
* When `positionTarget` is set, this property defines whether the overlay should overlap
7377
* the target element in the x-axis, or be positioned right next to it.
78+
*
79+
* @attr {boolean} no-horizontal-overlap
7480
*/
7581
noHorizontalOverlap: {
7682
type: Boolean,
@@ -80,6 +86,8 @@ export const PositionMixin = (superClass) =>
8086
/**
8187
* When `positionTarget` is set, this property defines whether the overlay should overlap
8288
* the target element in the y-axis, or be positioned right above/below it.
89+
*
90+
* @attr {boolean} no-vertical-overlap
8391
*/
8492
noVerticalOverlap: {
8593
type: Boolean,

‎packages/overlay/test/typings/overlay.types.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import '../../vaadin-overlay.js';
21
import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
32
import type { DirMixinClass } from '@vaadin/component-base/src/dir-mixin.js';
43
import type { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
4+
import type { PositionMixinClass } from '../../src/vaadin-overlay-position-mixin.js';
5+
import { PositionMixin } from '../../src/vaadin-overlay-position-mixin.js';
56
import type {
67
OverlayCloseEvent,
78
OverlayClosingEvent,
@@ -10,6 +11,7 @@ import type {
1011
OverlayOpenEvent,
1112
OverlayOutsideClickEvent,
1213
} from '../../vaadin-overlay.js';
14+
import { Overlay } from '../../vaadin-overlay.js';
1315

1416
const assertType = <TExpected>(actual: TExpected) => actual;
1517

@@ -47,3 +49,20 @@ overlay.addEventListener('vaadin-overlay-outside-click', (event) => {
4749
assertType<OverlayOutsideClickEvent>(event);
4850
assertType<MouseEvent>(event.detail.sourceEvent);
4951
});
52+
53+
class CustomOverlay extends PositionMixin(Overlay) {
54+
static get is() {
55+
return 'custom-overlay';
56+
}
57+
}
58+
59+
customElements.define('custom-overlay', CustomOverlay);
60+
61+
const customOverlay = new CustomOverlay();
62+
63+
assertType<PositionMixinClass>(customOverlay);
64+
assertType<boolean>(customOverlay.noHorizontalOverlap);
65+
assertType<boolean>(customOverlay.noVerticalOverlap);
66+
assertType<'end' | 'start'>(customOverlay.horizontalAlign);
67+
assertType<'bottom' | 'top'>(customOverlay.verticalAlign);
68+
assertType<HTMLElement>(customOverlay.positionTarget);

0 commit comments

Comments
 (0)