package.cjs.react-utils.useOnClickOutside.useOnClickOutside.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
{"version":3,"file":"useOnClickOutside.js","names":["_react","require","useOnClickOutside","ref","handler","_ref","arguments","length","undefined","_ref$enabled","enabled","useEffect","listener","event","current","contains","target","document","addEventListener","removeEventListener","_default","exports"],"sources":["../../../../src/react-utils/useOnClickOutside/useOnClickOutside.js"],"sourcesContent":["import { useEffect } from \"react\";\n\nconst useOnClickOutside = (ref, handler, { enabled = true } = {}) => {\n useEffect(() => {\n const listener = event => {\n // Do nothing if clicking ref's element or descendent elements\n if (!ref.current || ref.current.contains(event.target)) {\n return;\n }\n handler(event);\n };\n\n if (enabled) {\n document.addEventListener(\"mousedown\", listener);\n document.addEventListener(\"touchstart\", listener);\n }\n\n return () => {\n document.removeEventListener(\"mousedown\", listener);\n document.removeEventListener(\"touchstart\", listener);\n };\n }, [handler, enabled]);\n};\n\nexport default useOnClickOutside;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAIC,GAAG,EAAEC,OAAO,EAA8B;EAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAP,CAAC,CAAC;IAAAG,YAAA,GAAAJ,IAAA,CAArBK,OAAO;IAAPA,OAAO,GAAAD,YAAA,cAAG,IAAI,GAAAA,YAAA;EACvD,IAAAE,gBAAS,EAAC,YAAM;IACd,IAAMC,QAAQ,GAAG,SAAXA,QAAQA,CAAGC,KAAK,EAAI;MACxB;MACA,IAAI,CAACV,GAAG,CAACW,OAAO,IAAIX,GAAG,CAACW,OAAO,CAACC,QAAQ,CAACF,KAAK,CAACG,MAAM,CAAC,EAAE;QACtD;MACF;MACAZ,OAAO,CAACS,KAAK,CAAC;IAChB,CAAC;IAED,IAAIH,OAAO,EAAE;MACXO,QAAQ,CAACC,gBAAgB,CAAC,WAAW,EAAEN,QAAQ,CAAC;MAChDK,QAAQ,CAACC,gBAAgB,CAAC,YAAY,EAAEN,QAAQ,CAAC;IACnD;IAEA,OAAO,YAAM;MACXK,QAAQ,CAACE,mBAAmB,CAAC,WAAW,EAAEP,QAAQ,CAAC;MACnDK,QAAQ,CAACE,mBAAmB,CAAC,YAAY,EAAEP,QAAQ,CAAC;IACtD,CAAC;EACH,CAAC,EAAE,CAACR,OAAO,EAAEM,OAAO,CAAC,CAAC;AACxB,CAAC;AAAC,IAAAU,QAAA,GAAAC,OAAA,cAEanB,iBAAiB","ignoreList":[]}