@modular-web/rc-form
Version:
Un componente de formulario flexible y personalizable construido con React, TypeScript y TailwindCSS.
32 lines (29 loc) • 17.2 kB
JavaScript
(function(j,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("react"),require("classnames")):typeof define=="function"&&define.amd?define(["exports","react","classnames"],C):(j=typeof globalThis<"u"?globalThis:j||self,C(j.FormComponent={},j.React,j.classNames))})(this,function(j,C,se){"use strict";var Z={exports:{}},L={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var ue;function Ne(){if(ue)return L;ue=1;var g=C,k=Symbol.for("react.element"),I=Symbol.for("react.fragment"),O=Object.prototype.hasOwnProperty,q=g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,F={key:!0,ref:!0,__self:!0,__source:!0};function R(_,f,S){var v,y={},w=null,N=null;S!==void 0&&(w=""+S),f.key!==void 0&&(w=""+f.key),f.ref!==void 0&&(N=f.ref);for(v in f)O.call(f,v)&&!F.hasOwnProperty(v)&&(y[v]=f[v]);if(_&&_.defaultProps)for(v in f=_.defaultProps,f)y[v]===void 0&&(y[v]=f[v]);return{$$typeof:k,type:_,key:w,ref:N,props:y,_owner:q.current}}return L.Fragment=I,L.jsx=R,L.jsxs=R,L}var M={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var le;function Ve(){return le||(le=1,process.env.NODE_ENV!=="production"&&function(){var g=C,k=Symbol.for("react.element"),I=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),R=Symbol.for("react.provider"),_=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),N=Symbol.for("react.offscreen"),h=Symbol.iterator,E="@@iterator";function V(e){if(e===null||typeof e!="object")return null;var r=h&&e[h]||e[E];return typeof r=="function"?r:null}var x=g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function d(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];G("error",e,t)}}function G(e,r,t){{var n=x.ReactDebugCurrentFrame,o=n.getStackAddendum();o!==""&&(r+="%s",t=t.concat([o]));var s=t.map(function(i){return String(i)});s.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,s)}}var X=!1,H=!1,T=!1,Ue=!1,Ze=!1,de;de=Symbol.for("react.module.reference");function Be(e){return!!(typeof e=="string"||typeof e=="function"||e===O||e===F||Ze||e===q||e===S||e===v||Ue||e===N||X||H||T||typeof e=="object"&&e!==null&&(e.$$typeof===w||e.$$typeof===y||e.$$typeof===R||e.$$typeof===_||e.$$typeof===f||e.$$typeof===de||e.getModuleId!==void 0))}function Je(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return o!==""?t+"("+o+")":t}function ve(e){return e.displayName||"Context"}function P(e){if(e==null)return null;if(typeof e.tag=="number"&&d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case I:return"Portal";case F:return"Profiler";case q:return"StrictMode";case S:return"Suspense";case v:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case _:var r=e;return ve(r)+".Consumer";case R:var t=e;return ve(t._context)+".Provider";case f:return Je(e,e.render,"ForwardRef");case y:var n=e.displayName||null;return n!==null?n:P(e.type)||"Memo";case w:{var o=e,s=o._payload,i=o._init;try{return P(i(s))}catch{return null}}}return null}var D=Object.assign,$=0,pe,he,me,ge,be,ye,Ee;function Re(){}Re.__reactDisabledLog=!0;function Ke(){{if($===0){pe=console.log,he=console.info,me=console.warn,ge=console.error,be=console.group,ye=console.groupCollapsed,Ee=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Re,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}$++}}function ze(){{if($--,$===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:pe}),info:D({},e,{value:he}),warn:D({},e,{value:me}),error:D({},e,{value:ge}),group:D({},e,{value:be}),groupCollapsed:D({},e,{value:ye}),groupEnd:D({},e,{value:Ee})})}$<0&&d("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Q=x.ReactCurrentDispatcher,ee;function B(e,r,t){{if(ee===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);ee=n&&n[1]||""}return`
`+ee+e}}var re=!1,J;{var Ge=typeof WeakMap=="function"?WeakMap:Map;J=new Ge}function _e(e,r){if(!e||re)return"";{var t=J.get(e);if(t!==void 0)return t}var n;re=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=Q.current,Q.current=null,Ke();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(m){n=m}Reflect.construct(e,[],i)}else{try{i.call()}catch(m){n=m}e.call(i.prototype)}}else{try{throw Error()}catch(m){n=m}e()}}catch(m){if(m&&n&&typeof m.stack=="string"){for(var a=m.stack.split(`
`),p=n.stack.split(`
`),l=a.length-1,c=p.length-1;l>=1&&c>=0&&a[l]!==p[c];)c--;for(;l>=1&&c>=0;l--,c--)if(a[l]!==p[c]){if(l!==1||c!==1)do if(l--,c--,c<0||a[l]!==p[c]){var b=`
`+a[l].replace(" at new "," at ");return e.displayName&&b.includes("<anonymous>")&&(b=b.replace("<anonymous>",e.displayName)),typeof e=="function"&&J.set(e,b),b}while(l>=1&&c>=0);break}}}finally{re=!1,Q.current=s,ze(),Error.prepareStackTrace=o}var Y=e?e.displayName||e.name:"",A=Y?B(Y):"";return typeof e=="function"&&J.set(e,A),A}function Xe(e,r,t){return _e(e,!1)}function He(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function K(e,r,t){if(e==null)return"";if(typeof e=="function")return _e(e,He(e));if(typeof e=="string")return B(e);switch(e){case S:return B("Suspense");case v:return B("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Xe(e.render);case y:return K(e.type,r,t);case w:{var n=e,o=n._payload,s=n._init;try{return K(s(o),r,t)}catch{}}}return""}var U=Object.prototype.hasOwnProperty,xe={},Te=x.ReactDebugCurrentFrame;function z(e){if(e){var r=e._owner,t=K(e.type,e._source,r?r.type:null);Te.setExtraStackFrame(t)}else Te.setExtraStackFrame(null)}function Qe(e,r,t,n,o){{var s=Function.call.bind(U);for(var i in e)if(s(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var p=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw p.name="Invariant Violation",p}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){a=l}a&&!(a instanceof Error)&&(z(o),d("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof a),z(null)),a instanceof Error&&!(a.message in xe)&&(xe[a.message]=!0,z(o),d("Failed %s type: %s",t,a.message),z(null))}}}var er=Array.isArray;function te(e){return er(e)}function rr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function tr(e){try{return we(e),!1}catch{return!0}}function we(e){return""+e}function je(e){if(tr(e))return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",rr(e)),we(e)}var Ce=x.ReactCurrentOwner,nr={key:!0,ref:!0,__self:!0,__source:!0},Oe,Se;function ar(e){if(U.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function ir(e){if(U.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function or(e,r){typeof e.ref=="string"&&Ce.current}function sr(e,r){{var t=function(){Oe||(Oe=!0,d("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function ur(e,r){{var t=function(){Se||(Se=!0,d("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var lr=function(e,r,t,n,o,s,i){var a={$$typeof:k,type:e,key:r,ref:t,props:i,_owner:s};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function cr(e,r,t,n,o){{var s,i={},a=null,p=null;t!==void 0&&(je(t),a=""+t),ir(r)&&(je(r.key),a=""+r.key),ar(r)&&(p=r.ref,or(r,o));for(s in r)U.call(r,s)&&!nr.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var l=e.defaultProps;for(s in l)i[s]===void 0&&(i[s]=l[s])}if(a||p){var c=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&sr(i,c),p&&ur(i,c)}return lr(e,a,p,o,n,Ce.current,i)}}var ne=x.ReactCurrentOwner,Pe=x.ReactDebugCurrentFrame;function W(e){if(e){var r=e._owner,t=K(e.type,e._source,r?r.type:null);Pe.setExtraStackFrame(t)}else Pe.setExtraStackFrame(null)}var ae;ae=!1;function ie(e){return typeof e=="object"&&e!==null&&e.$$typeof===k}function ke(){{if(ne.current){var e=P(ne.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function fr(e){return""}var qe={};function dr(e){{var r=ke();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function Fe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=dr(r);if(qe[t])return;qe[t]=!0;var n="";e&&e._owner&&e._owner!==ne.current&&(n=" It was passed a child from "+P(e._owner.type)+"."),W(e),d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),W(null)}}function De(e,r){{if(typeof e!="object")return;if(te(e))for(var t=0;t<e.length;t++){var n=e[t];ie(n)&&Fe(n,r)}else if(ie(e))e._store&&(e._store.validated=!0);else if(e){var o=V(e);if(typeof o=="function"&&o!==e.entries)for(var s=o.call(e),i;!(i=s.next()).done;)ie(i.value)&&Fe(i.value,r)}}}function vr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===f||r.$$typeof===y))t=r.propTypes;else return;if(t){var n=P(r);Qe(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ae){ae=!0;var o=P(r);d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",o||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function pr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){W(e),d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),W(null);break}}e.ref!==null&&(W(e),d("Invalid attribute `ref` supplied to `React.Fragment`."),W(null))}}var Ae={};function Ie(e,r,t,n,o,s){{var i=Be(e);if(!i){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var p=fr();p?a+=p:a+=ke();var l;e===null?l="null":te(e)?l="array":e!==void 0&&e.$$typeof===k?(l="<"+(P(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):l=typeof e,d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",l,a)}var c=cr(e,r,t,o,s);if(c==null)return c;if(i){var b=r.children;if(b!==void 0)if(n)if(te(b)){for(var Y=0;Y<b.length;Y++)De(b[Y],e);Object.freeze&&Object.freeze(b)}else d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else De(b,e)}if(U.call(r,"key")){var A=P(e),m=Object.keys(r).filter(function(Er){return Er!=="key"}),oe=m.length>0?"{key: someKey, "+m.join(": ..., ")+": ...}":"{key: someKey}";if(!Ae[A+oe]){var yr=m.length>0?"{"+m.join(": ..., ")+": ...}":"{}";d(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,oe,A,yr,A),Ae[A+oe]=!0}}return e===O?pr(c):vr(c),c}}function hr(e,r,t){return Ie(e,r,t,!0)}function mr(e,r,t){return Ie(e,r,t,!1)}var gr=mr,br=hr;M.Fragment=O,M.jsx=gr,M.jsxs=br}()),M}var ce;function We(){return ce||(ce=1,process.env.NODE_ENV==="production"?Z.exports=Ne():Z.exports=Ve()),Z.exports}var u=We();const Ye=g=>u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 -960 960 960",width:"100px",height:"100px",fill:"blue",...g,children:u.jsx("path",{d:"M480-320q75 0 127.5-52.5T660-500q0-75-52.5-127.5T480-680q-75 0-127.5 52.5T300-500q0 75 52.5 127.5T480-320Zm0-72q-45 0-76.5-31.5T372-500q0-45 31.5-76.5T480-608q45 0 76.5 31.5T588-500q0 45-31.5 76.5T480-392Zm0 192q-146 0-266-81.5T40-500q54-137 174-218.5T480-800q146 0 266 81.5T920-500q-54 137-174 218.5T480-200Zm0-300Zm0 220q113 0 207.5-59.5T832-500q-50-101-144.5-160.5T480-720q-113 0-207.5 59.5T128-500q50 101 144.5 160.5T480-280Z"})}),Le=g=>u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 -960 960 960",...g,children:u.jsx("path",{d:"m644-428-58-58q9-47-27-88t-93-32l-58-58q17-8 34.5-12t37.5-4q75 0 127.5 52.5T660-500q0 20-4 37.5T644-428Zm128 126-58-56q38-29 67.5-63.5T832-500q-50-101-143.5-160.5T480-720q-29 0-57 4t-55 12l-62-62q41-17 84-25.5t90-8.5q151 0 269 83.5T920-500q-23 59-60.5 109.5T772-302Zm20 246L624-222q-35 11-70.5 16.5T480-200q-151 0-269-83.5T40-500q21-53 53-98.5t73-81.5L56-792l56-56 736 736-56 56ZM222-624q-29 26-53 57t-41 67q50 101 143.5 160.5T480-280q20 0 39-2.5t39-5.5l-36-38q-11 3-21 4.5t-21 1.5q-75 0-127.5-52.5T300-500q0-11 1.5-21t4.5-21l-84-82Zm319 93Zm-151 75Z"})}),Me=g=>u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 -960 960 960",...g,children:u.jsx("path",{d:"m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"})}),fe=[u.jsx(Ye,{width:"20px",height:"20px",fill:"#1F2937"}),u.jsx(Le,{width:"20px",height:"20px",fill:"#1F2937"})];function $e({inputs:g,title:k,textButton:I,className:O,submit:q,children:F}){const[R,_]=C.useState({}),[f,S]=C.useState({}),v=h=>{const{name:E,value:V}=h.target;_(x=>({...x,[E]:V}))},y=h=>{_(E=>({...E,[h]:""}))},w=h=>{S(E=>({...E,[h]:!f[h]}))},N=h=>{h.preventDefault(),console.log({values:R}),q&&q({values:R,event:h})};return u.jsxs(u.Fragment,{children:[u.jsxs("form",{className:se("bg-[#285cbdce] min-w-[500px] flex flex-col justify-center items-center gap-5 p-5",O),onSubmit:N,children:[u.jsx("h1",{className:"text-[#222] dark:text-white text-3xl font-bold",children:k}),g==null?void 0:g.map((h,E)=>{const{label:V,clearable:x,toggleable:d,required:G,className:X,type:H,...T}=h;return u.jsx("div",{className:"w-full flex items-center justify-center",children:u.jsxs("div",{className:"w-[80%]",children:[V&&u.jsx("label",{htmlFor:T.id,className:"inline-block mb-2 font-bold text-[#222]",children:V}),u.jsxs("div",{className:"relative w-full",children:[u.jsx("input",{...T,type:d&&f[T.id]?"text":H,className:se("text-base p-2 rounded-lg outline-none w-full",X),onChange:v,value:R[T.name]??"",...G&&{required:!0}},E),u.jsxs("div",{className:"absolute right-0 top-0 flex justify-center items-center p-1 gap-1",children:[x&&R[T.name]&&u.jsx("button",{type:"button",onClick:()=>y(T.name),className:"size-[30px] flex justify-center items-center rounded-full bg-[#ddd] outline-none",children:u.jsx(Me,{width:"20px",height:"20px",fill:"#1F2937"})}),d&&u.jsx("button",{type:"button",onClick:()=>w(T.id),className:"size-[30px] flex justify-center items-center rounded-full bg-[#ddd]",children:f[T.id]?fe[1]:fe[0]})]})]})]},E)},E)}),I&&u.jsx("button",{type:"submit",className:"p-4 bg-yellow-300 rounded-lg font-bold shadow-lg",children:I})]}),F&&F]})}j.FormComponent=$e,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=index.umd.js.map