{"version":3,"file":"useScrollIntoView.cjs","sources":["../../../../src/hooks/useScrollIntoView/useScrollIntoView.tsx"],"sourcesContent":["import { type RefObject, useEffect } from \"react\";\n\ntype ValueOf<T> = T[keyof T];\n\nexport interface ScrollIntoViewProps {\n    ref: RefObject<ValueOf<HTMLElementTagNameMap> | null> | null;\n    timeout?: number;\n    autoScroll?: boolean;\n    options?: ScrollIntoViewOptions;\n}\n\ntype ScrollFunction = () => void;\n\nexport const useScrollIntoView = ({\n    ref,\n    timeout = 0,\n    autoScroll = true,\n    options = { behavior: \"smooth\" },\n}: ScrollIntoViewProps): [ScrollFunction] => {\n    const scrollIntoView: ScrollFunction = () => {\n        if (ref?.current) {\n            ref.current.scrollIntoView(options);\n        }\n    };\n\n    // biome-ignore lint/correctness/useExhaustiveDependencies:\n    useEffect(() => {\n        if (!autoScroll) {\n            return;\n        }\n        const scrollFn = setTimeout(scrollIntoView, timeout);\n        return () => clearTimeout(scrollFn);\n    }, [ref, timeout, autoScroll]);\n\n    return [scrollIntoView];\n};\n"],"names":["ref","timeout","autoScroll","options","behavior","scrollIntoView","current","useEffect","scrollFn","setTimeout","clearTimeout"],"mappings":"mIAaiC,EAC7BA,IAAAA,EACAC,QAAAA,EAAU,EACVC,WAAAA,GAAa,EACbC,QAAAA,EAAU,CAAEC,SAAU,cAEtB,MAAMC,EAAiC,KAC/BL,GAAKM,SACLN,EAAIM,QAAQD,eAAeF,IAKnCI,OAAAA,EAAAA,UAAU,KACN,IAAKL,EACD,OAEJ,MAAMM,EAAWC,WAAWJ,EAAgBJ,GAC5C,MAAO,IAAMS,aAAaF,IAC3B,CAACR,EAAKC,EAASC,IAEX,CAACG"}