-
Notifications
You must be signed in to change notification settings - Fork 23
fix(header): added bigger logo with animation #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
48d8d35
fix(header): added logo animation
gfellerph 5225d63
chore: change update type to minor
gfellerph 217423d
Merge branch 'main' into 1529-header-test-new-logo-animation
gfellerph 844419a
chore: update title in docs file
gfellerph e1d7a5d
Update .changeset/stupid-pianos-rush.md
gfellerph e091bc5
Merge branch 'main' into 1529-header-test-new-logo-animation
gfellerph a6b4e7d
Merge branch 'main' into 1529-header-test-new-logo-animation
gfellerph c7aa5bb
fix: add resize listener to update logo size
gfellerph d9d3afe
fix: make language switch line visible again
gfellerph 9f21e88
Merge branch 'main' into 1529-header-test-new-logo-animation
gfellerph 65e6423
Update packages/internet-header/src/components/post-meta-navigation/p…
gfellerph f55ab59
fix: prevent animation in full stickyness mode
gfellerph e8e528f
Merge branch 'main' into 1529-header-test-new-logo-animation
gfellerph 3fdfcc8
fix: handle dynamically changing stickyness
gfellerph c15cb53
Merge branch 'main' into 1529-header-test-new-logo-animation
gfellerph b81c909
Merge branch 'main' into 1529-header-test-new-logo-animation
gfellerph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); | ||
|
oliverschuerch marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * 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( | ||
|
gfellerph marked this conversation as resolved.
|
||
| 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.