-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoverlay-picker-mixin.js
145 lines (131 loc) · 3.53 KB
/
overlay-picker-mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import './overlay-element.js';
/**
* mixin to extend an picker with an `overlay-element`
*
* @mixinFunction
* @polymer
*/
export const OverlayPickerMixin = dedupingMixin( superClass => {
return class extends superClass {
static get properties() {
return {
/**
* Set to true to keep overlay always on top.
*/
alwaysOnTop: {
type: Boolean
},
/**
* Will position the element around the positionTarget without overlapping it.
*/
noOverlap: {
type: Boolean,
value: false
},
/**
* Set to true to display a backdrop behind the overlay. It traps the focus
* within the light DOM of the overlay.
*/
withBackdrop: {
type: Boolean,
value: false
},
/**
* Set to true to disable canceling the overlay by clicking outside it.
*/
noCancelOnOutsideClick: {
type: Boolean,
value: false
},
/**
* If true, it will use `horizontalAlign` and `verticalAlign` values as preferred alignment
* and if there's not enough space, it will pick the values which minimize the cropping.
*/
dynamicAlign: {
type: Boolean,
reflectToAttribute: true
},
/**
* Set to true to auto-fit on attach.
*/
autoFitOnAttach: {
type: Boolean,
value: false
},
/**
* The element to fit the overlay into. By default it is the window.
*/
fitInto: {
type: Object
},
/**
* The element that should be used to position the overlay. If not set, it will
* default to the polyfill node.
*/
positionTarget: {
type: Element
},
_sizingTarget: {
type: Element,
readOnly: true
}
}
}
static get pickerTemplate() {
return html`
<overlay-element id="overlay"
always-on-top="[[alwaysOnTop]]"
with-backdrop="[[withBackdrop]]"
no-cancel-on-outside-click="[[noCancelOnOutsideClick]]"
no-cancel-on-esc-key="[[noCancelOnEscKey]]"
no-overlap="[[noOverlap]]"
auto-fit-on-attach="[[autoFitOnAttach]]"
dynamic-align="[[dynamicAlign]]"
vertical-align="[[verticalAlign]]"
horizontal-align="[[horizontalAlign]]"
position-target="[[positionTarget]]"
sizing-target="[[_sizingTarget]]"
fit-into="[[fitInto]]"
opened="{{opened}}">
${super.pickerTemplate}
</overlay-element>
`;
}
static get styleTemplate() {
return html`
${super.styleTemplate || html``}
<style>
#overlay {
display: inline-flex;
flex-shrink: 0;
padding: 0;
}
</style>
`;
}
connectedCallback() {
super.connectedCallback();
this.positionTarget = this;
this._set_sizingTarget(this.$.overlay);
this.fit();
}
/**
* Positions and fits the overlay into the `fitInto` element.
*/
fit() {
this.$.overlay.fit();
}
open() {
super.open();
this.fit();
}
/**
* notify manually the overlay to resize
*/
notifyResize() {
this.$.overlay.notifyResize();
}
}
});