-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds useOnScreen hook to monitor element visibility using Intersection Observer for optimized rendering. * Extended Next.js SSG revalidate time for reduced server load and improved cache utilization. * adjust image quality on mobile and addressed accessibility issues * chore: organized imports in layout.tsx
- Loading branch information
Showing
24 changed files
with
636 additions
and
485 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
20 changes: 20 additions & 0 deletions
20
composable-ui/src/components/__mocks__/intersection-observer.tsx
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,20 @@ | ||
export const mockedIntersectionObserver = class { | ||
root: null | ||
rootMargin: '0px' | ||
thresholds: [0] | ||
|
||
constructor(callback: IntersectionObserverCallback) { | ||
this.root = null | ||
this.rootMargin = '0px' | ||
this.thresholds = [0] | ||
|
||
callback([{ isIntersecting: true } as IntersectionObserverEntry], this) | ||
} | ||
|
||
observe() {} | ||
disconnect() {} | ||
unobserve() {} | ||
takeRecords(): IntersectionObserverEntry[] { | ||
return [] | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './use-cart' | ||
export * from './use-checkout' | ||
export * from './use-composable' | ||
export * from './use-on-screen' | ||
export * from './use-toast' |
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,33 @@ | ||
import { useState, useEffect, useRef } from 'react' | ||
|
||
type Options = { | ||
root?: Element | null | ||
rootMargin?: string | ||
threshold?: number | number[] | ||
} | ||
|
||
export const useOnScreen = <T extends HTMLElement>( | ||
options?: Options | ||
): [React.RefObject<T>, boolean] => { | ||
const ref = useRef<T>(null) | ||
const [isVisible, setIsVisible] = useState(false) | ||
|
||
useEffect(() => { | ||
const currentRef = ref.current | ||
const observer = new IntersectionObserver(([entry]) => { | ||
setIsVisible(entry.isIntersecting) | ||
}, options) | ||
|
||
if (currentRef) { | ||
observer.observe(currentRef) | ||
} | ||
|
||
return () => { | ||
if (currentRef) { | ||
observer.unobserve(currentRef) | ||
} | ||
} | ||
}, [options]) | ||
|
||
return [ref, isVisible] | ||
} |
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
Oops, something went wrong.
11c84dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
composable-ui-public – ./composable-ui
storefront.composable.com
composable-ui-public.vercel.app
composable-ui-public-composable.vercel.app
composable-ui-public-git-main-composable.vercel.app
11c84dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.