UNPKG

eip-components-web

Version:
36 lines 1.29 kB
'use client'; import { jsx as _jsx } from "react/jsx-runtime"; import { createContext, useContext, useMemo, } from 'react'; export const ScrollToContext = createContext({}); export const ScrollToProvider = ({ children, scrollToIds, fallback, }) => { const value = useMemo(() => scrollToIds.reduce((ids, id) => { const scrollViewRef = { current: null, }; const scrollToElementRef = { current: undefined }; const scrollToElement = () => { scrollToElementRef.current ? scrollToElementRef.current?.measureLayout(scrollViewRef.current.children[0], (left, top) => { scrollViewRef.current?.scrollTo({ y: top, animated: true, }); }) : fallback?.(); }; return { ...ids, [id]: { scrollViewRef, scrollToElementRef, scrollToElement, }, }; }, {}), []); return (_jsx(ScrollToContext.Provider, { value: value, children: children })); }; export const useScrollState = (name) => { const state = useContext(ScrollToContext); return state[name]; }; //# sourceMappingURL=scrollTo.js.map