-
Notifications
You must be signed in to change notification settings - Fork 4k
/
style.scss
558 lines (466 loc) · 13 KB
/
style.scss
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
// Navigation block and menu item styles.
// This also styles navigation links inside the Page List block,
// as that block is meant to behave as menu items when leveraged.
// The CSS lives here so that it is output even if you only use a
// Page List block inside your navigation block.
.wp-block-navigation {
position: relative;
// Horizontal layout
display: flex;
flex-wrap: wrap;
align-items: center;
// Vertical layout
&.is-vertical {
flex-direction: column;
align-items: flex-start;
}
// Normalize list styles.
ul,
ul li {
list-style: none;
// Overrides generic ".entry-content li" styles on the front end.
padding: 0;
}
// Menu item container.
.wp-block-pages-list__item,
.wp-block-navigation-link {
display: flex;
align-items: center;
position: relative;
.wp-block-navigation-link__container:empty {
display: none;
}
}
// Menu item link.
// By targetting the markup directly we enable greater global styles compatibility.
// The extra container specificity is due to global styles outputting link styles that need overriding.
&.wp-block-navigation a {
// Inherit colors set by the block color definition.
color: inherit;
display: block;
}
// Force links to inherit text decoration applied to navigation block.
// The extra selector adds specificity to ensure it works when user-set.
&[style*="text-decoration"] {
.wp-block-pages-list__item,
.wp-block-navigation-link__container,
.wp-block-navigation-link {
text-decoration: inherit;
}
a {
text-decoration: inherit;
&:focus,
&:active {
text-decoration: inherit;
}
}
}
&:not([style*="text-decoration"]) {
a {
text-decoration: none;
&:focus,
&:active {
text-decoration: none;
}
}
}
// Submenu indicator.
.wp-block-page-list__submenu-icon,
.wp-block-navigation-link__submenu-icon {
height: inherit;
margin-left: 6px;
svg {
stroke: currentColor;
}
}
}
// Styles for submenu flyout.
// These are separated out with reduced specificity to allow better inheritance from Global Styles.
.wp-block-navigation .has-child {
// We use :where to keep specificity minimal, yet still scope it to only the navigation block.
// That way if padding is set in theme.json, it still wins.
// https://css-tricks.com/almanac/selectors/w/where/
:where(.submenu-container, .wp-block-navigation-link__container) {
background-color: inherit;
color: inherit;
position: absolute;
z-index: 2;
display: flex;
flex-direction: column;
align-items: normal;
min-width: 200px;
// Hide until hover or focus within.
opacity: 0;
transition: opacity 0.1s linear;
visibility: hidden;
// Submenu items.
> .wp-block-pages-list__item,
> .wp-block-navigation-link {
> a {
display: flex;
flex-grow: 1;
// Right-align the chevron in submenus.
.wp-block-page-list__submenu-icon,
.wp-block-navigation-link__submenu-icon {
margin-right: 0;
margin-left: auto;
}
}
}
// Spacing in all submenus.
a {
margin: 0;
}
// Submenu indentation when there's no background.
left: -1em;
top: 100%;
// Indentation for all submenus.
// Nested submenus sit to the left on large breakpoints.
// On smaller breakpoints, they open vertically, accordion-style.
@include break-medium {
.submenu-container,
.wp-block-navigation-link__container {
left: 100%;
top: -1px; // Border width.
// Prevent the menu from disappearing when the mouse is over the gap
&::before {
content: "";
position: absolute;
right: 100%;
height: 100%;
display: block;
width: 0.5em;
background: transparent;
}
}
// Reset the submenu indicator for horizontal flyouts.
.wp-block-page-list__submenu-icon svg,
.wp-block-navigation-link__submenu-icon svg {
transform: rotate(-90deg);
}
}
}
// Separating out hover and focus-within so hover works again on IE: https://davidwalsh.name/css-focus-within#comment-513401
// We will need to replace focus-within with a JS solution for IE keyboard support.
// Custom menu items.
// Show submenus on hover.
&:hover > .wp-block-navigation-link__container {
visibility: visible;
opacity: 1;
}
// Keep submenus open when focus is within.
&:focus-within > .wp-block-navigation-link__container {
visibility: visible;
opacity: 1;
}
// Page list menu items.
&:hover {
cursor: pointer;
> .submenu-container {
visibility: visible;
opacity: 1;
}
}
&:focus-within {
cursor: pointer;
> .submenu-container {
visibility: visible;
opacity: 1;
}
}
}
// Submenu indentation when there's a background.
.wp-block-navigation.has-background .has-child .submenu-container,
.wp-block-navigation.has-background .has-child .wp-block-navigation-link__container {
left: 0;
top: 100%;
// There's no border on submenus when there are backgrounds.
@include break-medium {
.submenu-container,
.wp-block-navigation-link__container {
left: 100%;
top: 0;
}
}
}
/**
* Margins
* @todo: refactor this to use gap.
*/
// Menu items with no background.
.wp-block-page-list,
.wp-block-page-list > .wp-block-pages-list__item,
.wp-block-navigation__container > .wp-block-navigation-link {
margin: 0 2em 0 0;
// Margin of right-most margin should be zero, for right aligned or justified items.
&:last-child {
margin-right: 0;
}
}
// Menu items with background.
// We use :where to keep specificity minimal, yet still scope it to only the navigation block.
// That way if padding is set in theme.json, it still wins.
// https://css-tricks.com/almanac/selectors/w/where/
.wp-block-navigation:where(.has-background) {
.wp-block-page-list,
.wp-block-page-list > .wp-block-pages-list__item,
.wp-block-navigation__container > .wp-block-navigation-link {
margin: 0 0.5em 0 0;
// Don't show right margin on the last child.
&:last-child {
margin: 0;
}
}
}
/**
* Paddings
*/
// We use :where to keep specificity minimal, yet still scope it to only the navigation block.
// That way if padding is set in theme.json, it still wins.
// https://css-tricks.com/almanac/selectors/w/where/
// Set the default menu item padding to zero, to allow text-only buttons.
.wp-block-navigation a {
padding: 0;
}
// When the menu has a background, items have paddings, reduce margins to compensate.
// Treat margins and paddings differently when the block has a background.
.wp-block-navigation:where(.has-background) a {
padding: 0.5em 1em;
}
// Provide a default padding for submenus who should always have some, regardless of the top level menu items.
.wp-block-navigation :where(.submenu-container, .wp-block-navigation-link__container) a {
padding: 0.5em 1em;
}
/**
* Justifications.
*/
// When justified space-between, open submenus leftward for last menu item.
// When justified right, open all submenus leftwards.
// This needs high specificity.
.wp-block-navigation.items-justified-space-between .wp-block-page-list > .has-child:last-child,
.wp-block-navigation.items-justified-space-between > .wp-block-navigation__container > .has-child:last-child,
.wp-block-navigation.items-justified-right .wp-block-page-list > .has-child,
.wp-block-navigation.items-justified-right > .wp-block-navigation__container .has-child {
// First submenu.
.submenu-container,
.wp-block-navigation-link__container {
left: auto;
right: 0;
// Nested submenus.
.submenu-container,
.wp-block-navigation-link__container {
left: auto;
right: 100%;
}
}
}
// Default background and font color.
.wp-block-navigation:not(.has-background) {
.submenu-container, // This target items created by the Page List block.
.wp-block-navigation__container .wp-block-navigation-link__container {
// Set a background color for submenus so that they're not transparent.
// NOTE TO DEVS - if refactoring this code, please double-check that
// submenus have a default background color, this feature has regressed
// several times, so care needs to be taken.
background-color: #fff;
color: #000;
border: 1px solid rgba(0, 0, 0, 0.15);
}
}
// Navigation block inner container.
.wp-block-navigation__container {
// Vertically center child blocks, like Social Links or Search.
align-items: center;
// Reset the default list styles
list-style: none;
margin: 0;
padding-left: 0;
// Only hide the menu by default if responsiveness is active.
.is-responsive {
display: none;
}
// Horizontal layout
display: flex;
flex-wrap: wrap;
// Vertical layout
.is-vertical & {
display: block;
flex-direction: column;
align-items: flex-start;
}
}
// Justification.
// These target the named container class to work even with the additional mobile menu containers.
.items-justified-center .wp-block-navigation__container {
justify-content: center;
}
.items-justified-right .wp-block-navigation__container {
justify-content: flex-end;
}
.items-justified-space-between .wp-block-navigation__container {
justify-content: space-between;
}
// Vertical justification.
.is-vertical.items-justified-center > ul {
align-items: center;
}
.is-vertical.items-justified-right > ul {
align-items: flex-end;
.wp-block-navigation-link,
.wp-block-pages-list__item {
margin-right: 0;
justify-content: flex-end;
}
}
/**
* Mobile menu.
*/
.wp-block-navigation__responsive-container {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1;
align-items: flex-start;
justify-content: flex-start;
// Overlay menu.
// Provide an opinionated default style for menu items inside.
// Inherit as much as we can regarding colors, fonts, sizes,
// but otherwise provide a baseline.
// In a future version, we can explore more customizability.
&.is-menu-open {
display: flex;
flex-direction: column;
// Allow modal to scroll.
overflow: auto;
// Give it a z-index just higher than the adminbar.
z-index: 100000;
padding: 24px;
background-color: inherit;
.wp-block-navigation__container {
display: flex;
flex-direction: column;
margin-left: auto;
margin-right: auto;
align-items: flex-start;
line-height: 48px;
padding: 0;
.wp-block-page-list {
flex-direction: column;
}
}
// Remove background colors for items inside the overlay menu.
// Has to be !important to override global styles.
// @todo: We should revisit this so that the overlay colors can be applied, instead of the background.
.wp-block-pages-list__item .submenu-container,
.wp-block-navigation-link .wp-block-navigation-link__container,
.wp-block-pages-list__item,
.wp-block-navigation-link {
color: inherit !important;
background: transparent !important;
}
}
@include break-small() {
&:not(.is-menu-open) {
display: flex;
flex-direction: row;
position: relative;
background-color: inherit;
.wp-block-navigation__responsive-container-close {
display: none;
}
}
&.is-menu-open {
// Override breakpoint-inherited submenu rules.
.submenu-container.submenu-container.submenu-container.submenu-container,
.wp-block-navigation-link__container.wp-block-navigation-link__container.wp-block-navigation-link__container.wp-block-navigation-link__container {
left: 0;
}
}
}
}
// Default menu background and font color.
.wp-block-navigation:not(.has-background) .wp-block-navigation__responsive-container.is-menu-open {
background-color: #fff;
color: #000;
}
// Menu and close buttons.
.wp-block-navigation__responsive-container-open,
.wp-block-navigation__responsive-container-close {
vertical-align: middle;
cursor: pointer;
color: currentColor;
background: transparent;
border: none;
margin: 0;
padding: 0;
svg {
fill: currentColor;
pointer-events: none;
display: block;
width: 24px;
height: 24px;
}
}
// Button to open the menu.
.wp-block-navigation__responsive-container-open {
display: flex;
@include break-small {
display: none;
}
// Justify the button.
.items-justified-left & {
margin-left: 0;
margin-right: auto;
}
.items-justified-center & {
margin-left: auto;
margin-right: auto;
}
.items-justified-right & {
margin-left: auto;
margin-right: 0;
}
}
// Button to close the menus.
.wp-block-navigation__responsive-container-close {
position: absolute;
top: 24px;
right: 24px;
z-index: 2; // Needs to be above the modal z index itself.
}
// The menu adds wrapping containers.
.wp-block-navigation__responsive-close {
width: 100%;
}
.is-menu-open .wp-block-navigation__responsive-close,
.is-menu-open .wp-block-navigation__responsive-dialog,
.is-menu-open .wp-block-navigation__responsive-container-content {
width: 100%;
height: 100%;
}
// Always show submenus fully expanded inside the modal menu.
.wp-block-navigation .wp-block-navigation__responsive-container.is-menu-open {
.wp-block-page-list__submenu-icon,
.wp-block-navigation-link__submenu-icon {
display: none;
}
.has-child .submenu-container,
.has-child .wp-block-navigation-link__container {
position: relative;
opacity: 1;
visibility: visible;
padding: 0 0 0 32px;
border: none;
}
.wp-block-navigation-link,
.wp-block-pages-list__item {
flex-direction: column;
align-items: flex-start;
}
}
html.has-modal-open {
overflow: hidden;
}