jb-mobile-input
Version:
mobile input web component
2 lines • 2.3 kB
JavaScript
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(()=>{t.name?e?.current?.setAttribute("name",t.name||""):e?.current?.removeAttribute("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&&t.disabled?e?.current?.setAttribute("disabled",""):e?.current?.removeAttribute("disabled")},[t.disabled]),n(()=>{"string"==typeof t.required&&e?.current?.setAttribute("required",t.required),"boolean"==typeof t.required&&(t.required?e?.current?.setAttribute("required",""):e?.current?.removeAttribute("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,d]=o(0);return u(r,()=>l?l.current:{},[l]),n(()=>{d(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 n=i(null);return u(r,()=>n?n.current:void 0,[n]),c(n,t),a(n,t),e.createElement("jb-mobile-input",{ref:n,class:t.className},t.children)});s.displayName="JBMobileInput";export{s as JBMobileInput};
//# sourceMappingURL=JBMobileInput.js.map