Skip to content

Instantly share code, notes, and snippets.

@chooie
Created April 23, 2023 11:16
Show Gist options
  • Save chooie/93f2ea9a7f9b964163730d283e54ca35 to your computer and use it in GitHub Desktop.
Save chooie/93f2ea9a7f9b964163730d283e54ca35 to your computer and use it in GitHub Desktop.
@use "styles/constants";
$navbar: ".IIT-navbar";
$markerClass: ".active-marker";
:root {
--navbar-height: 50px;
--menu-inset: -8px;
}
.menu-text {
display: flex;
align-items: center;
gap: var(--spacing-1);
}
#{$navbar} {
/* There was a horizontal scrollbar from visually hidden text in Safari */
overflow-x: hidden;
background-color: var(--color-primary-1);
color: var(--color-white);
.navbar--inner-wrapper {
// Stretch everything out
display: grid;
min-height: var(--navbar-height);
}
.middle-divider {
flex: 1;
}
}
$mobile-ns: ".mobile-nav";
$desktop-ns: ".desktop-nav";
#{$mobile-ns} {
display: flex;
flex-wrap: wrap;
gap: var(--spacing-2);
--offset: 4px;
.nav-link {
// Need to add padding so that the focus outline doesn't display as a weird
// shape
padding-bottom: var(--offset);
}
.home-link p {
// Manual visual adjustment
transform: translateY(var(--offset));
}
}
#{$desktop-ns} {
display: none;
// Media query will set display to flex
gap: var(--spacing-6);
// Just introduce a horizontal scroll for viewport where the menu items don't
// fit
overflow-x: auto;
scrollbar-width: none; /* Firefox */
&::-webkit-scrollbar {
width: 0;
height: 0;
}
& > * {
min-width: fit-content;
}
}
@media #{map-get(constants.$QUERIES, tabletAndUp)} {
#{$mobile-ns} {
display: none;
}
#{$desktop-ns} {
display: flex;
}
}
.menu-toggler {
align-self: center;
position: relative;
top: 4px;
// Make menu flush with padding
margin-right: var(--menu-inset);
-webkit-tap-highlight-color: transparent;
padding: 0;
border: 0;
width: 40px;
height: 40px;
display: flex;
flex-direction: column;
align-items: center;
place-content: center;
.icon-container {
position: relative;
width: var(--size);
height: var(--size);
text-align: center;
}
.icon {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
will-change: opacity;
&.active {
opacity: 1;
transition: opacity 250ms;
}
}
p {
margin-top: -6px;
font-size: 0.5rem;
font-weight: bold;
}
}
.mobile-menu-close {
position: relative;
-webkit-tap-highlight-color: transparent;
width: 40px;
height: 40px;
display: grid;
place-content: center;
color: var(--color-text);
// transform: translateX(calc(-1 * var(--menu-inset)));
}
#{$navbar} .nav-link-wrapper {
--activeColor: var(--color-accent-1);
position: relative;
display: flex;
align-items: center;
// Need a bit of spacing at the ends because keyboard navigation highlight
// gets chopped off
&:first-of-type {
.nav-link {
margin-left: 4px;
}
}
&:last-of-type {
.nav-link {
margin-right: 4px;
}
}
.nav-link {
margin: var(--spacing-2) 0;
font-size: 1.2rem;
line-height: 1;
&.active {
color: var(--activeColor);
}
&.active ~ #{$markerClass} {
opacity: 1;
}
&:hover {
text-decoration: none;
}
}
#{$markerClass} {
opacity: 0;
position: absolute;
bottom: 0;
width: 100%;
height: 3px;
background-color: var(--activeColor);
}
}
$mobileMenu: ".IIT-mobile-menu";
#{$mobileMenu} {
.wrapper {
background: transparent;
}
&.active {
.wrapper {
pointer-events: auto;
}
.background {
opacity: 0.6;
}
}
}
#{$mobileMenu} .IIT-mobile-dialog--content {
--menu-width: 300px;
overflow: hidden;
width: min(var(--menu-width), 100%);
height: 100%;
position: absolute;
right: 0;
top: 0;
bottom: 0;
}
#{$mobileMenu} .wrapper {
// Can scroll if menu items overflow
overflow-y: auto;
position: relative;
height: 100%;
background: var(--color-background);
.wrapper--container {
min-height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.close-container {
width: 100%;
min-height: var(--navbar-height);
padding-left: var(--standard-side-padding);
padding-right: var(--standard-side-padding);
display: flex;
align-items: center;
justify-content: flex-end;
}
.spacer {
flex: 1;
}
.body {
--gap: var(--spacing-5);
padding-bottom: var(--navbar-height);
display: flex;
flex-direction: column;
gap: var(--gap);
.home-link {
svg {
// Manual visual adjustment
transform: translateY(1px);
}
}
}
.nav-link-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: var(--gap);
.nav-link {
font-size: 2rem;
line-height: 1;
color: var(--color-link);
&.active {
color: var(--color-accent-1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment