UNPKG

jb-mobile-input

Version:
2 lines 2.14 kB
import e,{forwardRef as t,useCallback as r,useEffect as n,useImperativeHandle as u,useRef as i,useState as o}from"react";import"jb-mobile-input";import"jb-input";function l(e,t,u,i=!1){let o=r(t=>{e.current&&"function"==typeof u&&u(t)},[e,u]);n(()=>{let r=e.current;return r&&r.addEventListener(t,o,{passive:i,capture:!1}),function(){r&&r.removeEventListener(t,o,{passive:i,capture:!1})}},[e,t,u,i])}function a(e,t){l(e,"enter",t.onEnter),l(e,"input",t.onInput),l(e,"beforeinput",t.onBeforeinput),l(e,"change",t.onChange),l(e,"keydown",t.onKeydown),l(e,"keyup",t.onKeyup),l(e,"focus",t.onFocus),l(e,"blur",t.onBlur)}function c(e,t){n(()=>{let r=t.value;(null==t.value||void 0===t.value)&&(r=""),e&&e.current&&e.current&&(e.current.value=r?.toString()||"")},[t.value]),n(()=>{t.type&&e?.current?.setAttribute("type",t.type)},[t.type]),n(()=>{e?.current?.setAttribute("name",t.name||"")},[t.name]),n(()=>{e&&e.current&&(e.current.validation.list=t.validationList||[])},[t.validationList]),n(()=>{e?.current?.setAttribute("label",t.label||"")},[t.label]),n(()=>{"boolean"==typeof t.disabled&&e?.current?.setAttribute("disabled",`${t.disabled}`)},[t.disabled]),n(()=>{"boolean"==typeof t.required&&e?.current?.setAttribute("required",`${t.required}`)},[t.required]),n(()=>{t.inputmode?e.current?.setAttribute("inputmode",t.inputmode):e.current?.removeAttribute("inputmode")},[t.inputmode]),n(()=>{e?.current?.setAttribute("message",t.message||"")},[t.message]),n(()=>{e?.current?.setAttribute("placeholder",t.placeholder||"")},[t.placeholder]),n(()=>{t.error?e?.current?.setAttribute("error",t.error):e?.current?.removeAttribute("error")},[t.error])}t((t,r)=>{let l=i(null),[s,p]=o(0);return u(r,()=>l?l.current:{},[l]),n(()=>{p(s+1)},[l.current]),a(l,t),c(l,t),e.createElement("jb-input",{ref:l,class:t.className},t.children)}).displayName="JBInput";let s=t((t,r)=>{let l=i(null),[s,p]=o(0);return u(r,()=>l?l.current:{},[l]),n(()=>{p(s+1)},[l.current]),c(l,t),a(l,t),e.createElement("jb-mobile-input",{ref:l,class:t.className},t.children)});s.displayName="JBMobileInput";export{s as JBMobileInput}; //# sourceMappingURL=JBMobileInput.js.map