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