-
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: add responsive support and lazy img
- Loading branch information
1 parent
b1735e0
commit 2ca07c6
Showing
12 changed files
with
106 additions
and
23 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
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,3 @@ | ||
export const Counter = () => { | ||
return <div>Counter</div>; | ||
}; |
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
38 changes: 38 additions & 0 deletions
38
src/lib/simple-headless-carousel/hooks/useIntersectionObserver.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,38 @@ | ||
import { useEffect, useState, RefObject } from 'react'; | ||
|
||
type UseIntersectionObserverResult = { | ||
entry?: IntersectionObserverEntry; | ||
}; | ||
|
||
type UseIntersectionObserverProps<T> = { | ||
ref: RefObject<T>; | ||
opts: IntersectionObserverInit; | ||
}; | ||
|
||
export const useIntersectionObserver = <T extends HTMLElement>({ | ||
ref, | ||
opts = {}, | ||
}: UseIntersectionObserverProps<T>): UseIntersectionObserverResult => { | ||
const [entry, setEntry] = useState<IntersectionObserverEntry>(); | ||
|
||
useEffect(() => { | ||
if (!ref.current) return; | ||
|
||
const handleObserver = (entries: IntersectionObserverEntry[]) => { | ||
for (const e of entries) { | ||
if (e.target === ref.current) { | ||
setEntry(e); | ||
} | ||
} | ||
}; | ||
|
||
const observer = new IntersectionObserver(handleObserver, opts); | ||
observer.observe(ref.current); | ||
|
||
return () => { | ||
observer.disconnect(); | ||
}; | ||
}, [ref, opts.threshold, opts.root, opts.rootMargin]); | ||
|
||
return { entry }; | ||
}; |
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,2 +1,3 @@ | ||
export const clsx = (...args: (string | boolean | undefined)[]) => | ||
args.filter(Boolean).join(' '); | ||
export const clsx = (...args: (string | boolean | undefined)[]) => { | ||
return args.filter(Boolean).join(' '); | ||
}; |
7 changes: 5 additions & 2 deletions
7
src/lib/simple-headless-carousel/services/getSliderClientX.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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import type { SlideEvent } from './types'; | ||
|
||
export const getSlideClientX = (event: SlideEvent) => | ||
event instanceof MouseEvent ? event.clientX : event.changedTouches[0].clientX; | ||
export const getSlideClientX = (event: SlideEvent) => { | ||
return event instanceof MouseEvent | ||
? event.clientX | ||
: event.changedTouches[0].clientX; | ||
}; |