3BmF-CSc.js 3.99 KB
import{d as z,H as B,o as n,k as S,w as q,x as d,S as C,g as a,P as $,T as V,U as j,V as F,al as x,p as D,ad as N,y as E,e as I,Y as o,c as f,f as K,l as m,t as v,n as y,s as b,at as L,au as O,a0 as w,ao as P,aB as W,aC as U}from"./BtEn9SvP.js";var T=z({__name:"Label",props:{for:{type:String,required:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1,default:"label"}},setup(t){const e=t;return B(),(l,h)=>(n(),S(a($),C(e,{onMousedown:h[0]||(h[0]=r=>{!r.defaultPrevented&&r.detail>1&&r.preventDefault()})}),{default:q(()=>[d(l.$slots,"default")]),_:3},16))}}),A=T;const H={slots:{root:"",wrapper:"",labelWrapper:"flex content-center items-center justify-between gap-1",label:"block font-medium text-default",container:"relative",description:"text-muted",error:"mt-2 text-error",hint:"text-muted",help:"mt-2 text-muted"},variants:{size:{xs:{root:"text-xs"},sm:{root:"text-xs"},md:{root:"text-sm"},lg:{root:"text-sm"},xl:{root:"text-base"}},required:{true:{label:"after:content-['*'] after:ms-0.5 after:text-error"}},orientation:{vertical:{container:"mt-1"},horizontal:{root:"flex justify-between place-items-baseline gap-2"}}},defaultVariants:{size:"md",orientation:"vertical"}},M=["id"],Y=["id"],G=["id"],J=["id"],X={__name:"UFormField",props:{as:{type:null,required:!1},name:{type:String,required:!1},errorPattern:{type:null,required:!1},label:{type:String,required:!1},description:{type:String,required:!1},help:{type:String,required:!1},error:{type:[Boolean,String],required:!1,default:void 0},hint:{type:String,required:!1},size:{type:null,required:!1},required:{type:Boolean,required:!1},eagerValidation:{type:Boolean,required:!1},validateOnInputDelay:{type:Number,required:!1},orientation:{type:null,required:!1},class:{type:null,required:!1},ui:{type:Object,required:!1}},setup(t){const e=t,l=V(),h=j(),r=F("formField",e),s=b(()=>w({extend:w(H),...h.ui?.formField||{}})({size:e.size,required:e.required,orientation:e.orientation})),k=x(L,null),u=b(()=>e.error||k?.value?.find(i=>i.name===e.name||e.errorPattern&&i.name?.match(e.errorPattern))?.message),c=D(N()),p=c.value,g=x(O,void 0);return E(c,()=>{g&&e.name&&(g.value[e.name]={id:c.value,pattern:e.errorPattern})},{immediate:!0}),P(W,c),P(U,b(()=>({error:u.value,name:e.name,size:e.size,eagerValidation:e.eagerValidation,validateOnInputDelay:e.validateOnInputDelay,errorPattern:e.errorPattern,hint:e.hint,description:e.description,help:e.help,ariaId:p}))),(i,Q)=>(n(),S(a($),{as:t.as,"data-orientation":t.orientation,"data-slot":"root",class:o(s.value.root({class:[a(r)?.root,e.class]}))},{default:q(()=>[I("div",{"data-slot":"wrapper",class:o(s.value.wrapper({class:a(r)?.wrapper}))},[t.label||l.label?(n(),f("div",{key:0,"data-slot":"labelWrapper",class:o(s.value.labelWrapper({class:a(r)?.labelWrapper}))},[K(a(A),{for:c.value,"data-slot":"label",class:o(s.value.label({class:a(r)?.label}))},{default:q(()=>[d(i.$slots,"label",{label:t.label},()=>[m(v(t.label),1)])]),_:3},8,["for","class"]),t.hint||l.hint?(n(),f("span",{key:0,id:`${a(p)}-hint`,"data-slot":"hint",class:o(s.value.hint({class:a(r)?.hint}))},[d(i.$slots,"hint",{hint:t.hint},()=>[m(v(t.hint),1)])],10,M)):y("",!0)],2)):y("",!0),t.description||l.description?(n(),f("p",{key:1,id:`${a(p)}-description`,"data-slot":"description",class:o(s.value.description({class:a(r)?.description}))},[d(i.$slots,"description",{description:t.description},()=>[m(v(t.description),1)])],10,Y)):y("",!0)],2),I("div",{class:o([(t.label||!!l.label||t.description||!!l.description)&&s.value.container({class:a(r)?.container})])},[d(i.$slots,"default",{error:u.value}),e.error!==!1&&(typeof u.value=="string"&&u.value||l.error)?(n(),f("div",{key:0,id:`${a(p)}-error`,"data-slot":"error",class:o(s.value.error({class:a(r)?.error}))},[d(i.$slots,"error",{error:u.value},()=>[m(v(u.value),1)])],10,G)):t.help||l.help?(n(),f("div",{key:1,id:`${a(p)}-help`,"data-slot":"help",class:o(s.value.help({class:a(r)?.help}))},[d(i.$slots,"help",{help:t.help},()=>[m(v(t.help),1)])],10,J)):y("",!0)],2)]),_:3},8,["as","data-orientation","class"]))}};export{A as L,X as _};