package.cjs.react-utils.useFieldSubmit.useFieldSubmit.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":"useFieldSubmit.js","names":["_react","require","useFieldSubmit","onSubmit","ref","useRef","keyDownHandler","useCallback","event","key","shiftKey","stopPropagation","preventDefault","useEffect","element","current","undefined","addEventListener","removeEventListener","_default","exports"],"sources":["../../../../src/react-utils/useFieldSubmit/useFieldSubmit.js"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\n\nconst useFieldSubmit = onSubmit => {\n /** @type {{ current: HTMLInputElement & HTMLTextAreaElement }} */\n // @ts-ignore\n const ref = useRef(null);\n\n const keyDownHandler = useCallback(event => {\n if (event.key !== \"Enter\") return;\n\n if (event.shiftKey) {\n event.stopPropagation();\n } else {\n onSubmit();\n event.preventDefault();\n }\n }, []);\n\n useEffect(() => {\n const element = ref.current;\n if (!element) return undefined;\n\n element.addEventListener(\"keydown\", keyDownHandler);\n\n return () => element.removeEventListener(\"keydown\", keyDownHandler);\n }, []);\n\n return ref;\n};\n\nexport default useFieldSubmit;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAGC,QAAQ,EAAI;EACjC;EACA;EACA,IAAMC,GAAG,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAExB,IAAMC,cAAc,GAAG,IAAAC,kBAAW,EAAC,UAAAC,KAAK,EAAI;IAC1C,IAAIA,KAAK,CAACC,GAAG,KAAK,OAAO,EAAE;IAE3B,IAAID,KAAK,CAACE,QAAQ,EAAE;MAClBF,KAAK,CAACG,eAAe,CAAC,CAAC;IACzB,CAAC,MAAM;MACLR,QAAQ,CAAC,CAAC;MACVK,KAAK,CAACI,cAAc,CAAC,CAAC;IACxB;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,IAAAC,gBAAS,EAAC,YAAM;IACd,IAAMC,OAAO,GAAGV,GAAG,CAACW,OAAO;IAC3B,IAAI,CAACD,OAAO,EAAE,OAAOE,SAAS;IAE9BF,OAAO,CAACG,gBAAgB,CAAC,SAAS,EAAEX,cAAc,CAAC;IAEnD,OAAO;MAAA,OAAMQ,OAAO,CAACI,mBAAmB,CAAC,SAAS,EAAEZ,cAAc,CAAC;IAAA;EACrE,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,GAAG;AACZ,CAAC;AAAC,IAAAe,QAAA,GAAAC,OAAA,cAEalB,cAAc","ignoreList":[]}