diff --git a/packages/components/src/components/post-header/post-header.scss b/packages/components/src/components/post-header/post-header.scss index 8bea0377cf..933157d216 100644 --- a/packages/components/src/components/post-header/post-header.scss +++ b/packages/components/src/components/post-header/post-header.scss @@ -9,11 +9,21 @@ :host { --global-header-height: 72px; + --global-header-minimal-height: 24px; --main-header-height: 56px; --header-height: calc(var(--global-header-height) + var(--main-header-height)); + @include media.min(lg) { + display: block; + position: sticky; + inset-inline: 0; + inset-block-start: calc(-1 * (var(--global-header-height) + var(--main-header-height) - var(--global-header-minimal-height))); + box-shadow: var(--post-core-elevation-3); + } + @include media.max(lg) { --global-header-height: 64px; + --main-header-height: 48px; } } @@ -31,18 +41,17 @@ justify-content: space-between; align-items: center; position: sticky; - z-index: 2; - padding-inline-start: 4px; - padding-inline-end: 12px; - + padding-inline: var(--post-core-dimension-4); height: var(--global-header-height); + z-index: 1; @include media.max(lg) { - top: 0; + inset-block-start: 0; } @include media.min(lg) { - top: calc((var(--global-header-height) - 24px) * -1); + padding-inline-end: var(--post-core-dimension-12); + top: calc((var(--global-header-height) - var(--global-header-minimal-height)) * -1); } } @@ -53,7 +62,7 @@ slot[name='post-logo'] { .global-sub { display: flex; align-items: center; - gap: 2rem; + gap: var(--post-core-dimension-24); height: var(--global-header-height); } @@ -65,7 +74,7 @@ slot[name='post-logo'] { flex: 1 0 auto; height: var(--global-header-height); width: var(--global-header-height); - min-height: 24px; + min-height: var(--global-header-minimal-height); align-self: flex-end; @include media.min(lg) { @@ -82,25 +91,38 @@ slot[name='post-logo'] { } .title-header { - position: relative; - z-index: 1; display: flex; align-items: center; - padding-inline: 12px; - background: white; + gap: var(--post-core-dimension-4); height: var(--main-header-height); + background: var(--post-core-color-brand-white); + + @include media.min(lg) { + padding: var(--post-core-dimension-18) var(--post-core-dimension-16) var(--post-core-dimension-4) var(--post-core-dimension-12); + } @include media.max(lg) { - border-bottom: 1px solid black; + position: sticky; + z-index: 1; + inset-block-start: var(--global-header-height); + padding-inline: var(--post-core-dimension-8) var(--post-core-dimension-16); } } + :host(:not(:has([slot='title']))) .title-header { display: none; } ::slotted(h1) { margin: 0 !important; - font-size: 28px !important; + + @include media.min(lg) { + font-size: var(--post-core-font-size-28) !important; + } + + @include media.max(lg) { + font-size: var(--post-core-font-size-20) !important; + } } .mobile-toggle { @@ -111,36 +133,35 @@ slot[name='post-logo'] { .navigation { background: var(--post-core-color-brand-white); - box-shadow: var(--post-core-elevation-3); + + @include media.min(lg) { + position: sticky; + z-index: 1; + inset-block-start: var(--global-header-minimal-height); + } } // only for tablet and mobile @include media.max(lg) { .navigation { - position: absolute; + position: fixed; inset-inline: 0; inset-block-end: calc(100vh - var(--header-height)); - transition: transform animation.$transition-time-area-medium animation.$transition-easing-accelerate; - - &.extended { - transform: translateY(100%); - transition-timing-function: animation.$transition-easing-decelerate; - } + box-shadow: var(--post-core-elevation-3); + min-height: var(--post-core-dimension-10); // needed for the box-shadow to always show + max-height: calc(100vh - var(--header-height)); + overflow: auto; } ::slotted(post-mainnavigation), .navigation-footer { - display: flex; + display: none; flex-direction: column; padding-block: var(--post-core-dimension-16) var(--post-core-dimension-24); padding-inline: var(--post-core-dimension-32); - opacity: 0; - transition-property: opacity; - transition-delay: animation.$transition-time-area-medium; .navigation.extended & { - opacity: 1; - transition-delay: 0s; + display: flex; } } diff --git a/packages/components/src/components/post-header/post-header.tsx b/packages/components/src/components/post-header/post-header.tsx index ac74a52518..01fa94263b 100644 --- a/packages/components/src/components/post-header/post-header.tsx +++ b/packages/components/src/components/post-header/post-header.tsx @@ -1,7 +1,8 @@ -import { Component, h, Host, State, Element, Method } from '@stencil/core'; +import { Component, h, Host, State, Element, Method, Watch } from '@stencil/core'; import { throttle } from 'throttle-debounce'; import { version } from '@root/package.json'; import { SwitchVariant } from '@/components'; +import { slideDown, slideUp } from '@/animations/slide'; type DEVICE_SIZE = 'mobile' | 'tablet' | 'desktop' | null; @@ -11,11 +12,8 @@ type DEVICE_SIZE = 'mobile' | 'tablet' | 'desktop' | null; styleUrl: './post-header.scss', }) export class PostHeader { - @Element() host: HTMLPostHeaderElement; - @State() device: DEVICE_SIZE = null; - @State() mobileMenuExtended: boolean = false; - private scrollParent = null; + private mobileMenu: HTMLElement; private throttledScroll = () => this.handleScrollEvent(); private throttledResize = throttle(50, () => this.handleResize()); @@ -27,14 +25,30 @@ export class PostHeader { this.handleScrollEvent(); } + @Element() host: HTMLPostHeaderElement; + + @State() device: DEVICE_SIZE = null; + @State() mobileMenuExtended: boolean = false; + + @Watch('mobileMenuExtended') + frozeBody(isMobileMenuExtended: boolean) { + document.body.style.overflow = isMobileMenuExtended ? 'hidden' : ''; + } + /** * Toggles the mobile navigation. */ @Method() async toggleMobileMenu() { - if (this.device !== 'desktop') { - this.mobileMenuExtended = !this.mobileMenuExtended; + if (this.device === 'desktop') return; + + if (this.mobileMenuExtended) { + await slideUp(this.mobileMenu).finished; + } else { + slideDown(this.mobileMenu); } + + this.mobileMenuExtended = !this.mobileMenuExtended; } private handleScrollEvent() { @@ -125,7 +139,6 @@ export class PostHeader { -