UNPKG

zod-form-radix

Version:

Radix UI integration for zod-form-kit

31 lines (28 loc) 31.9 kB
(function(p,L){typeof exports=="object"&&typeof module<"u"?L(exports,require("react"),require("clsx"),require("tailwind-merge"),require("@radix-ui/react-label"),require("class-variance-authority"),require("@radix-ui/react-slot"),require("@radix-ui/react-checkbox"),require("@radix-ui/react-switch"),require("@radix-ui/react-select"),require("zod-form-kit"),require("zod")):typeof define=="function"&&define.amd?define(["exports","react","clsx","tailwind-merge","@radix-ui/react-label","class-variance-authority","@radix-ui/react-slot","@radix-ui/react-checkbox","@radix-ui/react-switch","@radix-ui/react-select","zod-form-kit","zod"],L):(p=typeof globalThis<"u"?globalThis:p||self,L(p["zod-radix-adapter"]={},p.React,p.clsx,p.tailwindMerge,p.LabelPrimitive,p.classVarianceAuthority,p.reactSlot,p.CheckboxPrimitive,p.SwitchPrimitive,p.SelectPrimitive,p.ZodFormKit,p.z))})(this,function(p,L,nr,ar,sr,ye,ir,or,lr,cr,ie,Y){"use strict";function q(a){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const o in a)if(o!=="default"){const c=Object.getOwnPropertyDescriptor(a,o);Object.defineProperty(s,o,c.get?c:{enumerable:!0,get:()=>a[o]})}}return s.default=a,Object.freeze(s)}const Q=q(L),je=q(sr),we=q(or),Re=q(lr),C=q(cr);var oe={exports:{}},z={};/** * @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 Ee;function ur(){if(Ee)return z;Ee=1;var a=L,s=Symbol.for("react.element"),o=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,u=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,h={key:!0,ref:!0,__self:!0,__source:!0};function m(l,d,N){var R,_={},g=null,k=null;N!==void 0&&(g=""+N),d.key!==void 0&&(g=""+d.key),d.ref!==void 0&&(k=d.ref);for(R in d)c.call(d,R)&&!h.hasOwnProperty(R)&&(_[R]=d[R]);if(l&&l.defaultProps)for(R in d=l.defaultProps,d)_[R]===void 0&&(_[R]=d[R]);return{$$typeof:s,type:l,key:g,ref:k,props:_,_owner:u.current}}return z.Fragment=o,z.jsx=m,z.jsxs=m,z}var J={};/** * @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 _e;function dr(){return _e||(_e=1,process.env.NODE_ENV!=="production"&&function(){var a=L,s=Symbol.for("react.element"),o=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),u=Symbol.for("react.strict_mode"),h=Symbol.for("react.profiler"),m=Symbol.for("react.provider"),l=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),R=Symbol.for("react.suspense_list"),_=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),k=Symbol.for("react.offscreen"),E=Symbol.iterator,x="@@iterator";function F(e){if(e===null||typeof e!="object")return null;var t=E&&e[E]||e[x];return typeof t=="function"?t:null}var j=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(e){{for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];A("error",e,n)}}function A(e,t,n){{var i=j.ReactDebugCurrentFrame,y=i.getStackAddendum();y!==""&&(t+="%s",n=n.concat([y]));var w=n.map(function(v){return String(v)});w.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,w)}}var G=!1,gr=!1,yr=!1,jr=!1,wr=!1,Se;Se=Symbol.for("react.module.reference");function Rr(e){return!!(typeof e=="string"||typeof e=="function"||e===c||e===h||wr||e===u||e===N||e===R||jr||e===k||G||gr||yr||typeof e=="object"&&e!==null&&(e.$$typeof===g||e.$$typeof===_||e.$$typeof===m||e.$$typeof===l||e.$$typeof===d||e.$$typeof===Se||e.getModuleId!==void 0))}function Er(e,t,n){var i=e.displayName;if(i)return i;var y=t.displayName||t.name||"";return y!==""?n+"("+y+")":n}function Fe(e){return e.displayName||"Context"}function V(e){if(e==null)return null;if(typeof e.tag=="number"&&b("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 c:return"Fragment";case o:return"Portal";case h:return"Profiler";case u:return"StrictMode";case N:return"Suspense";case R:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case l:var t=e;return Fe(t)+".Consumer";case m:var n=e;return Fe(n._context)+".Provider";case d:return Er(e,e.render,"ForwardRef");case _:var i=e.displayName||null;return i!==null?i:V(e.type)||"Memo";case g:{var y=e,w=y._payload,v=y._init;try{return V(v(w))}catch{return null}}}return null}var W=Object.assign,X=0,Ie,De,Ae,$e,Ve,Le,We;function Ue(){}Ue.__reactDisabledLog=!0;function _r(){{if(X===0){Ie=console.log,De=console.info,Ae=console.warn,$e=console.error,Ve=console.group,Le=console.groupCollapsed,We=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ue,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}X++}}function kr(){{if(X--,X===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:W({},e,{value:Ie}),info:W({},e,{value:De}),warn:W({},e,{value:Ae}),error:W({},e,{value:$e}),group:W({},e,{value:Ve}),groupCollapsed:W({},e,{value:Le}),groupEnd:W({},e,{value:We})})}X<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var fe=j.ReactCurrentDispatcher,me;function te(e,t,n){{if(me===void 0)try{throw Error()}catch(y){var i=y.stack.trim().match(/\n( *(at )?)/);me=i&&i[1]||""}return` `+me+e}}var pe=!1,ne;{var Nr=typeof WeakMap=="function"?WeakMap:Map;ne=new Nr}function Ye(e,t){if(!e||pe)return"";{var n=ne.get(e);if(n!==void 0)return n}var i;pe=!0;var y=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var w;w=fe.current,fe.current=null,_r();try{if(t){var v=function(){throw Error()};if(Object.defineProperty(v.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(v,[])}catch(I){i=I}Reflect.construct(e,[],v)}else{try{v.call()}catch(I){i=I}e.call(v.prototype)}}else{try{throw Error()}catch(I){i=I}e()}}catch(I){if(I&&i&&typeof I.stack=="string"){for(var f=I.stack.split(` `),S=i.stack.split(` `),T=f.length-1,P=S.length-1;T>=1&&P>=0&&f[T]!==S[P];)P--;for(;T>=1&&P>=0;T--,P--)if(f[T]!==S[P]){if(T!==1||P!==1)do if(T--,P--,P<0||f[T]!==S[P]){var $=` `+f[T].replace(" at new "," at ");return e.displayName&&$.includes("<anonymous>")&&($=$.replace("<anonymous>",e.displayName)),typeof e=="function"&&ne.set(e,$),$}while(T>=1&&P>=0);break}}}finally{pe=!1,fe.current=w,kr(),Error.prepareStackTrace=y}var B=e?e.displayName||e.name:"",U=B?te(B):"";return typeof e=="function"&&ne.set(e,U),U}function Tr(e,t,n){return Ye(e,!1)}function Cr(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function ae(e,t,n){if(e==null)return"";if(typeof e=="function")return Ye(e,Cr(e));if(typeof e=="string")return te(e);switch(e){case N:return te("Suspense");case R:return te("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return Tr(e.render);case _:return ae(e.type,t,n);case g:{var i=e,y=i._payload,w=i._init;try{return ae(w(y),t,n)}catch{}}}return""}var H=Object.prototype.hasOwnProperty,Me={},Be=j.ReactDebugCurrentFrame;function se(e){if(e){var t=e._owner,n=ae(e.type,e._source,t?t.type:null);Be.setExtraStackFrame(n)}else Be.setExtraStackFrame(null)}function Or(e,t,n,i,y){{var w=Function.call.bind(H);for(var v in e)if(w(e,v)){var f=void 0;try{if(typeof e[v]!="function"){var S=Error((i||"React class")+": "+n+" type `"+v+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[v]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw S.name="Invariant Violation",S}f=e[v](t,v,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(T){f=T}f&&!(f instanceof Error)&&(se(y),b("%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).",i||"React class",n,v,typeof f),se(null)),f instanceof Error&&!(f.message in Me)&&(Me[f.message]=!0,se(y),b("Failed %s type: %s",n,f.message),se(null))}}}var Pr=Array.isArray;function ve(e){return Pr(e)}function Sr(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,n=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function Fr(e){try{return qe(e),!1}catch{return!0}}function qe(e){return""+e}function ze(e){if(Fr(e))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Sr(e)),qe(e)}var Je=j.ReactCurrentOwner,Ir={key:!0,ref:!0,__self:!0,__source:!0},Ze,Ke;function Dr(e){if(H.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function Ar(e){if(H.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function $r(e,t){typeof e.ref=="string"&&Je.current}function Vr(e,t){{var n=function(){Ze||(Ze=!0,b("%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)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function Lr(e,t){{var n=function(){Ke||(Ke=!0,b("%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)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var Wr=function(e,t,n,i,y,w,v){var f={$$typeof:s,type:e,key:t,ref:n,props:v,_owner:w};return f._store={},Object.defineProperty(f._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(f,"_self",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.defineProperty(f,"_source",{configurable:!1,enumerable:!1,writable:!1,value:y}),Object.freeze&&(Object.freeze(f.props),Object.freeze(f)),f};function Ur(e,t,n,i,y){{var w,v={},f=null,S=null;n!==void 0&&(ze(n),f=""+n),Ar(t)&&(ze(t.key),f=""+t.key),Dr(t)&&(S=t.ref,$r(t,y));for(w in t)H.call(t,w)&&!Ir.hasOwnProperty(w)&&(v[w]=t[w]);if(e&&e.defaultProps){var T=e.defaultProps;for(w in T)v[w]===void 0&&(v[w]=T[w])}if(f||S){var P=typeof e=="function"?e.displayName||e.name||"Unknown":e;f&&Vr(v,P),S&&Lr(v,P)}return Wr(e,f,S,y,i,Je.current,v)}}var xe=j.ReactCurrentOwner,Ge=j.ReactDebugCurrentFrame;function M(e){if(e){var t=e._owner,n=ae(e.type,e._source,t?t.type:null);Ge.setExtraStackFrame(n)}else Ge.setExtraStackFrame(null)}var he;he=!1;function be(e){return typeof e=="object"&&e!==null&&e.$$typeof===s}function Xe(){{if(xe.current){var e=V(xe.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function Yr(e){return""}var He={};function Mr(e){{var t=Xe();if(!t){var n=typeof e=="string"?e:e.displayName||e.name;n&&(t=` Check the top-level render call using <`+n+">.")}return t}}function Qe(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=Mr(t);if(He[n])return;He[n]=!0;var i="";e&&e._owner&&e._owner!==xe.current&&(i=" It was passed a child from "+V(e._owner.type)+"."),M(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,i),M(null)}}function er(e,t){{if(typeof e!="object")return;if(ve(e))for(var n=0;n<e.length;n++){var i=e[n];be(i)&&Qe(i,t)}else if(be(e))e._store&&(e._store.validated=!0);else if(e){var y=F(e);if(typeof y=="function"&&y!==e.entries)for(var w=y.call(e),v;!(v=w.next()).done;)be(v.value)&&Qe(v.value,t)}}}function Br(e){{var t=e.type;if(t==null||typeof t=="string")return;var n;if(typeof t=="function")n=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===d||t.$$typeof===_))n=t.propTypes;else return;if(n){var i=V(t);Or(n,e.props,"prop",i,e)}else if(t.PropTypes!==void 0&&!he){he=!0;var y=V(t);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",y||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function qr(e){{for(var t=Object.keys(e.props),n=0;n<t.length;n++){var i=t[n];if(i!=="children"&&i!=="key"){M(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),M(null);break}}e.ref!==null&&(M(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),M(null))}}var rr={};function tr(e,t,n,i,y,w){{var v=Rr(e);if(!v){var f="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(f+=" 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 S=Yr();S?f+=S:f+=Xe();var T;e===null?T="null":ve(e)?T="array":e!==void 0&&e.$$typeof===s?(T="<"+(V(e.type)||"Unknown")+" />",f=" Did you accidentally export a JSX literal instead of a component?"):T=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",T,f)}var P=Ur(e,t,n,y,w);if(P==null)return P;if(v){var $=t.children;if($!==void 0)if(i)if(ve($)){for(var B=0;B<$.length;B++)er($[B],e);Object.freeze&&Object.freeze($)}else b("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 er($,e)}if(H.call(t,"key")){var U=V(e),I=Object.keys(t).filter(function(Xr){return Xr!=="key"}),ge=I.length>0?"{key: someKey, "+I.join(": ..., ")+": ...}":"{key: someKey}";if(!rr[U+ge]){var Gr=I.length>0?"{"+I.join(": ..., ")+": ...}":"{}";b(`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} />`,ge,U,Gr,U),rr[U+ge]=!0}}return e===c?qr(P):Br(P),P}}function zr(e,t,n){return tr(e,t,n,!0)}function Jr(e,t,n){return tr(e,t,n,!1)}var Zr=Jr,Kr=zr;J.Fragment=c,J.jsx=Zr,J.jsxs=Kr}()),J}process.env.NODE_ENV==="production"?oe.exports=ur():oe.exports=dr();var r=oe.exports;function O(...a){return ar.twMerge(nr.clsx(a))}const Z=Q.forwardRef(({className:a,type:s,...o},c)=>r.jsx("input",{type:s,className:O("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",a),ref:c,...o}));Z.displayName="Input";const fr=ye.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),D=Q.forwardRef(({className:a,...s},o)=>r.jsx(je.Root,{ref:o,className:O(fr(),a),...s}));D.displayName=je.Root.displayName;const ke=ye.cva("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),ee=Q.forwardRef(({className:a,variant:s,size:o,asChild:c=!1,...u},h)=>{const m=c?ir.Slot:"button";return r.jsx(m,{className:O(ke({variant:s,size:o,className:a})),ref:h,...u})});ee.displayName="Button";const Ne=Q.forwardRef(({className:a,...s},o)=>r.jsx("textarea",{className:O("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",a),ref:o,...s}));Ne.displayName="Textarea";function re({name:a,label:s,value:o="",onChange:c,error:u,required:h,options:m={},className:l=""}){var N;const d=mr(m.format);return r.jsxs("div",{className:O("space-y-2",l),children:[s&&r.jsxs(D,{htmlFor:a,children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),r.jsx(Z,{id:a,name:a,type:d,value:o,onChange:R=>c(R.target.value),className:O(u&&"border-red-500 focus-visible:ring-red-500"),required:h,readOnly:m.readonly,minLength:m.minLength,maxLength:m.maxLength,pattern:(N=m.pattern)==null?void 0:N.source,placeholder:m.format==="email"?"Enter email address":m.format==="url"?"Enter URL":s?`Enter ${s.toLowerCase()}`:void 0}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:u})]})}function mr(a){switch(a){case"email":return"email";case"url":return"url";case"password":return"password";default:return"text"}}function le({name:a,label:s,value:o=0,onChange:c,error:u,required:h,options:m={},className:l=""}){const{min:d,max:N,step:R=1,readonly:_}=m,g=k=>{const E=k.target.value;if(E==="")c(0);else{const x=Number(E);isNaN(x)||c(x)}};return r.jsxs("div",{className:O("space-y-2",l),children:[s&&r.jsxs(D,{htmlFor:a,children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),r.jsx(Z,{id:a,name:a,type:"number",value:o,onChange:g,className:O(u&&"border-red-500 focus-visible:ring-red-500"),required:h,readOnly:_,min:d,max:N,step:R}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:u})]})}function ce({name:a,label:s,value:o=!1,onChange:c,error:u,required:h,options:m={},className:l=""}){const{variant:d="checkbox"}=m;return d==="switch"?r.jsxs("div",{className:O("flex items-center space-x-2",l),children:[r.jsx(Re.Root,{id:a,name:a,checked:o,onCheckedChange:c,className:"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",children:r.jsx(Re.Thumb,{className:"pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"})}),s&&r.jsxs(D,{htmlFor:a,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:u})]}):r.jsxs("div",{className:O("flex items-center space-x-2",l),children:[r.jsx(we.Root,{id:a,name:a,checked:o,onCheckedChange:c,className:"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",children:r.jsx(we.Indicator,{className:"flex items-center justify-center text-current",children:r.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"20,6 9,17 4,12"})})})}),s&&r.jsxs(D,{htmlFor:a,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:u})]})}function ue({name:a,label:s,value:o=null,onChange:c,error:u,required:h,options:m={},className:l=""}){const{format:d="date",min:N,max:R}=m,_=E=>{if(!E)return"";switch(d){case"datetime-local":return E.toISOString().slice(0,16);case"time":return E.toTimeString().slice(0,5);case"date":default:return E.toISOString().split("T")[0]}},g=E=>{if(!E)return null;const x=new Date(E);return isNaN(x.getTime())?null:x},k=E=>{const x=g(E.target.value);c(x)};return r.jsxs("div",{className:O("space-y-2",l),children:[s&&r.jsxs(D,{htmlFor:a,children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),r.jsx(Z,{id:a,name:a,type:d,value:_(o),onChange:k,className:O(u&&"border-red-500 focus-visible:ring-red-500"),required:h,min:N,max:R}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:u})]})}function Te({label:a,value:s=[],onChange:o,error:c,required:u,itemSchema:h,errors:m,path:l,options:d={},className:N=""}){const{minLength:R=0,maxLength:_}=d,g=()=>{const j=[...s,pr(h)];o(l,j)},k=j=>{const b=s.filter((A,G)=>G!==j);o(l,b)},E=(j,b)=>{const A=[...s];A[j]=b,o(l,A)},x=!_||s.length<_,F=s.length>R;return r.jsxs("div",{className:O("space-y-4",N),children:[r.jsxs("div",{className:"flex items-center justify-between",children:[a&&r.jsxs(D,{children:[a,u&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),r.jsx(ee,{type:"button",variant:"outline",size:"sm",onClick:g,disabled:!x,children:"Add Item"})]}),s.length===0?r.jsx("div",{className:"text-sm text-muted-foreground p-4 border-2 border-dashed rounded-lg text-center",children:'No items added yet. Click "Add Item" to get started.'}):r.jsx("div",{className:"space-y-3",children:s.map((j,b)=>r.jsx("div",{className:"flex items-start space-x-2 p-3 border rounded-lg bg-card",children:r.jsxs("div",{className:"flex-1",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("span",{className:"text-sm font-medium",children:["Item ",b+1]}),F&&r.jsx(ee,{type:"button",variant:"destructive",size:"sm",onClick:()=>k(b),children:"Remove"})]}),r.jsx("div",{className:"space-y-2",children:typeof j=="string"?r.jsx("input",{type:"text",value:j,onChange:A=>E(b,A.target.value),className:"w-full px-3 py-2 border border-input rounded-md bg-background",placeholder:`Enter ${h.type||"value"}`}):typeof j=="number"?r.jsx("input",{type:"number",value:j,onChange:A=>E(b,Number(A.target.value)),className:"w-full px-3 py-2 border border-input rounded-md bg-background",placeholder:`Enter ${h.type||"number"}`}):r.jsxs("div",{className:"text-sm text-muted-foreground",children:["Complex item type - ",JSON.stringify(j)]})}),m[`${l}.${b}`]&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:m[`${l}.${b}`]})]})},b))}),c&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:c})]})}function pr(a){if(a.defaultValue!==void 0)return a.defaultValue;switch(a.type){case"string":return"";case"number":return 0;case"boolean":return!1;case"date":return new Date;case"array":return[];case"object":return{};default:return null}}function de({name:a,label:s,value:o={},onChange:c,error:u,required:h,properties:m={},errors:l={},path:d,className:N=""}){const R=(g,k)=>{c(g,k)},_=(g,k,E,x)=>{const F=d?`${d}.${g}`:g,j={name:`${a}-${g}`,label:k.label||g,value:E,onChange:b=>R(F,b),error:x,required:k.required,path:F};switch(k.type){case"string":return r.jsx(re,{...j});case"number":return r.jsx(le,{...j});case"boolean":return r.jsx(ce,{...j});case"date":return r.jsx(ue,{...j});case"object":return r.jsx(de,{...j,properties:k.properties||{},errors:l});default:return r.jsxs("div",{className:"text-sm text-muted-foreground p-2 border border-dashed rounded",children:[r.jsxs("div",{className:"font-medium mb-1",children:["Unsupported field type: ",k.type]}),r.jsxs("div",{className:"text-xs",children:["Property: ",g]}),r.jsxs("div",{className:"text-xs",children:["Current value: ",JSON.stringify(E)]})]})}};return r.jsxs("div",{className:O("space-y-4",N),children:[s&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs(D,{htmlFor:a,children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),r.jsx("hr",{className:"border-border"})]}),r.jsx("div",{className:O("space-y-4","pl-4 border-l-2 border-border"),children:Object.entries(m).map(([g,k])=>{if(!k)return console.warn(`ObjectField: Schema for property '${g}' is undefined`),null;const E=o[g],x=(l==null?void 0:l[`${d}.${g}`])||(l==null?void 0:l[g]);return r.jsx("div",{children:_(g,k,E,x)},g)})}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-2",children:u})]})}function Ce({name:a,label:s,value:o={},onChange:c,error:u,required:h,discriminator:m,variants:l,errors:d,path:N,className:R=""}){const _=o[m],g=Object.keys(l),k=x=>{const F={[m]:x};c(N,F)},E=(x,F)=>{const j={...o,[x]:F};c(N,j)};return r.jsxs("div",{className:O("space-y-4",R),children:[s&&r.jsxs(D,{children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(D,{htmlFor:`${a}-discriminator`,children:"Type"}),r.jsxs(C.Root,{value:_||"",onValueChange:k,children:[r.jsxs(C.Trigger,{id:`${a}-discriminator`,className:"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:[r.jsx(C.Value,{placeholder:"Select type..."}),r.jsx(C.Icon,{asChild:!0,children:r.jsx("svg",{className:"h-4 w-4 opacity-50",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"6,9 12,15 18,9"})})})]}),r.jsx(C.Portal,{children:r.jsx(C.Content,{className:"relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",children:r.jsx(C.Viewport,{className:"p-1",children:g.map(x=>r.jsxs(C.Item,{value:x,className:"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",children:[r.jsx(C.ItemIndicator,{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:r.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"20,6 9,17 4,12"})})}),r.jsx(C.ItemText,{children:x})]},x))})})})]})]}),_&&l[_]&&r.jsxs("div",{className:"space-y-4 p-4 border rounded-lg bg-card",children:[r.jsxs("h4",{className:"text-sm font-semibold text-card-foreground",children:[_," Properties"]}),r.jsx("div",{className:"space-y-3",children:Object.entries(l[_].properties||{}).map(([x,F])=>{if(x===m)return null;const j=`${N}.${x}`,b=o[x],A=d[j];return r.jsxs("div",{className:"space-y-2",children:[r.jsxs(D,{htmlFor:`${a}-${x}`,children:[F.label||x,F.required&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),vr(`${a}-${x}`,x,b,F,A,G=>E(x,G)),A&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:A})]},x)})})]}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:u})]})}function vr(a,s,o,c,u,h){const m=O("w-full px-3 py-2 border border-input rounded-md bg-background",u&&"border-red-500 focus-visible:ring-red-500");switch(c.type){case"string":return r.jsx("input",{id:a,name:s,type:"text",value:o||"",onChange:l=>h(l.target.value),className:m,placeholder:`Enter ${c.label||s}`});case"number":return r.jsx("input",{id:a,name:s,type:"number",value:o||0,onChange:l=>h(Number(l.target.value)),className:m,min:c.min,max:c.max,step:c.step});case"boolean":return r.jsxs("div",{className:"flex items-center space-x-2",children:[r.jsx("input",{id:a,name:s,type:"checkbox",checked:o||!1,onChange:l=>h(l.target.checked),className:"h-4 w-4 rounded border-input"}),r.jsx("span",{className:"text-sm",children:"Yes"})]});default:return r.jsxs("div",{className:"text-sm text-muted-foreground p-2 border border-dashed rounded",children:["Unsupported property type: ",c.type,r.jsx("br",{}),"Current value: ",JSON.stringify(o)]})}}function Oe({name:a,label:s,value:o="",onChange:c,error:u,required:h,values:m,className:l=""}){return r.jsxs("div",{className:O("space-y-2",l),children:[s&&r.jsxs(D,{htmlFor:a,children:[s,h&&r.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),r.jsxs(C.Root,{value:o,onValueChange:c,children:[r.jsxs(C.Trigger,{id:a,className:O("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",u&&"border-red-500 focus:ring-red-500"),children:[r.jsx(C.Value,{placeholder:"Select an option..."}),r.jsx(C.Icon,{asChild:!0,children:r.jsx("svg",{className:"h-4 w-4 opacity-50",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"6,9 12,15 18,9"})})})]}),r.jsx(C.Portal,{children:r.jsx(C.Content,{className:"relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",children:r.jsx(C.Viewport,{className:"p-1",children:m.map(d=>r.jsxs(C.Item,{value:d,className:"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",children:[r.jsx(C.ItemIndicator,{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:r.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"20,6 9,17 4,12"})})}),r.jsx(C.ItemText,{children:d})]},d))})})})]}),u&&r.jsx("p",{className:"text-sm text-red-500 mt-1",children:u})]})}const K={name:"radix-themes",components:{string:re,string1:re,number:le,boolean:ce,date:ue,array:Te,object:de,discriminatedUnion:Ce}};function xr(){return ie.registerUIAdapter(K),ie.registerFieldRenderer("enum",Oe),console.log("Radix Themes Adapter registered successfully:",K.name),K}function Pe(a){return r.jsx(ie.ZodForm,{registerUIAdapter:K,...a})}const hr=Y.z.object({name:Y.z.string().min(1,"Name is required"),email:Y.z.string().email("Invalid email"),age:Y.z.number().min(18,"Must be at least 18"),subscribe:Y.z.boolean(),role:Y.z.enum(["admin","user","moderator"])});function br(){const a=s=>{console.log("Form submitted:",s)};return r.jsxs("div",{className:"max-w-md mx-auto p-6",children:[r.jsx("h1",{className:"text-2xl font-bold mb-6",children:"ZodForm with Radix Adapter"}),r.jsx(Pe,{schema:hr,onSubmit:a,defaultValues:{name:"",email:"",age:18,subscribe:!1,role:"user"},className:"space-y-4"})]})}p.ArrayField=Te,p.BooleanField=ce,p.Button=ee,p.DateField=ue,p.DiscriminatedUnionField=Ce,p.EnumField=Oe,p.Input=Z,p.Label=D,p.NumberField=le,p.ObjectField=de,p.StringField=re,p.Textarea=Ne,p.ZodForm=Pe,p.ZodFormExample=br,p.buttonVariants=ke,p.cn=O,p.radixThemesAdapter=K,p.registerRadixThemesAdapter=xr,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});