-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add useScroll
utility hook
#9
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from "./types.js" | ||
export {Motion} from "./motion.jsx" | ||
export {Presence, PresenceContext} from "./presence.jsx" | ||
export {createMotion, motion} from "./primitives.js" | ||
export {createMotion, motion, useScroll} from "./primitives.js" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,17 @@ | ||||||
import {createMotionState, createStyles, MotionState, style} from "@motionone/dom" | ||||||
import {Accessor, createEffect, onCleanup, useContext} from "solid-js" | ||||||
import { | ||||||
AxisScrollInfo, | ||||||
createMotionState, | ||||||
createStyles, | ||||||
MotionState, | ||||||
style, | ||||||
scroll, | ||||||
ScrollOptions, | ||||||
} from "@motionone/dom" | ||||||
import {Accessor, batch, createEffect, createSignal, onCleanup, onMount, useContext} from "solid-js" | ||||||
|
||||||
import {PresenceContext, PresenceContextState} from "./presence.jsx" | ||||||
import {Options} from "./types.js" | ||||||
import {createStore, produce} from "solid-js/store" | ||||||
|
||||||
/** @internal */ | ||||||
export function createAndBindMotionState( | ||||||
|
@@ -65,6 +74,44 @@ export function createMotion( | |||||
return state | ||||||
} | ||||||
|
||||||
export function useScroll(options?: ScrollOptions): { | ||||||
time: Accessor<number> | ||||||
scrollX: AxisScrollInfo | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
scrollY: AxisScrollInfo | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} { | ||||||
const [time, setTime] = createSignal(0) | ||||||
const [scrollX, setScrollX] = createStore<AxisScrollInfo>({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
current: 0, | ||||||
offset: [], | ||||||
progress: 0, | ||||||
scrollLength: 0, | ||||||
velocity: 0, | ||||||
targetOffset: 0, | ||||||
targetLength: 0, | ||||||
containerLength: 0, | ||||||
}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const [scrollY, setScrollY] = createStore<AxisScrollInfo>({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
current: 0, | ||||||
offset: [], | ||||||
progress: 0, | ||||||
scrollLength: 0, | ||||||
velocity: 0, | ||||||
targetOffset: 0, | ||||||
targetLength: 0, | ||||||
containerLength: 0, | ||||||
}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
onMount(() => | ||||||
scroll(({time, x, y}) => { | ||||||
setTime(time) | ||||||
setScrollX(x) | ||||||
setScrollY(y) | ||||||
}, options), | ||||||
) | ||||||
|
||||||
return {time, scrollX, scrollY} | ||||||
} | ||||||
|
||||||
/** | ||||||
* motion is a Solid directive that makes binding to elements easier. | ||||||
* | ||||||
|
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.