UNPKG

13.6 kBSCSSView Raw
1@use '../internal' as *;
2
3@mixin mobile-dropdown-menu-show {
4 border-radius: 0;
5 box-shadow: none;
6 display: block;
7 position: relative;
8 top: 1rem;
9 float: none;
10 border: none;
11 background-color: transparent;
12 margin-bottom: 1rem;
13}
14
15/* These styles can also be used on menus in the body */
16@mixin nav-bar-position($position) {
17 align-items: stretch;
18 flex-basis: 0;
19 flex-grow: 1;
20 flex-shrink: 0;
21 display: flex;
22
23 justify-content: flex-#{$position};
24 white-space: nowrap;
25}
26
27$generate-utility: should-generate-classes($HEADER);
28
29@if $generate-utility {
30
31 /* HEADER */
32 .header {
33 flex-grow: 1;
34 width: 100%;
35 z-index: 100;
36 margin-bottom: 20px;
37 box-shadow: 0 3px 15px rgba(57, 63, 72, 0.1);
38 background-color: var(--cirrus-bg);
39 max-height: 100vh;
40 padding: 0 2rem;
41 transition: all 0.3s;
42 display: flex;
43 --header-link-color: #{fill('gray', '700')};
44 --header-link-color-hover: #{lighten(fill('gray', '700'), 10)};
45
46 /* Remove any padding set for headers in default.scss */
47 @for $i from 1 through 6 {
48 h#{$i} {
49 margin: 0;
50 }
51 }
52
53 a {
54 color: var(--header-link-color);
55
56 &:hover {
57 color: var(--header-link-color-hover);
58 }
59 }
60
61 /* Header dark theme */
62 &.header-dark {
63 background-color: rgba(0, 0, 0, 0.87);
64 color: #fff;
65 --header-link-color: #fff;
66 --header-link-color-hover: #fff;
67
68 /* Theme for dark menu */
69 // .nav-item a {
70 // color: #fff;
71 // }
72 }
73
74 &.header-clear {
75 background-color: transparent;
76 box-shadow: none;
77
78 /* Add border radius to whole menu with clear header */
79 .nav-item .dropdown-menu {
80 border-radius: 4px;
81 }
82 }
83
84 /* Add transition to nav menu when it drops down */
85 &.header-animated .header-nav {
86 transition: all 0.3s;
87 }
88
89 /* The container that contains all the header menu components. Child of header */
90 .header-nav {
91 /* Flex display 768px and higher */
92 overflow: auto;
93 }
94
95 .header-brand {
96 align-items: stretch;
97 display: flex;
98 flex-shrink: 0;
99 max-width: 100vw;
100 min-height: 3.25rem;
101 overflow-x: auto;
102 overflow-y: hidden;
103 }
104
105 /* Static header at the top of the screen */
106 &.header-fixed {
107 position: fixed;
108 top: 0; /* Change this if you want to float the header somewhere else */
109 }
110
111 /* Hover effect for header elements when appropriate */
112 &:not(.header-clear) .nav-item:not(.no-hover):hover,
113 &:not(.header-clear) .nav-item:not(.no-hover).hovered {
114 background-color: rgba(216, 216, 216, 0.15);
115 transition: all 0.3s;
116 }
117
118 &:not(.header-clear) .nav-item.active, /* active:hover removes the transition effect when hovering over the dropdown menu */
119 &:not(.header-clear) .nav-item.active:hover {
120 background-color: rgba(216, 216, 216, 0.35);
121 }
122
123 .nav-btn {
124 cursor: pointer;
125 display: block;
126 height: 3.5rem;
127 position: relative;
128 width: 3.5rem;
129 }
130
131 #{$button-selectors} {
132 margin: 0;
133 }
134 }
135
136 /* Styles for header menu (aka the nav bar) */
137 .nav-menu {
138 transition: all 0.3s;
139
140 .has-sub {
141 position: relative;
142 }
143 }
144
145 /* Allow the user to scroll through navbar items if it exceeds nav-left, nav-center, or nav-right widths */
146 .nav-overflow-x {
147 justify-content: inherit;
148 overflow-x: scroll;
149 }
150
151 /* Wrapper to vertically center header items */
152 .nav-item {
153 align-items: center;
154 display: flex;
155 position: relative;
156 flex-grow: 0;
157 flex-shrink: 0;
158 justify-content: center;
159 transition: all 0.3s;
160 padding: 0 0.3rem;
161 cursor: pointer;
162
163 a {
164 align-items: center;
165 display: flex;
166 }
167
168 /* HEADER DROP DOWN MENU */
169 .dropdown-menu {
170 background-color: var(--cirrus-bg);
171 position: absolute;
172 top: 95%;
173 /*right: 0; /* Unable to solve problem when we have multiple drop down menus */
174 z-index: 1000;
175 float: left;
176 min-width: 160px;
177 padding: 5px 0;
178 margin: 2px 0 0;
179 font-size: 14px;
180 text-align: left;
181 list-style: none;
182 background-clip: padding-box;
183 border: 1px solid fill('gray', '200');
184 border-radius: 0 0 4px 4px;
185 box-shadow: 0 0.5rem 1rem rgba(10, 10, 10, 0.1);
186
187 /* Just add a transition in general */
188 &.dropdown-animated {
189 transition: all var(--animation-duration);
190 }
191
192 & > li > a {
193 display: block;
194 padding: 0.5rem 1rem;
195 clear: both;
196 line-height: 1.42857143;
197 white-space: nowrap;
198 }
199
200 & > li {
201 margin: 0;
202 transition: all 0.3s;
203 }
204
205 & > li:hover {
206 transition: all 0.3s;
207 background-color: rgba(216, 216, 216, 0.15);
208 }
209
210 & > li:active {
211 transition: all 0.3s;
212 background-color: rgba(216, 216, 216, 0.25);
213 }
214
215 & > li:last-child {
216 margin-bottom: 0;
217 }
218
219 .dropdown-menu-divider {
220 border: none;
221 background-color: rgba(216, 216, 216, 0.15);
222 height: 1px;
223 margin: 0.5rem 0;
224 }
225 }
226
227 /* Add room for the dropdown chevron pseudoelement */
228 &.has-sub .nav-dropdown-link {
229 padding-right: 2.5rem;
230 position: relative; /* Needed for hiding glyphs in mobile header */
231
232 /* Dropdown menu location adjustment located below for sizes above phones */
233 /* Dropdown menu indicator */
234 &::after {
235 border: 2px solid $cirrus-primary; /* Must be first to create the triangle shape */
236 border-right: 0; /* Create the triangle effect */
237 border-top: 0;
238 display: block;
239 height: 0.5em;
240 width: 0.5em;
241 content: ' ';
242 transform: rotate(-45deg);
243 pointer-events: none;
244 margin-top: -0.435em;
245 right: 1.125em;
246 top: 50%;
247 position: absolute;
248 }
249 }
250 }
251
252 /* Dark dropdown menu theme */
253 .nav-item .dropdown-menu.dropdown-dark,
254 .header.header-dark .dropdown-menu {
255 background-color: rgba(0, 0, 0, 0.87);
256 border: 1px solid fill('gray', '800');
257 color: #fff;
258 }
259
260 .dropdown-menu.dropdown-shown,
261 .nav-item.active {
262 opacity: 1;
263 }
264
265 @include screen-above($sm) {
266 .header {
267 align-items: stretch;
268 display: flex;
269
270 .header-nav {
271 flex-grow: 1;
272 align-items: stretch; /* Make items fill up all available space regardless of width https://drafts.csswg.org/css-align/ */
273 display: flex;
274 position: relative;
275 text-align: center;
276 width: 100%;
277 top: 0;
278 overflow: visible; /* Only visible for showing dropdown menus, hidden for mobile */
279 }
280
281 /* Align items to the left */
282 .nav-left {
283 @include nav-bar-position('start');
284
285 /* Align dropdown menu to the left side of the parent nav-item for header-left */
286 .has-sub .dropdown-menu {
287 left: 0;
288 right: auto;
289 }
290 }
291
292 /* Align items to the right */
293 .nav-right {
294 @include nav-bar-position('end');
295
296 /* Align dropdown menu to the right side of the parent nav-item for header-right */
297 .has-sub .dropdown-menu {
298 left: auto;
299 right: 0;
300 }
301 }
302
303 /* Centering items, best used when nav-brand is not used to prevent offset */
304 .nav-center {
305 align-items: stretch;
306 display: flex;
307 flex-grow: 0;
308 flex-shrink: 0;
309 justify-content: center;
310 margin-left: auto;
311 margin-right: auto;
312 }
313
314 /* Hide hamburger button */
315 .nav-btn {
316 display: none;
317 }
318
319 .nav-item {
320 /* Expand link area for desktop views so it is easier to click */
321 a {
322 padding: 0.5rem 1rem;
323 }
324
325 .dropdown-menu {
326 opacity: 0;
327 pointer-events: none; /* Make cursor not respond to menu links when not displayed */
328 }
329
330 .dropdown-menu.dropdown-animated {
331 transform: translateY(-5px);
332 }
333
334 .dropdown-menu.dropdown-shown,
335 &.toggle-hover:hover .dropdown-menu,
336 .dropdown-menu.dropdown-animated.dropdown-shown {
337 opacity: 1;
338 transform: none;
339 pointer-events: auto;
340 }
341 }
342 }
343 }
344
345 @include screen-below($sm) {
346 /* Add scrolling support in header */
347 .header {
348 flex-direction: column;
349
350 .header-brand .nav-item:first-child {
351 padding: 0 1rem; /* Add padding to the first child, usually the logo */
352 }
353
354 /* Hide dropdown menu on mobile */
355 .header-nav {
356 height: 0;
357
358 /* Show the dropdown */
359 &.active {
360 height: 100vh;
361 }
362
363 /* Make the menu items larger in the dropdown menu */
364 .nav-item {
365 padding: 1rem;
366 }
367
368 /* Get rid of extra spaces */
369 .nav-item > a {
370 padding: 0;
371 width: 100%; /* Stretch the link to span the entire list item */
372 }
373 }
374 }
375
376 /* Remove flex for mobile devices */
377 .nav-item.has-sub {
378 display: block;
379
380 .dropdown-menu {
381 /* Hide the menu by default in mobile view (overflow on header-right can expose it) */
382 display: none;
383
384 &.dropdown-shown {
385 @include mobile-dropdown-menu-show();
386 }
387
388 &.dropdown-dark {
389 background-color: rgba(0, 0, 0, 0.17);
390 border: 0;
391 }
392 }
393 }
394
395 /* Hamburger button */
396 .nav-btn {
397 cursor: pointer;
398 display: block;
399 position: relative;
400 margin-left: auto;
401
402 span {
403 background-color: var(--header-link-color);
404 display: block;
405 height: 2px;
406 left: 50%;
407 margin-left: -7px;
408 position: absolute;
409 top: 50%;
410 transition: all 86ms ease-out;
411 width: 15px;
412
413 /* Line spacing in hamburger button */
414 &:nth-child(1) {
415 margin-top: -6px;
416 }
417
418 &:nth-child(2) {
419 margin-top: -1px;
420 }
421
422 &:nth-child(3) {
423 margin-top: 4px;
424 }
425 }
426
427 /* Hamburger button on active */
428 &.active span:nth-child(1) {
429 margin-left: -5px;
430 transform: rotate(45deg);
431 transform-origin: left top;
432 }
433
434 &.active span:nth-child(2) {
435 opacity: 0;
436 }
437
438 &.active span:nth-child(3) {
439 margin-left: -5px;
440 transform: rotate(-45deg);
441 transform-origin: left bottom;
442 }
443 }
444
445 /* Hide drop down menu items */
446 .nav-left,
447 .nav-center,
448 .nav-right {
449 overflow: hidden;
450 }
451
452 /* No need for JS to show dropdown menu on mobile devices now */
453 .header .nav-item.has-sub.toggle-hover:not(.no-hover):hover > .dropdown-menu {
454 @include mobile-dropdown-menu-show();
455 }
456 }
457}