-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: revert css-only solution and dynamically determine height of ov…
…erview page squash for desktop
- Loading branch information
1 parent
895c046
commit a8f318c
Showing
8 changed files
with
224 additions
and
87 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
.squash-container { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
display: grid; | ||
justify-content: center; | ||
align-items: flex-end; | ||
bottom: calc(60% + 7vw); | ||
left: 55%; | ||
|
||
@media (min-width: 500px) { | ||
bottom: calc(18% + 7vw); | ||
left: 40%; | ||
} | ||
|
||
@media (min-width: 760px) { | ||
transform: rotate(0deg); | ||
right: 0; | ||
left: 0; | ||
bottom: -10%; | ||
} | ||
|
||
@media (min-width: 1250px) { | ||
bottom: 0; | ||
} | ||
|
||
.squash-image-wrapper { | ||
transform: scaleX(-1) rotate(-80deg); | ||
position: relative; | ||
width: 100%; | ||
// Ideally height is about 100% subtracted by half of expectations list (~8em) and padding (2rem) | ||
@media (min-width: 500px) { | ||
width: min(90%, 520px); | ||
transform: rotate(-90deg); | ||
} | ||
|
||
@media (min-width: 760px) { | ||
width: auto; | ||
transform: rotate(0deg); | ||
} | ||
|
||
@media (min-width: $tablet-breakpoint) { | ||
opacity: 0; | ||
} | ||
|
||
&.pop-up { | ||
opacity: 1; | ||
animation: PopUp 0.2s ease-in-out forwards; | ||
} | ||
|
||
@keyframes PopUp { | ||
0% { | ||
transform: scale(0); | ||
} | ||
|
||
80% { | ||
transform: scale(1.2); | ||
} | ||
100% { | ||
transform: scale(1); | ||
} | ||
} | ||
} | ||
|
||
.squash { | ||
object-fit: contain; | ||
object-position: bottom; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
} |
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,39 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import SquashGooglyEyes from '../SquashGooglyEyes/SquashGooglyEyes'; | ||
import SquashImage from '@/assets/images/squash.webp'; | ||
import './Squash.scss'; | ||
import { RefObject, useRef } from 'react'; | ||
import { useHandleSquashSizing } from './hooks/useHandleSquashSizing'; | ||
|
||
type SquashProps = { | ||
expectationRefs: { | ||
containerRef: RefObject<HTMLDivElement>; | ||
listRef: RefObject<HTMLUListElement>; | ||
titleRef: RefObject<HTMLHeadingElement>; | ||
}; | ||
}; | ||
|
||
export default function Squash({ expectationRefs }: SquashProps) { | ||
const { containerRef, listRef, titleRef } = expectationRefs; | ||
const squashContainerRef = useRef<HTMLDivElement>(null); | ||
const squashWrapperRef = useRef<HTMLDivElement>(null); | ||
|
||
useHandleSquashSizing({ | ||
containerRef, | ||
listRef, | ||
titleRef, | ||
squashContainerRef, | ||
squashWrapperRef | ||
}); | ||
|
||
return ( | ||
<div ref={squashContainerRef} className="squash-container"> | ||
<div ref={squashWrapperRef} className="squash-image-wrapper"> | ||
<Image className="squash" src={SquashImage} alt="Squash" priority /> | ||
<SquashGooglyEyes /> | ||
</div> | ||
</div> | ||
); | ||
} |
74 changes: 74 additions & 0 deletions
74
src/app/components/Overview/Squash/hooks/useHandleSquashSizing.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,74 @@ | ||
import { RefObject, useEffect } from 'react'; | ||
|
||
// Threshold for space under expectation list to determine if squash should be aligned to the left | ||
const SPACE_THRESHOLD = 130; | ||
// The smaller end of the squash is about 60% of its height | ||
const SQUASH_SMALLER_END_RATIO = 0.67; // 309 / 465 | ||
|
||
const TABLET_BREAKPOINT = 1000; | ||
|
||
type UseHandleSquashSizingProps = { | ||
containerRef: RefObject<HTMLDivElement>; | ||
listRef: RefObject<HTMLUListElement>; | ||
titleRef: RefObject<HTMLHeadingElement>; | ||
squashContainerRef: RefObject<HTMLDivElement>; | ||
squashWrapperRef: RefObject<HTMLDivElement>; | ||
}; | ||
|
||
export const useHandleSquashSizing = ({ | ||
containerRef, | ||
listRef, | ||
titleRef, | ||
squashContainerRef, | ||
squashWrapperRef | ||
}: UseHandleSquashSizingProps) => { | ||
useEffect(() => { | ||
const container = containerRef.current; | ||
const squashContainer = squashContainerRef.current; | ||
const squashWrapper = squashWrapperRef.current; | ||
const title = titleRef.current; | ||
const listRect = listRef.current?.getBoundingClientRect(); | ||
|
||
if (!container || !title || !listRect || !squashContainer || !squashWrapper) | ||
return; | ||
|
||
const handleSquashSizing = () => { | ||
if (window.innerWidth < TABLET_BREAKPOINT) { | ||
// Reset styles potentially set by logic below | ||
squashContainer.style.justifyContent = ''; | ||
squashWrapper.style.height = ''; | ||
squashWrapper.classList.remove('pop-up'); | ||
} else { | ||
const containerRect = container.getBoundingClientRect(); | ||
const containerPadding = parseInt( | ||
getComputedStyle(container).paddingTop | ||
); | ||
const spaceUnderList = containerRect.height - listRect.height; | ||
console.log({ spaceUnderList }); | ||
const spaceUnderTitle = | ||
containerRect.height - title.getBoundingClientRect().height; | ||
|
||
// If there's too little space under list, make the squash aligned to the left | ||
if (spaceUnderList < SPACE_THRESHOLD) { | ||
squashContainer.style.justifyContent = 'flex-start'; | ||
squashWrapper.style.height = `${spaceUnderTitle / 1.5}px`; | ||
} else { | ||
const squashHeight = | ||
spaceUnderList + | ||
listRect.height * (1 - SQUASH_SMALLER_END_RATIO) - | ||
containerPadding; | ||
squashWrapper.style.height = `${squashHeight}px`; | ||
} | ||
squashWrapper.classList.add('pop-up'); | ||
} | ||
}; | ||
|
||
handleSquashSizing(); | ||
|
||
window.addEventListener('resize', handleSquashSizing); | ||
|
||
return () => { | ||
window.removeEventListener('resize', handleSquashSizing); | ||
}; | ||
}, [containerRef, listRef, squashContainerRef, squashWrapperRef, titleRef]); | ||
}; |
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
Oops, something went wrong.