All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.react-utils.useOnClickOutside.useOnClickOutside.js.map Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
{"version":3,"file":"useOnClickOutside.js","names":["useEffect","useOnClickOutside","ref","handler","_ref","arguments","length","undefined","_ref$enabled","enabled","listener","event","current","contains","target","document","addEventListener","removeEventListener"],"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,SAASA,SAAS,QAAQ,OAAO;AAEjC,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;EACvDR,SAAS,CAAC,YAAM;IACd,IAAMU,QAAQ,GAAG,SAAXA,QAAQA,CAAGC,KAAK,EAAI;MACxB;MACA,IAAI,CAACT,GAAG,CAACU,OAAO,IAAIV,GAAG,CAACU,OAAO,CAACC,QAAQ,CAACF,KAAK,CAACG,MAAM,CAAC,EAAE;QACtD;MACF;MACAX,OAAO,CAACQ,KAAK,CAAC;IAChB,CAAC;IAED,IAAIF,OAAO,EAAE;MACXM,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,CAACP,OAAO,EAAEM,OAAO,CAAC,CAAC;AACxB,CAAC;AAED,eAAeR,iBAAiB"}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy