ynotsoft-dynamic-form 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +19 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import{
|
|
2
|
-
${
|
|
3
|
-
`,children:[F(b.Value,{placeholder:e.placeholder||`Select ${((
|
|
1
|
+
import{useState as Q,useEffect as Be,useMemo as Nt}from"react";import{toast as De}from"react-hot-toast";import ze from"dayjs";import{jsx as Te}from"react/jsx-runtime";function Oe(e){return Te("input",{type:"hidden",name:e.name,value:e.value},e.name)}var le=Oe;import Ae from"react-select";import Ue from"react-select/animated";import{jsx as je}from"react/jsx-runtime";function He({field:e,formValues:c,handleChange:r,touched:h,errors:u,handleBlur:d}){let s=e.disabled&&e.disabled(c),l=e.options||[],n=Ue(),p=c[e.name]||[];return je(Ae,{components:n,isMulti:!0,isDisabled:s,name:e.label,value:p,onChange:v=>r(e.name,v),options:l,placeholder:e.placeholder,closeMenuOnSelect:!1})}var ie=He;import*as b from"@radix-ui/react-select";import"react";import{ChevronDownIcon as Ge}from"@heroicons/react/20/solid";import{jsx as F,jsxs as q}from"react/jsx-runtime";function _e({field:e,formValues:c,handleChange:r,handleBlur:h}){var l;let u=c[e.name]||"",d=typeof e.disabled=="function"?e.disabled(c):e.disabled,s=e.options||[];return q(b.Root,{value:u,onValueChange:n=>r(e.name,n),disabled:d,children:[q(b.Trigger,{id:e.name,onBlur:()=>h(e.name),className:`inline-flex items-center justify-between w-full px-3 py-2 border rounded-md text-sm transition-all
|
|
2
|
+
${d?"bg-gray-100 text-gray-500 cursor-not-allowed":"border-gray-300 hover:border-gray-400 focus:ring-2 focus:ring-blue-500"}
|
|
3
|
+
`,children:[F(b.Value,{placeholder:e.placeholder||`Select ${((l=e.label)==null?void 0:l.toLowerCase())||""}`}),F(b.Icon,{className:"ml-2 text-gray-500",children:F(Ge,{className:"w-4 h-4"})})]}),F(b.Portal,{children:q(b.Content,{className:"bg-white border border-gray-200 rounded-md shadow-lg z-50 min-w-[var(--radix-select-trigger-width)]",position:"popper",sideOffset:5,children:[F(b.ScrollUpButton,{className:"flex items-center justify-center h-6 text-gray-500 bg-gray-50",children:F(b.Arrow,{className:"fill-white stroke-gray-200"})}),q(b.Viewport,{className:"p-1",children:[e.groupLabel&&F(b.Group,{children:F(b.Label,{className:"px-2 py-1 text-xs text-gray-500 uppercase tracking-wide",children:e.groupLabel})}),s.map(n=>F(b.Item,{value:n.value,className:`relative flex items-center px-3 py-2 text-sm rounded cursor-pointer select-none
|
|
4
4
|
data-[state=checked]:bg-blue-50
|
|
5
5
|
data-[state=checked]:text-blue-600
|
|
6
|
-
`,children:F(b.ItemText,{children:
|
|
6
|
+
`,children:F(b.ItemText,{children:n.label})},n.value)),e.separator&&F(b.Separator,{className:"my-1 h-px bg-gray-200"})]}),F(b.Arrow,{className:"fill-white stroke-gray-200"})]})})]})}var ce=_e;import"react";import{jsx as qe}from"react/jsx-runtime";function We({field:e,formValues:c,handleChange:r,handleBlur:h,touched:u,errors:d}){let s=e.readOnly&&e.disabled;return qe("input",{...e.props,type:"email",value:c[e.name]||"",onChange:n=>r(e.name,n.target.value),onBlur:()=>h(e.name),disabled:s,name:e.name,placeholder:e.placeholder,className:`w-full px-3 py-2 border rounded-md ${!1?"border-red-500":"border-gray-300"} ${s?"bg-gray-100 text-gray-500 cursor-not-allowed":""}`})}var de=We;import"react";import{jsx as Ye}from"react/jsx-runtime";function Ve({field:e,formValues:c,handleChange:r,handleBlur:h,touched:u,errors:d}){console.log("Rendering InputField for",e);let s=e.readOnly||e.disabled;return Ye("input",{...e.props,id:e.name,type:e.type||"text",value:c[e.name]||"",onChange:n=>r(e.name,n.target.value),onBlur:()=>h(e.name),disabled:s,name:e.name,placeholder:e.placeholder,min:e.minLength,max:e.maxLength,className:`flex h-10 w-full rounded-md border 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 ${!1?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${s?"bg-gray-50 text-gray-500":"bg-background"}`})}var te=Ve;import"react";import{jsx as me}from"react/jsx-runtime";function Ke({field:e,formValues:c}){let r=c[e.name]||e.content||"";return me("div",{className:`mb-4 ${e.fieldClass?e.fieldClass:"col-span-full"}`,id:e.name.toLowerCase()+"_id",children:me("div",{className:"w-full px-3 py-2 border rounded-md overflow-y-auto max-h-40 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:r}})},e.name)}var ue=Ke;import{jsx as oe,jsxs as pe}from"react/jsx-runtime";function Xe({field:e,formValues:c,handleChange:r,handleBlur:h,touched:u,errors:d}){let s=e.disabled&&e.disabled(c),l=!1;return pe("div",{className:"mt-1 space-x-2",children:[oe("input",{...e.props,id:"id_"+e.name,type:"checkbox",checked:c[e.name]||!1,onChange:n=>r(e.name,n.target.checked),onBlur:()=>h(e.name),disabled:s,className:`rounded border-gray-300 ${s?"opacity-50 cursor-not-allowed":""}`}),pe("label",{className:"",htmlFor:"id_"+e.name,children:[e.label,e.required&&oe("span",{className:"text-red-500",children:"*"})]}),l&&oe("p",{className:"mt-1 text-sm text-red-500",children:l})]})}var be=Xe;import*as O from"@radix-ui/react-popover";import{useState as Je}from"react";import{DayPicker as Qe}from"react-day-picker";import"react-day-picker/dist/style.css";import{jsx as $,jsxs as _}from"react/jsx-runtime";function Ze({field:e,formValues:c,handleChange:r,handleBlur:h}){let[u,d]=Je(!1),s=c[e.name]??{from:null,to:null},l=p=>r(e.name,p),n=()=>r(e.name,{from:null,to:null});return $("div",{children:_(O.Root,{open:u,onOpenChange:d,children:[$(O.Trigger,{asChild:!0,children:_("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":u,onClick:()=>d(!0),onKeyDown:p=>p.key==="Enter"&&d(!0),className:`
|
|
7
7
|
inline-flex items-center justify-between gap-2
|
|
8
8
|
w-full h-9 rounded-md border border-gray-300 bg-white
|
|
9
9
|
px-3 py-2 text-sm font-normal shadow-sm
|
|
10
10
|
hover:bg-gray-50 hover:text-gray-900
|
|
11
11
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
|
|
12
12
|
disabled:cursor-not-allowed disabled:opacity-50
|
|
13
|
-
`,children:[
|
|
13
|
+
`,children:[s.from?s.to?_("span",{children:[s.from.toLocaleDateString()," \u2013 ",s.to.toLocaleDateString()]}):$("span",{children:s.from.toLocaleDateString()}):$("span",{className:"text-muted-foreground",children:e.placeholder||"Select date range"}),$("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:$("path",{d:"m6 9 6 6 6-6"})})]})}),_(O.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[$(Qe,{mode:"range",selected:s,onSelect:l,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),_("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[$("button",{type:"button",onClick:n,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),$("button",{type:"button",onClick:()=>d(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var ge=Ze;import"react";import{toast as he}from"react-hot-toast";import{Fragment as tt,jsx as P,jsxs as C}from"react/jsx-runtime";function et({field:e,formValues:c,touched:r,errors:h,fileUploads:u,setFileUploads:d,fileInputRefs:s,handleChange:l,onFieldsChange:n,api_URL:p}){let v=r[e.name]&&h[e.name],f=e.type==="multifile",w=u[e.name]||{},M=c[e.name],k=f?M||[]:[M].filter(Boolean),E=e.disabled&&e.disabled(c),j=`px-4 py-2 bg-gray-100 border rounded hover:bg-gray-200 ${E?"cursor-not-allowed":""}`,z=p?`${p}uploads`:null;!z&&e.uploadEndpoint&&console.error(`api_URL prop is required when using FileField with upload functionality for field "${e.name}"`);let B=i=>{if(i===0)return"0 Bytes";let t=1024,o=["Bytes","KB","MB","GB"],a=Math.floor(Math.log(i)/Math.log(t));return parseFloat((i/Math.pow(t,a)).toFixed(2))+" "+o[a]},x=async(i,t)=>{let o=new FormData;o.append("file",i);let a=await fetch(`${z}`,{method:"POST",body:o});if(!a.ok)throw he.error("Upload failed"),new Error("Upload failed");return await a.json()},S=async(i,t)=>{if(!t)return;if(i.maxSize&&t.size>i.maxSize)throw new Error(`File size must not exceed ${B(i.maxSize)}`);let o=await x(t,i.name),a={...c,[i.name]:o};l(i.name,o),n(a)},Z=async(i,t)=>{let o=c[i.name]||[];if(o.length+t.length>i.maxFiles)throw new Error(`Maximum ${i.maxFiles} files allowed`);t.forEach(N=>{if(i.maxSize&&N.size>i.maxSize)throw new Error(`Each file must not exceed ${B(i.maxSize)}`)});let a=await Promise.all(t.map(N=>x(N,i.name))),m=[...o,...a];l(i.name,m),n({...c,[i.name]:m})},W=async(i,t)=>{let o=Array.from(t);try{e.type==="file"?await S(e,o[0]):e.type==="multifile"&&await Z(e,o),s.current[i]&&(s.current[i].value="")}catch(a){he.error(`Upload failed: ${a.message}`)}},ee=async(i,t)=>{let o;e.type==="file"?o="":o=(c[i]||[]).filter(m=>m!==t),l(i,o),n({...c,[i]:o}),s.current[i]&&(s.current[i].value="")};return C("div",{className:`mb-4 ${e.fieldClass||"col-span-full"}`,children:[C("label",{className:"block font-medium mb-1",children:[e.label,e.required&&P("span",{className:"text-red-500",children:"*"})]}),C("div",{className:"space-y-2",children:[C("div",{className:"items-center space-x-2",children:[C("button",{type:"button",disabled:E,onClick:()=>s.current[e.name].click(),className:j,children:["Choose ",f?"Files":"File"]}),f&&k.length>0&&C("span",{className:"text-sm text-gray-600",children:[k.length," of ",e.maxFiles," files uploaded"]})]}),P("input",{ref:i=>s.current[e.name]=i,type:"file",accept:e.accept,multiple:f,className:"hidden",onChange:i=>W(e.name,i.target.files)}),P("div",{className:"space-y-2",children:k.map((i,t)=>{let o=Object.values(w).find(a=>a.file===i);return C("div",{className:"flex items-center justify-between p-2 bg-gray-50 rounded",children:[C("div",{className:"flex items-center space-x-2",children:[o&&C(tt,{children:[P("span",{className:"text-sm",children:o.fileName}),C("span",{className:"text-xs text-gray-500",children:["(",B(o.fileSize),")"]})]}),!o&&P("span",{className:"text-sm",children:i.original_name})]}),P("button",{type:"button",onClick:()=>ee(e.name,i),className:"text-red-500 hover:text-red-700 ml-3",children:"Remove"})]},i)})}),Object.entries(w).map(([i,t])=>t.status==="uploading"?C("div",{className:"relative pt-1",children:[C("div",{className:"flex items-center justify-between",children:[C("span",{className:"text-xs font-semibold inline-block text-blue-600",children:["Uploading ",i]}),C("span",{className:"text-xs font-semibold inline-block text-blue-600",children:[t.progress,"%"]})]}),P("div",{className:"overflow-hidden h-2 mt-1 text-xs flex rounded bg-blue-200",children:P("div",{className:"shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-blue-500",style:{width:`${t.progress}%`}})})]},i):null)]}),v&&P("p",{className:"mt-1 text-sm text-red-500",children:v})]},e.name)}var re=et;import{useRef as ot,useEffect as rt}from"react";import{jsx as xe,jsxs as ye}from"react/jsx-runtime";function at({field:e,formValues:c,handleChange:r,handleBlur:h,touched:u,errors:d,charCount:s,setCharCounts:l}){let n=ot(null),p=c[e.name]||"",v=typeof e.disabled=="function"?e.disabled(c):e.disabled||e.readOnly,f=u!=null&&u[e.name]&&(d!=null&&d[e.name])?d[e.name]:null,w=()=>{let k=n.current;k&&(k.style.height="auto",k.style.height=`${k.scrollHeight+2}px`)};rt(()=>{w()},[p]);let M=k=>{r(e.name,k.target.value),w(),l&&l(E=>({...E,[e.name]:k.target.value.length}))};return ye("div",{className:"space-y-2",children:[xe("textarea",{...e.props,ref:n,id:e.name,name:e.name,placeholder:e.placeholder||"",value:p,onChange:M,onBlur:()=>h(e.name),disabled:v,maxLength:e.maxLength,rows:e.rows||3,className:`flex w-full rounded-md border 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 resize-none overflow-y-auto ${f?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${v?"bg-gray-50 text-gray-500":"bg-background"}`,style:{minHeight:"80px",maxHeight:"400px"}}),xe("div",{className:"flex justify-between items-center",children:e.maxLength&&!e.readOnly&&ye("span",{className:"text-xs text-gray-500",children:[s||0,"/",e.maxLength," characters"]})})]})}var ve=at;import"react";import{jsx as fe,jsxs as st}from"react/jsx-runtime";function nt({field:e,formValues:c,handleChange:r,handleBlur:h,touched:u,errors:d}){return st("div",{children:[fe("input",{type:"datetime-local",value:e.value||"",onChange:s=>r(e.name,s.target.value),onBlur:h,className:"border rounded px-3 py-2 w-full",placeholder:"Select date and time"}),fe("p",{className:"text-sm text-gray-500 mt-1",children:"Note: Install @mui/x-date-pickers for enhanced date picker functionality"})]})}var we=nt;import{Separator as ae}from"@radix-ui/react-separator";import{jsx as V,jsxs as it}from"react/jsx-runtime";function lt({field:e}){return e!=null&&e.label?it("div",{className:"relative flex items-center py-4",children:[V(ae,{className:"flex-1 h-px bg-gray-300"}),V("span",{className:"px-3 font-medium text-gray-600 bg-white",children:e.label}),V(ae,{className:"flex-1 h-px bg-gray-300"})]}):V(ae,{className:"my-4 h-px bg-gray-300"})}var Ne=lt;import"react";import*as A from"@radix-ui/react-radio-group";import{jsx as T,jsxs as ke}from"react/jsx-runtime";function ct({field:e,formValues:c,handleChange:r,handleBlur:h}){let u=c[e.name]||"",d=typeof e.disabled=="function"?e.disabled(c):e.disabled,s=e.options||[],l=e.inline||!1;return T(A.Root,{value:u,onValueChange:n=>r(e.name,n),onBlur:()=>h(e.name),disabled:d,className:l?"flex flex-wrap gap-4":"space-y-3","aria-label":e.label||e.name,children:s.map(n=>{let p=typeof n=="object"?n.value:n,v=typeof n=="object"?n.label:n,f=typeof n=="object"?n.description:null,w=`${e.name}-${p}`;return ke("div",{className:"relative flex items-start",children:[T("div",{className:"flex h-6 items-center",children:T(A.Item,{value:p,id:w,disabled:d,className:`
|
|
14
14
|
relative size-4 rounded-full border transition-all
|
|
15
|
-
${
|
|
15
|
+
${d?"border-gray-300 bg-gray-100 cursor-not-allowed":"border-gray-300 bg-white hover:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"}
|
|
16
16
|
data-[state=checked]:border-blue-600 data-[state=checked]:bg-blue-600
|
|
17
|
-
`,children:
|
|
18
|
-
${
|
|
19
|
-
${
|
|
17
|
+
`,children:T(A.Indicator,{className:"flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-1.5 after:h-1.5 after:rounded-full after:bg-white"})})}),ke("div",{className:"ml-3 text-sm",children:[T("label",{htmlFor:w,className:`font-medium ${d?"text-gray-500":"text-gray-900 cursor-pointer"}`,children:v}),f&&!l&&T("p",{className:`text-sm ${d?"text-gray-400":"text-gray-500"}`,children:f})]})]},p)})})}var Ce=ct;import"react";import{jsx as Se,jsxs as mt}from"react/jsx-runtime";function dt({field:e}){let c=e.text||e.label||"",r=e.description||"",h=e.size||"lg",u=e.underline||!1,d=e.align||"left",s=e.className||"",l={sm:"text-base font-semibold",md:"text-lg font-semibold",lg:"text-xl font-bold",xl:"text-2xl font-bold","2xl":"text-3xl font-bold","3xl":"text-4xl font-bold","4xl":"text-5xl font-bold"},n={left:"text-left",center:"text-center",right:"text-right"},p=`
|
|
18
|
+
${l[h]||l.lg}
|
|
19
|
+
${n[d]||n.left}
|
|
20
20
|
${u?"border-b-2 border-gray-300 pb-2":""}
|
|
21
|
-
${
|
|
21
|
+
${s}
|
|
22
22
|
text-gray-900
|
|
23
|
-
`.trim(),
|
|
23
|
+
`.trim(),v=`
|
|
24
24
|
mt-1 text-sm text-gray-600
|
|
25
|
-
${
|
|
26
|
-
`.trim();return
|
|
25
|
+
${n[d]||n.left}
|
|
26
|
+
`.trim();return mt("div",{className:"my-4",children:[Se("h2",{className:p,children:c}),r&&Se("p",{className:v,children:r})]})}var Fe=dt;import*as U from"@radix-ui/react-popover";import{useState as ut}from"react";import{DayPicker as pt}from"react-day-picker";import"react-day-picker/dist/style.css";import{jsx as L,jsxs as Y}from"react/jsx-runtime";function bt({field:e,formValues:c,handleChange:r,handleBlur:h}){let[u,d]=ut(!1),s=c[e.name]??null,l=p=>r(e.name,p),n=()=>r(e.name,null);return L("div",{children:Y(U.Root,{open:u,onOpenChange:d,children:[L(U.Trigger,{asChild:!0,children:Y("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":u,onClick:()=>d(!0),onKeyDown:p=>p.key==="Enter"&&d(!0),className:`
|
|
27
27
|
inline-flex items-center justify-between gap-2
|
|
28
28
|
w-full h-9 rounded-md border border-gray-300 bg-white
|
|
29
29
|
px-3 py-2 text-sm font-normal shadow-sm
|
|
30
30
|
hover:bg-gray-50 hover:text-gray-900
|
|
31
31
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
|
|
32
32
|
disabled:cursor-not-allowed disabled:opacity-50
|
|
33
|
-
`,children:[
|
|
33
|
+
`,children:[s?L("span",{children:s.toLocaleDateString()}):L("span",{className:"text-muted-foreground",children:e.placeholder||"Select date"}),L("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:L("path",{d:"m6 9 6 6 6-6"})})]})}),Y(U.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[L(pt,{mode:"single",selected:s,onSelect:l,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),Y("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[L("button",{type:"button",onClick:n,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),L("button",{type:"button",onClick:()=>d(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var Re=bt;import gt,{useState as K}from"react";import*as H from"@radix-ui/react-popover";import{jsx as g,jsxs as I}from"react/jsx-runtime";function ht({field:e,formValues:c,handleChange:r,handleBlur:h}){let[u,d]=K(!1),[s,l]=K("12"),[n,p]=K("00"),[v,f]=K("PM"),w=c[e.name]||"";gt.useEffect(()=>{if(w){let x=w.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);x&&(l(x[1].padStart(2,"0")),p(x[2]),f(x[3].toUpperCase()))}},[w]);let M=()=>{let x=`${s}:${n} ${v}`;r(e.name,x),d(!1)},k=()=>{r(e.name,""),l("12"),p("00"),f("PM")},E=()=>{let x=parseInt(s);l((x%12+1).toString().padStart(2,"0"))},j=()=>{let x=parseInt(s);l((x===1?12:x-1).toString().padStart(2,"0"))},z=()=>{let x=parseInt(n);p(((x+5)%60).toString().padStart(2,"0"))},B=()=>{let x=parseInt(n);p((x===0?55:x-5).toString().padStart(2,"0"))};return g("div",{children:I(H.Root,{open:u,onOpenChange:d,children:[g(H.Trigger,{asChild:!0,children:I("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":u,onClick:()=>d(!0),className:`
|
|
34
34
|
inline-flex items-center justify-between gap-2
|
|
35
35
|
w-full h-9 rounded-md border border-gray-300 bg-white
|
|
36
36
|
px-3 py-2 text-sm font-normal shadow-sm
|
|
37
37
|
hover:bg-gray-50 hover:text-gray-900
|
|
38
38
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
|
|
39
39
|
disabled:cursor-not-allowed disabled:opacity-50
|
|
40
|
-
`,children:[w?
|
|
40
|
+
`,children:[w?g("span",{children:w}):g("span",{className:"text-gray-400",children:e.placeholder||"Select time"}),I("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-clock opacity-70",children:[g("circle",{cx:"12",cy:"12",r:"10"}),g("polyline",{points:"12 6 12 12 16 14"})]})]})}),g(H.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-4 shadow-md w-64",children:I("div",{className:"flex flex-col gap-4",children:[I("div",{className:"flex items-center justify-center gap-2",children:[I("div",{className:"flex flex-col items-center",children:[g("button",{type:"button",onClick:E,className:"p-1 hover:bg-gray-100 rounded",children:g("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:g("polyline",{points:"18 15 12 9 6 15"})})}),g("input",{type:"text",value:s,onChange:x=>{let S=x.target.value.replace(/\D/g,"");(S===""||parseInt(S)>=1&&parseInt(S)<=12)&&l(S.padStart(2,"0"))},className:"w-14 text-center text-2xl font-semibold border-0 focus:outline-none focus:ring-2 focus:ring-blue-500 rounded py-2",maxLength:"2"}),g("button",{type:"button",onClick:j,className:"p-1 hover:bg-gray-100 rounded",children:g("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:g("polyline",{points:"6 9 12 15 18 9"})})})]}),g("span",{className:"text-2xl font-semibold",children:":"}),I("div",{className:"flex flex-col items-center",children:[g("button",{type:"button",onClick:z,className:"p-1 hover:bg-gray-100 rounded",children:g("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:g("polyline",{points:"18 15 12 9 6 15"})})}),g("input",{type:"text",value:n,onChange:x=>{let S=x.target.value.replace(/\D/g,"");(S===""||parseInt(S)>=0&&parseInt(S)<=59)&&p(S.padStart(2,"0"))},className:"w-14 text-center text-2xl font-semibold border-0 focus:outline-none focus:ring-2 focus:ring-blue-500 rounded py-2",maxLength:"2"}),g("button",{type:"button",onClick:B,className:"p-1 hover:bg-gray-100 rounded",children:g("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:g("polyline",{points:"6 9 12 15 18 9"})})})]}),I("div",{className:"flex flex-col gap-1 ml-2",children:[g("button",{type:"button",onClick:()=>f("AM"),className:`
|
|
41
41
|
px-3 py-1 text-sm font-medium rounded
|
|
42
|
-
${
|
|
43
|
-
`,children:"AM"}),
|
|
42
|
+
${v==="AM"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}
|
|
43
|
+
`,children:"AM"}),g("button",{type:"button",onClick:()=>f("PM"),className:`
|
|
44
44
|
px-3 py-1 text-sm font-medium rounded
|
|
45
|
-
${
|
|
46
|
-
`,children:"PM"})]})]}),
|
|
45
|
+
${v==="PM"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}
|
|
46
|
+
`,children:"PM"})]})]}),I("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 pt-3",children:[g("button",{type:"button",onClick:k,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),g("button",{type:"button",onClick:M,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})})]})})}var $e=ht;import"react";import{InformationCircleIcon as xt,XCircleIcon as yt}from"@heroicons/react/20/solid";import{CheckCircleIcon as vt}from"@heroicons/react/20/solid";import{ExclamationCircleIcon as ft}from"@heroicons/react/24/outline";import{jsx as R,jsxs as X}from"react/jsx-runtime";function Pe({message:e}){return R("div",{className:"rounded-lg bg-red-50 border border-red-100 p-4 shadow-sm",children:X("div",{className:"flex items-center gap-3",children:[R(yt,{"aria-hidden":"true",className:"size-5 text-red-500 shrink-0"}),R("span",{className:"text-sm font-medium text-red-900",children:e})]})})}function Le({message:e}){return R("div",{className:"rounded-lg bg-amber-50 border border-amber-100 p-4 shadow-sm",children:X("div",{className:"flex items-center gap-3",children:[R(ft,{"aria-hidden":"true",className:"size-5 text-amber-600 shrink-0"}),R("span",{className:"text-sm font-medium text-amber-900",children:e})]})})}function Ie({message:e}){return R("div",{className:"rounded-lg bg-green-50 border border-green-100 p-4 shadow-sm",children:X("div",{className:"flex items-center gap-3",children:[R(vt,{"aria-hidden":"true",className:"size-5 text-green-600 shrink-0"}),R("span",{className:"text-sm font-medium text-green-900",children:e})]})})}function Me({message:e}){return R("div",{className:"rounded-lg bg-blue-50 border border-blue-100 p-4 shadow-sm",children:X("div",{className:"flex items-center gap-3",children:[R(xt,{"aria-hidden":"true",className:"size-5 text-blue-600 shrink-0"}),R("span",{className:"text-sm font-medium text-blue-900",children:e})]})})}import{jsx as J}from"react/jsx-runtime";function wt({field:e}){let{variant:c="info",message:r,content:h}=e,u=r||h||"";switch(c.toLowerCase()){case"error":case"danger":return J(Pe,{message:u});case"success":return J(Ie,{message:u});case"warning":case"warn":return J(Le,{message:u});case"info":case"information":default:return J(Me,{message:u})}}var Ee=wt;import{Label as kt}from"@radix-ui/react-label";import{Fragment as St,jsx as D,jsxs as ne}from"react/jsx-runtime";var Ct=({apiClient:e,api_URL:c,formDefinition:r,sendFormValues:h,children:u,defaultValues:d={},onFieldsChange:s=()=>{}})=>{let[l,n]=Q({...d}),[p,v]=Q({}),[f,w]=Q({}),[M,k]=Q({}),E=["hidden","html","linebreak","header","alert"],j=Nt(()=>({file:re,multifile:re,dateRange:ge,date:Re,dayTimePicker:we,time:$e,hidden:le,multiselect:ie,select:ce,email:de,litertext:ue,checkbox:be,radiogroup:Ce,input:te,textarea:ve,header:Fe,alert:Ee,linebreak:Ne}),[]),z=async(t,o=null)=>{if(!e){let a=`apiClient prop is required when using fields with optionsUrl. Field "${t.name}" requires optionsUrl but no apiClient was provided.`;console.error(a),De.error(a);return}try{let a=await e(`/${t.optionsUrl}`);console.log(a);let m=[];t.type==="select"?m=[{value:"",label:`Select ${t.label.toLowerCase()}`},...a.data]:m=[...a.data.map(N=>({value:N.value,label:N.label}))],r.fields.forEach(N=>{N.name===t.name&&(N.options=m)})}catch(a){console.error(`Failed to load options for ${t.name}:`,a)}finally{}};Be(()=>{if(r!=null&&r.fields&&r.fields.length>0){if(!r.fields.some(a=>a.value))return;r.fields.forEach(a=>{a.optionsUrl&&z(a)});let o={};r.fields.forEach(a=>{o[a.name]=d[a.name]??a.value??(a.type==="multiselect"?[]:"")}),n(o)}},[r]);let B=(t,o,a)=>{if(t.disabled&&t.disabled(a))return null;if(t.required){if(!o)return`${t.label} is required`;if(Array.isArray(o)&&o.length===0)return`Please select at least one ${t.label.toLowerCase()}`}if(t.validate){let m=t.validate(o,a);if(m)return m}if(t.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o))return"Please enter a valid email address";if(t.type==="number"){if(t.min!==void 0&&o<t.min)return`${t.label} must be at least ${t.min}`;if(t.max!==void 0&&o>t.max)return`${t.label} must be no more than ${t.max}`}return t.type==="date"&&!ze(o).isValid()?`${t.label} must be a valid date`:t.maxLength&&o&&o.length>t.maxLength?`${t.label} must not exceed ${t.maxLength} characters`:null},x=(t,o)=>{let a=r.fields.find(y=>y.name===t);if(!a)return;let m={...l};console.log(o),a.type==="multiselect"?m[t]=Array.isArray(o)?o:Array.from(o.target.selectedOptions).map(y=>y.value):a.type==="dateRange"?(console.log(o),m[t]=[{startDate:o[0].from,endDate:o[0].to,key:"selection"}]):a.type==="dayTimePicker"?m[t]=o?ze(o).format("YYYY-MM-DD HH:mm:ss"):"":m[t]=o,a.type==="select"&&r.fields.forEach(y=>{y.showIf&&!y.showIf(m)&&(m[y.name]=y.type==="multiselect"?[]:"")}),r.fields.forEach(y=>{y.disabled&&y.disabled(m)&&(m[y.name]=y.type==="multiselect"?[]:"")}),n(m);let N={};r.fields.forEach(y=>{if(!y.showIf||y.showIf(m)){let G=B(y,m[y.name],m);G&&(N[y.name]=G)}}),v(N)},S=t=>{w({...f,[t]:!0})},Z=t=>{t.preventDefault();let o={};r.fields.forEach(m=>{o[m.name]=!0}),w(o);let a={};r.fields.forEach(m=>{if((!m.showIf||m.showIf(l))&&(!m.disabled||!m.disabled(l))){let N=B(m,l[m.name],l);N&&(a[m.name]=N)}}),v(a),Object.keys(a).length===0?h(l):De.error("Please correct the errors in the form")};Be(()=>{s(l)},[l,s]);let W={green:"border-green-500 bg-green-50",blue:"border-blue-500 bg-blue-50",red:"border-red-500 bg-red-50",yellow:"border-yellow-500 bg-yellow-50",purple:"border-purple-500 bg-purple-50",indigo:"border-indigo-500 bg-indigo-50",gray:"border-gray-500 bg-gray-50",pink:"border-pink-500 bg-pink-50",orange:"border-orange-500 bg-orange-50"};function ee(t,o,a){if(E.includes(o.type))return D("div",{className:o.fieldClass||"col-span-8",children:t});let m=o.containerStyle,N=o.color||"blue",y=m==="card"?`rounded-lg border text-card-foreground shadow-sm p-4 ${o.containerClassName||W[N]||W.blue}`:"",G=ne(St,{children:[o.label&&ne(kt,{htmlFor:o.name,className:"block text-sm font-medium mb-1",children:[o.label,o.required&&D("span",{className:"text-red-500 ml-1",children:"*"})]}),D("div",{children:t}),a&&D("p",{className:"mt-1 text-sm text-red-500",children:a})]});return D("div",{className:`mb-4 ${o.fieldClass||"col-span-8"}`,children:m==="card"?D("div",{className:y,children:G}):G})}let i=t=>{if(t.showIf&&!t.showIf(l))return null;let o=j[t.type]||te;l[t.name]===void 0&&(l[t.name]=t.value!==void 0?t.value:t.type==="multiselect"?[]:"");let a=f[t.name]&&p[t.name]?p[t.name]:null;return ee(D(o,{field:t,formValues:l,handleChange:x,handleBlur:()=>S(t.name),setCharCounts:k,charCount:M[t.name]||0,api_URL:c}),t)};return ne("form",{onSubmit:Z,className:"grid grid-cols-12 gap-x-4 mx-auto",children:[r?r.fields.map(i):D("div",{children:"Loading..."}),u]})},se=Ct;var hr=se;export{se as DynamicForm,se as DynamicFormComponent,hr as default};
|
|
47
47
|
//# sourceMappingURL=index.js.map
|