-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(header): added bigger logo with animation (#1552)
Co-authored-by: Alizé Debray <[email protected]> Co-authored-by: Oliver Schürch <[email protected]>
- Loading branch information
1 parent
17db6b2
commit 2baa121
Showing
12 changed files
with
134 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@swisspost/internet-header': minor | ||
--- | ||
|
||
Updated the logo size, the post logo now spans the meta-navigation and scales down on scroll. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...es/internet-header/src/components/post-internet-header/logo-animation/logo-animation.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@use '../../../utils/mixins.scss'; | ||
|
||
/** | ||
* Default position: scrolled | ||
* Logo is being scaled up for the initial view (scrollY = 0). This enables media queries to override | ||
* mobile behaviour without re-calculation | ||
*/ | ||
:host { | ||
--logo-scale: 1; | ||
|
||
@include mixins.max(lg) { | ||
--logo-scale: 1 !important; | ||
} | ||
} | ||
|
||
post-logo { | ||
height: var(--header-height); | ||
transform-origin: bottom left; | ||
transform: scale(var(--logo-scale)); | ||
} | ||
|
||
post-main-navigation { | ||
margin-left: calc((var(--header-height) * var(--logo-scale)) - var(--header-height)); | ||
} |
59 changes: 59 additions & 0 deletions
59
...ages/internet-header/src/components/post-internet-header/logo-animation/logo-animation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { debounce } from 'throttle-debounce'; | ||
import { state } from '../../../data/store'; | ||
|
||
export const registerLogoAnimationObserver = ( | ||
target: HTMLElement, | ||
headerRef: HTMLSwisspostInternetHeaderElement, | ||
) => { | ||
/** | ||
* Set intersection ratio as CSS custom property | ||
*/ | ||
const handleScroll = () => { | ||
const fullStickyness = state.stickyness === 'full'; | ||
let scale = 1; | ||
// Minus 1px border at the bottom that the logo is not covering | ||
const adjustedHeaderHeight = headerRef.clientHeight - 1; | ||
const scrollY = fullStickyness ? 0 : window.scrollY; | ||
|
||
// If meta navigation is not visible (mobile, not configured), scale should just be 1 | ||
if (target.clientHeight > 0) { | ||
scale = Math.max( | ||
(adjustedHeaderHeight - Math.max(scrollY, 0)) / | ||
(adjustedHeaderHeight - target.clientHeight), | ||
1, | ||
); | ||
} | ||
headerRef.style.setProperty('--logo-scale', scale.toString()); | ||
}; | ||
|
||
const debounced = debounce(150, handleScroll); | ||
|
||
/** | ||
* Observe the meta navigation in order to not track scroll events throughout the whole page. | ||
* This ensures that the scroll listener is only active while the meta navigation is visible. | ||
*/ | ||
const observer = new IntersectionObserver( | ||
entries => { | ||
entries.forEach(entry => { | ||
if (entry.isIntersecting && entry.intersectionRatio > 0) { | ||
window.addEventListener('scroll', handleScroll, { passive: true }); | ||
window.addEventListener('resize', debounced); | ||
|
||
// Ensure callback is called at least once in case main thread is too busy while scrolling up | ||
window.requestAnimationFrame(handleScroll); | ||
} else { | ||
window.removeEventListener('scroll', handleScroll); | ||
window.removeEventListener('resize', debounced); | ||
window.requestAnimationFrame(handleScroll); | ||
} | ||
}); | ||
}, | ||
{ | ||
// Fires when element leaves viewport (0) and when it just about enters it (0.001) | ||
threshold: [0, 0.001], | ||
}, | ||
); | ||
observer.observe(target); | ||
|
||
return handleScroll; | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/internet-header/src/components/post-internet-header/post-internet-header.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters