UNPKG

jb-input

Version:

input web component with built in validation

2 lines 1.8 kB
import e,{forwardRef as t,useEffect as r,useImperativeHandle as u,useRef as n,useState as i}from"react";import"jb-input";import{useEvent as o}from"jb-core/react";function a(e,t){o(e,"enter",t.onEnter),o(e,"input",t.onInput),o(e,"beforeinput",t.onBeforeinput),o(e,"change",t.onChange),o(e,"keydown",t.onKeydown),o(e,"keyup",t.onKeyup),o(e,"focus",t.onFocus),o(e,"blur",t.onBlur)}function l(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(()=>{t.name?e?.current?.setAttribute("name",t.name||""):e?.current?.removeAttribute("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&&t.disabled?e?.current?.setAttribute("disabled",""):e?.current?.removeAttribute("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,o)=>{let c=n(null),[s,p]=i(0);return u(o,()=>c?c.current:{},[c]),r(()=>{p(s+1)},[c.current]),a(c,t),l(c,t),e.createElement("jb-input",{ref:c,class:t.className},t.children)});c.displayName="JBInput";export{c as JBInput,l as useJBInputAttribute,a as useJBInputEvents}; //# sourceMappingURL=JBInput.js.map