-
Notifications
You must be signed in to change notification settings - Fork 25
/
dropdown-content-styles.js
358 lines (303 loc) · 9.96 KB
/
dropdown-content-styles.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import '../colors/colors.js';
import { _offscreenStyleDeclarations } from '../offscreen/offscreen.js';
import { css } from 'lit';
const pointerLength = 16;
const pointerRotatedLength = Math.SQRT2 * parseFloat(pointerLength);
export const dropdownContentStyles = css`
:host {
--d2l-dropdown-above-animation-name: d2l-dropdown-above-animation;
--d2l-dropdown-animation-name: d2l-dropdown-animation;
--d2l-dropdown-background-color: #ffffff;
--d2l-dropdown-border-color: var(--d2l-color-mica);
--d2l-dropdown-foreground-color: var(--d2l-color-ferrite);
--d2l-dropdown-shadow-color: rgba(0, 0, 0, 0.15);
box-sizing: border-box;
color: var(--d2l-dropdown-foreground-color);
display: none;
left: 0;
position: absolute;
text-align: left;
top: calc(100% + var(--d2l-dropdown-verticaloffset, 16px));
width: 100%;
z-index: 998; /* position on top of floating buttons */
}
:host([_fixed-positioning]) {
position: fixed;
top: 0;
}
:host([theme="dark"]) {
--d2l-dropdown-above-animation-name: d2l-dropdown-above-animation-dark;
--d2l-dropdown-animation-name: d2l-dropdown-animation-dark;
--d2l-dropdown-background-color: #333536; /* tungsten @ 70% */
--d2l-dropdown-border-color: var(--d2l-color-tungsten);
--d2l-dropdown-foreground-color: var(--d2l-color-sylvite);
--d2l-dropdown-shadow-color: rgba(0, 0, 0, 1);
opacity: 0.9;
}
:host([opened]) {
animation: var(--d2l-dropdown-animation-name) 300ms ease;
display: inline-block;
}
:host([opened-above]) {
animation: var(--d2l-dropdown-above-animation-name) 300ms ease;
bottom: calc(100% + var(--d2l-dropdown-verticaloffset, 16px));
top: auto;
}
:host([data-mobile][opened]:not([mobile-tray])) {
animation: var(--d2l-dropdown-animation-name) 300ms ease;
display: inline-block;
}
:host([data-mobile][opened-above]:not([mobile-tray])) {
animation: var(--d2l-dropdown-above-animation-name) 300ms ease;
bottom: calc(100% + var(--d2l-dropdown-verticaloffset, 16px));
top: auto;
}
:host([_fixed-positioning][opened-above]),
:host([_fixed-positioning][data-mobile][opened-above]:not([mobile-tray])) {
bottom: 0;
}
.d2l-dropdown-content-pointer {
clip: rect(-5px, 21px, 8px, -7px);
display: inline-block;
left: calc(50% - 7px); /* todo: cleanup when switched to fixed positioning */
position: absolute;
top: -7px; /* todo: cleanup when switched to fixed positioning */
z-index: 1;
}
:host([_fixed-positioning][dir="rtl"]) .d2l-dropdown-content-pointer {
left: auto;
}
:host([align="start"]) .d2l-dropdown-content-pointer,
:host([align="end"][dir="rtl"]) .d2l-dropdown-content-pointer {
/* todo: cleanup when switched to fixed positioning */
left: min(calc(1rem + ${(pointerRotatedLength - pointerLength) / 2}px), calc(50% - ${pointerLength / 2}px)); /* 1rem corresponds to .d2l-dropdown-content-container padding */
right: auto;
}
:host([align="end"]) .d2l-dropdown-content-pointer,
:host([align="start"][dir="rtl"]) .d2l-dropdown-content-pointer {
/* todo: cleanup when switched to fixed positioning */
left: auto;
right: min(calc(1rem + ${(pointerRotatedLength - pointerLength) / 2}px), calc(50% - ${pointerLength / 2}px)); /* 1rem corresponds to .d2l-dropdown-content-container padding */
}
.d2l-dropdown-content-pointer > div {
background-color: var(--d2l-dropdown-background-color);
border: 1px solid var(--d2l-dropdown-border-color);
border-radius: 0.1rem;
box-shadow: -4px -4px 12px -5px rgba(32, 33, 34, 0.2); /* ferrite */
height: ${pointerLength}px;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
width: ${pointerLength}px;
}
:host([opened-above]) .d2l-dropdown-content-pointer {
bottom: -8px;
clip: rect(9px, 21px, 22px, -3px);
top: auto;
}
:host([_fixed-positioning][opened-above]) .d2l-dropdown-content-pointer {
bottom: auto;
}
:host([opened-above]) .d2l-dropdown-content-pointer > div {
box-shadow: 4px 4px 12px -5px rgba(32, 33, 34, 0.2); /* ferrite */
}
:host([no-pointer]) .d2l-dropdown-content-pointer {
display: none;
}
.d2l-dropdown-content-position {
border-radius: 0.3rem;
display: inline-block;
position: absolute;
}
.d2l-dropdown-content-width {
align-items: flex-start;
background-color: var(--d2l-dropdown-background-color);
border: 1px solid var(--d2l-dropdown-border-color);
border-radius: 0.3rem;
box-shadow: 0 2px 12px 0 var(--d2l-dropdown-shadow-color);
box-sizing: border-box;
display: flex;
flex-direction: column;
max-width: 370px;
min-width: 70px;
position: absolute;
width: 100vw;
}
d2l-focus-trap {
position: absolute;
}
:host([opened-above]) .d2l-dropdown-content-width {
bottom: 100%;
}
.d2l-dropdown-content-container {
box-sizing: border-box;
max-width: 100%;
outline: none;
overflow-y: auto;
padding: 1rem;
}
.d2l-dropdown-content-top,
.d2l-dropdown-content-bottom {
box-sizing: border-box;
max-width: 100%;
min-height: 5px;
position: relative;
z-index: 2;
}
.d2l-dropdown-content-header {
border-bottom: 1px solid var(--d2l-dropdown-border-color);
padding: 1rem;
}
.d2l-dropdown-content-footer {
border-top: 1px solid var(--d2l-dropdown-border-color);
padding: 1rem;
}
:host([no-padding]) .d2l-dropdown-content-container,
:host([no-padding-header]) .d2l-dropdown-content-header,
:host([no-padding-footer]) .d2l-dropdown-content-footer {
padding: 0;
}
.d2l-dropdown-content-top {
border-top-left-radius: 0.3rem;
border-top-right-radius: 0.3rem;
}
.d2l-dropdown-content-bottom {
border-bottom-left-radius: 0.3rem;
border-bottom-right-radius: 0.3rem;
}
.d2l-dropdown-content-top-scroll {
box-shadow: 0 3px 3px 0 var(--d2l-dropdown-shadow-color);
}
.d2l-dropdown-content-bottom-scroll {
box-shadow: 0 -3px 3px 0 var(--d2l-dropdown-shadow-color);
}
:host([dir="rtl"]) {
left: auto;
right: 0;
text-align: right;
}
:host(.d2l-dropdown-content-fading) {
opacity: 0;
/* matches DropdownOpenerMixin _closeTimerStart function */
transition: opacity 0.4s ease-out 0.3s;
}
@media (prefers-reduced-motion: reduce) {
:host(.d2l-dropdown-content-fading) {
opacity: 1;
transition: none;
}
}
@media (prefers-reduced-motion: reduce) {
:host([opened]), :host([opened-above]) {
animation: none !important;
}
}
@keyframes d2l-dropdown-animation {
0% { opacity: 0; transform: translate(0, -10px); }
100% { opacity: 1; transform: translate(0, 0); }
}
@keyframes d2l-dropdown-animation-dark {
0% { opacity: 0; transform: translate(0, -10px); }
100% { opacity: 0.9; transform: translate(0, 0); }
}
@keyframes d2l-dropdown-above-animation {
0% { opacity: 0; transform: translate(0, 10px); }
100% { opacity: 1; transform: translate(0, 0); }
}
@keyframes d2l-dropdown-above-animation-dark {
0% { opacity: 0; transform: translate(0, 10px); }
100% { opacity: 0.9; transform: translate(0, 0); }
}
@keyframes d2l-dropdown-mobile-tray-right {
0% { opacity: 0; transform: translateX(100%); }
100% { opacity: 1; transform: translate(0, 0); }
}
@keyframes d2l-dropdown-mobile-tray-right-close {
0% { opacity: 1; transform: translate(0, 0); }
100% { opacity: 0; transform: translateX(100%); }
}
@keyframes d2l-dropdown-mobile-tray-left {
0% { opacity: 0; transform: translateX(-100%); }
100% { opacity: 1; transform: translate(0, 0); }
}
@keyframes d2l-dropdown-mobile-tray-left-close {
0% { opacity: 1; transform: translate(0, 0); }
100% { opacity: 0; transform: translateX(-100%); }
}
@keyframes d2l-dropdown-mobile-tray-bottom {
0% { opacity: 0; transform: translateY(100%); }
100% { opacity: 1; transform: translate(0, 0); }
}
@keyframes d2l-dropdown-mobile-tray-bottom-close {
0% { opacity: 1; transform: translate(0, 0); }
100% { opacity: 0; transform: translateY(100%); }
}
:host([data-mobile][mobile-tray="left"]) .d2l-dropdown-content-width {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
bottom: 0;
position: fixed;
top: 0;
z-index: 1000;
}
:host([data-mobile][mobile-tray="right"]) .d2l-dropdown-content-width {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
bottom: 0;
position: fixed;
top: 0;
z-index: 1000;
}
:host([data-mobile][mobile-tray="bottom"]) .d2l-dropdown-content-width {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
left: 0;
position: fixed;
z-index: 1000;
}
:host([data-mobile][mobile-tray="right"][opened]) .d2l-dropdown-content-width {
animation: d2l-dropdown-mobile-tray-right 300ms ease-out;
right: 0;
}
:host([data-mobile][mobile-tray="left"][opened]) .d2l-dropdown-content-width {
animation: d2l-dropdown-mobile-tray-left 300ms ease-out;
left: 0;
}
:host([data-mobile][mobile-tray="bottom"][opened]) .d2l-dropdown-content-width {
animation: d2l-dropdown-mobile-tray-bottom 300ms ease-out;
bottom: 0;
}
:host([data-mobile][mobile-tray="right"][opened]) .d2l-dropdown-content-width[data-closing] {
animation: d2l-dropdown-mobile-tray-right-close 300ms ease-out;
}
:host([data-mobile][mobile-tray="left"][opened]) .d2l-dropdown-content-width[data-closing] {
animation: d2l-dropdown-mobile-tray-left-close 300ms ease-out;
}
:host([data-mobile][mobile-tray="bottom"][opened]) .d2l-dropdown-content-width[data-closing] {
animation: d2l-dropdown-mobile-tray-bottom-close 300ms ease-out;
}
:host([data-mobile][mobile-tray="left"][opened]) .d2l-dropdown-content-container,
:host([data-mobile][mobile-tray="right"][opened]) .d2l-dropdown-content-container {
height: 100vh;
}
:host([data-mobile][mobile-tray]) > .d2l-dropdown-content-pointer {
display: none;
}
:host([data-mobile][mobile-tray][opened]) {
animation: none;
}
:host([data-mobile][mobile-tray]) .d2l-dropdown-content-bottom,
:host([data-mobile][mobile-tray]) .d2l-dropdown-content-top {
min-height: auto;
}
@media (prefers-reduced-motion: reduce) {
:host([data-mobile][mobile-tray][opened]) .d2l-dropdown-content-width {
animation: none;
}
:host([data-mobile][mobile-tray][opened]) .d2l-dropdown-content-width[data-closing] {
animation: none;
}
}
:host([offscreen]) {
${_offscreenStyleDeclarations}
}
`;