UNPKG

9.78 kBSCSSView Raw
1// Foundation for Sites by ZURB
2// foundation.zurb.com
3// Licensed under MIT Open Source
4
5////
6/// @group menu
7////
8
9/// Margin of a menu.
10/// @type Number
11$menu-margin: 0 !default;
12
13/// Left-hand margin of a nested menu.
14/// @type Number
15$menu-nested-margin: $global-menu-nested-margin !default;
16
17/// Padding for items in a pill menu.
18/// @type Number
19$menu-items-padding: $global-menu-padding !default;
20
21/// margin for items in a simple menu.
22/// @type Number
23$menu-simple-margin: 1rem !default;
24
25/// Text color of an active menu item.
26/// @type Color
27$menu-item-color-active: $white !default;
28
29/// Background color of an active menu item.
30/// @type Color
31$menu-item-background-active: get-color(primary) !default;
32
33/// Spacing between an icon and text in a menu item.
34/// @type Number
35$menu-icon-spacing: 0.25rem !default;
36
37/// Background color for an hovered menu item.
38/// @type Color
39$menu-item-background-hover: $light-gray !default;
40
41/// Backward compatibility for menu state. If true, this duplicate `active` with `is-active`.
42/// But please note that `active` will be removed in upcoming versions.
43/// @type Boolean
44$menu-state-back-compat: true !default;
45
46/// Backward compatibility for menu centered. If true, this duplicate `.menu-centered > .menu` with `.menu.align-center`.
47/// But please note that `menu-centered` will be removed in upcoming versions.
48/// @type Boolean
49$menu-centered-back-compat: true !default;
50
51/// Backward compatibility for using `icon-*` classes without `.icons` classes
52/// But please note that this backward compatibility will be removed in upcoming versions.
53/// @type Boolean
54$menu-icons-back-compat: true !default;
55
56/// Creates the base styles for a Menu.
57@mixin menu-base {
58 padding: 0;
59 margin: 0;
60 list-style: none;
61 position: relative;
62
63 @if $global-flexbox {
64 display: flex;
65 flex-wrap: wrap;
66 }
67
68 li {
69 @include disable-mouse-outline;
70 }
71
72 a,
73 .button {
74 line-height: 1;
75 text-decoration: none;
76 display: block;
77 padding: $menu-items-padding;
78 }
79
80 // Reset styles of inner elements
81 input,
82 select,
83 a,
84 button {
85 margin-bottom: 0;
86 }
87
88 input {
89 display: inline-block;
90 }
91}
92
93/// Expands the items of a Menu, so each item is the same width.
94@mixin menu-expand {
95 @if $global-flexbox {
96 li {
97 flex: 1 1 0px; // sass-lint:disable-line zero-unit
98 }
99 }
100 @else {
101 display: table;
102 width: 100%;
103
104 > li {
105 display: table-cell;
106 vertical-align: middle;
107 }
108 }
109}
110
111/// Align menu items.
112@mixin menu-align($alignment) {
113 @if $alignment == left {
114 @if $global-flexbox {
115 justify-content: flex-start;
116 }
117 @else {
118 text-align: $global-left;
119 }
120 }
121 @else if $alignment == right {
122 @if $global-flexbox {
123 li {
124 display: flex;
125 justify-content: flex-end;
126
127 .submenu li {
128 justify-content: flex-start;
129 }
130 }
131
132 &.vertical li {
133 display: block;
134 text-align: $global-right;
135
136 .submenu li {
137 text-align: $global-right;
138 }
139 }
140 }
141 @else {
142 text-align: $global-right;
143
144 .submenu li {
145 text-align: $global-left;
146 }
147
148 &.vertical {
149 .submenu li {
150 text-align: $global-right;
151 }
152 }
153 }
154 }
155 @else if $alignment == center {
156 @if $global-flexbox {
157 li {
158 display: flex;
159 justify-content: center;
160
161 .submenu li {
162 justify-content: flex-start;
163 }
164 }
165 }
166 @else {
167 text-align: center;
168
169 .submenu li {
170 text-align: $global-left;
171 }
172 }
173 }
174}
175
176/// Sets the direction of a Menu.
177/// @param {Keyword} $dir [horizontal] - Direction of the Menu. Can be `horizontal` or `vertical`.
178@mixin menu-direction($dir: horizontal) {
179 @if $dir == horizontal {
180 @if $global-flexbox {
181 flex-wrap: wrap;
182 flex-direction: row;
183 }
184 @else {
185 li {
186 display: inline-block;
187 }
188 }
189 }
190 @else if $dir == vertical {
191 @if $global-flexbox {
192 flex-wrap: nowrap;
193 flex-direction: column;
194 }
195 @else {
196 li {
197 display: block;
198 }
199 }
200 }
201 @else {
202 @warn 'The direction used for menu-direction() must be horizontal or vertical.';
203 }
204}
205
206/// Creates a simple Menu, which has no padding or hover state.
207/// @param {Keyword} $dir [$global-left] - Direction of the menu. This effects the side of the `<li>` that receives the margin.
208/// @param {Number} $margin [$menu-simple-margin] - The margin to apply to each `<li>`.
209@mixin menu-simple($dir: $global-left, $margin: $menu-simple-margin) {
210 @if $global-flexbox {
211 align-items: center;
212 }
213
214 li + li {
215 margin-#{$dir}: $margin;
216 }
217
218 a {
219 padding: 0;
220 }
221}
222
223/// Adds styles for a nested Menu, by adding `margin-left` to the menu.
224/// @param {Keyword|Number} $margin [$menu-nested-margin] - Length of the margin.
225/// @param {Keyword} $nested-alignment [left] - Alignment of the nested class
226@mixin menu-nested(
227 $margin: $menu-nested-margin,
228 $nested-alignment: left
229) {
230 @if $nested-alignment == right {
231 margin-#{$global-right}: $margin;
232 margin-#{$global-left}: 0;
233 }
234 @else {
235 margin-#{$global-right}: 0;
236 margin-#{$global-left}: $margin;
237 }
238
239}
240
241/// Adds basic styles for icons in menus.
242@mixin menu-icons() {
243 @if $global-flexbox {
244 a {
245 display: flex;
246 }
247 }
248 @else {
249 img,
250 i,
251 svg {
252 vertical-align: middle;
253
254 + span {
255 vertical-align: middle;
256 }
257 }
258 }
259}
260
261/// Adds position classes for icons within a menu.
262@mixin menu-icon-position($position: left, $spacing: $menu-icon-spacing) {
263 @if $position == left {
264 li a {
265 @if $global-flexbox {
266 flex-flow: row nowrap;
267 }
268
269 img,
270 i,
271 svg {
272 margin-#{$global-right}: $spacing;
273
274 @if not $global-flexbox {
275 display: inline-block;
276 }
277 }
278 }
279 }
280 @else if $position == right {
281 li a {
282 @if $global-flexbox {
283 flex-flow: row nowrap;
284 }
285
286 img,
287 i,
288 svg {
289 margin-#{$global-left}: $spacing;
290
291 @if not $global-flexbox {
292 display: inline-block;
293 }
294 }
295 }
296 }
297 @else if $position == top {
298 li a {
299 @if $global-flexbox {
300 flex-flow: column nowrap;
301 }
302 @else {
303 text-align: center;
304 }
305
306 img,
307 i,
308 svg {
309 @if not $global-flexbox {
310 display: block;
311 margin: 0 auto $spacing;
312 }
313 @else {
314 align-self: stretch;
315 margin-bottom: $spacing;
316 text-align: center;
317 }
318 }
319 }
320 }
321 @else if $position == bottom {
322 li a {
323 @if $global-flexbox {
324 flex-flow: column nowrap;
325 }
326 @else {
327 text-align: center;
328 }
329
330 img,
331 i,
332 svg {
333 @if not $global-flexbox {
334 display: block;
335 margin: $spacing auto 0;
336 }
337 @else {
338 align-self: stretch;
339 margin-bottom: $spacing;
340 text-align: center;
341 }
342 }
343 }
344 }
345}
346
347@mixin menu-text {
348 padding: $global-menu-padding;
349
350 font-weight: bold;
351 line-height: 1;
352 color: inherit;
353}
354
355@mixin menu-state-active {
356 background: $menu-item-background-active;
357 color: $menu-item-color-active;
358}
359
360@mixin foundation-menu {
361 .menu {
362 @include menu-base;
363
364 // Default orientation: horizontal
365 &, &.horizontal {
366 @include menu-direction(horizontal);
367 }
368
369 // Vertical orientation modifier
370 &.vertical {
371 @include menu-direction(vertical);
372 }
373
374 // Even-width modifier for horizontal orientation
375 &.expanded {
376 @include menu-expand;
377 }
378
379 // Simple
380 &.simple {
381 @include menu-simple;
382 }
383
384 // Breakpoint specific versions
385 @include -zf-each-breakpoint($small: false) {
386 &.#{$-zf-size}-horizontal {
387 @include menu-direction(horizontal);
388 }
389
390 &.#{$-zf-size}-vertical {
391 @include menu-direction(vertical);
392 }
393
394 &.#{$-zf-size}-expanded {
395 @include menu-expand;
396 }
397
398 &.#{$-zf-size}-simple {
399 @include menu-expand;
400 }
401 }
402
403 // Nesting
404 &.nested {
405 @include menu-nested;
406 }
407
408 // Icon Base Styles
409 &.icons {
410 @include menu-icons;
411 }
412
413 // Backward Compatibility for active state
414 @if $menu-icons-back-compat {
415 &.icon-top,
416 &.icon-right,
417 &.icon-bottom,
418 &.icon-left {
419 @include menu-icons;
420 }
421 }
422
423 // Icon Left
424 &.icon-left {
425 @include menu-icon-position(left);
426 }
427
428 // Icon Right
429 &.icon-right {
430 @include menu-icon-position(right);
431 }
432
433 // Icon Top
434 &.icon-top {
435 @include menu-icon-position(top);
436 }
437
438 // Icon Bottom
439 &.icon-bottom {
440 @include menu-icon-position(bottom);
441 }
442
443 // Active state
444 .is-active > a {
445 @include menu-state-active;
446 }
447
448 // Backward Compatibility for active state
449 @if $menu-state-back-compat {
450 .active > a {
451 @include menu-state-active;
452 }
453 }
454
455 // Align left
456 &.align-#{$global-left} {
457 @include menu-align(left);
458 }
459
460 // Align right
461 &.align-#{$global-right} {
462 @include menu-align(right);
463
464 .nested {
465 @include menu-nested($nested-alignment: right);
466 }
467 }
468
469 // Align center
470 &.align-center {
471 @include menu-align(center);
472 }
473
474 .menu-text {
475 @include menu-text;
476 }
477 }
478
479 @if $menu-centered-back-compat {
480 .menu-centered {
481 > .menu {
482 @if $global-flexbox {
483 justify-content: center;
484 }
485
486 @include menu-align(center);
487 }
488 }
489 }
490
491 // Prevent FOUC when using the Responsive Menu plugin
492 .no-js [data-responsive-menu] ul {
493 display: none;
494 }
495}