Skip to content

Commit f4e525d

Browse files
authored
refactor: extract overlay base styles to reusable css literal (#6124)
1 parent ae31f5f commit f4e525d

2 files changed

Lines changed: 70 additions & 66 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 overlayStyles = css`
9+
:host {
10+
z-index: 200;
11+
position: fixed;
12+
13+
/* Despite of what the names say, <vaadin-overlay> is just a container
14+
for position/sizing/alignment. The actual overlay is the overlay part. */
15+
16+
/* Default position constraints: the entire viewport. Note: themes can
17+
override this to introduce gaps between the overlay and the viewport. */
18+
inset: 0;
19+
bottom: var(--vaadin-overlay-viewport-bottom);
20+
21+
/* Use flexbox alignment for the overlay part. */
22+
display: flex;
23+
flex-direction: column; /* makes dropdowns sizing easier */
24+
/* Align to center by default. */
25+
align-items: center;
26+
justify-content: center;
27+
28+
/* Allow centering when max-width/max-height applies. */
29+
margin: auto;
30+
31+
/* The host is not clickable, only the overlay part is. */
32+
pointer-events: none;
33+
34+
/* Remove tap highlight on touch devices. */
35+
-webkit-tap-highlight-color: transparent;
36+
37+
/* CSS API for host */
38+
--vaadin-overlay-viewport-bottom: 0;
39+
}
40+
41+
:host([hidden]),
42+
:host(:not([opened]):not([closing])) {
43+
display: none !important;
44+
}
45+
46+
[part='overlay'] {
47+
-webkit-overflow-scrolling: touch;
48+
overflow: auto;
49+
pointer-events: auto;
50+
51+
/* Prevent overflowing the host */
52+
max-width: 100%;
53+
box-sizing: border-box;
54+
55+
-webkit-tap-highlight-color: initial; /* reenable tap highlight inside */
56+
}
57+
58+
[part='backdrop'] {
59+
z-index: -1;
60+
content: '';
61+
background: rgba(0, 0, 0, 0.5);
62+
position: fixed;
63+
inset: 0;
64+
pointer-events: auto;
65+
}
66+
`;

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

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
77
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
88
import { processTemplates } from '@vaadin/component-base/src/templates.js';
9-
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9+
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
1010
import { OverlayMixin } from './vaadin-overlay-mixin.js';
11+
import { overlayStyles } from './vaadin-overlay-styles.js';
12+
13+
registerStyles('vaadin-overlay', overlayStyles, { moduleId: 'vaadin-overlay-styles' });
1114

1215
/**
1316
* `<vaadin-overlay>` is a Web Component for creating overlays. The content of the overlay
@@ -76,71 +79,6 @@ import { OverlayMixin } from './vaadin-overlay-mixin.js';
7679
class Overlay extends OverlayMixin(ThemableMixin(DirMixin(PolymerElement))) {
7780
static get template() {
7881
return html`
79-
<style>
80-
:host {
81-
z-index: 200;
82-
position: fixed;
83-
84-
/* Despite of what the names say, <vaadin-overlay> is just a container
85-
for position/sizing/alignment. The actual overlay is the overlay part. */
86-
87-
/* Default position constraints: the entire viewport. Note: themes can
88-
override this to introduce gaps between the overlay and the viewport. */
89-
top: 0;
90-
right: 0;
91-
bottom: var(--vaadin-overlay-viewport-bottom);
92-
left: 0;
93-
94-
/* Use flexbox alignment for the overlay part. */
95-
display: flex;
96-
flex-direction: column; /* makes dropdowns sizing easier */
97-
/* Align to center by default. */
98-
align-items: center;
99-
justify-content: center;
100-
101-
/* Allow centering when max-width/max-height applies. */
102-
margin: auto;
103-
104-
/* The host is not clickable, only the overlay part is. */
105-
pointer-events: none;
106-
107-
/* Remove tap highlight on touch devices. */
108-
-webkit-tap-highlight-color: transparent;
109-
110-
/* CSS API for host */
111-
--vaadin-overlay-viewport-bottom: 0;
112-
}
113-
114-
:host([hidden]),
115-
:host(:not([opened]):not([closing])) {
116-
display: none !important;
117-
}
118-
119-
[part='overlay'] {
120-
-webkit-overflow-scrolling: touch;
121-
overflow: auto;
122-
pointer-events: auto;
123-
124-
/* Prevent overflowing the host in MSIE 11 */
125-
max-width: 100%;
126-
box-sizing: border-box;
127-
128-
-webkit-tap-highlight-color: initial; /* reenable tap highlight inside */
129-
}
130-
131-
[part='backdrop'] {
132-
z-index: -1;
133-
content: '';
134-
background: rgba(0, 0, 0, 0.5);
135-
position: fixed;
136-
top: 0;
137-
left: 0;
138-
bottom: 0;
139-
right: 0;
140-
pointer-events: auto;
141-
}
142-
</style>
143-
14482
<div id="backdrop" part="backdrop" hidden$="[[!withBackdrop]]"></div>
14583
<div part="overlay" id="overlay" tabindex="0">
14684
<div part="content" id="content">

0 commit comments

Comments
 (0)