@splenddev/kreativ-ui 0.2.0 → 0.2.2
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 +4053 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -18
- package/dist/index.d.ts +44 -18
- package/dist/index.js +4003 -5
- package/dist/index.js.map +1 -1
- package/dist/styles/index.css +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4004 @@
|
|
|
1
|
-
import {createContext,forwardRef,useState,useId,useRef,useEffect,useCallback,useLayoutEffect,useContext,useMemo,useReducer}from'react';import {useReducedMotion,motion,AnimatePresence}from'framer-motion';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {Lock,Hash,Search,Link2,Phone,Mail,EyeOff,Eye,X,ChevronDown,Check,Sun,Moon,Monitor}from'lucide-react';import {cva}from'class-variance-authority';var jn=Object.defineProperty;var i=(e,n)=>jn(e,"name",{value:n,configurable:true});function u(...e){return twMerge(clsx(e))}i(u,"cn");var he=createContext(null);function J(){let e=useContext(he);if(!e)throw new Error("useTheme() was called outside <UIProvider>. Wrap your app in <UIProvider> from 'kreativ-ui'.");return e}i(J,"useTheme");function pe(e,n=false,t="size"){let{theme:o,fallbackSize:a}=J();return useMemo(()=>{let r=o.sizes,l=r[e]??r[a]??Object.values(r)[0]??{},s={};if(l.height&&(s.height=l.height),l.width?s.width=l.width:n&&l.height&&(s.width=l.height),!n&&l.paddingX&&(s.paddingLeft=l.paddingX,s.paddingRight=l.paddingX),l.paddingY&&(s.paddingTop=l.paddingY,s.paddingBottom=l.paddingY),l.fontSize&&(s.fontSize=l.fontSize),l.gap&&(s.gap=n?0:l.gap),l.radius){let d=`--kui-${t}-radius`;s[d]=l.radius;}return {style:s,iconSize:l.iconSize}},[o.sizes,e,a,n])}i(pe,"useSizeStyle");function Qn(e,n){return {...e,base:n.base??e.base,variants:{...e.variants,...n.variants},defaultVariants:{...e.defaultVariants,...n.defaultVariants},compoundVariants:n.compoundVariants??e.compoundVariants}}i(Qn,"mergeRecipeDefinition");function Ct(e,n){if(!n)return e;let t={...e};for(let[o,a]of Object.entries(n)){let r=e[o];if(!r){t[o]=a;continue}t[o]=Qn(r,a);}return t}i(Ct,"mergeRecipes");function Zn(e,n){return Object.entries(e).every(([t,o])=>n[t]===o)}i(Zn,"matchesConditions");function ae(e,n={}){if(!e)return "";let t={...e.defaultVariants,...n},o=[];if(e.base&&o.push(e.base),e.variants)for(let[a,r]of Object.entries(e.variants)){let l=t[a];if(l===void 0)continue;let s=r[String(l)];s&&o.push(s);}if(e.compoundVariants)for(let a of e.compoundVariants)Zn(a.conditions,t)&&o.push(a.className);return u(...o)}i(ae,"resolveRecipe");var eo="inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none",to={solid:"",outline:"border bg-transparent",ghost:"bg-transparent",soft:"",link:"bg-transparent p-0 h-auto hover:underline"},wt={brand:{solid:"bg-brand text-brand-fg hover:bg-brand-hover",outline:"border-brand text-brand hover:bg-brand/10",ghost:"text-brand hover:bg-brand/10",soft:"bg-brand/10 text-brand hover:bg-brand/20",link:"text-brand"},destructive:{solid:"bg-destructive text-destructive-fg hover:bg-destructive-hover",outline:"border-destructive text-destructive hover:bg-destructive/10",ghost:"text-destructive hover:bg-destructive/10",soft:"bg-destructive/10 text-destructive hover:bg-destructive/20",link:"text-destructive"},success:{solid:"bg-success text-success-fg hover:bg-success-hover",outline:"border-success text-success hover:bg-success/10",ghost:"text-success hover:bg-success/10",soft:"bg-success/10 text-success hover:bg-success/20",link:"text-success"},warning:{solid:"bg-warning text-warning-fg hover:bg-warning-hover",outline:"border-warning text-warning hover:bg-warning/10",ghost:"text-warning hover:bg-warning/10",soft:"bg-warning/10 text-warning hover:bg-warning/20",link:"text-warning"},info:{solid:"bg-info text-info-fg hover:bg-info-hover",outline:"border-info text-info hover:bg-info/10",ghost:"text-info hover:bg-info/10",soft:"bg-info/10 text-info hover:bg-info/20",link:"text-info"},white:{solid:"bg-white text-black hover:bg-gray-50",outline:"border-white/30 text-white hover:bg-white/10",ghost:"text-white hover:bg-white/10",soft:"bg-white/10 text-white hover:bg-white/20",link:"text-white"},neutral:{solid:"bg-surface-raised text-text hover:bg-surface-sunken",outline:"border-border text-text hover:bg-surface-raised",ghost:"text-text hover:bg-surface-raised",soft:"bg-surface-raised text-text hover:bg-surface-sunken",link:"text-text"}},no=i(()=>{let e=[];for(let[n,t]of Object.entries(wt))for(let[o,a]of Object.entries(t))e.push({conditions:{color:n,variant:o},className:a});return e},"buildCompoundVariants"),kt={base:eo,variants:{variant:to,color:Object.fromEntries(Object.keys(wt).map(e=>[e,""]))},defaultVariants:{variant:"solid",color:"brand"},compoundVariants:no()};var oo="flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:pointer-events-none disabled:cursor-not-allowed",It={base:oo,variants:{variant:{outline:"",filled:"",ghost:""}},defaultVariants:{variant:"outline"}};var ro="group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-colors duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-2 ",io={outline:"border border-border bg-transparent text-text hover:border-brand",filled:"border border-transparent bg-surface-raised text-text hover:bg-surface",ghost:"border border-transparent bg-transparent text-text hover:bg-surface-raised"},so={none:"focus-within:ring-brand/20",error:"border-destructive focus-within:ring-destructive/20",success:"border-success focus-within:ring-success/20"},Tt={base:ro,variants:{variant:io,state:so,rounded:{true:"rounded-full",false:""},fullWidth:{true:"w-full",false:""},disabled:{true:"pointer-events-none cursor-not-allowed opacity-50",false:""},hasAdornment:{true:"px-2",false:""}},defaultVariants:{variant:"outline",state:"none",rounded:false,fullWidth:true,disabled:false,hasAdornment:false}};var Rt=new Set(["Enter"," "]),ve=forwardRef(({variant:e="solid",color:n="brand",size:t="md",isLoading:o=false,leftIcon:a,rightIcon:r,fullWidth:l=false,disabled:s,className:d,style:c,iconOnly:f,children:g,render:v,onKeyDown:m,onKeyUp:p,...b},k)=>{let{theme:y}=J(),{style:w,iconSize:I}=pe(t,f,"button"),D=useReducedMotion(),R=!s&&!o,[h,T]=useState(false);function H(S){m?.(S),R&&Rt.has(S.key)&&T(true);}i(H,"handleKeyDown");function z(S){p?.(S),Rt.has(S.key)&&T(false);}i(z,"handleKeyUp");let L=ae(y.recipes.Button,{variant:e,color:n}),A=u(L,l&&"w-full",o&&"animate-kui-pulse",d),V={...w,...c},N=jsxs(Fragment,{children:[o&&jsx("span",{className:"animate-kui-spin rounded-full border-2 border-current border-t-transparent",style:{width:I,height:I},"aria-hidden":"true"}),!o&&a,f&&o?null:g,!o&&r]});return v?v({className:A,style:V,disabled:s||o,"aria-busy":o||void 0,children:N}):jsx(motion.button,{ref:k,disabled:s||o,className:A,style:V,"aria-busy":o||void 0,animate:{scale:h?.975:1},whileHover:R?{scale:1.015}:void 0,whileTap:R?{scale:.975}:void 0,transition:D?{duration:0}:{type:"spring",stiffness:500,damping:30},onKeyDown:H,onKeyUp:z,...b,children:N})});ve.displayName="Button";var Vt=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function hs(e){let n=e.trim();if(Vt.test(n))return n.length===4?("#"+[...n.slice(1)].map(o=>o+o).join("")).toUpperCase():n.toUpperCase();let t=n.replace(/[^\d,]/g,"").split(",").map(Number);return t.length!==3||t.some(Number.isNaN)?"#000000":"#"+t.map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}i(hs,"rgbToHex");function vs(e){if(!Vt.test(e))return null;let n=e.length===4?"#"+[...e.slice(1)].map(r=>r+r).join(""):e,t=parseInt(n.slice(1,3),16),o=parseInt(n.slice(3,5),16),a=parseInt(n.slice(5,7),16);return `${t} ${o} ${a}`}i(vs,"hexToRgbString");var yo={type:"none",duration:300,delay:0,easing:"ease-in-out"},So=i(e=>{switch(e){case "fade":return {initial:{opacity:0},animate:{opacity:1},exit:{opacity:0}};case "slide":return {initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20}};case "scale":return {initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},exit:{opacity:0,scale:1.5}};case "rotate":return {initial:{opacity:0,rotate:-90},animate:{opacity:1,rotate:0},exit:{opacity:0,rotate:90}};default:return {initial:{opacity:1},animate:{opacity:1},exit:{opacity:1}}}},"getIconVariants");function Co({variant:e="ghost",activeVariant:n="solid",color:t="neutral",activeColor:o="brand",size:a="sm",iconOnly:r=false,allowSystem:l=false,orientation:s="horizontal",rounded:d=false,unstyled:c=false,labels:f,icons:g,className:v,buttonProps:m={},display:p="buttons",transition:b=yo}){let{mode:k,setMode:y,resolvedMode:w}=J(),I=l?k:w,D=[{key:"light",label:f?.light??"Light",icon:g?.light??jsx(Sun,{size:16})},{key:"dark",label:f?.dark??"Dark",icon:g?.dark??jsx(Moon,{size:16})},...l?[{key:"system",label:f?.system??"System",icon:g?.system??jsx(Monitor,{size:16})}]:[]],R=D.map(M=>M.key),h=D.find(({key:M})=>M===I)??D[0],T=d&&!(s==="vertical"&&!r);useEffect(()=>{d&&!T&&console.warn("[kreativ-ui/ThemeToggler] `rounded` is ignored when orientation='vertical' and iconOnly={false}.");},[d,T]);let H=i(()=>{let M=R.indexOf(I);y(R[(M+1)%R.length]);},"handleCycle"),z=i(M=>M==="system"?k==="system":I===M,"isActive"),L=u("inline-flex gap-1",s==="vertical"&&"flex-col",!c&&["border border-border bg-surface p-1",T?"rounded-full":"rounded-lg"],v),A=T?"rounded-full":"rounded-lg",V=p==="cycle"&&b.type!=="none",N=So(b.type||"none"),S={duration:(b.duration||300)/1e3,delay:(b.delay||0)/1e3,ease:b.easing||"ease-in-out"};if(p==="cycle")return jsxs(ve,{size:a,variant:e,color:t,onClick:H,"aria-label":`Current theme: ${h.label}`,className:u(T&&"rounded-full",m.className),...m,children:[jsx(AnimatePresence,{mode:"wait",children:jsx(motion.span,{initial:V?N.initial:void 0,animate:V?N.animate:void 0,exit:V?N.exit:void 0,transition:S,children:h.icon},h.key)}),!r&&h.label]});let F=D.map(({key:M,label:K,icon:G})=>{let $=z(M);return jsx(ve,{size:a,variant:$?n:e,color:$?o:t,onClick:()=>y(M),className:u(A,m.className),leftIcon:G,"aria-pressed":$,...m,children:!r&&K},M)});return c?jsx("div",{role:"group","aria-label":"Theme selector",className:u("inline-flex gap-1",s==="vertical"&&"flex-col",v),children:F}):jsx("div",{role:"group","aria-label":"Theme selector",className:L,children:F})}i(Co,"ThemeToggler");var To={sm:640,md:768,lg:1024,xl:1280,"2xl":1536};function Ls(e){let n=`(min-width: ${To[e]}px)`,[t,o]=useState(()=>typeof window<"u"&&window.matchMedia(n).matches);return useEffect(()=>{let a=window.matchMedia(n),r=i(l=>o(l.matches),"listener");return a.addEventListener("change",r),o(a.matches),()=>a.removeEventListener("change",r)},[n]),t}i(Ls,"useBreakpoint");var Ft={email:Mail,tel:Phone,url:Link2,search:Search,numeric:Hash,"password-current":Lock,"password-new":Lock};function Dt({size:e=14}){return jsx("span",{className:"animate-kui-spin rounded-full border-2 border-inherit border-t-transparent shrink-0",style:{width:e,height:e},"aria-hidden":"true"})}i(Dt,"Spinner");var Lt={text:{placeholder:"Type something..."},email:{type:"email",inputMode:"email",autoComplete:"email",placeholder:"you@company.com"},tel:{type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:"+234 800 000 0000"},url:{type:"url",inputMode:"url",autoComplete:"url",placeholder:"https://company.com"},search:{type:"search",inputMode:"search",autoComplete:"off",placeholder:"Search..."},numeric:{type:"text",inputMode:"numeric",autoComplete:"off",placeholder:"Enter a number"},"password-current":{type:"password",autoComplete:"current-password",placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"},"password-new":{type:"password",autoComplete:"new-password",placeholder:"Create a password"},number:{type:"number",inputMode:"decimal",autoComplete:"off",placeholder:"0.00"},date:{type:"date",inputMode:"none",placeholder:"YYYY-MM-DD"},time:{type:"time",inputMode:"none",placeholder:"HH:MM"},"datetime-local":{type:"datetime-local",inputMode:"none",placeholder:"YYYY-MM-DDTHH:MM"},month:{type:"month",inputMode:"none",placeholder:"YYYY-MM"},week:{type:"week",inputMode:"none",placeholder:"YYYY-Www"}};var Po=1500;function Pt(e){let n=useRef(e),[t,o]=useState();return useEffect(()=>{if(e===n.current)return;if(n.current=e,e==="none"){o(void 0);return}o(e);let a=window.setTimeout(()=>{o(void 0);},Po);return ()=>window.clearTimeout(a)},[e]),t}i(Pt,"useStateTransition");var Ve=createContext(null);function fe(){let e=useContext(Ve);if(!e)throw new Error("FormField components must be used inside <FormField />");return e}i(fe,"useFormField");function Y(){return useContext(Ve)}i(Y,"useOptionalFormField");function $o(...e){return n=>{e.forEach(t=>{t&&(typeof t=="function"?t(n):t.current=n);});}}i($o,"mergeRefs");var At=forwardRef(({className:e,inputClassName:n,variant:t="outline",size:o="md",error:a,success:r,startIcon:l,endIcon:s,fullWidth:d=true,disabled:c,rounded:f=false,isLoading:g=false,clearable:v=false,onClear:m,kind:p="text",hideKindIcon:b=false,id:k,type:y,inputMode:w,autoComplete:I,placeholder:D,onChange:R,readOnly:h,value:T,defaultValue:H,style:z,...L},A)=>{let V=useId(),{theme:N}=J(),S=Y(),F=k??S?.id??V,M=a||S?.invalid||false,K=S?.describedBy??void 0,G=S?.required??L.required,$=useRef(null),{style:x,iconSize:E}=pe(o,false,"input"),[C,B]=useState(()=>!!(T??H??"")),[j,Z]=useState(false);useEffect(()=>{T!==void 0&&B(!!T);},[T]);let ee=Lt[p],te=y??ee.type,ce=te==="password",W=ce?j?"text":"password":te,X$1=Ft[p],Ie=!b&&X$1?jsx(X$1,{size:Number(E)||15}):void 0,Te=l||Ie?jsx("span",{className:"flex shrink-0 items-center justify-center",children:l??Ie}):null,ie=[];ce&&ie.push(jsx("button",{type:"button",tabIndex:-1,onClick:()=>Z(U=>!U),"aria-label":j?"Hide password":"Show password",className:"flex items-center justify-center text-text-muted transition-colors hover:text-text",children:j?jsx(EyeOff,{size:16}):jsx(Eye,{size:16})},"toggle-visibility")),v&&C&&!c&&ie.push(jsx("button",{type:"button",tabIndex:-1,onClick:Gn,"aria-label":"Clear input",className:"flex items-center justify-center text-text-muted transition-colors hover:text-text",children:jsx(X,{size:14})},"clear"));let O=g?jsx(Dt,{size:Number(E)||14}):s||(ie.length?jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:ie}):null),P=!!(Te||O),q=a?"error":r?"success":"none",de=Pt(q);console.log({state:q,stateTransition:de});let Re=u(ae(N.recipes.FormControl,{variant:t,state:q,rounded:f,fullWidth:d,disabled:!!(c||g),hasIcon:P}),e),Me=u(ae(N.recipes.Input,{variant:t}),n),ue={...x,...z};function se(U){B(!!U.target.value),R?.(U);}i(se,"handleChange");function Gn(){let U=$.current;if(!U)return;Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value")?.set?.call(U,""),U.dispatchEvent(new Event("input",{bubbles:true})),U.focus(),B(false),m?.();}return i(Gn,"handleClear"),useEffect(()=>{if(!a)return;let U=$.current;U&&U.scrollIntoView({behavior:"smooth",block:"center"});},[a]),jsxs("div",{className:Re,style:ue,"data-state":q,"data-state-transition":de,children:[Te,jsx("input",{...L,ref:$o($,A),id:F,type:W,inputMode:w??ee.inputMode,autoComplete:I??ee.autoComplete,placeholder:D??ee.placeholder,value:T,defaultValue:H,onChange:se,readOnly:g||h,disabled:g||c,"aria-busy":g||void 0,"aria-invalid":M||void 0,"aria-describedby":K,"aria-required":G||void 0,className:Me,"data-variant":t,"data-size":o,"data-success":r||void 0,"data-disabled":c||void 0,"data-loading":g||void 0}),O]},de??"idle")});At.displayName="Input";function ye({id:e,error:n,required:t=false,children:o}){let a=useId(),r=e??a,l=`${r}-label`,s=`${r}-description`,d=`${r}-message`,[c,f]=useState(void 0),[g,v]=useState(0),m=useCallback(w=>{n===void 0&&f(w?.invalid?w.message:void 0);},[n]),p=useCallback(()=>(v(w=>w+1),()=>v(w=>w-1)),[]),b=g>0,k=n??c,y=k?"error":"none";return jsx(Ve.Provider,{value:{id:r,labelId:l,descriptionId:s,messageId:d,state:y,describedBy:[s,k?d:void 0].filter(Boolean).join(" ")||void 0,invalid:!!k,required:t,reportValidity:m,registerLabel:p,hasExternalLabel:b},children:jsxs("div",{className:"flex flex-col gap-2",children:[o,k&&jsx(Ee,{children:k})]})})}i(ye,"FormField");ye.Label=Ye;ye.Control=Xe;ye.Description=Ue;ye.Message=Ee;function Ye({children:e,className:n}){let t=fe();return useEffect(()=>t.registerLabel(),[t]),jsxs("label",{id:t.labelId,htmlFor:t.id,className:u("text-sm font-medium text-text",n),children:[e,t.required&&jsx("span",{"aria-hidden":true,className:"ml-1 text-destructive",children:"*"})]})}i(Ye,"FormFieldLabel");function Ue({children:e}){let{descriptionId:n}=fe();return jsx("p",{id:n,className:"text-sm text-text-muted",children:e})}i(Ue,"FormFieldDescription");function Ee({children:e}){let{messageId:n}=fe();return jsx("p",{id:n,role:"alert",className:`\r
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`,children:e})}i(Ee,"FormFieldMessage");function Xe({children:e}){return jsx(Fragment,{children:e})}i(Xe,"FormFieldControl");var _e=createContext(null);function oe(e){let n=useContext(_e);if(!n)throw new Error(`<${e} /> must be rendered inside <Select>.`);return n}i(oe,"useSelectContext");var ze=createContext(null);function Je(e){return [...e.entries()].filter(([,n])=>!n.disabled).map(([n])=>n)}i(Je,"orderedEnabledValues");var Fe=forwardRef(({className:e,children:n,onKeyDown:t,...o},a)=>{let r=oe("SelectTrigger"),{theme:l}=J(),{style:s,iconSize:d}=pe(r.size,false,"select"),c=r.isInvalid?"error":r.isSuccess?"success":"none",f=u(ae(l.recipes.FormControl,{variant:r.variant,state:c,rounded:!!r.rounded,fullWidth:true,disabled:r.disabled,hasAdornment:true}),e),g=r.clearable&&r.value!==void 0&&!r.disabled,v=useCallback(p=>{let b=Je(r.items);if(!b.length)return;let k=r.activeValue?b.indexOf(r.activeValue):-1,y=k===-1?p===1?0:b.length-1:(k+p+b.length)%b.length;r.setActiveValue(b[y]);},[r]),m=useCallback(p=>{if(t?.(p),!p.defaultPrevented)switch(p.key){case "ArrowDown":p.preventDefault(),r.open?v(1):r.setOpen(true);break;case "ArrowUp":p.preventDefault(),r.open?v(-1):r.setOpen(true);break;case "Home":{if(!r.open)break;p.preventDefault();let b=Je(r.items);b.length&&r.setActiveValue(b[0]);break}case "End":{if(!r.open)break;p.preventDefault();let b=Je(r.items);b.length&&r.setActiveValue(b[b.length-1]);break}case "Enter":case " ":p.preventDefault(),r.open?r.activeValue!==void 0&&r.onValueChange(r.activeValue):r.setOpen(true);break;case "Escape":r.open&&(p.preventDefault(),r.setOpen(false));break;case "Backspace":case "Delete":r.clearable&&r.value!==void 0&&!r.open&&(p.preventDefault(),r.onClear());break;}},[r,v,t]);return jsxs("div",{ref:r.triggerRef,className:f,style:s,children:[jsxs("button",{ref:a,type:"button",id:r.triggerId,role:"combobox","aria-haspopup":"listbox","aria-expanded":r.open,"aria-labelledby":r.labelId,"aria-controls":r.contentId,"aria-activedescendant":r.open&&r.activeValue?r.optionId(r.activeValue):void 0,tabIndex:r.tabIndex,"aria-invalid":r.isInvalid||void 0,"aria-describedby":r.describedBy,"aria-required":r.required||void 0,disabled:r.disabled,"data-state":r.open?"open":"closed",onClick:()=>!r.disabled&&r.setOpen(!r.open),onKeyDown:m,className:"relative min-w-0 flex-1 bg-transparent cursor-pointer text-left outline-none disabled:cursor-not-allowed h-full",...o,children:[n,jsx("span",{"aria-hidden":true,className:"pointer-events-none absolute right-0 top-1/2 flex -translate-y-1/2 items-center gap-1.5 text-text-muted",children:jsx(ChevronDown,{size:14,className:u("transition-transform duration-200",r.open&&"rotate-180")})})]}),g&&jsx("button",{type:"button",tabIndex:-1,"aria-label":"Clear selection",onClick:p=>{p.preventDefault(),p.stopPropagation(),r.onClear();},onMouseDown:p=>{p.preventDefault(),p.stopPropagation();},className:"flex h-4 w-4 items-center justify-center text-text-muted transition-colors hover:text-text",children:jsx(X,{size:Number(d)||14})})]})});Fe.displayName="SelectTrigger";var Yt=8;function Qe({className:e,children:n,...t}){let o=oe("SelectContent"),a=useRef(null),[r,l]=useState("bottom");return useLayoutEffect(()=>{if(!o.open)return;let s=o.triggerRef.current,d=a.current;if(!s||!d)return;function c(){let f=s.getBoundingClientRect(),g=d?.offsetHeight,v=window.innerHeight-f.bottom-Yt,m=f.top-Yt;l(g&&g>v&&m>v?"top":"bottom");}return i(c,"measure"),c(),window.addEventListener("resize",c),window.addEventListener("scroll",c,true),()=>{window.removeEventListener("resize",c),window.removeEventListener("scroll",c,true);}},[o.open,o.triggerRef]),o.open?jsx("div",{ref:a,id:o.contentId,role:"listbox","aria-labelledby":o.triggerId,"data-state":o.open?"open":"closed","data-side":r,className:u("animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-(--kui-radii-md) border border-border bg-surface p-1 shadow-lg",r==="bottom"?"top-full mt-1":"bottom-full mb-1",e),...t,children:n}):null}i(Qe,"SelectContent");function Ze({value:e,disabled:n=false,children:t,className:o,...a}){let r=oe("SelectItem"),l=r.value===e,s=r.activeValue===e,d=useRef(null);return useLayoutEffect(()=>r.registerItem(e,{label:t,disabled:n}),[e,n,t]),useEffect(()=>{s&&d.current?.scrollIntoView({block:"nearest"});},[s]),jsx("div",{ref:d,id:r.optionId(e),role:"option","aria-selected":l,"aria-disabled":n||void 0,"data-state":l?"selected":void 0,"data-active":s||void 0,"data-disabled":n||void 0,onMouseEnter:()=>!n&&r.setActiveValue(e),onClick:()=>!n&&r.onValueChange(e),className:u("flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",s&&"bg-brand/15 text-brand",l&&!s&&"bg-surface-raised",n&&"pointer-events-none cursor-not-allowed opacity-50",o),...a,children:t})}i(Ze,"SelectItem");function et({placeholder:e,className:n}){let t=oe("SelectValue"),o=t.selectedLabel??e??t.placeholder;return jsx("span",{className:u("min-w-0 truncate",n),children:o})}i(et,"SelectValue");function tt({children:e,className:n}){let t=useId(),[o,a]=useState(void 0);return jsx(ze.Provider,{value:{labelId:o??t,setHasLabel:a},children:jsx("div",{role:"group","aria-labelledby":o,className:u("py-1",n),children:e})})}i(tt,"SelectGroup");function Xt({children:e,className:n}){let t=useId(),o=useContext(ze);return useEffect(()=>{o?.setHasLabel(t);},[o,t]),jsx("div",{id:t,className:u("px-2.5 py-1.5 font-mono text-[11px] text-text-muted",n),children:e})}i(Xt,"SelectLabel");function le({value:e,defaultValue:n,onValueChange:t,disabled:o=false,required:a,name:r,variant:l="outline",size:s="md",className:d,placeholder:c,"aria-describedby":f,clearable:g=false,error:v,success:m,tabIndex:p,rounded:b,children:k}){let y=useId(),w=Y(),I=w?.id??y,D=useRef(null),R=`${I}-listbox`,h=w?.labelId,[T,H]=useState(n),z=e!==void 0?e:T,L=v||w?.invalid||false,A=!!(m&&!L),V=w?.describedBy??f,N=w?.required??a,[S,F]=useState(false),[M,K]=useState(z),[G,$]=useState(),x=useRef(new Map),[E,C]=useState(new Map),B=useCallback((W,X)=>(x.current.set(W,X),C(new Map(x.current)),()=>{x.current.delete(W),C(new Map(x.current));}),[]),j=useCallback(W=>{let X=x.current.get(W)?.label??W;$(X),e===void 0&&H(W),t?.(W),F(false);},[e,t]),Z=useCallback(()=>{K(void 0),H(void 0),t?.(void 0),$(void 0);},[e,t]),ee=useCallback(W=>`${R}-option-${W}`,[R]);useEffect(()=>{S&&K(z);},[S,z]),useEffect(()=>{if(z!==void 0){let W=x.current.get(z)?.label;W!==void 0&&$(W);}},[z,E]);let te=useRef(null);useEffect(()=>{if(!S)return;function W(X){te.current&&!te.current.contains(X.target)&&F(false);}return i(W,"handlePointerDown"),document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[S]);let ce=useMemo(()=>({value:z,selectedLabel:G,onValueChange:j,disabled:o,variant:l,size:s,open:S,setOpen:F,triggerId:I,contentId:R,labelId:h,isInvalid:L,isSuccess:A,describedBy:V,required:N,activeValue:M,setActiveValue:K,items:E,registerItem:B,optionId:ee,placeholder:c,clearable:g,onClear:Z,triggerRef:D,rounded:b,tabIndex:p}),[z,E,G,j,o,l,s,S,I,R,L,A,V,N,M,B,ee,c,g,Z,D,b,h,p]);return jsx(_e.Provider,{value:ce,children:jsxs("div",{ref:te,className:u("relative inline-block w-full",d),children:[k,r&&jsx("input",{type:"hidden",name:r,value:z??"",disabled:o,required:N})]})})}i(le,"Select");le.Trigger=Fe;le.Content=Qe;le.Item=Ze;le.Value=et;le.Group=tt;le.Label=Xt;var Jt=["flex","w-full","font-sans","transition-colors","duration-[var(--kui-duration-fast)]","outline-none","border-0","bg-transparent","placeholder:text-text-muted","disabled:opacity-50","disabled:pointer-events-none","disabled:cursor-not-allowed"].join(" "),Qt=cva("relative rounded-[var(--kui-radii-md)] transition-colors",{variants:{variant:{outline:"border border-border bg-transparent hover:border-brand focus-within:border-brand",filled:"border border-transparent bg-surface-raised hover:bg-surface",ghost:"border border-transparent bg-transparent hover:bg-surface-raised"},state:{none:"focus-within:ring-2 focus-within:ring-brand/20",error:"border-danger focus-within:ring-2 focus-within:ring-danger/20",success:"border-success focus-within:ring-2 focus-within:ring-success/20"},fullWidth:{true:"w-full",false:""},disabled:{true:"pointer-events-none cursor-not-allowed opacity-50",false:""}},defaultVariants:{variant:"outline",state:"none",fullWidth:true,disabled:false}}),Zt={sm:"px-2 py-1.5 text-xs",md:"px-3 py-2 text-sm",lg:"px-4 py-2.5 text-base"},en={none:"resize-none",both:"resize",horizontal:"resize-x",vertical:"resize-y"};function wr(...e){return n=>{e.forEach(t=>{t&&(typeof t=="function"?t(n):t.current=n);});}}i(wr,"mergeRefs");var sn=forwardRef(({className:e,value:n,defaultValue:t,size:o="md",fullWidth:a=true,resize:r="vertical",autoResize:l=false,minRows:s,maxRows:d,clearable:c=false,onClear:f,characterCounter:g=false,debounceDelay:v=0,trimOnBlur:m=false,error:p,success:b,onValidate:k,disabled:y,id:w,maxLength:I,variant:D="outline",onValueChange:R,onChange:h,onBlur:T,rows:H,...z},L)=>{let A=useId(),V=Y(),N=V?.id??w??A,S=useRef(null),F=useRef(null),[M,K]=useState(()=>n??t??"");useEffect(()=>{n!==void 0&&K(n);},[n]);let[G,$]=useState({}),x=p??V?.invalid??G.invalid??false,E=b??(k&&G.invalid===false)??false,C=V?.describedBy;function B(O){let P=O.target.value;K(P),v>0?(F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{R?.(P),h?.(O);},v)):(R?.(P),h?.(O));}i(B,"handleChange"),useEffect(()=>()=>{F.current&&clearTimeout(F.current);},[]);function j(O){let P=S.current;if(!P)return;Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,"value")?.set?.call(P,O),P.dispatchEvent(new Event("input",{bubbles:true}));}i(j,"dispatchValue");function Z(O){if(!k||p!==void 0||b!==void 0)return;let P=k(O),q=P===true?{invalid:false,message:void 0}:P===false?{invalid:true,message:void 0}:{invalid:true,message:P};$(q),V?.reportValidity(q.invalid?q:null);}i(Z,"runValidation");function ee(O){let P=M;if(m){let q=M.trim();q!==M&&(j(q),K(q),P=q);}Z(P),T?.(O);}i(ee,"handleBlur");function te(){j(""),K(""),S.current?.focus(),$({}),V?.reportValidity(null),f?.();}i(te,"handleClear"),useLayoutEffect(()=>{if(!l)return;let O=S.current;if(!O)return;let P=window.getComputedStyle(O),q=parseFloat(P.lineHeight)||parseFloat(P.fontSize)*1.2,de=parseFloat(P.paddingTop)+parseFloat(P.paddingBottom),Re=parseFloat(P.borderTopWidth)+parseFloat(P.borderBottomWidth),Me=s?q*s+de+Re:void 0,ue=d?q*d+de+Re:void 0;O.style.height="auto";let se=O.scrollHeight;Me&&(se=Math.max(se,Me)),ue&&(se=Math.min(se,ue)),O.style.height=`${se}px`,O.style.overflowY=ue&&O.scrollHeight>ue?"auto":"hidden";},[l,M,s,d]);let ce=M.length>0,W=c&&ce&&!y,X$1=g,Ie=I?M.length>=I*.9:false,Te=x?"error":E?"success":"none",ie=V?.describedBy?void 0:x||E?`${N}-message`:void 0;return jsxs("div",{className:u(Qt({variant:D,state:Te,fullWidth:a,disabled:!!y}),e),children:[jsx("textarea",{ref:wr(S,L),id:N,value:n!==void 0?M:void 0,defaultValue:n===void 0?t:void 0,onChange:B,onBlur:ee,disabled:y,maxLength:I,rows:l?void 0:H??s,"aria-invalid":x||void 0,"aria-describedby":C??ie,"aria-required":z.required,className:u(Jt,Zt[o],!l&&en[r],l&&"resize-none overflow-hidden",(W||X$1)&&"pb-6","text-text"),"data-size":o,"data-invalid":x||void 0,"data-success":E||void 0,"data-disabled":y||void 0,"data-autoresize":l||void 0,...z}),W&&jsx("button",{type:"button",tabIndex:-1,"aria-label":"Clear textarea",onClick:te,className:"absolute right-2 top-2 flex items-center justify-center text-text-muted transition-colors hover:text-text",children:jsx(X,{size:14})}),X$1&&jsxs("div",{className:u("pointer-events-none absolute bottom-1.5 right-2.5 font-mono text-[11px]",Ie?"text-danger":"text-text-muted"),children:[M.length,I?`/${I}`:""]}),G.message&&!V&&jsx("p",{id:ie,className:"mt-1.5 px-0.5 text-xs text-danger",children:G.message})]})});sn.displayName="Textarea";var an=cva("flex shrink-0 items-center justify-center rounded-[calc(var(--kui-radii-md)-2px)] border transition-colors duration-[var(--kui-duration-fast)]",{variants:{size:{sm:"h-4 w-4",md:"h-5 w-5",lg:"h-6 w-6"},state:{none:"",error:"border-danger",success:"border-success"},checked:{true:"bg-brand border-brand text-brand-fg",false:"border-border bg-transparent"},disabled:{true:"cursor-not-allowed",false:"cursor-pointer"}},defaultVariants:{size:"md",state:"none",checked:false,disabled:false},compoundVariants:[{checked:false,state:"error",class:"border-danger"},{checked:false,state:"success",class:"border-success"}]}),rt={sm:10,md:12,lg:14};function cn({size:e}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:3,strokeLinecap:"round","aria-hidden":"true",children:jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}i(cn,"DashIcon");function Vr(...e){return n=>{e.forEach(t=>{t&&(typeof t=="function"?t(n):t.current=n);});}}i(Vr,"mergeRefs");var pn=forwardRef(({className:e,checked:n,defaultChecked:t,onCheckedChange:o,indeterminate:a=false,size:r="md",error:l,success:s,disabled:d,label:c,description:f,id:g,onChange:v,required:m,...p},b)=>{let k=useId(),y=Y(),w=y?.id??g??k,I=useRef(null),[D,R]=useState(t??false),h=n!==void 0?n:D,T=useRef(false);useEffect(()=>{process.env?.NODE_ENV!=="production"&&(T.current||c&&y?.hasExternalLabel&&(console.warn("[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor. That renders two <label> elements pointing at the same input, which double-announces in screen readers. Use Checkbox's `label` prop instead of <FormField.Label> when the control is a checkbox."),T.current=true));},[c,y?.hasExternalLabel]),useEffect(()=>{I.current&&(I.current.indeterminate=a);},[a]);let H=l??y?.invalid??false,L=H?"error":s??false?"success":"none";function A(S){let F=S.target.checked;n===void 0&&R(F),o?.(F),v?.(S);}i(A,"handleChange");let V=f?`${w}-description`:void 0,N=y?.describedBy??V;return jsxs("div",{className:u("flex gap-2.5",d&&"cursor-not-allowed opacity-50",e),children:[jsxs("div",{className:"relative mt-0.5 inline-flex",children:[jsx("input",{ref:Vr(I,b),type:"checkbox",id:w,checked:h,disabled:d,required:m??y?.required,onChange:A,"aria-invalid":H||void 0,"aria-describedby":N,className:"peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed","data-invalid":H||void 0,...p}),jsx("div",{"aria-hidden":"true",className:u(an({size:r,state:L,checked:h||a,disabled:!!d}),"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"),children:a?jsx(cn,{size:rt[r]}):h?jsx(Check,{size:rt[r]}):null})]}),(c||f)&&jsxs("div",{className:"flex flex-col gap-0.5",children:[c&&jsx("label",{htmlFor:w,className:u("text-sm text-text",!d&&"cursor-pointer"),children:c}),f&&jsx("p",{id:V,className:"text-xs text-text-muted",children:f})]})]})});pn.displayName="Checkbox";var st=createContext(null);function fn(){let e=useContext(st);if(!e)throw new Error("<Radio /> must be rendered inside <RadioGroup>.");return e}i(fn,"useRadioGroupContext");function Lr({value:e,defaultValue:n,onValueChange:t,name:o,disabled:a=false,required:r=false,orientation:l="vertical",size:s="md",error:d,success:c,className:f,children:g}){let v=useId(),m=o??v,p=Y(),[b,k]=useState(n),y=e!==void 0?e:b,w=useCallback(T=>{e===void 0&&k(T),t?.(T);},[e,t]),I=d??p?.invalid??false,R=I?"error":c??false?"success":"none",h=r||!!p?.required;return jsx(st.Provider,{value:{name:m,value:y,onValueChange:w,disabled:a,size:s,state:R,groupRequired:h},children:jsx("div",{role:"radiogroup","aria-labelledby":p?.hasExternalLabel?`${p.id}-label`:void 0,"aria-describedby":p?.describedBy,"aria-required":h||void 0,"aria-invalid":I||void 0,className:u("flex gap-3",l==="horizontal"?"flex-row flex-wrap":"flex-col",f),children:g})})}i(Lr,"RadioGroup");var bn=cva("flex shrink-0 items-center justify-center rounded-full border transition-colors duration-[var(--kui-duration-fast)]",{variants:{size:{sm:"h-4 w-4",md:"h-5 w-5",lg:"h-6 w-6"},state:{none:"",error:"border-danger",success:"border-success"},checked:{true:"border-brand",false:"border-border bg-transparent"},disabled:{true:"cursor-not-allowed",false:"cursor-pointer"}},defaultVariants:{size:"md",state:"none",checked:false,disabled:false},compoundVariants:[{checked:false,state:"error",class:"border-danger"},{checked:false,state:"success",class:"border-success"}]}),gn={sm:"h-1.5 w-1.5",md:"h-2 w-2",lg:"h-2.5 w-2.5"};function Br({value:e,disabled:n,label:t,description:o,className:a,...r}){let l=fn(),s=`${l.name}-${e}`,d=l.value===e,c=n||l.disabled,f=o?`${s}-description`:void 0;return jsxs("div",{className:u("flex gap-2.5",c&&"cursor-not-allowed opacity-50",a),children:[jsxs("div",{className:"relative mt-0.5 inline-flex",children:[jsx("input",{type:"radio",id:s,name:l.name,value:e,checked:d,disabled:c,onChange:()=>l.onValueChange(e),"aria-describedby":f,className:"peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed","data-invalid":l.state==="error"||void 0,...r}),jsx("div",{"aria-hidden":"true",className:u(bn({size:l.size,state:l.state,checked:d,disabled:c}),"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"),children:d&&jsx("div",{className:u("rounded-full bg-brand",gn[l.size])})})]}),(t||o)&&jsxs("div",{className:"flex flex-col gap-0.5",children:[t&&jsx("label",{htmlFor:s,className:u("text-sm text-text",!c&&"cursor-pointer",l.size==="sm"&&"text-xs"),children:t}),o&&jsx("p",{id:f,className:u("text-xs text-text-muted",l.size==="sm"&&"text-[10px]"),children:o})]})]})}i(Br,"Radio");var xn=cva("relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-colors duration-[var(--kui-duration-fast)]",{variants:{size:{sm:"h-4 w-7",md:"h-5 w-9",lg:"h-6 w-11"},checked:{true:"bg-brand",false:"bg-surface-raised"},disabled:{true:"cursor-not-allowed",false:"cursor-pointer"}},defaultVariants:{size:"md",checked:false,disabled:false}}),hn={sm:{thumb:"h-3 w-3",translate:"translate-x-3"},md:{thumb:"h-4 w-4",translate:"translate-x-4"},lg:{thumb:"h-5 w-5",translate:"translate-x-5"}};function $r({checked:e,defaultChecked:n,onCheckedChange:t,size:o="md",disabled:a,label:r,description:l,className:s,id:d,onChange:c,...f}){let g=useId(),v=Y(),m=v?.id??d??g,[p,b]=useState(n??false),k=e!==void 0?e:p;function y(R){let h=R.target.checked;e===void 0&&b(h),t?.(h),c?.(R);}i(y,"handleChange");let w=l?`${m}-description`:void 0,{thumb:I,translate:D}=hn[o];return jsxs("div",{className:u("flex gap-2.5",a&&"cursor-not-allowed opacity-50",s),children:[jsxs("div",{className:"relative inline-flex",children:[jsx("input",{type:"checkbox",role:"switch",id:m,checked:k,disabled:a,onChange:y,"aria-describedby":v?.describedBy??w,className:"peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",...f}),jsx("div",{"aria-hidden":"true",className:u(xn({size:o,checked:k,disabled:!!a}),"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"),children:jsx("div",{className:u("absolute left-0.5 rounded-full bg-white shadow transition-transform duration-[var(--kui-duration-fast)]",I,k&&D)})})]}),(r||l)&&jsxs("div",{className:"flex flex-col gap-0.5",children:[r&&jsx("label",{htmlFor:m,className:u("text-sm text-text",!a&&"cursor-pointer"),children:r}),l&&jsx("p",{id:w,className:"text-xs text-text-muted",children:l})]})]})}i($r,"Switch");var ct=createContext(null);function re(e){let n=useContext(ct);if(!n)throw new Error(`<${e} /> must be rendered inside <Combobox>.`);return n}i(re,"useComboboxContext");var vn=["flex","items-center","font-sans","transition-colors","duration-[var(--kui-duration-fast)]","outline-none","placeholder:text-text-muted","disabled:opacity-50","disabled:pointer-events-none","disabled:cursor-not-allowed"].join(" "),Pe=cva("group relative inline-flex items-center gap-2 transition-colors",{variants:{variant:{outline:"border border-border bg-transparent text-text hover:border-brand",filled:"border border-transparent bg-surface-raised text-text hover:bg-surface",ghost:"border border-transparent bg-transparent text-text hover:bg-surface-raised"},state:{none:"focus-within:ring-2 focus-within:ring-brand/20",error:"border-danger focus-within:ring-2 focus-within:ring-danger/20",success:"border-success focus-within:ring-2 focus-within:ring-success/20"},rounded:{true:"rounded-full",false:"rounded-[var(--kui-radii-md)]"},fullWidth:{true:"w-full",false:""},hasIcon:{true:"px-2",false:""},disabled:{true:"pointer-events-none cursor-not-allowed opacity-50",false:""}},defaultVariants:{variant:"outline",state:"none",rounded:false,fullWidth:true,hasIcon:false,disabled:false}}),yn={sm:"h-8 px-2 text-xs",md:"h-10 px-3 text-sm",lg:"h-12 px-4 text-base"};function Yr(e,n){let t=n.trim().toLowerCase();return [...e.items.entries()].filter(([,o])=>!o.disabled).filter(([,o])=>!t||String(o.label).toLowerCase().includes(t)).map(([o])=>o)}i(Yr,"orderedFilteredValues");var Be=forwardRef(({variant:e="outline",size:n="md",placeholder:t,clearable:o=false,allowFreeText:a=false,className:r},l)=>{let s=re("ComboboxInput"),d=s.isInvalid?"error":s.isSuccess?"success":"none",c=o&&s.inputValue.length>0&&!s.disabled;useEffect(()=>{if(console.log(s),s.value===void 0)return;let m=s.items.get(s.value);m&&!s.open&&s.setInputValue(String(m.label));},[s.value,s.open,s.items]);function f(m){s.setInputValue(m.target.value),s.open||s.setOpen(true),s.setActiveValue(void 0),a&&s.onValueChange(m.target.value||void 0);}i(f,"handleChange");function g(m){let p=Yr(s,s.inputValue);switch(m.key){case "ArrowDown":{if(m.preventDefault(),!s.open){s.setOpen(true);return}let b=s.activeValue?p.indexOf(s.activeValue):-1;s.setActiveValue(p[(b+1)%p.length]);break}case "ArrowUp":{if(m.preventDefault(),!s.open){s.setOpen(true);return}let b=s.activeValue?p.indexOf(s.activeValue):-1;s.setActiveValue(p[(b-1+p.length)%p.length]);break}case "Enter":m.preventDefault(),s.activeValue!==void 0?s.onValueChange(s.activeValue):a&&s.setOpen(false);break;case "Escape":s.open&&(m.preventDefault(),s.setOpen(false));break;}}i(g,"handleKeyDown");function v(){!a&&s.value===void 0&&s.setInputValue(""),setTimeout(()=>s.setOpen(false),120);}return i(v,"handleBlur"),jsxs("div",{className:u(Pe({variant:e,state:d,fullWidth:true,disabled:s.disabled,rounded:s.rounded}),"px-2",r),children:[jsx("input",{ref:m=>{s.triggerRef.current=m,typeof l=="function"?l(m):l&&(l.current=m);},id:s.triggerId,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-expanded":s.open,"aria-controls":s.contentId,"aria-activedescendant":s.open&&s.activeValue?s.optionId(s.activeValue):void 0,"aria-invalid":s.isInvalid||void 0,"aria-describedby":s.describedBy,disabled:s.disabled,value:s.inputValue,placeholder:t,onChange:f,onFocus:()=>s.setOpen(true),onKeyDown:g,onBlur:v,"data-state":s.open?"open":"closed",className:u(vn,"flex-1 border-0 bg-transparent outline-none",yn[n],"px-0")}),c&&jsx("button",{type:"button",tabIndex:-1,"aria-label":"Clear",onMouseDown:m=>m.preventDefault(),onClick:()=>{s.setInputValue(""),s.onValueChange(void 0);},className:"flex items-center justify-center text-text-muted transition-colors hover:text-text",children:jsx(X,{size:14})})]})});Be.displayName="ComboboxInput";function pt({value:e,disabled:n=false,children:t,className:o}){let a=re("ComboboxItem"),r=useRef(null),l=a.activeValue===e,s=a.value===e;useEffect(()=>a.registerItem(e,{label:t,disabled:n,visible:true}),[e,n,t]),useEffect(()=>{l&&r.current?.scrollIntoView({block:"nearest"});},[l]);let d=a.inputValue.trim().toLowerCase(),c=!d||String(t).toLowerCase().includes(d);return useEffect(()=>{a.setItemVisibility(e,c);},[c,e]),c?jsx("div",{ref:r,id:a.optionId(e),role:"option","aria-selected":s,"aria-disabled":n||void 0,onMouseEnter:()=>!n&&a.setActiveValue(e),onMouseDown:f=>f.preventDefault(),onClick:()=>!n&&a.onValueChange(e),className:u("flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",l&&"bg-brand/15 text-brand",s&&!l&&"bg-surface-raised",n&&"pointer-events-none cursor-not-allowed opacity-50",o),children:t}):null}i(pt,"ComboboxItem");var Sn=8;function He(e,n){let t=useRef(null),[o,a]=useState("bottom");return useLayoutEffect(()=>{if(!n)return;let r=e.current,l=t.current;if(!r||!l)return;function s(){let d=r.getBoundingClientRect(),c=l.offsetHeight,f=window.innerHeight-d.bottom-Sn,g=d.top-Sn;a(c>f&&g>f?"top":"bottom");}return i(s,"measure"),s(),window.addEventListener("resize",s),window.addEventListener("scroll",s,true),()=>{window.removeEventListener("resize",s),window.removeEventListener("scroll",s,true);}},[n,e]),{contentRef:t,side:o}}i(He,"useFloatingSide");function ft({className:e,children:n}){let t=re("ComboboxContent"),{contentRef:o,side:a}=He(t.triggerRef,t.open);return t.open?jsx("div",{ref:o,id:t.contentId,role:"listbox","aria-labelledby":t.triggerId,"data-side":a,className:u("animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",a==="bottom"?"top-full mt-1":"bottom-full mb-1",e),children:n}):null}i(ft,"ComboboxContent");function Cn({children:e}){return [...re("ComboboxEmpty").items.values()].filter(o=>o.visible&&!o.disabled).length>0?null:jsx("div",{className:"px-2 py-3 text-center text-sm text-text-muted",children:e??"No results found"})}i(Cn,"ComboboxEmpty");function wn({children:e="Loading...",className:n}){return jsx("div",{role:"status","aria-live":"polite",className:u("px-2 py-3 text-center text-sm text-text-muted",n),children:e})}i(wn,"ComboboxLoading");function be({value:e,onValueChange:n,inputValue:t,defaultInputValue:o="",onInputChange:a,disabled:r=false,name:l,error:s,success:d,rounded:c,className:f,children:g}){let v=useId(),m=Y(),p=m?.id??v,b=`${p}-listbox`,k=s||m?.invalid||false,y=!!(d&&!k),[w,I]=useState(o),D=t!==void 0?t:w;function R(x){t===void 0&&I(x),a?.(x);}i(R,"setInputValue");let[h,T]=useState(false),[H,z]=useState(void 0),L=useRef(new Map),[A,V]=useState(new Map),N=useCallback((x,E)=>{let C={...E,visible:true};return L.current.set(x,C),V(B=>{let j=new Map(B);return j.set(x,C),j}),()=>F(x)},[]);function S(x,E){V(B=>{let j=B.get(x);if(!j||j.visible===E)return B;let Z=new Map(B);return Z.set(x,{...j,visible:E}),Z});let C=L.current.get(x);C&&L.current.set(x,{...C,visible:E});}i(S,"setItemVisibility");function F(x){V(E=>{if(!E.has(x))return E;let C=new Map(E);return C.delete(x),C}),L.current.delete(x);}i(F,"unregisterItem");let M=useRef(null),K=useRef(null);useEffect(()=>{if(!h)return;function x(E){K.current&&!K.current.contains(E.target)&&T(false);}return i(x,"handlePointerDown"),document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[h]);let G=useCallback(x=>`${b}-option-${x}`,[b]);useEffect(()=>{if(!e){R("");return}let x=L.current.get(e);x&&!h&&R(String(x.label));},[e,h]);let $=useMemo(()=>({value:e,inputValue:D,setInputValue:R,onValueChange:i(x=>{n?.(x);let E=x?L.current.get(x):void 0;E&&R(String(E.label)),T(false);},"onValueChange"),disabled:r,open:h,setOpen:T,triggerId:p,contentId:b,triggerRef:M,isInvalid:k,isSuccess:y,describedBy:m?.describedBy,activeValue:H,setActiveValue:z,items:A,registerItem:N,rounded:c,optionId:G,setItemVisibility:S,unregisterItem:F}),[e,D,n,r,h,p,b,m?.invalid,m?.describedBy,H,N,G,d,c,A,S,F]);return jsx(ct.Provider,{value:$,children:jsxs("div",{ref:K,className:f??"relative w-full",children:[g,l&&jsx("input",{type:"hidden",name:l,value:e??"",disabled:r})]})})}i(be,"Combobox");be.Input=Be;be.Item=pt;be.Content=ft;be.Empty=Cn;be.Loading=wn;var bt=createContext(null);function ge(e){let n=useContext(bt);if(!n)throw new Error(`<${e} /> must be rendered inside <MultiSelect>.`);return n}i(ge,"useMultiSelectContext");var Mn=cva("",{variants:{size:{sm:"min-h-[2.25rem] py-1 px-2 text-xs gap-1",md:"min-h-[2.75rem] py-1.5 px-3 text-sm gap-1.5",lg:"min-h-[3.25rem] py-2 px-4 text-base gap-2"}},defaultVariants:{size:"md"}}),Vn=cva("inline-flex items-center rounded-full",{variants:{size:{sm:"text-[10px] px-1.5 py-0.5 gap-0.5",md:"text-xs px-2 py-0.5 gap-1",lg:"text-sm px-2.5 py-1 gap-1.5"}},defaultVariants:{size:"md"}});function ci(e){return [...e.entries()].filter(([,n])=>!n.disabled).map(([n])=>n)}i(ci,"orderedEnabledValues");var $e=forwardRef(({className:e},n)=>{let t=ge("MultiSelectTrigger"),o=t.isInvalid?"error":t.isSuccess?"success":"none",a=t.clearable&&t.value.length>0&&!t.disabled,r=t.maxVisibleChips?t.value.slice(0,t.maxVisibleChips):t.value,l=t.value.length-r.length;function s(c){let f=ci(t.items);if(!f.length)return;let g=t.activeValue?f.indexOf(t.activeValue):-1;t.setActiveValue(f[(g+c+f.length)%f.length]);}i(s,"move");function d(c){switch(c.key){case "ArrowDown":c.preventDefault(),t.open?s(1):t.setOpen(true);break;case "ArrowUp":c.preventDefault(),t.open?s(-1):t.setOpen(true);break;case "Enter":case " ":c.preventDefault(),t.open?t.activeValue&&t.toggleValue(t.activeValue):t.setOpen(true);break;case "Escape":t.open&&(c.preventDefault(),t.setOpen(false));break;}}return i(d,"handleKeyDown"),jsxs("div",{ref:t.triggerRef,className:u(Pe({variant:t.variant,state:o,fullWidth:true,disabled:t.disabled,rounded:t.rounded}),Mn({size:t.size}),"flex flex-wrap items-center gap-1",e),children:[jsxs("button",{ref:n,type:"button",id:t.triggerId,role:"combobox","aria-haspopup":"listbox","aria-expanded":t.open,"aria-controls":t.contentId,"aria-invalid":t.isInvalid||void 0,"aria-describedby":t.describedBy,"aria-required":t.required||void 0,disabled:t.disabled,onClick:()=>!t.disabled&&t.setOpen(!t.open),onKeyDown:d,className:"flex flex-1 flex-wrap items-center gap-1 bg-transparent text-left outline-none cursor-pointer disabled:cursor-not-allowed",children:[t.value.length===0&&jsx("span",{className:"text-text-muted",children:t.placeholder}),r.map(c=>{let f=t.items.get(c);return jsxs("span",{className:u(Vn({size:t.size}),"bg-brand/15 text-brand"),children:[f?.label??c,jsx("span",{role:"button",tabIndex:-1,"aria-label":`Remove ${f?.label??c}`,onClick:g=>{g.stopPropagation(),t.removeValue(c);},className:"hover:opacity-70",children:jsx(X,{size:t.size==="sm"?8:t.size==="md"?10:12})})]},c)}),l>0&&jsxs("span",{className:u("text-text-muted",t.size==="sm"?"text-[10px]":t.size==="md"?"text-xs":"text-sm"),children:["+",l," more"]})]}),a&&jsx("button",{type:"button",tabIndex:-1,"aria-label":"Clear selection",onClick:c=>{c.preventDefault(),c.stopPropagation(),t.onClear();},className:"flex h-4 w-4 shrink-0 items-center justify-center text-text-muted transition-colors hover:text-text",children:jsx(X,{size:14})})]})});$e.displayName="MultiSelectTrigger";function gt({className:e,children:n,...t}){let o=ge("MultiSelectContent"),{side:a,contentRef:r}=He(o.triggerRef,o.open);return o.open?jsx("div",{ref:r,id:o.contentId,role:"listbox","aria-labelledby":o.triggerId,"data-state":o.open?"open":"closed","data-side":a,className:u("animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",a==="bottom"?"top-full mt-1":"bottom-full mb-1",e),...t,children:n}):null}i(gt,"MultiSelectContent");function pi(){return jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polyline",{points:"20 6 9 17 4 12"})})}i(pi,"CheckIcon");function xt({value:e,disabled:n=false,children:t,className:o}){let a=ge("MultiSelectItem"),r=useRef(null),l=a.value.includes(e),s=a.activeValue===e;return useEffect(()=>a.registerItem(e,{label:t,disabled:n}),[e,n,t]),useEffect(()=>{s&&r.current?.scrollIntoView({block:"nearest"});},[s]),jsxs("div",{ref:r,id:a.optionId(e),role:"option","aria-selected":l,"aria-disabled":n||void 0,onMouseEnter:()=>!n&&a.setActiveValue(e),onClick:()=>!n&&a.toggleValue(e),className:u("flex cursor-pointer items-center justify-between rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",s&&"bg-brand/15 text-brand",n&&"pointer-events-none cursor-not-allowed opacity-50",o),children:[jsx("span",{children:t}),l&&jsx(pi,{})]})}i(xt,"MultiSelectItem");function Ke({value:e,defaultValue:n=[],onValueChange:t,disabled:o=false,required:a,name:r,variant:l="outline",size:s="md",placeholder:d,maxVisibleChips:c,className:f,children:g,error:v,success:m,rounded:p,clearable:b}){let k=useId(),y=Y(),w=y?.id??k,I=`${w}-listbox`,[D,R]=useState(n),h=e!==void 0?e:D,[T,H]=useState(false),[z,L]=useState(void 0),A=useRef(new Map),[,V]=useReducer(C=>C+1,0),N=useCallback((C,B)=>(A.current.set(C,B),V(),()=>{A.current.delete(C),V();}),[]),S=useCallback(C=>{e===void 0&&R(C),t?.(C);},[e,t]),F=useCallback(C=>S(h.includes(C)?h.filter(B=>B!==C):[...h,C]),[h,S]),M=useCallback(C=>S(h.filter(B=>B!==C)),[h,S]),K=useCallback(()=>{S([]);},[S]),G=useRef(null),$=useRef(null);useEffect(()=>{if(!T)return;function C(B){$.current&&!$.current.contains(B.target)&&H(false);}return i(C,"handlePointerDown"),document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[T]);let x=useCallback(C=>`${I}-option-${C}`,[I]),E=useMemo(()=>({value:h,toggleValue:F,removeValue:M,disabled:o,variant:l,size:s,open:T,setOpen:H,triggerId:w,contentId:I,triggerRef:G,isInvalid:y?.invalid??v??false,describedBy:y?.describedBy,required:y?.required??a,placeholder:d,maxVisibleChips:c,activeValue:z,setActiveValue:L,items:A.current,registerItem:N,optionId:x,isSuccess:m,rounded:p,clearable:b,onClear:K}),[h,F,M,o,l,s,T,w,I,y?.invalid,y?.describedBy,y?.required,a,d,c,z,N,x,v,m,p,b,K]);return jsx(bt.Provider,{value:E,children:jsxs("div",{ref:$,className:f??"relative w-full",children:[g,r&&h.map(C=>jsx("input",{type:"hidden",name:`${r}[]`,value:C,disabled:o},C))]})})}i(Ke,"MultiSelect");Ke.Trigger=$e;Ke.Content=gt;Ke.Item=xt;var Nn={colors:{blue:{300:{value:"#5EA6ED"},400:{value:"#4799EB"},500:{value:"#1A80E6"},600:{value:"#1773CF"}},red:{300:{value:"#EB4747"},400:{value:"#E83030"},500:{value:"#E61A1A"},600:{value:"#CF1717"}},green:{300:{value:"#26D997"},400:{value:"#22C388"},500:{value:"#16A249"},600:{value:"#12875C"}},amber:{300:{value:"#F7B23B"},400:{value:"#F6A823"},500:{value:"#F59F0A"},600:{value:"#D38909"}},cyan:{300:{value:"#6CC3EF"},400:{value:"#47B4EB"},500:{value:"#1791CF"},600:{value:"#137BAE"}},gray:{50:{value:"#FAFAFA"},100:{value:"#EBEBEB"},200:{value:"#D9D9D9"},300:{value:"#BDBDBD"},400:{value:"#999999"},500:{value:"#666666"},600:{value:"#4D4D4D"},700:{value:"#333333"},800:{value:"#2E2E2E"},900:{value:"#1F1F1F"},950:{value:"#141414"},1e3:{value:"#0A0A0A"}},white:{value:"#FFFFFF"},black:{value:"#000000"}},spacing:{1:{value:"0.25rem"},2:{value:"0.5rem"},3:{value:"0.75rem"},4:{value:"1rem"},5:{value:"1.25rem"},6:{value:"1.5rem"},8:{value:"2rem"},10:{value:"2.5rem"},12:{value:"3rem"},16:{value:"4rem"}},radii:{none:{value:"0"},sm:{value:"0.25rem"},md:{value:"0.5rem"},lg:{value:"0.75rem"},xl:{value:"1rem"},full:{value:"9999px"}},fonts:{body:{value:"Inter, sans-serif"},heading:{value:"Inter, sans-serif"},mono:{value:"ui-monospace, SFMono-Regular, Menlo, monospace"}},fontSizes:{xs:{value:"0.75rem"},sm:{value:"0.875rem"},md:{value:"1rem"},lg:{value:"1.125rem"},xl:{value:"1.25rem"},"2xl":{value:"1.5rem"},"3xl":{value:"1.875rem"},"4xl":{value:"2.25rem"}},fontWeights:{normal:{value:"400"},medium:{value:"500"},semibold:{value:"600"},bold:{value:"700"}},lineHeights:{tight:{value:"1.25"},normal:{value:"1.5"},relaxed:{value:"1.75"}},letterSpacings:{tighter:{value:"-0.025em"},tight:{value:"-0.01em"},normal:{value:"0"},wide:{value:"0.025em"}},animations:{"slide-in-right":{value:"slide-in-right 0.5s ease-in-out"}}};var Fn={colors:{brand:{value:{light:"{colors.blue.500}",dark:"{colors.blue.400}"}},brandHover:{value:{light:"{colors.blue.600}",dark:"{colors.blue.300}"}},brandFg:{value:"{colors.white}"},surface:{value:{light:"{colors.gray.50}",dark:"{colors.gray.900}"}},surfaceRaised:{value:{light:"{colors.white}",dark:"{colors.gray.800}"}},surfaceSunken:{value:{light:"{colors.gray.100}",dark:"{colors.gray.950}"}},border:{value:{light:"{colors.gray.200}",dark:"{colors.gray.600}"}},text:{value:{light:"{colors.gray.900}",dark:"{colors.gray.50}"}},textMuted:{value:{light:"{colors.gray.500}",dark:"{colors.gray.400}"}},destructive:{value:{light:"{colors.red.500}",dark:"{colors.red.400}"}},destructiveFg:{value:"{colors.white}"},destructiveHover:{value:{light:"{colors.red.600}",dark:"{colors.red.300}"}},success:{value:{light:"{colors.green.500}",dark:"{colors.green.400}"}},successFg:{value:"{colors.white}"},successHover:{value:{light:"{colors.green.600}",dark:"{colors.green.300}"}},warning:{value:{light:"{colors.amber.500}",dark:"{colors.amber.400}"}},warningFg:{value:"{colors.black}"},warningHover:{value:{light:"{colors.amber.600}",dark:"{colors.amber.300}"}},info:{value:{light:"{colors.cyan.500}",dark:"{colors.cyan.400}"}},infoFg:{value:"{colors.white}"},infoHover:{value:{light:"{colors.cyan.600}",dark:"{colors.cyan.300}"}}}};var vi={xs:{height:"1.75rem",paddingX:"0.5rem",fontSize:"0.75rem",gap:"0.25rem",iconSize:"0.875rem",radius:"0.65rem"},sm:{height:"2rem",paddingX:"0.75rem",fontSize:"0.8125rem",gap:"0.375rem",iconSize:"1rem",radius:"0.8rem"},md:{height:"2.5rem",paddingX:"1rem",fontSize:"0.875rem",gap:"0.5rem",iconSize:"1.125rem",radius:"1rem"},lg:{height:"3rem",paddingX:"1.5rem",fontSize:"1rem",gap:"0.625rem",iconSize:"1.25rem",radius:"1.15rem"}},yi={body:{fontFamily:"{fonts.body}",fontSize:"{fontSizes.md}",fontWeight:"{fontWeights.normal}",lineHeight:"{lineHeights.normal}"},bodySmall:{fontFamily:"{fonts.body}",fontSize:"{fontSizes.sm}",fontWeight:"{fontWeights.normal}",lineHeight:"{lineHeights.normal}"},heading:{fontFamily:"{fonts.heading}",fontSize:"{fontSizes.2xl}",fontWeight:"{fontWeights.bold}",lineHeight:"{lineHeights.tight}"},headingSmall:{fontFamily:"{fonts.heading}",fontSize:"{fontSizes.xl}",fontWeight:"{fontWeights.semibold}",lineHeight:"{lineHeights.tight}"},caption:{fontFamily:"{fonts.body}",fontSize:"{fontSizes.xs}",fontWeight:"{fontWeights.normal}",lineHeight:"{lineHeights.normal}"}},Si={Button:kt,FormControl:Tt,Input:It},Dn={tokens:Nn,semanticTokens:Fn,textStyles:yi,recipes:Si,intensity:50,sizes:vi};function Ln(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}i(Ln,"toKebabCase");function Ci(e){let n=e.trim(),t=n.match(/^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i);if(t)return `${t[1]} ${t[2]} ${t[3]}`;if(n.startsWith("#")){let o=n.slice(1);if(o.length===3){let a=parseInt(o[0]+o[0],16),r=parseInt(o[1]+o[1],16),l=parseInt(o[2]+o[2],16);return `${a} ${r} ${l}`}if(o.length===6){let a=parseInt(o.slice(0,2),16),r=parseInt(o.slice(2,4),16),l=parseInt(o.slice(4,6),16);return `${a} ${r} ${l}`}}return /^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(n)?n:e}i(Ci,"colorToRgbChannels");function wi(e,n){let t=e.replace(/^\{/,"").replace(/\}$/,"").split("."),o=n;for(let a of t){if(typeof o!="object"||o===null||!(a in o))return;o=o[a];}if(typeof o=="object"&&o!==null&&"value"in o){let a=o.value;if(typeof a=="string"||typeof a=="number")return a}}i(wi,"getTokenValue");function Pn(e,n,t=new Set){if(t.has(e)){console.error(`[kreativ-ui] Circular token reference detected: ${e}`);return}let o=new Set(t);o.add(e);let a=wi(e,n);if(a===void 0){console.warn(`[kreativ-ui] Unable to resolve token reference: ${e}`);return}return typeof a=="number"?String(a):a.startsWith("{")&&a.endsWith("}")?Pn(a,n,o):a}i(Pn,"resolveReference");function yt(e,n){if(typeof e=="number")return String(e);if(typeof e=="string")return e.startsWith("{")&&e.endsWith("}")?Pn(e,n):e}i(yt,"resolveValue");function Bn(e,n,t,o){if(!(typeof e!="object"||e===null)){if("value"in e){let a=e.value,r=yt(a,o);r!==void 0&&(t[n.join(".")]=r);return}for(let[a,r]of Object.entries(e))Bn(r,[...n,a],t,o);}}i(Bn,"flattenTokens");function ki(e,n,t){if(typeof e=="object"&&e!==null&&"light"in e&&"dark"in e){let o=e[n];return yt(o,t)}return yt(e,t)}i(ki,"resolveSemanticValue");function Ii(e,n,t){let o={};function a(r,l){if(!(typeof r!="object"||r===null)){if("value"in r){let s=r.value,d=ki(s,t,n);d!==void 0&&(o[l.join(".")]=d);return}for(let[s,d]of Object.entries(r))a(d,[...l,s]);}}return i(a,"walk"),a(e,[]),o}i(Ii,"resolveSemanticTokens");function Hn(e,n,t){let o={};Bn(e,[],o,e);let a=Ii(n,e,t);return {...o,...a}}i(Hn,"resolveTokens");function St(e,n,t){let o={};for(let[a,r]of Object.entries(e)){let l=a.split("."),s=l.length===2&&l[0]==="colors",d=l.length>=3&&l[0]==="colors",c=s?`--kui-${Ln(l[1])}`:`--kui-${l.map(Ln).join("-")}`,f=s||d?Ci(r):r;o[c]=f;}return {...o,"--kui-mode":n,"--kui-intensity":String(t)}}i(St,"tokensToCssVars");var Ti=/^-?\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr)$|^(auto|min-content|max-content|fit-content)$/,Ri=new Set(["auto","min-content","max-content","fit-content"]),Mi=["height","width","paddingX","paddingY","fontSize","gap","iconSize","radius"];function An(e){return Ri.has(e)}i(An,"isCssKeyword");function On(e){if(An(e))return;let n=parseFloat(e);if(!Number.isNaN(n)){if(e.endsWith("px"))return n;if(e.endsWith("rem")||e.endsWith("em"))return n*16}}i(On,"toPx");function Vi(e,n){if(Mi.forEach(t=>{let o=n[t];if(o===void 0)return;if(!Ti.test(o)){console.error(`[kreativ-ui] Invalid size "${e}.${t}": "${o}" is not a valid CSS size.`);return}if(An(o))return;parseFloat(o)<0&&console.error(`[kreativ-ui] Invalid size "${e}.${t}": "${o}" is negative.`);}),n.height&&n.fontSize){let t=On(n.height),o=On(n.fontSize);t!==void 0&&o!==void 0&&o>=t&&console.warn(`[kreativ-ui] Size "${e}" has conflicting dimensions: height=${n.height} (${t}px), fontSize=${n.fontSize} (${o}px).
|
|
5
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, forwardRef, useState, useId, useRef, useEffect, useCallback, useLayoutEffect, useMemo, useContext, useReducer } from 'react';
|
|
3
|
+
import { useReducedMotion, motion, AnimatePresence } from 'framer-motion';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
import { twMerge } from 'tailwind-merge';
|
|
6
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
import { ChevronDown, X, Heading, Bold, Italic, ListOrdered, ClipboardList, Code, Link, Check, Lock, Hash, Search, Link2, Phone, Mail, EyeOff, Eye, Sun, Moon, Monitor } from 'lucide-react';
|
|
8
|
+
import { cva } from 'class-variance-authority';
|
|
9
|
+
|
|
10
|
+
console.log("BANNER TEST");
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
function cn(...inputs) {
|
|
14
|
+
return twMerge(clsx(inputs));
|
|
15
|
+
}
|
|
16
|
+
__name(cn, "cn");
|
|
17
|
+
var ThemeContext = createContext(null);
|
|
18
|
+
|
|
19
|
+
// src/hooks/useTheme.ts
|
|
20
|
+
function useTheme() {
|
|
21
|
+
const ctx = useContext(ThemeContext);
|
|
22
|
+
if (!ctx) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"useTheme() was called outside <UIProvider>. Wrap your app in <UIProvider> from 'kreativ-ui'."
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return ctx;
|
|
28
|
+
}
|
|
29
|
+
__name(useTheme, "useTheme");
|
|
30
|
+
function useSizeStyle(size, iconOnly = false, component = "button", options = {}) {
|
|
31
|
+
const { includeHeight = true } = options;
|
|
32
|
+
const { theme, fallbackSize } = useTheme();
|
|
33
|
+
return useMemo(() => {
|
|
34
|
+
const scale = theme.sizes;
|
|
35
|
+
const token = scale[size] ?? scale[fallbackSize] ?? Object.values(scale)[0] ?? {};
|
|
36
|
+
const style = {};
|
|
37
|
+
if (includeHeight && token.height) {
|
|
38
|
+
style.height = token.height;
|
|
39
|
+
}
|
|
40
|
+
if (token.width) {
|
|
41
|
+
style.width = token.width;
|
|
42
|
+
} else if (iconOnly && includeHeight && token.height) {
|
|
43
|
+
style.width = token.height;
|
|
44
|
+
}
|
|
45
|
+
if (!iconOnly && token.paddingX) {
|
|
46
|
+
style.paddingLeft = token.paddingX;
|
|
47
|
+
style.paddingRight = token.paddingX;
|
|
48
|
+
}
|
|
49
|
+
if (token.paddingY) {
|
|
50
|
+
style.paddingTop = token.paddingY;
|
|
51
|
+
style.paddingBottom = token.paddingY;
|
|
52
|
+
}
|
|
53
|
+
if (token.fontSize) {
|
|
54
|
+
style.fontSize = token.fontSize;
|
|
55
|
+
}
|
|
56
|
+
if (token.gap) {
|
|
57
|
+
style.gap = iconOnly ? 0 : token.gap;
|
|
58
|
+
}
|
|
59
|
+
if (token.radius) {
|
|
60
|
+
const varName = `--kui-${component}-radius`;
|
|
61
|
+
style[varName] = token.radius;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
style,
|
|
65
|
+
iconSize: token.iconSize
|
|
66
|
+
};
|
|
67
|
+
}, [theme.sizes, size, fallbackSize, iconOnly, includeHeight, component]);
|
|
68
|
+
}
|
|
69
|
+
__name(useSizeStyle, "useSizeStyle");
|
|
70
|
+
|
|
71
|
+
// src/theme/recipes/defineRecipe.ts
|
|
72
|
+
function defineRecipe(recipe) {
|
|
73
|
+
return recipe;
|
|
74
|
+
}
|
|
75
|
+
__name(defineRecipe, "defineRecipe");
|
|
76
|
+
|
|
77
|
+
// src/theme/recipes/mergeRecipes.ts
|
|
78
|
+
function mergeRecipeDefinition(base, override) {
|
|
79
|
+
return {
|
|
80
|
+
...base,
|
|
81
|
+
base: override.base ?? base.base,
|
|
82
|
+
variants: {
|
|
83
|
+
...base.variants,
|
|
84
|
+
...override.variants
|
|
85
|
+
},
|
|
86
|
+
defaultVariants: {
|
|
87
|
+
...base.defaultVariants,
|
|
88
|
+
...override.defaultVariants
|
|
89
|
+
},
|
|
90
|
+
compoundVariants: override.compoundVariants ?? base.compoundVariants
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
__name(mergeRecipeDefinition, "mergeRecipeDefinition");
|
|
94
|
+
function mergeRecipes(base, override) {
|
|
95
|
+
if (!override) {
|
|
96
|
+
return base;
|
|
97
|
+
}
|
|
98
|
+
const result = {
|
|
99
|
+
...base
|
|
100
|
+
};
|
|
101
|
+
for (const [name, recipeOverride] of Object.entries(override)) {
|
|
102
|
+
const baseRecipe = base[name];
|
|
103
|
+
if (!baseRecipe) {
|
|
104
|
+
result[name] = recipeOverride;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
result[name] = mergeRecipeDefinition(
|
|
108
|
+
baseRecipe,
|
|
109
|
+
recipeOverride
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
__name(mergeRecipes, "mergeRecipes");
|
|
115
|
+
|
|
116
|
+
// src/theme/recipes/resolveRecipe.ts
|
|
117
|
+
function matchesConditions(conditions, props) {
|
|
118
|
+
return Object.entries(conditions).every(
|
|
119
|
+
([key, expected]) => props[key] === expected
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
__name(matchesConditions, "matchesConditions");
|
|
123
|
+
function resolveRecipe(recipe, props = {}) {
|
|
124
|
+
if (!recipe) return "";
|
|
125
|
+
const resolvedProps = {
|
|
126
|
+
...recipe.defaultVariants,
|
|
127
|
+
...props
|
|
128
|
+
};
|
|
129
|
+
const classes = [];
|
|
130
|
+
if (recipe.base) {
|
|
131
|
+
classes.push(recipe.base);
|
|
132
|
+
}
|
|
133
|
+
if (recipe.variants) {
|
|
134
|
+
for (const [variantName, variantValues] of Object.entries(
|
|
135
|
+
recipe.variants
|
|
136
|
+
)) {
|
|
137
|
+
const value = resolvedProps[variantName];
|
|
138
|
+
if (value === void 0) continue;
|
|
139
|
+
const variantClass = variantValues[String(value)];
|
|
140
|
+
if (variantClass) {
|
|
141
|
+
classes.push(variantClass);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (recipe.compoundVariants) {
|
|
146
|
+
for (const compound of recipe.compoundVariants) {
|
|
147
|
+
if (matchesConditions(compound.conditions, resolvedProps)) {
|
|
148
|
+
classes.push(compound.className);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return cn(...classes);
|
|
153
|
+
}
|
|
154
|
+
__name(resolveRecipe, "resolveRecipe");
|
|
155
|
+
|
|
156
|
+
// src/theme/defaults/recipes/button.ts
|
|
157
|
+
var buttonBase = "inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none";
|
|
158
|
+
var buttonVariants = {
|
|
159
|
+
solid: "",
|
|
160
|
+
outline: "border bg-transparent",
|
|
161
|
+
ghost: "bg-transparent",
|
|
162
|
+
soft: "",
|
|
163
|
+
link: "bg-transparent p-0 h-auto hover:underline"
|
|
164
|
+
};
|
|
165
|
+
var buttonColors = {
|
|
166
|
+
brand: {
|
|
167
|
+
solid: "bg-brand text-brand-fg hover:bg-brand-hover",
|
|
168
|
+
outline: "border-brand text-brand hover:bg-brand/10",
|
|
169
|
+
ghost: "text-brand hover:bg-brand/10",
|
|
170
|
+
soft: "bg-brand/10 text-brand hover:bg-brand/20",
|
|
171
|
+
link: "text-brand"
|
|
172
|
+
},
|
|
173
|
+
destructive: {
|
|
174
|
+
solid: "bg-destructive text-destructive-fg hover:bg-destructive-hover",
|
|
175
|
+
outline: "border-destructive text-destructive hover:bg-destructive/10",
|
|
176
|
+
ghost: "text-destructive hover:bg-destructive/10",
|
|
177
|
+
soft: "bg-destructive/10 text-destructive hover:bg-destructive/20",
|
|
178
|
+
link: "text-destructive"
|
|
179
|
+
},
|
|
180
|
+
success: {
|
|
181
|
+
solid: "bg-success text-success-fg hover:bg-success-hover",
|
|
182
|
+
outline: "border-success text-success hover:bg-success/10",
|
|
183
|
+
ghost: "text-success hover:bg-success/10",
|
|
184
|
+
soft: "bg-success/10 text-success hover:bg-success/20",
|
|
185
|
+
link: "text-success"
|
|
186
|
+
},
|
|
187
|
+
warning: {
|
|
188
|
+
solid: "bg-warning text-warning-fg hover:bg-warning-hover",
|
|
189
|
+
outline: "border-warning text-warning hover:bg-warning/10",
|
|
190
|
+
ghost: "text-warning hover:bg-warning/10",
|
|
191
|
+
soft: "bg-warning/10 text-warning hover:bg-warning/20",
|
|
192
|
+
link: "text-warning"
|
|
193
|
+
},
|
|
194
|
+
info: {
|
|
195
|
+
solid: "bg-info text-info-fg hover:bg-info-hover",
|
|
196
|
+
outline: "border-info text-info hover:bg-info/10",
|
|
197
|
+
ghost: "text-info hover:bg-info/10",
|
|
198
|
+
soft: "bg-info/10 text-info hover:bg-info/20",
|
|
199
|
+
link: "text-info"
|
|
200
|
+
},
|
|
201
|
+
white: {
|
|
202
|
+
solid: "bg-white text-black hover:bg-gray-50",
|
|
203
|
+
outline: "border-white/30 text-white hover:bg-white/10",
|
|
204
|
+
ghost: "text-white hover:bg-white/10",
|
|
205
|
+
soft: "bg-white/10 text-white hover:bg-white/20",
|
|
206
|
+
link: "text-white"
|
|
207
|
+
},
|
|
208
|
+
neutral: {
|
|
209
|
+
solid: "bg-surface-raised text-text hover:bg-surface-sunken",
|
|
210
|
+
outline: "border-border text-text hover:bg-surface-raised",
|
|
211
|
+
ghost: "text-text hover:bg-surface-raised",
|
|
212
|
+
soft: "bg-surface-raised text-text hover:bg-surface-sunken",
|
|
213
|
+
link: "text-text"
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var buildCompoundVariants = /* @__PURE__ */ __name(() => {
|
|
217
|
+
const compounds = [];
|
|
218
|
+
for (const [color, variantMap] of Object.entries(buttonColors)) {
|
|
219
|
+
for (const [variant, className] of Object.entries(variantMap)) {
|
|
220
|
+
compounds.push({
|
|
221
|
+
conditions: { color, variant },
|
|
222
|
+
className
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return compounds;
|
|
227
|
+
}, "buildCompoundVariants");
|
|
228
|
+
var buttonRecipe = defineRecipe({
|
|
229
|
+
base: buttonBase,
|
|
230
|
+
variants: {
|
|
231
|
+
variant: buttonVariants,
|
|
232
|
+
color: Object.fromEntries(
|
|
233
|
+
Object.keys(buttonColors).map((color) => [color, ""])
|
|
234
|
+
)
|
|
235
|
+
},
|
|
236
|
+
defaultVariants: {
|
|
237
|
+
variant: "solid",
|
|
238
|
+
color: "brand"
|
|
239
|
+
},
|
|
240
|
+
compoundVariants: buildCompoundVariants()
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// src/theme/defaults/recipes/input.ts
|
|
244
|
+
var inputBase = "flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:pointer-events-none disabled:cursor-not-allowed";
|
|
245
|
+
var inputRecipe = defineRecipe({
|
|
246
|
+
base: inputBase,
|
|
247
|
+
variants: {
|
|
248
|
+
variant: {
|
|
249
|
+
outline: "",
|
|
250
|
+
filled: "",
|
|
251
|
+
ghost: ""
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
defaultVariants: {
|
|
255
|
+
variant: "outline"
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// src/theme/defaults/recipes/formControl.ts
|
|
260
|
+
var formControlBase = "group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-colors duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-2 ";
|
|
261
|
+
var formControlVariants = {
|
|
262
|
+
outline: "border border-border bg-transparent text-text hover:border-brand",
|
|
263
|
+
filled: "border border-transparent bg-surface-raised text-text hover:bg-surface",
|
|
264
|
+
ghost: "border border-transparent bg-transparent text-text hover:bg-surface-raised"
|
|
265
|
+
};
|
|
266
|
+
var formControlStates = {
|
|
267
|
+
none: "focus-within:ring-brand/20",
|
|
268
|
+
error: "border-destructive focus-within:ring-destructive/20",
|
|
269
|
+
success: "border-success focus-within:ring-success/20"
|
|
270
|
+
};
|
|
271
|
+
var formControlRecipe = defineRecipe({
|
|
272
|
+
base: formControlBase,
|
|
273
|
+
variants: {
|
|
274
|
+
variant: formControlVariants,
|
|
275
|
+
state: formControlStates,
|
|
276
|
+
rounded: {
|
|
277
|
+
true: "rounded-full",
|
|
278
|
+
false: ""
|
|
279
|
+
},
|
|
280
|
+
fullWidth: {
|
|
281
|
+
true: "w-full",
|
|
282
|
+
false: ""
|
|
283
|
+
},
|
|
284
|
+
disabled: {
|
|
285
|
+
true: "pointer-events-none cursor-not-allowed opacity-50",
|
|
286
|
+
false: ""
|
|
287
|
+
},
|
|
288
|
+
hasAdornment: {
|
|
289
|
+
true: "px-2",
|
|
290
|
+
false: ""
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
defaultVariants: {
|
|
294
|
+
variant: "outline",
|
|
295
|
+
state: "none",
|
|
296
|
+
rounded: false,
|
|
297
|
+
fullWidth: true,
|
|
298
|
+
disabled: false,
|
|
299
|
+
hasAdornment: false
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
var ACTIVATION_KEYS = /* @__PURE__ */ new Set(["Enter", " "]);
|
|
303
|
+
var Button = forwardRef(
|
|
304
|
+
({
|
|
305
|
+
variant = "solid",
|
|
306
|
+
color = "brand",
|
|
307
|
+
size = "md",
|
|
308
|
+
isLoading = false,
|
|
309
|
+
leftIcon,
|
|
310
|
+
rightIcon,
|
|
311
|
+
fullWidth = false,
|
|
312
|
+
disabled,
|
|
313
|
+
className,
|
|
314
|
+
style,
|
|
315
|
+
iconOnly,
|
|
316
|
+
children,
|
|
317
|
+
render,
|
|
318
|
+
onKeyDown,
|
|
319
|
+
onKeyUp,
|
|
320
|
+
...rest
|
|
321
|
+
}, ref) => {
|
|
322
|
+
const { theme } = useTheme();
|
|
323
|
+
const { style: sizeStyle, iconSize } = useSizeStyle(
|
|
324
|
+
size,
|
|
325
|
+
iconOnly,
|
|
326
|
+
"button"
|
|
327
|
+
);
|
|
328
|
+
const prefersReducedMotion = useReducedMotion();
|
|
329
|
+
const isInteractive = !disabled && !isLoading;
|
|
330
|
+
const [isKeyboardPressed, setIsKeyboardPressed] = useState(false);
|
|
331
|
+
function handleKeyDown(e) {
|
|
332
|
+
onKeyDown?.(e);
|
|
333
|
+
if (isInteractive && ACTIVATION_KEYS.has(e.key)) {
|
|
334
|
+
setIsKeyboardPressed(true);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
__name(handleKeyDown, "handleKeyDown");
|
|
338
|
+
function handleKeyUp(e) {
|
|
339
|
+
onKeyUp?.(e);
|
|
340
|
+
if (ACTIVATION_KEYS.has(e.key)) {
|
|
341
|
+
setIsKeyboardPressed(false);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
__name(handleKeyUp, "handleKeyUp");
|
|
345
|
+
const recipeClasses = resolveRecipe(theme.recipes.Button, {
|
|
346
|
+
variant,
|
|
347
|
+
color
|
|
348
|
+
});
|
|
349
|
+
const resolvedClassName = cn(
|
|
350
|
+
recipeClasses,
|
|
351
|
+
fullWidth && "w-full",
|
|
352
|
+
isLoading && "animate-kui-pulse",
|
|
353
|
+
className
|
|
354
|
+
);
|
|
355
|
+
const resolvedStyle = {
|
|
356
|
+
...sizeStyle,
|
|
357
|
+
...style
|
|
358
|
+
};
|
|
359
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
360
|
+
isLoading && /* @__PURE__ */ jsx(
|
|
361
|
+
"span",
|
|
362
|
+
{
|
|
363
|
+
className: "animate-kui-spin rounded-full border-2 border-current border-t-transparent",
|
|
364
|
+
style: {
|
|
365
|
+
width: iconSize,
|
|
366
|
+
height: iconSize
|
|
367
|
+
},
|
|
368
|
+
"aria-hidden": "true"
|
|
369
|
+
}
|
|
370
|
+
),
|
|
371
|
+
!isLoading && leftIcon,
|
|
372
|
+
iconOnly && isLoading ? null : children,
|
|
373
|
+
!isLoading && rightIcon
|
|
374
|
+
] });
|
|
375
|
+
if (render) {
|
|
376
|
+
return render({
|
|
377
|
+
className: resolvedClassName,
|
|
378
|
+
style: resolvedStyle,
|
|
379
|
+
disabled: disabled || isLoading,
|
|
380
|
+
"aria-busy": isLoading || void 0,
|
|
381
|
+
children: content
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
return /* @__PURE__ */ jsx(
|
|
385
|
+
motion.button,
|
|
386
|
+
{
|
|
387
|
+
ref,
|
|
388
|
+
disabled: disabled || isLoading,
|
|
389
|
+
className: resolvedClassName,
|
|
390
|
+
style: resolvedStyle,
|
|
391
|
+
"aria-busy": isLoading || void 0,
|
|
392
|
+
animate: {
|
|
393
|
+
scale: isKeyboardPressed ? 0.975 : 1
|
|
394
|
+
},
|
|
395
|
+
whileHover: isInteractive ? { scale: 1.015 } : void 0,
|
|
396
|
+
whileTap: isInteractive ? { scale: 0.975 } : void 0,
|
|
397
|
+
transition: prefersReducedMotion ? { duration: 0 } : {
|
|
398
|
+
type: "spring",
|
|
399
|
+
stiffness: 500,
|
|
400
|
+
damping: 30
|
|
401
|
+
},
|
|
402
|
+
onKeyDown: handleKeyDown,
|
|
403
|
+
onKeyUp: handleKeyUp,
|
|
404
|
+
...rest,
|
|
405
|
+
children: content
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
);
|
|
410
|
+
Button.displayName = "Button";
|
|
411
|
+
|
|
412
|
+
// src/utils/color.ts
|
|
413
|
+
var HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
414
|
+
function rgbToHex(value) {
|
|
415
|
+
const trimmed = value.trim();
|
|
416
|
+
if (HEX_RE.test(trimmed)) {
|
|
417
|
+
if (trimmed.length === 4) {
|
|
418
|
+
return ("#" + [...trimmed.slice(1)].map((char) => char + char).join("")).toUpperCase();
|
|
419
|
+
}
|
|
420
|
+
return trimmed.toUpperCase();
|
|
421
|
+
}
|
|
422
|
+
const values = trimmed.replace(/[^\d,]/g, "").split(",").map(Number);
|
|
423
|
+
if (values.length !== 3 || values.some(Number.isNaN)) {
|
|
424
|
+
return "#000000";
|
|
425
|
+
}
|
|
426
|
+
return "#" + values.map((x) => x.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
427
|
+
}
|
|
428
|
+
__name(rgbToHex, "rgbToHex");
|
|
429
|
+
function hexToRgbString(hex) {
|
|
430
|
+
if (!HEX_RE.test(hex)) return null;
|
|
431
|
+
const full = hex.length === 4 ? "#" + [...hex.slice(1)].map((c) => c + c).join("") : hex;
|
|
432
|
+
const r = parseInt(full.slice(1, 3), 16);
|
|
433
|
+
const g = parseInt(full.slice(3, 5), 16);
|
|
434
|
+
const b = parseInt(full.slice(5, 7), 16);
|
|
435
|
+
return `${r} ${g} ${b}`;
|
|
436
|
+
}
|
|
437
|
+
__name(hexToRgbString, "hexToRgbString");
|
|
438
|
+
var defaultTransition = {
|
|
439
|
+
type: "none",
|
|
440
|
+
duration: 300,
|
|
441
|
+
delay: 0,
|
|
442
|
+
easing: "ease-in-out"
|
|
443
|
+
};
|
|
444
|
+
var getIconVariants = /* @__PURE__ */ __name((type) => {
|
|
445
|
+
switch (type) {
|
|
446
|
+
case "fade":
|
|
447
|
+
return {
|
|
448
|
+
initial: { opacity: 0 },
|
|
449
|
+
animate: { opacity: 1 },
|
|
450
|
+
exit: { opacity: 0 }
|
|
451
|
+
};
|
|
452
|
+
case "slide":
|
|
453
|
+
return {
|
|
454
|
+
initial: { opacity: 0, x: -20 },
|
|
455
|
+
animate: { opacity: 1, x: 0 },
|
|
456
|
+
exit: { opacity: 0, x: 20 }
|
|
457
|
+
};
|
|
458
|
+
case "scale":
|
|
459
|
+
return {
|
|
460
|
+
initial: { opacity: 0, scale: 0.5 },
|
|
461
|
+
animate: { opacity: 1, scale: 1 },
|
|
462
|
+
exit: { opacity: 0, scale: 1.5 }
|
|
463
|
+
};
|
|
464
|
+
case "rotate":
|
|
465
|
+
return {
|
|
466
|
+
initial: { opacity: 0, rotate: -90 },
|
|
467
|
+
animate: { opacity: 1, rotate: 0 },
|
|
468
|
+
exit: { opacity: 0, rotate: 90 }
|
|
469
|
+
};
|
|
470
|
+
case "none":
|
|
471
|
+
default:
|
|
472
|
+
return {
|
|
473
|
+
initial: { opacity: 1 },
|
|
474
|
+
animate: { opacity: 1 },
|
|
475
|
+
exit: { opacity: 1 }
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
}, "getIconVariants");
|
|
479
|
+
function ThemeToggler({
|
|
480
|
+
variant = "ghost",
|
|
481
|
+
activeVariant = "solid",
|
|
482
|
+
color = "neutral",
|
|
483
|
+
activeColor = "brand",
|
|
484
|
+
size = "sm",
|
|
485
|
+
iconOnly = false,
|
|
486
|
+
allowSystem = false,
|
|
487
|
+
orientation = "horizontal",
|
|
488
|
+
rounded = false,
|
|
489
|
+
unstyled = false,
|
|
490
|
+
labels,
|
|
491
|
+
icons,
|
|
492
|
+
className,
|
|
493
|
+
buttonProps = {},
|
|
494
|
+
display = "buttons",
|
|
495
|
+
transition = defaultTransition
|
|
496
|
+
}) {
|
|
497
|
+
const { mode, setMode, resolvedMode } = useTheme();
|
|
498
|
+
const activeMode = allowSystem ? mode : resolvedMode;
|
|
499
|
+
const modes = [
|
|
500
|
+
{
|
|
501
|
+
key: "light",
|
|
502
|
+
label: labels?.light ?? "Light",
|
|
503
|
+
icon: icons?.light ?? /* @__PURE__ */ jsx(Sun, { size: 16 })
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
key: "dark",
|
|
507
|
+
label: labels?.dark ?? "Dark",
|
|
508
|
+
icon: icons?.dark ?? /* @__PURE__ */ jsx(Moon, { size: 16 })
|
|
509
|
+
},
|
|
510
|
+
...allowSystem ? [
|
|
511
|
+
{
|
|
512
|
+
key: "system",
|
|
513
|
+
label: labels?.system ?? "System",
|
|
514
|
+
icon: icons?.system ?? /* @__PURE__ */ jsx(Monitor, { size: 16 })
|
|
515
|
+
}
|
|
516
|
+
] : []
|
|
517
|
+
];
|
|
518
|
+
const allowedModes = modes.map((item) => item.key);
|
|
519
|
+
const currentMode = modes.find(({ key }) => key === activeMode) ?? modes[0];
|
|
520
|
+
const effectiveRounded = rounded && !(orientation === "vertical" && !iconOnly);
|
|
521
|
+
useEffect(() => {
|
|
522
|
+
if (rounded && !effectiveRounded) {
|
|
523
|
+
console.warn(
|
|
524
|
+
"[kreativ-ui/ThemeToggler] `rounded` is ignored when orientation='vertical' and iconOnly={false}."
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
}, [rounded, effectiveRounded]);
|
|
528
|
+
const handleCycle = /* @__PURE__ */ __name(() => {
|
|
529
|
+
const index = allowedModes.indexOf(
|
|
530
|
+
activeMode
|
|
531
|
+
);
|
|
532
|
+
setMode(allowedModes[(index + 1) % allowedModes.length]);
|
|
533
|
+
}, "handleCycle");
|
|
534
|
+
const isActive = /* @__PURE__ */ __name((key) => key === "system" ? mode === "system" : activeMode === key, "isActive");
|
|
535
|
+
const containerClasses = cn(
|
|
536
|
+
"inline-flex gap-1",
|
|
537
|
+
orientation === "vertical" && "flex-col",
|
|
538
|
+
!unstyled && [
|
|
539
|
+
"border border-border bg-surface p-1",
|
|
540
|
+
effectiveRounded ? "rounded-full" : "rounded-lg"
|
|
541
|
+
],
|
|
542
|
+
className
|
|
543
|
+
);
|
|
544
|
+
const buttonRadius = effectiveRounded ? "rounded-full" : "rounded-lg";
|
|
545
|
+
const animateIcon = display === "cycle" && transition.type !== "none";
|
|
546
|
+
const iconVariants = getIconVariants(transition.type || "none");
|
|
547
|
+
const motionTransition = {
|
|
548
|
+
duration: (transition.duration || 300) / 1e3,
|
|
549
|
+
delay: (transition.delay || 0) / 1e3,
|
|
550
|
+
ease: transition.easing || "ease-in-out"
|
|
551
|
+
};
|
|
552
|
+
if (display === "cycle") {
|
|
553
|
+
return /* @__PURE__ */ jsxs(
|
|
554
|
+
Button,
|
|
555
|
+
{
|
|
556
|
+
size,
|
|
557
|
+
variant,
|
|
558
|
+
color,
|
|
559
|
+
onClick: handleCycle,
|
|
560
|
+
"aria-label": `Current theme: ${currentMode.label}`,
|
|
561
|
+
className: cn(
|
|
562
|
+
effectiveRounded && "rounded-full",
|
|
563
|
+
buttonProps.className
|
|
564
|
+
),
|
|
565
|
+
...buttonProps,
|
|
566
|
+
children: [
|
|
567
|
+
/* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: /* @__PURE__ */ jsx(
|
|
568
|
+
motion.span,
|
|
569
|
+
{
|
|
570
|
+
initial: animateIcon ? iconVariants.initial : void 0,
|
|
571
|
+
animate: animateIcon ? iconVariants.animate : void 0,
|
|
572
|
+
exit: animateIcon ? iconVariants.exit : void 0,
|
|
573
|
+
transition: motionTransition,
|
|
574
|
+
children: currentMode.icon
|
|
575
|
+
},
|
|
576
|
+
currentMode.key
|
|
577
|
+
) }),
|
|
578
|
+
!iconOnly && currentMode.label
|
|
579
|
+
]
|
|
580
|
+
}
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
const buttons = modes.map(({ key, label, icon }) => {
|
|
584
|
+
const active = isActive(key);
|
|
585
|
+
return /* @__PURE__ */ jsx(
|
|
586
|
+
Button,
|
|
587
|
+
{
|
|
588
|
+
size,
|
|
589
|
+
variant: active ? activeVariant : variant,
|
|
590
|
+
color: active ? activeColor : color,
|
|
591
|
+
onClick: () => setMode(key),
|
|
592
|
+
className: cn(buttonRadius, buttonProps.className),
|
|
593
|
+
leftIcon: icon,
|
|
594
|
+
"aria-pressed": active,
|
|
595
|
+
...buttonProps,
|
|
596
|
+
children: !iconOnly && label
|
|
597
|
+
},
|
|
598
|
+
key
|
|
599
|
+
);
|
|
600
|
+
});
|
|
601
|
+
if (unstyled) {
|
|
602
|
+
return /* @__PURE__ */ jsx(
|
|
603
|
+
"div",
|
|
604
|
+
{
|
|
605
|
+
role: "group",
|
|
606
|
+
"aria-label": "Theme selector",
|
|
607
|
+
className: cn(
|
|
608
|
+
"inline-flex gap-1",
|
|
609
|
+
orientation === "vertical" && "flex-col",
|
|
610
|
+
className
|
|
611
|
+
),
|
|
612
|
+
children: buttons
|
|
613
|
+
}
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
return /* @__PURE__ */ jsx("div", { role: "group", "aria-label": "Theme selector", className: containerClasses, children: buttons });
|
|
617
|
+
}
|
|
618
|
+
__name(ThemeToggler, "ThemeToggler");
|
|
619
|
+
var BREAKPOINTS = {
|
|
620
|
+
sm: 640,
|
|
621
|
+
md: 768,
|
|
622
|
+
lg: 1024,
|
|
623
|
+
xl: 1280,
|
|
624
|
+
"2xl": 1536
|
|
625
|
+
};
|
|
626
|
+
function useBreakpoint(breakpoint) {
|
|
627
|
+
const query = `(min-width: ${BREAKPOINTS[breakpoint]}px)`;
|
|
628
|
+
const [matches, setMatches] = useState(
|
|
629
|
+
() => typeof window !== "undefined" && window.matchMedia(query).matches
|
|
630
|
+
);
|
|
631
|
+
useEffect(() => {
|
|
632
|
+
const mql = window.matchMedia(query);
|
|
633
|
+
const listener = /* @__PURE__ */ __name((e) => setMatches(e.matches), "listener");
|
|
634
|
+
mql.addEventListener("change", listener);
|
|
635
|
+
setMatches(mql.matches);
|
|
636
|
+
return () => mql.removeEventListener("change", listener);
|
|
637
|
+
}, [query]);
|
|
638
|
+
return matches;
|
|
639
|
+
}
|
|
640
|
+
__name(useBreakpoint, "useBreakpoint");
|
|
641
|
+
var inputKindIcons = {
|
|
642
|
+
email: Mail,
|
|
643
|
+
tel: Phone,
|
|
644
|
+
url: Link2,
|
|
645
|
+
search: Search,
|
|
646
|
+
numeric: Hash,
|
|
647
|
+
"password-current": Lock,
|
|
648
|
+
"password-new": Lock
|
|
649
|
+
};
|
|
650
|
+
function Spinner({ size = 14 }) {
|
|
651
|
+
return /* @__PURE__ */ jsx(
|
|
652
|
+
"span",
|
|
653
|
+
{
|
|
654
|
+
className: "animate-kui-spin rounded-full border-2 border-inherit border-t-transparent shrink-0",
|
|
655
|
+
style: { width: size, height: size },
|
|
656
|
+
"aria-hidden": "true"
|
|
657
|
+
}
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
__name(Spinner, "Spinner");
|
|
661
|
+
|
|
662
|
+
// src/components/Input/Input.constants.ts
|
|
663
|
+
var inputKindDefaults = {
|
|
664
|
+
text: { placeholder: "Type something..." },
|
|
665
|
+
email: {
|
|
666
|
+
type: "email",
|
|
667
|
+
inputMode: "email",
|
|
668
|
+
autoComplete: "email",
|
|
669
|
+
placeholder: "you@company.com"
|
|
670
|
+
},
|
|
671
|
+
tel: {
|
|
672
|
+
type: "tel",
|
|
673
|
+
inputMode: "tel",
|
|
674
|
+
autoComplete: "tel",
|
|
675
|
+
placeholder: "+234 800 000 0000"
|
|
676
|
+
},
|
|
677
|
+
url: {
|
|
678
|
+
type: "url",
|
|
679
|
+
inputMode: "url",
|
|
680
|
+
autoComplete: "url",
|
|
681
|
+
placeholder: "https://company.com"
|
|
682
|
+
},
|
|
683
|
+
search: {
|
|
684
|
+
type: "search",
|
|
685
|
+
inputMode: "search",
|
|
686
|
+
autoComplete: "off",
|
|
687
|
+
placeholder: "Search..."
|
|
688
|
+
},
|
|
689
|
+
numeric: {
|
|
690
|
+
type: "text",
|
|
691
|
+
inputMode: "numeric",
|
|
692
|
+
autoComplete: "off",
|
|
693
|
+
placeholder: "Enter a number"
|
|
694
|
+
},
|
|
695
|
+
"password-current": {
|
|
696
|
+
type: "password",
|
|
697
|
+
autoComplete: "current-password",
|
|
698
|
+
placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"
|
|
699
|
+
},
|
|
700
|
+
"password-new": {
|
|
701
|
+
type: "password",
|
|
702
|
+
autoComplete: "new-password",
|
|
703
|
+
placeholder: "Create a password"
|
|
704
|
+
},
|
|
705
|
+
number: {
|
|
706
|
+
type: "number",
|
|
707
|
+
inputMode: "decimal",
|
|
708
|
+
autoComplete: "off",
|
|
709
|
+
placeholder: "0.00"
|
|
710
|
+
},
|
|
711
|
+
date: {
|
|
712
|
+
type: "date",
|
|
713
|
+
inputMode: "none",
|
|
714
|
+
placeholder: "YYYY-MM-DD"
|
|
715
|
+
},
|
|
716
|
+
time: {
|
|
717
|
+
type: "time",
|
|
718
|
+
inputMode: "none",
|
|
719
|
+
placeholder: "HH:MM"
|
|
720
|
+
},
|
|
721
|
+
"datetime-local": {
|
|
722
|
+
type: "datetime-local",
|
|
723
|
+
inputMode: "none",
|
|
724
|
+
placeholder: "YYYY-MM-DDTHH:MM"
|
|
725
|
+
},
|
|
726
|
+
month: {
|
|
727
|
+
type: "month",
|
|
728
|
+
inputMode: "none",
|
|
729
|
+
placeholder: "YYYY-MM"
|
|
730
|
+
},
|
|
731
|
+
week: {
|
|
732
|
+
type: "week",
|
|
733
|
+
inputMode: "none",
|
|
734
|
+
placeholder: "YYYY-Www"
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
var TRANSITION_DURATION = 1500;
|
|
738
|
+
function useStateTransition(state) {
|
|
739
|
+
const previousState = useRef(state);
|
|
740
|
+
const [transitionState, setTransitionState] = useState();
|
|
741
|
+
useEffect(() => {
|
|
742
|
+
if (state === previousState.current) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
previousState.current = state;
|
|
746
|
+
if (state === "none") {
|
|
747
|
+
setTransitionState(void 0);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
setTransitionState(state);
|
|
751
|
+
const timeout = window.setTimeout(() => {
|
|
752
|
+
setTransitionState(void 0);
|
|
753
|
+
}, TRANSITION_DURATION);
|
|
754
|
+
return () => window.clearTimeout(timeout);
|
|
755
|
+
}, [state]);
|
|
756
|
+
return transitionState;
|
|
757
|
+
}
|
|
758
|
+
__name(useStateTransition, "useStateTransition");
|
|
759
|
+
var FormFieldContext = createContext(
|
|
760
|
+
null
|
|
761
|
+
);
|
|
762
|
+
function useFormField() {
|
|
763
|
+
const context = useContext(FormFieldContext);
|
|
764
|
+
if (!context) {
|
|
765
|
+
throw new Error("FormField components must be used inside <FormField />");
|
|
766
|
+
}
|
|
767
|
+
return context;
|
|
768
|
+
}
|
|
769
|
+
__name(useFormField, "useFormField");
|
|
770
|
+
function useOptionalFormField() {
|
|
771
|
+
return useContext(FormFieldContext);
|
|
772
|
+
}
|
|
773
|
+
__name(useOptionalFormField, "useOptionalFormField");
|
|
774
|
+
function mergeRefs(...refs) {
|
|
775
|
+
return (node) => {
|
|
776
|
+
refs.forEach((ref) => {
|
|
777
|
+
if (!ref) return;
|
|
778
|
+
if (typeof ref === "function") {
|
|
779
|
+
ref(node);
|
|
780
|
+
} else {
|
|
781
|
+
ref.current = node;
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
__name(mergeRefs, "mergeRefs");
|
|
787
|
+
var Input = forwardRef(
|
|
788
|
+
({
|
|
789
|
+
className,
|
|
790
|
+
inputClassName,
|
|
791
|
+
variant = "outline",
|
|
792
|
+
size = "md",
|
|
793
|
+
error,
|
|
794
|
+
success,
|
|
795
|
+
startIcon,
|
|
796
|
+
endIcon,
|
|
797
|
+
fullWidth = true,
|
|
798
|
+
disabled,
|
|
799
|
+
rounded = false,
|
|
800
|
+
isLoading = false,
|
|
801
|
+
clearable = false,
|
|
802
|
+
onClear,
|
|
803
|
+
kind = "text",
|
|
804
|
+
hideKindIcon = false,
|
|
805
|
+
id: externalId,
|
|
806
|
+
type: typeProp,
|
|
807
|
+
inputMode: inputModeProp,
|
|
808
|
+
autoComplete: autoCompleteProp,
|
|
809
|
+
placeholder: placeholderProp,
|
|
810
|
+
onChange: onChangeProp,
|
|
811
|
+
readOnly: readOnlyProp,
|
|
812
|
+
value,
|
|
813
|
+
defaultValue,
|
|
814
|
+
style,
|
|
815
|
+
...props
|
|
816
|
+
}, ref) => {
|
|
817
|
+
const autoId = useId();
|
|
818
|
+
const { theme } = useTheme();
|
|
819
|
+
const field = useOptionalFormField();
|
|
820
|
+
const id = externalId ?? field?.id ?? autoId;
|
|
821
|
+
const isInvalid = error || field?.invalid || false;
|
|
822
|
+
const describedBy = field?.describedBy ?? void 0;
|
|
823
|
+
const isRequired = field?.required ?? props.required;
|
|
824
|
+
const internalRef = useRef(null);
|
|
825
|
+
const { style: sizeStyle, iconSize } = useSizeStyle(size, false, "input");
|
|
826
|
+
const [hasValue, setHasValue] = useState(
|
|
827
|
+
() => Boolean(value ?? defaultValue ?? "")
|
|
828
|
+
);
|
|
829
|
+
const [visible, setVisible] = useState(false);
|
|
830
|
+
useEffect(() => {
|
|
831
|
+
if (value !== void 0) {
|
|
832
|
+
setHasValue(Boolean(value));
|
|
833
|
+
}
|
|
834
|
+
}, [value]);
|
|
835
|
+
const kindDefaults = inputKindDefaults[kind];
|
|
836
|
+
const resolvedType = typeProp ?? kindDefaults.type;
|
|
837
|
+
const isPasswordField = resolvedType === "password";
|
|
838
|
+
const effectiveType = isPasswordField ? visible ? "text" : "password" : resolvedType;
|
|
839
|
+
const KindIcon = inputKindIcons[kind];
|
|
840
|
+
const defaultStartIcon = !hideKindIcon && KindIcon ? /* @__PURE__ */ jsx(KindIcon, { size: Number(iconSize) || 15 }) : void 0;
|
|
841
|
+
const startSlot = startIcon || defaultStartIcon ? /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-center justify-center", children: startIcon ?? defaultStartIcon }) : null;
|
|
842
|
+
const builtInEnd = [];
|
|
843
|
+
if (isPasswordField) {
|
|
844
|
+
builtInEnd.push(
|
|
845
|
+
/* @__PURE__ */ jsx(
|
|
846
|
+
"button",
|
|
847
|
+
{
|
|
848
|
+
type: "button",
|
|
849
|
+
tabIndex: -1,
|
|
850
|
+
onClick: () => setVisible((current) => !current),
|
|
851
|
+
"aria-label": visible ? "Hide password" : "Show password",
|
|
852
|
+
className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
|
|
853
|
+
children: visible ? /* @__PURE__ */ jsx(EyeOff, { size: 16 }) : /* @__PURE__ */ jsx(Eye, { size: 16 })
|
|
854
|
+
},
|
|
855
|
+
"toggle-visibility"
|
|
856
|
+
)
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
if (clearable && hasValue && !disabled) {
|
|
860
|
+
builtInEnd.push(
|
|
861
|
+
/* @__PURE__ */ jsx(
|
|
862
|
+
"button",
|
|
863
|
+
{
|
|
864
|
+
type: "button",
|
|
865
|
+
tabIndex: -1,
|
|
866
|
+
onClick: handleClear,
|
|
867
|
+
"aria-label": "Clear input",
|
|
868
|
+
className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
|
|
869
|
+
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
870
|
+
},
|
|
871
|
+
"clear"
|
|
872
|
+
)
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
const endSlot = isLoading ? /* @__PURE__ */ jsx(Spinner, { size: Number(iconSize) || 14 }) : endIcon ? endIcon : builtInEnd.length ? /* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center gap-1.5", children: builtInEnd }) : null;
|
|
876
|
+
const hasIcon = Boolean(startSlot || endSlot);
|
|
877
|
+
const state = error ? "error" : success ? "success" : "none";
|
|
878
|
+
const stateTransition = useStateTransition(state);
|
|
879
|
+
const wrapperClasses = cn(
|
|
880
|
+
resolveRecipe(theme.recipes.FormControl, {
|
|
881
|
+
variant,
|
|
882
|
+
state,
|
|
883
|
+
rounded,
|
|
884
|
+
fullWidth,
|
|
885
|
+
disabled: Boolean(disabled || isLoading),
|
|
886
|
+
hasIcon
|
|
887
|
+
}),
|
|
888
|
+
className
|
|
889
|
+
);
|
|
890
|
+
const inputClasses = cn(
|
|
891
|
+
resolveRecipe(theme.recipes.Input, {
|
|
892
|
+
variant
|
|
893
|
+
}),
|
|
894
|
+
inputClassName
|
|
895
|
+
);
|
|
896
|
+
const resolvedStyle = {
|
|
897
|
+
...sizeStyle,
|
|
898
|
+
...style
|
|
899
|
+
};
|
|
900
|
+
function handleChange(event) {
|
|
901
|
+
setHasValue(Boolean(event.target.value));
|
|
902
|
+
onChangeProp?.(event);
|
|
903
|
+
}
|
|
904
|
+
__name(handleChange, "handleChange");
|
|
905
|
+
function handleClear() {
|
|
906
|
+
const element = internalRef.current;
|
|
907
|
+
if (!element) return;
|
|
908
|
+
const setter = Object.getOwnPropertyDescriptor(
|
|
909
|
+
window.HTMLInputElement.prototype,
|
|
910
|
+
"value"
|
|
911
|
+
)?.set;
|
|
912
|
+
setter?.call(element, "");
|
|
913
|
+
element.dispatchEvent(
|
|
914
|
+
new Event("input", {
|
|
915
|
+
bubbles: true
|
|
916
|
+
})
|
|
917
|
+
);
|
|
918
|
+
element.focus();
|
|
919
|
+
setHasValue(false);
|
|
920
|
+
onClear?.();
|
|
921
|
+
}
|
|
922
|
+
__name(handleClear, "handleClear");
|
|
923
|
+
useEffect(() => {
|
|
924
|
+
if (!error) return;
|
|
925
|
+
const element = internalRef.current;
|
|
926
|
+
if (!element) return;
|
|
927
|
+
element.scrollIntoView({
|
|
928
|
+
behavior: "smooth",
|
|
929
|
+
block: "center"
|
|
930
|
+
});
|
|
931
|
+
}, [error]);
|
|
932
|
+
return /* @__PURE__ */ jsxs(
|
|
933
|
+
"div",
|
|
934
|
+
{
|
|
935
|
+
className: wrapperClasses,
|
|
936
|
+
style: resolvedStyle,
|
|
937
|
+
"data-state": state,
|
|
938
|
+
"data-state-transition": stateTransition,
|
|
939
|
+
children: [
|
|
940
|
+
startSlot,
|
|
941
|
+
/* @__PURE__ */ jsx(
|
|
942
|
+
"input",
|
|
943
|
+
{
|
|
944
|
+
...props,
|
|
945
|
+
ref: mergeRefs(internalRef, ref),
|
|
946
|
+
id,
|
|
947
|
+
type: effectiveType,
|
|
948
|
+
inputMode: inputModeProp ?? kindDefaults.inputMode,
|
|
949
|
+
autoComplete: autoCompleteProp ?? kindDefaults.autoComplete,
|
|
950
|
+
placeholder: placeholderProp ?? kindDefaults.placeholder,
|
|
951
|
+
value,
|
|
952
|
+
defaultValue,
|
|
953
|
+
onChange: handleChange,
|
|
954
|
+
readOnly: isLoading || readOnlyProp,
|
|
955
|
+
disabled: isLoading || disabled,
|
|
956
|
+
"aria-busy": isLoading || void 0,
|
|
957
|
+
"aria-invalid": isInvalid || void 0,
|
|
958
|
+
"aria-describedby": describedBy,
|
|
959
|
+
"aria-required": isRequired || void 0,
|
|
960
|
+
className: inputClasses,
|
|
961
|
+
"data-variant": variant,
|
|
962
|
+
"data-size": size,
|
|
963
|
+
"data-success": success || void 0,
|
|
964
|
+
"data-disabled": disabled || void 0,
|
|
965
|
+
"data-loading": isLoading || void 0
|
|
966
|
+
}
|
|
967
|
+
),
|
|
968
|
+
endSlot
|
|
969
|
+
]
|
|
970
|
+
},
|
|
971
|
+
stateTransition ?? "idle"
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
);
|
|
975
|
+
Input.displayName = "Input";
|
|
976
|
+
function FormField({
|
|
977
|
+
id: externalId,
|
|
978
|
+
error,
|
|
979
|
+
required = false,
|
|
980
|
+
className,
|
|
981
|
+
children
|
|
982
|
+
}) {
|
|
983
|
+
const generatedId = useId();
|
|
984
|
+
const id = externalId ?? generatedId;
|
|
985
|
+
const labelId = `${id}-label`;
|
|
986
|
+
const descriptionId = `${id}-description`;
|
|
987
|
+
const messageId = `${id}-message`;
|
|
988
|
+
const [reportedMessage, setReportedMessage] = useState(
|
|
989
|
+
void 0
|
|
990
|
+
);
|
|
991
|
+
const [labelCount, setLabelCount] = useState(0);
|
|
992
|
+
const reportValidity = useCallback(
|
|
993
|
+
(result) => {
|
|
994
|
+
if (error !== void 0) return;
|
|
995
|
+
setReportedMessage(result?.invalid ? result.message : void 0);
|
|
996
|
+
},
|
|
997
|
+
[error]
|
|
998
|
+
);
|
|
999
|
+
const registerLabel = useCallback(() => {
|
|
1000
|
+
setLabelCount((n) => n + 1);
|
|
1001
|
+
return () => setLabelCount((n) => n - 1);
|
|
1002
|
+
}, []);
|
|
1003
|
+
const hasExternalLabel = labelCount > 0;
|
|
1004
|
+
const displayedMessage = error ?? reportedMessage;
|
|
1005
|
+
const state = displayedMessage ? "error" : "none";
|
|
1006
|
+
return /* @__PURE__ */ jsx(
|
|
1007
|
+
FormFieldContext.Provider,
|
|
1008
|
+
{
|
|
1009
|
+
value: {
|
|
1010
|
+
id,
|
|
1011
|
+
labelId,
|
|
1012
|
+
descriptionId,
|
|
1013
|
+
messageId,
|
|
1014
|
+
state,
|
|
1015
|
+
describedBy: [descriptionId, displayedMessage ? messageId : void 0].filter(Boolean).join(" ") || void 0,
|
|
1016
|
+
invalid: Boolean(displayedMessage),
|
|
1017
|
+
required,
|
|
1018
|
+
reportValidity,
|
|
1019
|
+
registerLabel,
|
|
1020
|
+
hasExternalLabel
|
|
1021
|
+
},
|
|
1022
|
+
children: /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-2", className), children: [
|
|
1023
|
+
children,
|
|
1024
|
+
displayedMessage && /* @__PURE__ */ jsx(FormFieldMessage, { children: displayedMessage })
|
|
1025
|
+
] })
|
|
1026
|
+
}
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
__name(FormField, "FormField");
|
|
1030
|
+
FormField.Label = FormFieldLabel;
|
|
1031
|
+
FormField.Control = FormFieldControl;
|
|
1032
|
+
FormField.Description = FormFieldDescription;
|
|
1033
|
+
FormField.Message = FormFieldMessage;
|
|
1034
|
+
function FormFieldLabel({
|
|
1035
|
+
children,
|
|
1036
|
+
className
|
|
1037
|
+
}) {
|
|
1038
|
+
const field = useFormField();
|
|
1039
|
+
useEffect(() => {
|
|
1040
|
+
return field.registerLabel();
|
|
1041
|
+
}, [field]);
|
|
1042
|
+
return /* @__PURE__ */ jsxs(
|
|
1043
|
+
"label",
|
|
1044
|
+
{
|
|
1045
|
+
id: field.labelId,
|
|
1046
|
+
htmlFor: field.id,
|
|
1047
|
+
className: cn("text-sm font-medium text-text", className),
|
|
1048
|
+
children: [
|
|
1049
|
+
children,
|
|
1050
|
+
field.required && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "ml-1 text-destructive", children: "*" })
|
|
1051
|
+
]
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
__name(FormFieldLabel, "FormFieldLabel");
|
|
1056
|
+
function FormFieldDescription({
|
|
1057
|
+
children
|
|
1058
|
+
}) {
|
|
1059
|
+
const {
|
|
1060
|
+
descriptionId
|
|
1061
|
+
} = useFormField();
|
|
1062
|
+
return /* @__PURE__ */ jsx(
|
|
1063
|
+
"p",
|
|
1064
|
+
{
|
|
1065
|
+
id: descriptionId,
|
|
1066
|
+
className: "text-sm text-text-muted",
|
|
1067
|
+
children
|
|
1068
|
+
}
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
__name(FormFieldDescription, "FormFieldDescription");
|
|
1072
|
+
function FormFieldMessage({ children }) {
|
|
1073
|
+
const { messageId } = useFormField();
|
|
1074
|
+
return /* @__PURE__ */ jsx(
|
|
1075
|
+
"p",
|
|
1076
|
+
{
|
|
1077
|
+
id: messageId,
|
|
1078
|
+
role: "alert",
|
|
1079
|
+
className: "\r\n animate-kui-shake [animation-delay:500ms]\r\n text-sm text-destructive\r\n ",
|
|
1080
|
+
children
|
|
1081
|
+
}
|
|
1082
|
+
);
|
|
1083
|
+
}
|
|
1084
|
+
__name(FormFieldMessage, "FormFieldMessage");
|
|
1085
|
+
function FormFieldControl({
|
|
1086
|
+
children
|
|
1087
|
+
}) {
|
|
1088
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
1089
|
+
}
|
|
1090
|
+
__name(FormFieldControl, "FormFieldControl");
|
|
1091
|
+
var SelectContext = createContext(null);
|
|
1092
|
+
function useSelectContext(componentName) {
|
|
1093
|
+
const ctx = useContext(SelectContext);
|
|
1094
|
+
if (!ctx) {
|
|
1095
|
+
throw new Error(`<${componentName} /> must be rendered inside <Select>.`);
|
|
1096
|
+
}
|
|
1097
|
+
return ctx;
|
|
1098
|
+
}
|
|
1099
|
+
__name(useSelectContext, "useSelectContext");
|
|
1100
|
+
var SelectGroupContext = createContext(null);
|
|
1101
|
+
function orderedEnabledValues(items) {
|
|
1102
|
+
return [...items.entries()].filter(([, meta]) => !meta.disabled).map(([value]) => value);
|
|
1103
|
+
}
|
|
1104
|
+
__name(orderedEnabledValues, "orderedEnabledValues");
|
|
1105
|
+
var SelectTrigger = forwardRef(
|
|
1106
|
+
({ className, children, onKeyDown, ...props }, ref) => {
|
|
1107
|
+
const ctx = useSelectContext("SelectTrigger");
|
|
1108
|
+
const { theme } = useTheme();
|
|
1109
|
+
const { style: sizeStyle, iconSize } = useSizeStyle(
|
|
1110
|
+
ctx.size,
|
|
1111
|
+
false,
|
|
1112
|
+
"select"
|
|
1113
|
+
);
|
|
1114
|
+
const state = ctx.isInvalid ? "error" : ctx.isSuccess ? "success" : "none";
|
|
1115
|
+
const wrapperClasses = cn(
|
|
1116
|
+
resolveRecipe(theme.recipes.FormControl, {
|
|
1117
|
+
variant: ctx.variant,
|
|
1118
|
+
state,
|
|
1119
|
+
rounded: Boolean(ctx.rounded),
|
|
1120
|
+
fullWidth: true,
|
|
1121
|
+
disabled: ctx.disabled,
|
|
1122
|
+
hasAdornment: true
|
|
1123
|
+
}),
|
|
1124
|
+
className
|
|
1125
|
+
);
|
|
1126
|
+
const showClear = ctx.clearable && ctx.value !== void 0 && !ctx.disabled;
|
|
1127
|
+
const move = useCallback(
|
|
1128
|
+
(delta) => {
|
|
1129
|
+
const values = orderedEnabledValues(ctx.items);
|
|
1130
|
+
if (!values.length) return;
|
|
1131
|
+
const currentIndex = ctx.activeValue ? values.indexOf(ctx.activeValue) : -1;
|
|
1132
|
+
const nextIndex = currentIndex === -1 ? delta === 1 ? 0 : values.length - 1 : (currentIndex + delta + values.length) % values.length;
|
|
1133
|
+
ctx.setActiveValue(values[nextIndex]);
|
|
1134
|
+
},
|
|
1135
|
+
[ctx]
|
|
1136
|
+
);
|
|
1137
|
+
const handleKeyDown = useCallback(
|
|
1138
|
+
(e) => {
|
|
1139
|
+
onKeyDown?.(e);
|
|
1140
|
+
if (e.defaultPrevented) return;
|
|
1141
|
+
switch (e.key) {
|
|
1142
|
+
case "ArrowDown":
|
|
1143
|
+
e.preventDefault();
|
|
1144
|
+
if (!ctx.open) ctx.setOpen(true);
|
|
1145
|
+
else move(1);
|
|
1146
|
+
break;
|
|
1147
|
+
case "ArrowUp":
|
|
1148
|
+
e.preventDefault();
|
|
1149
|
+
if (!ctx.open) ctx.setOpen(true);
|
|
1150
|
+
else move(-1);
|
|
1151
|
+
break;
|
|
1152
|
+
case "Home": {
|
|
1153
|
+
if (!ctx.open) break;
|
|
1154
|
+
e.preventDefault();
|
|
1155
|
+
const values = orderedEnabledValues(ctx.items);
|
|
1156
|
+
if (values.length) ctx.setActiveValue(values[0]);
|
|
1157
|
+
break;
|
|
1158
|
+
}
|
|
1159
|
+
case "End": {
|
|
1160
|
+
if (!ctx.open) break;
|
|
1161
|
+
e.preventDefault();
|
|
1162
|
+
const values = orderedEnabledValues(ctx.items);
|
|
1163
|
+
if (values.length) ctx.setActiveValue(values[values.length - 1]);
|
|
1164
|
+
break;
|
|
1165
|
+
}
|
|
1166
|
+
case "Enter":
|
|
1167
|
+
case " ":
|
|
1168
|
+
e.preventDefault();
|
|
1169
|
+
if (!ctx.open) ctx.setOpen(true);
|
|
1170
|
+
else if (ctx.activeValue !== void 0)
|
|
1171
|
+
ctx.onValueChange(ctx.activeValue);
|
|
1172
|
+
break;
|
|
1173
|
+
case "Escape":
|
|
1174
|
+
if (ctx.open) {
|
|
1175
|
+
e.preventDefault();
|
|
1176
|
+
ctx.setOpen(false);
|
|
1177
|
+
}
|
|
1178
|
+
break;
|
|
1179
|
+
case "Backspace":
|
|
1180
|
+
case "Delete":
|
|
1181
|
+
if (ctx.clearable && ctx.value !== void 0 && !ctx.open) {
|
|
1182
|
+
e.preventDefault();
|
|
1183
|
+
ctx.onClear();
|
|
1184
|
+
}
|
|
1185
|
+
break;
|
|
1186
|
+
}
|
|
1187
|
+
},
|
|
1188
|
+
[ctx, move, onKeyDown]
|
|
1189
|
+
);
|
|
1190
|
+
return /* @__PURE__ */ jsxs("div", { ref: ctx.triggerRef, className: wrapperClasses, style: sizeStyle, children: [
|
|
1191
|
+
/* @__PURE__ */ jsxs(
|
|
1192
|
+
"button",
|
|
1193
|
+
{
|
|
1194
|
+
ref,
|
|
1195
|
+
type: "button",
|
|
1196
|
+
id: ctx.triggerId,
|
|
1197
|
+
role: "combobox",
|
|
1198
|
+
"aria-haspopup": "listbox",
|
|
1199
|
+
"aria-expanded": ctx.open,
|
|
1200
|
+
"aria-labelledby": ctx.labelId,
|
|
1201
|
+
"aria-controls": ctx.contentId,
|
|
1202
|
+
"aria-activedescendant": ctx.open && ctx.activeValue ? ctx.optionId(ctx.activeValue) : void 0,
|
|
1203
|
+
tabIndex: ctx.tabIndex,
|
|
1204
|
+
"aria-invalid": ctx.isInvalid || void 0,
|
|
1205
|
+
"aria-describedby": ctx.describedBy,
|
|
1206
|
+
"aria-required": ctx.required || void 0,
|
|
1207
|
+
disabled: ctx.disabled,
|
|
1208
|
+
"data-state": ctx.open ? "open" : "closed",
|
|
1209
|
+
onClick: () => !ctx.disabled && ctx.setOpen(!ctx.open),
|
|
1210
|
+
onKeyDown: handleKeyDown,
|
|
1211
|
+
className: "relative min-w-0 flex-1 bg-transparent cursor-pointer text-left outline-none disabled:cursor-not-allowed h-full",
|
|
1212
|
+
...props,
|
|
1213
|
+
children: [
|
|
1214
|
+
children,
|
|
1215
|
+
/* @__PURE__ */ jsx(
|
|
1216
|
+
"span",
|
|
1217
|
+
{
|
|
1218
|
+
"aria-hidden": true,
|
|
1219
|
+
className: "pointer-events-none absolute right-0 top-1/2 flex -translate-y-1/2 items-center gap-1.5 text-text-muted",
|
|
1220
|
+
children: /* @__PURE__ */ jsx(
|
|
1221
|
+
ChevronDown,
|
|
1222
|
+
{
|
|
1223
|
+
size: 14,
|
|
1224
|
+
className: cn(
|
|
1225
|
+
"transition-transform duration-200",
|
|
1226
|
+
ctx.open && "rotate-180"
|
|
1227
|
+
)
|
|
1228
|
+
}
|
|
1229
|
+
)
|
|
1230
|
+
}
|
|
1231
|
+
)
|
|
1232
|
+
]
|
|
1233
|
+
}
|
|
1234
|
+
),
|
|
1235
|
+
showClear && /* @__PURE__ */ jsx(
|
|
1236
|
+
"button",
|
|
1237
|
+
{
|
|
1238
|
+
type: "button",
|
|
1239
|
+
tabIndex: -1,
|
|
1240
|
+
"aria-label": "Clear selection",
|
|
1241
|
+
onClick: (e) => {
|
|
1242
|
+
e.preventDefault();
|
|
1243
|
+
e.stopPropagation();
|
|
1244
|
+
ctx.onClear();
|
|
1245
|
+
},
|
|
1246
|
+
onMouseDown: (e) => {
|
|
1247
|
+
e.preventDefault();
|
|
1248
|
+
e.stopPropagation();
|
|
1249
|
+
},
|
|
1250
|
+
className: "flex h-4 w-4 items-center justify-center text-text-muted transition-colors hover:text-text",
|
|
1251
|
+
children: /* @__PURE__ */ jsx(X, { size: Number(iconSize) || 14 })
|
|
1252
|
+
}
|
|
1253
|
+
)
|
|
1254
|
+
] });
|
|
1255
|
+
}
|
|
1256
|
+
);
|
|
1257
|
+
SelectTrigger.displayName = "SelectTrigger";
|
|
1258
|
+
var VIEWPORT_PADDING = 8;
|
|
1259
|
+
function SelectContent({
|
|
1260
|
+
className,
|
|
1261
|
+
children,
|
|
1262
|
+
...props
|
|
1263
|
+
}) {
|
|
1264
|
+
const ctx = useSelectContext("SelectContent");
|
|
1265
|
+
const contentRef = useRef(null);
|
|
1266
|
+
const [side, setSide] = useState("bottom");
|
|
1267
|
+
useLayoutEffect(() => {
|
|
1268
|
+
if (!ctx.open) return;
|
|
1269
|
+
const trigger = ctx.triggerRef.current;
|
|
1270
|
+
const content = contentRef.current;
|
|
1271
|
+
if (!trigger || !content) return;
|
|
1272
|
+
function measure() {
|
|
1273
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
1274
|
+
const contentHeight = content?.offsetHeight;
|
|
1275
|
+
const spaceBelow = window.innerHeight - triggerRect.bottom - VIEWPORT_PADDING;
|
|
1276
|
+
const spaceAbove = triggerRect.top - VIEWPORT_PADDING;
|
|
1277
|
+
setSide(
|
|
1278
|
+
contentHeight && contentHeight > spaceBelow && spaceAbove > spaceBelow ? "top" : "bottom"
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
__name(measure, "measure");
|
|
1282
|
+
measure();
|
|
1283
|
+
window.addEventListener("resize", measure);
|
|
1284
|
+
window.addEventListener("scroll", measure, true);
|
|
1285
|
+
return () => {
|
|
1286
|
+
window.removeEventListener("resize", measure);
|
|
1287
|
+
window.removeEventListener("scroll", measure, true);
|
|
1288
|
+
};
|
|
1289
|
+
}, [ctx.open, ctx.triggerRef]);
|
|
1290
|
+
if (!ctx.open) return null;
|
|
1291
|
+
return /* @__PURE__ */ jsx(
|
|
1292
|
+
"div",
|
|
1293
|
+
{
|
|
1294
|
+
ref: contentRef,
|
|
1295
|
+
id: ctx.contentId,
|
|
1296
|
+
role: "listbox",
|
|
1297
|
+
"aria-labelledby": ctx.triggerId,
|
|
1298
|
+
"data-state": ctx.open ? "open" : "closed",
|
|
1299
|
+
"data-side": side,
|
|
1300
|
+
className: cn(
|
|
1301
|
+
"animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-(--kui-radii-md) border border-border bg-surface p-1 shadow-lg",
|
|
1302
|
+
side === "bottom" ? "top-full mt-1" : "bottom-full mb-1",
|
|
1303
|
+
className
|
|
1304
|
+
),
|
|
1305
|
+
...props,
|
|
1306
|
+
children
|
|
1307
|
+
}
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
__name(SelectContent, "SelectContent");
|
|
1311
|
+
function SelectItem({
|
|
1312
|
+
value,
|
|
1313
|
+
disabled = false,
|
|
1314
|
+
children,
|
|
1315
|
+
className,
|
|
1316
|
+
...props
|
|
1317
|
+
}) {
|
|
1318
|
+
const ctx = useSelectContext("SelectItem");
|
|
1319
|
+
const selected = ctx.value === value;
|
|
1320
|
+
const active = ctx.activeValue === value;
|
|
1321
|
+
const ref = useRef(null);
|
|
1322
|
+
useLayoutEffect(() => {
|
|
1323
|
+
return ctx.registerItem(value, { label: children, disabled });
|
|
1324
|
+
}, [value, disabled, children]);
|
|
1325
|
+
useEffect(() => {
|
|
1326
|
+
if (active) ref.current?.scrollIntoView({ block: "nearest" });
|
|
1327
|
+
}, [active]);
|
|
1328
|
+
return /* @__PURE__ */ jsx(
|
|
1329
|
+
"div",
|
|
1330
|
+
{
|
|
1331
|
+
ref,
|
|
1332
|
+
id: ctx.optionId(value),
|
|
1333
|
+
role: "option",
|
|
1334
|
+
"aria-selected": selected,
|
|
1335
|
+
"aria-disabled": disabled || void 0,
|
|
1336
|
+
"data-state": selected ? "selected" : void 0,
|
|
1337
|
+
"data-active": active || void 0,
|
|
1338
|
+
"data-disabled": disabled || void 0,
|
|
1339
|
+
onMouseEnter: () => !disabled && ctx.setActiveValue(value),
|
|
1340
|
+
onClick: () => !disabled && ctx.onValueChange(value),
|
|
1341
|
+
className: cn(
|
|
1342
|
+
"flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",
|
|
1343
|
+
active && "bg-brand/15 text-brand",
|
|
1344
|
+
selected && !active && "bg-surface-raised",
|
|
1345
|
+
disabled && "pointer-events-none cursor-not-allowed opacity-50",
|
|
1346
|
+
className
|
|
1347
|
+
),
|
|
1348
|
+
...props,
|
|
1349
|
+
children
|
|
1350
|
+
}
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
__name(SelectItem, "SelectItem");
|
|
1354
|
+
function SelectValue({ placeholder, className }) {
|
|
1355
|
+
const ctx = useSelectContext("SelectValue");
|
|
1356
|
+
const displayLabel = ctx.selectedLabel ?? placeholder ?? ctx.placeholder;
|
|
1357
|
+
return /* @__PURE__ */ jsx("span", { className: cn("min-w-0 truncate", className), children: displayLabel });
|
|
1358
|
+
}
|
|
1359
|
+
__name(SelectValue, "SelectValue");
|
|
1360
|
+
function SelectGroup({ children, className }) {
|
|
1361
|
+
const fallbackId = useId();
|
|
1362
|
+
const [labelId, setLabelId] = useState(void 0);
|
|
1363
|
+
return /* @__PURE__ */ jsx(SelectGroupContext.Provider, { value: { labelId: labelId ?? fallbackId, setHasLabel: setLabelId }, children: /* @__PURE__ */ jsx("div", { role: "group", "aria-labelledby": labelId, className: cn("py-1", className), children }) });
|
|
1364
|
+
}
|
|
1365
|
+
__name(SelectGroup, "SelectGroup");
|
|
1366
|
+
function SelectLabel({ children, className }) {
|
|
1367
|
+
const id = useId();
|
|
1368
|
+
const group = useContext(SelectGroupContext);
|
|
1369
|
+
useEffect(() => {
|
|
1370
|
+
group?.setHasLabel(id);
|
|
1371
|
+
}, [group, id]);
|
|
1372
|
+
return /* @__PURE__ */ jsx("div", { id, className: cn("px-2.5 py-1.5 font-mono text-[11px] text-text-muted", className), children });
|
|
1373
|
+
}
|
|
1374
|
+
__name(SelectLabel, "SelectLabel");
|
|
1375
|
+
function Select({
|
|
1376
|
+
value: valueProp,
|
|
1377
|
+
defaultValue,
|
|
1378
|
+
onValueChange,
|
|
1379
|
+
disabled = false,
|
|
1380
|
+
required,
|
|
1381
|
+
name,
|
|
1382
|
+
variant = "outline",
|
|
1383
|
+
size = "md",
|
|
1384
|
+
className,
|
|
1385
|
+
placeholder,
|
|
1386
|
+
"aria-describedby": ariaDescribedBy,
|
|
1387
|
+
clearable = false,
|
|
1388
|
+
error,
|
|
1389
|
+
success,
|
|
1390
|
+
tabIndex,
|
|
1391
|
+
rounded,
|
|
1392
|
+
children
|
|
1393
|
+
}) {
|
|
1394
|
+
const autoId = useId();
|
|
1395
|
+
const field = useOptionalFormField();
|
|
1396
|
+
const triggerId = field?.id ?? autoId;
|
|
1397
|
+
const triggerRef = useRef(null);
|
|
1398
|
+
const contentId = `${triggerId}-listbox`;
|
|
1399
|
+
const labelId = field?.labelId;
|
|
1400
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
1401
|
+
const value = valueProp !== void 0 ? valueProp : internalValue;
|
|
1402
|
+
const isInvalid = error || field?.invalid || false;
|
|
1403
|
+
const isSuccess = success && !isInvalid ? true : false;
|
|
1404
|
+
const describedBy = field?.describedBy ?? ariaDescribedBy;
|
|
1405
|
+
const isRequired = field?.required ?? required;
|
|
1406
|
+
const [open, setOpen] = useState(false);
|
|
1407
|
+
const [activeValue, setActiveValue] = useState(value);
|
|
1408
|
+
const [selectedLabel, setSelectedLabel] = useState();
|
|
1409
|
+
const itemsRef = useRef(/* @__PURE__ */ new Map());
|
|
1410
|
+
const [items, setItems] = useState(/* @__PURE__ */ new Map());
|
|
1411
|
+
const registerItem = useCallback(
|
|
1412
|
+
(val, meta) => {
|
|
1413
|
+
itemsRef.current.set(val, meta);
|
|
1414
|
+
setItems(new Map(itemsRef.current));
|
|
1415
|
+
return () => {
|
|
1416
|
+
itemsRef.current.delete(val);
|
|
1417
|
+
setItems(new Map(itemsRef.current));
|
|
1418
|
+
};
|
|
1419
|
+
},
|
|
1420
|
+
[]
|
|
1421
|
+
);
|
|
1422
|
+
const handleValueChange = useCallback(
|
|
1423
|
+
(val) => {
|
|
1424
|
+
const label = itemsRef.current.get(val)?.label ?? val;
|
|
1425
|
+
setSelectedLabel(label);
|
|
1426
|
+
if (valueProp === void 0) {
|
|
1427
|
+
setInternalValue(val);
|
|
1428
|
+
}
|
|
1429
|
+
onValueChange?.(val);
|
|
1430
|
+
setOpen(false);
|
|
1431
|
+
},
|
|
1432
|
+
[valueProp, onValueChange]
|
|
1433
|
+
);
|
|
1434
|
+
const handleClear = useCallback(() => {
|
|
1435
|
+
setActiveValue(void 0);
|
|
1436
|
+
setInternalValue(void 0);
|
|
1437
|
+
onValueChange?.(void 0);
|
|
1438
|
+
setSelectedLabel(void 0);
|
|
1439
|
+
}, [valueProp, onValueChange]);
|
|
1440
|
+
const optionId = useCallback(
|
|
1441
|
+
(val) => `${contentId}-option-${val}`,
|
|
1442
|
+
[contentId]
|
|
1443
|
+
);
|
|
1444
|
+
useEffect(() => {
|
|
1445
|
+
if (open) setActiveValue(value);
|
|
1446
|
+
}, [open, value]);
|
|
1447
|
+
useEffect(() => {
|
|
1448
|
+
if (value !== void 0) {
|
|
1449
|
+
const label = itemsRef.current.get(value)?.label;
|
|
1450
|
+
if (label !== void 0) setSelectedLabel(label);
|
|
1451
|
+
}
|
|
1452
|
+
}, [value, items]);
|
|
1453
|
+
const rootRef = useRef(null);
|
|
1454
|
+
useEffect(() => {
|
|
1455
|
+
if (!open) return;
|
|
1456
|
+
function handlePointerDown(e) {
|
|
1457
|
+
if (rootRef.current && !rootRef.current.contains(e.target)) {
|
|
1458
|
+
setOpen(false);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
__name(handlePointerDown, "handlePointerDown");
|
|
1462
|
+
document.addEventListener("mousedown", handlePointerDown);
|
|
1463
|
+
return () => document.removeEventListener("mousedown", handlePointerDown);
|
|
1464
|
+
}, [open]);
|
|
1465
|
+
const ctxValue = useMemo(
|
|
1466
|
+
() => ({
|
|
1467
|
+
value,
|
|
1468
|
+
selectedLabel,
|
|
1469
|
+
onValueChange: handleValueChange,
|
|
1470
|
+
disabled,
|
|
1471
|
+
variant,
|
|
1472
|
+
size,
|
|
1473
|
+
open,
|
|
1474
|
+
setOpen,
|
|
1475
|
+
triggerId,
|
|
1476
|
+
contentId,
|
|
1477
|
+
labelId,
|
|
1478
|
+
isInvalid,
|
|
1479
|
+
isSuccess,
|
|
1480
|
+
describedBy,
|
|
1481
|
+
required: isRequired,
|
|
1482
|
+
activeValue,
|
|
1483
|
+
setActiveValue,
|
|
1484
|
+
items,
|
|
1485
|
+
registerItem,
|
|
1486
|
+
optionId,
|
|
1487
|
+
placeholder,
|
|
1488
|
+
clearable,
|
|
1489
|
+
onClear: handleClear,
|
|
1490
|
+
triggerRef,
|
|
1491
|
+
rounded,
|
|
1492
|
+
tabIndex
|
|
1493
|
+
}),
|
|
1494
|
+
[
|
|
1495
|
+
value,
|
|
1496
|
+
items,
|
|
1497
|
+
selectedLabel,
|
|
1498
|
+
handleValueChange,
|
|
1499
|
+
disabled,
|
|
1500
|
+
variant,
|
|
1501
|
+
size,
|
|
1502
|
+
open,
|
|
1503
|
+
triggerId,
|
|
1504
|
+
contentId,
|
|
1505
|
+
isInvalid,
|
|
1506
|
+
isSuccess,
|
|
1507
|
+
describedBy,
|
|
1508
|
+
isRequired,
|
|
1509
|
+
activeValue,
|
|
1510
|
+
registerItem,
|
|
1511
|
+
optionId,
|
|
1512
|
+
placeholder,
|
|
1513
|
+
clearable,
|
|
1514
|
+
handleClear,
|
|
1515
|
+
triggerRef,
|
|
1516
|
+
rounded,
|
|
1517
|
+
labelId,
|
|
1518
|
+
tabIndex
|
|
1519
|
+
]
|
|
1520
|
+
);
|
|
1521
|
+
return /* @__PURE__ */ jsx(SelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxs(
|
|
1522
|
+
"div",
|
|
1523
|
+
{
|
|
1524
|
+
ref: rootRef,
|
|
1525
|
+
className: cn("relative inline-block w-full", className),
|
|
1526
|
+
children: [
|
|
1527
|
+
children,
|
|
1528
|
+
name && /* @__PURE__ */ jsx(
|
|
1529
|
+
"input",
|
|
1530
|
+
{
|
|
1531
|
+
type: "hidden",
|
|
1532
|
+
name,
|
|
1533
|
+
value: value ?? "",
|
|
1534
|
+
disabled,
|
|
1535
|
+
required: isRequired
|
|
1536
|
+
}
|
|
1537
|
+
)
|
|
1538
|
+
]
|
|
1539
|
+
}
|
|
1540
|
+
) });
|
|
1541
|
+
}
|
|
1542
|
+
__name(Select, "Select");
|
|
1543
|
+
Select.Trigger = SelectTrigger;
|
|
1544
|
+
Select.Content = SelectContent;
|
|
1545
|
+
Select.Item = SelectItem;
|
|
1546
|
+
Select.Value = SelectValue;
|
|
1547
|
+
Select.Group = SelectGroup;
|
|
1548
|
+
Select.Label = SelectLabel;
|
|
1549
|
+
|
|
1550
|
+
// src/components/Textarea/Textarea.styles.ts
|
|
1551
|
+
var textareaBase = cn(
|
|
1552
|
+
"flex w-full min-w-0 bg-transparent font-sans outline-none border-0",
|
|
1553
|
+
"text-text placeholder:text-text-muted",
|
|
1554
|
+
"transition-colors duration-[var(--kui-duration-fast)]",
|
|
1555
|
+
"disabled:opacity-50 disabled:pointer-events-none disabled:cursor-not-allowed"
|
|
1556
|
+
);
|
|
1557
|
+
var textareaResizeVariants = {
|
|
1558
|
+
none: "resize-none",
|
|
1559
|
+
both: "resize",
|
|
1560
|
+
horizontal: "resize-x",
|
|
1561
|
+
vertical: "resize-y"
|
|
1562
|
+
};
|
|
1563
|
+
function mergeRefs2(...refs) {
|
|
1564
|
+
return (node) => {
|
|
1565
|
+
refs.forEach((r) => {
|
|
1566
|
+
if (!r) return;
|
|
1567
|
+
if (typeof r === "function") r(node);
|
|
1568
|
+
else r.current = node;
|
|
1569
|
+
});
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
__name(mergeRefs2, "mergeRefs");
|
|
1573
|
+
var TextareaCore = forwardRef(
|
|
1574
|
+
({
|
|
1575
|
+
className,
|
|
1576
|
+
value: valueProp,
|
|
1577
|
+
defaultValue,
|
|
1578
|
+
size = "md",
|
|
1579
|
+
fullWidth = true,
|
|
1580
|
+
resize = "vertical",
|
|
1581
|
+
autoResize = false,
|
|
1582
|
+
minRows,
|
|
1583
|
+
maxRows,
|
|
1584
|
+
clearable = false,
|
|
1585
|
+
onClear,
|
|
1586
|
+
characterCounter = false,
|
|
1587
|
+
debounceDelay = 0,
|
|
1588
|
+
trimOnBlur = false,
|
|
1589
|
+
error,
|
|
1590
|
+
success,
|
|
1591
|
+
onValidate,
|
|
1592
|
+
disabled,
|
|
1593
|
+
id: externalId,
|
|
1594
|
+
maxLength,
|
|
1595
|
+
variant = "outline",
|
|
1596
|
+
onValueChange: onValueChangeProp,
|
|
1597
|
+
onChange: onChangeProp,
|
|
1598
|
+
onBlur: onBlurProp,
|
|
1599
|
+
rows,
|
|
1600
|
+
...props
|
|
1601
|
+
}, ref) => {
|
|
1602
|
+
const autoId = useId();
|
|
1603
|
+
const field = useOptionalFormField();
|
|
1604
|
+
const id = field?.id ?? externalId ?? autoId;
|
|
1605
|
+
const { theme } = useTheme();
|
|
1606
|
+
const internalRef = useRef(null);
|
|
1607
|
+
const debounceTimer = useRef(null);
|
|
1608
|
+
const [draft, setDraft] = useState(() => valueProp ?? defaultValue ?? "");
|
|
1609
|
+
useEffect(() => {
|
|
1610
|
+
if (valueProp !== void 0) setDraft(valueProp);
|
|
1611
|
+
}, [valueProp]);
|
|
1612
|
+
const [internalValidation, setInternalValidation] = useState({});
|
|
1613
|
+
const isInvalid = error ?? field?.invalid ?? internalValidation.invalid ?? false;
|
|
1614
|
+
const isSuccess = success ?? (onValidate ? internalValidation.invalid === false : false);
|
|
1615
|
+
const state = isInvalid ? "error" : isSuccess ? "success" : "none";
|
|
1616
|
+
useEffect(
|
|
1617
|
+
() => () => {
|
|
1618
|
+
if (debounceTimer.current) clearTimeout(debounceTimer.current);
|
|
1619
|
+
},
|
|
1620
|
+
[]
|
|
1621
|
+
);
|
|
1622
|
+
function commitValue(next, { immediate = false } = {}) {
|
|
1623
|
+
setDraft(next);
|
|
1624
|
+
if (debounceTimer.current) clearTimeout(debounceTimer.current);
|
|
1625
|
+
if (debounceDelay > 0 && !immediate) {
|
|
1626
|
+
debounceTimer.current = setTimeout(() => {
|
|
1627
|
+
onValueChangeProp?.(next);
|
|
1628
|
+
}, debounceDelay);
|
|
1629
|
+
} else {
|
|
1630
|
+
onValueChangeProp?.(next);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
__name(commitValue, "commitValue");
|
|
1634
|
+
function handleChange(e) {
|
|
1635
|
+
commitValue(e.target.value);
|
|
1636
|
+
onChangeProp?.(e);
|
|
1637
|
+
}
|
|
1638
|
+
__name(handleChange, "handleChange");
|
|
1639
|
+
function runValidation(next) {
|
|
1640
|
+
if (!onValidate || error !== void 0 || success !== void 0) return;
|
|
1641
|
+
const result = onValidate(next);
|
|
1642
|
+
const parsed = result === true ? { invalid: false, message: void 0 } : result === false ? { invalid: true, message: void 0 } : { invalid: true, message: result };
|
|
1643
|
+
setInternalValidation(parsed);
|
|
1644
|
+
field?.reportValidity(parsed.invalid ? parsed : null);
|
|
1645
|
+
}
|
|
1646
|
+
__name(runValidation, "runValidation");
|
|
1647
|
+
function handleBlur(e) {
|
|
1648
|
+
let finalValue = draft;
|
|
1649
|
+
if (trimOnBlur) {
|
|
1650
|
+
const trimmed = draft.trim();
|
|
1651
|
+
if (trimmed !== draft) {
|
|
1652
|
+
commitValue(trimmed, { immediate: true });
|
|
1653
|
+
finalValue = trimmed;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
runValidation(finalValue);
|
|
1657
|
+
onBlurProp?.(e);
|
|
1658
|
+
}
|
|
1659
|
+
__name(handleBlur, "handleBlur");
|
|
1660
|
+
function handleClear() {
|
|
1661
|
+
commitValue("", { immediate: true });
|
|
1662
|
+
internalRef.current?.focus();
|
|
1663
|
+
setInternalValidation({});
|
|
1664
|
+
field?.reportValidity(null);
|
|
1665
|
+
onClear?.();
|
|
1666
|
+
}
|
|
1667
|
+
__name(handleClear, "handleClear");
|
|
1668
|
+
useLayoutEffect(() => {
|
|
1669
|
+
if (!autoResize) return;
|
|
1670
|
+
const el = internalRef.current;
|
|
1671
|
+
if (!el) return;
|
|
1672
|
+
const computed = window.getComputedStyle(el);
|
|
1673
|
+
const lineHeight = parseFloat(computed.lineHeight) || parseFloat(computed.fontSize) * 1.2;
|
|
1674
|
+
const paddingY = parseFloat(computed.paddingTop) + parseFloat(computed.paddingBottom);
|
|
1675
|
+
const borderY = parseFloat(computed.borderTopWidth) + parseFloat(computed.borderBottomWidth);
|
|
1676
|
+
const minHeight = minRows ? lineHeight * minRows + paddingY + borderY : void 0;
|
|
1677
|
+
const maxHeight = maxRows ? lineHeight * maxRows + paddingY + borderY : void 0;
|
|
1678
|
+
el.style.height = "auto";
|
|
1679
|
+
let next = el.scrollHeight;
|
|
1680
|
+
if (minHeight) next = Math.max(next, minHeight);
|
|
1681
|
+
if (maxHeight) next = Math.min(next, maxHeight);
|
|
1682
|
+
el.style.height = `${next}px`;
|
|
1683
|
+
el.style.overflowY = maxHeight && el.scrollHeight > maxHeight ? "auto" : "hidden";
|
|
1684
|
+
}, [autoResize, draft, minRows, maxRows]);
|
|
1685
|
+
const hasValue = draft.length > 0;
|
|
1686
|
+
const showClear = clearable && hasValue && !disabled;
|
|
1687
|
+
const showCounter = characterCounter;
|
|
1688
|
+
const nearLimit = maxLength ? draft.length >= maxLength * 0.9 : false;
|
|
1689
|
+
const needsBottomSpace = showClear || showCounter;
|
|
1690
|
+
const messageId = !field?.describedBy && (isInvalid || isSuccess) ? `${id}-message` : void 0;
|
|
1691
|
+
const counterId = showCounter ? `${id}-counter` : void 0;
|
|
1692
|
+
const describedBy = cn(field?.describedBy, messageId, counterId).trim() || void 0;
|
|
1693
|
+
const wrapperClassName = cn(
|
|
1694
|
+
resolveRecipe(theme.recipes.FormControl, {
|
|
1695
|
+
variant,
|
|
1696
|
+
state,
|
|
1697
|
+
fullWidth,
|
|
1698
|
+
disabled: !!disabled
|
|
1699
|
+
}),
|
|
1700
|
+
"items-start",
|
|
1701
|
+
className
|
|
1702
|
+
);
|
|
1703
|
+
const { style: sizeStyle } = useSizeStyle(size, false, "textarea", {
|
|
1704
|
+
includeHeight: false
|
|
1705
|
+
});
|
|
1706
|
+
const textareaStyle = { ...sizeStyle };
|
|
1707
|
+
if (needsBottomSpace) {
|
|
1708
|
+
const existingBottom = sizeStyle.paddingBottom;
|
|
1709
|
+
textareaStyle.paddingBottom = existingBottom ? `calc(${existingBottom} + 1.25rem)` : "1.5rem";
|
|
1710
|
+
}
|
|
1711
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClassName, children: [
|
|
1712
|
+
/* @__PURE__ */ jsx(
|
|
1713
|
+
"textarea",
|
|
1714
|
+
{
|
|
1715
|
+
ref: mergeRefs2(internalRef, ref),
|
|
1716
|
+
id,
|
|
1717
|
+
value: draft,
|
|
1718
|
+
onChange: handleChange,
|
|
1719
|
+
onBlur: handleBlur,
|
|
1720
|
+
disabled,
|
|
1721
|
+
maxLength,
|
|
1722
|
+
rows: autoResize ? void 0 : rows ?? minRows,
|
|
1723
|
+
"aria-invalid": isInvalid || void 0,
|
|
1724
|
+
"aria-describedby": describedBy,
|
|
1725
|
+
style: textareaStyle,
|
|
1726
|
+
className: cn(
|
|
1727
|
+
textareaBase,
|
|
1728
|
+
!autoResize && textareaResizeVariants[resize],
|
|
1729
|
+
autoResize && "resize-none overflow-hidden"
|
|
1730
|
+
),
|
|
1731
|
+
"data-size": size,
|
|
1732
|
+
"data-invalid": isInvalid || void 0,
|
|
1733
|
+
"data-success": isSuccess || void 0,
|
|
1734
|
+
"data-disabled": disabled || void 0,
|
|
1735
|
+
"data-autoresize": autoResize || void 0,
|
|
1736
|
+
...props
|
|
1737
|
+
}
|
|
1738
|
+
),
|
|
1739
|
+
showClear && /* @__PURE__ */ jsx(
|
|
1740
|
+
"button",
|
|
1741
|
+
{
|
|
1742
|
+
type: "button",
|
|
1743
|
+
"aria-label": "Clear textarea",
|
|
1744
|
+
onClick: handleClear,
|
|
1745
|
+
className: "absolute right-2 top-2 flex items-center justify-center text-text-muted transition-colors hover:text-text",
|
|
1746
|
+
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
1747
|
+
}
|
|
1748
|
+
),
|
|
1749
|
+
showCounter && /* @__PURE__ */ jsxs(
|
|
1750
|
+
"div",
|
|
1751
|
+
{
|
|
1752
|
+
id: counterId,
|
|
1753
|
+
className: cn(
|
|
1754
|
+
"pointer-events-none absolute bottom-1.5 right-2.5 font-mono text-[11px]",
|
|
1755
|
+
nearLimit ? "text-danger" : "text-text-muted"
|
|
1756
|
+
),
|
|
1757
|
+
children: [
|
|
1758
|
+
draft.length,
|
|
1759
|
+
maxLength ? `/${maxLength}` : ""
|
|
1760
|
+
]
|
|
1761
|
+
}
|
|
1762
|
+
),
|
|
1763
|
+
internalValidation.message && !field && /* @__PURE__ */ jsx(
|
|
1764
|
+
"p",
|
|
1765
|
+
{
|
|
1766
|
+
id: messageId,
|
|
1767
|
+
role: "alert",
|
|
1768
|
+
className: "mt-1.5 px-0.5 text-xs text-danger",
|
|
1769
|
+
children: internalValidation.message
|
|
1770
|
+
}
|
|
1771
|
+
)
|
|
1772
|
+
] });
|
|
1773
|
+
}
|
|
1774
|
+
);
|
|
1775
|
+
TextareaCore.displayName = "TextareaCore";
|
|
1776
|
+
|
|
1777
|
+
// src/components/MarkdownEditor/markdownActions.ts
|
|
1778
|
+
function lineBounds(value, index) {
|
|
1779
|
+
const start = value.lastIndexOf("\n", index - 1) + 1;
|
|
1780
|
+
const nextBreak = value.indexOf("\n", index);
|
|
1781
|
+
const end = nextBreak === -1 ? value.length : nextBreak;
|
|
1782
|
+
return { start, end };
|
|
1783
|
+
}
|
|
1784
|
+
__name(lineBounds, "lineBounds");
|
|
1785
|
+
function selectedLineRange(value, start, end) {
|
|
1786
|
+
const first = lineBounds(value, start);
|
|
1787
|
+
const last = lineBounds(value, Math.max(end - 1, start));
|
|
1788
|
+
return { from: first.start, to: last.end };
|
|
1789
|
+
}
|
|
1790
|
+
__name(selectedLineRange, "selectedLineRange");
|
|
1791
|
+
function toggleWrap(value, start, end, marker) {
|
|
1792
|
+
const before = value.slice(Math.max(0, start - marker.length), start);
|
|
1793
|
+
const after = value.slice(end, end + marker.length);
|
|
1794
|
+
if (before === marker && after === marker) {
|
|
1795
|
+
const next2 = value.slice(0, start - marker.length) + value.slice(start, end) + value.slice(end + marker.length);
|
|
1796
|
+
return {
|
|
1797
|
+
value: next2,
|
|
1798
|
+
selectionStart: start - marker.length,
|
|
1799
|
+
selectionEnd: end - marker.length
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
const selected = value.slice(start, end);
|
|
1803
|
+
const next = value.slice(0, start) + marker + selected + marker + value.slice(end);
|
|
1804
|
+
return selected.length === 0 ? {
|
|
1805
|
+
value: next,
|
|
1806
|
+
selectionStart: start + marker.length,
|
|
1807
|
+
selectionEnd: start + marker.length
|
|
1808
|
+
} : {
|
|
1809
|
+
value: next,
|
|
1810
|
+
selectionStart: start,
|
|
1811
|
+
selectionEnd: end + marker.length * 2
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
__name(toggleWrap, "toggleWrap");
|
|
1815
|
+
function toggleLinePrefix(value, start, end, prefix) {
|
|
1816
|
+
const { from, to } = selectedLineRange(value, start, end);
|
|
1817
|
+
const line = value.slice(from, to);
|
|
1818
|
+
const next = line.startsWith(prefix) ? value.slice(0, from) + line.slice(prefix.length) + value.slice(to) : value.slice(0, from) + prefix + line + value.slice(to);
|
|
1819
|
+
const delta = (line.startsWith(prefix) ? -1 : 1) * prefix.length;
|
|
1820
|
+
return {
|
|
1821
|
+
value: next,
|
|
1822
|
+
selectionStart: start + delta,
|
|
1823
|
+
selectionEnd: end + delta
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
__name(toggleLinePrefix, "toggleLinePrefix");
|
|
1827
|
+
function toggleListPrefix(value, start, end, makePrefix) {
|
|
1828
|
+
const { from, to } = selectedLineRange(value, start, end);
|
|
1829
|
+
const block = value.slice(from, to);
|
|
1830
|
+
const lines = block.split("\n");
|
|
1831
|
+
const alreadyListed = lines.every(
|
|
1832
|
+
(l) => l.startsWith(makePrefix(0)) || /^\d+\.\s/.test(l)
|
|
1833
|
+
);
|
|
1834
|
+
const nextLines = lines.map(
|
|
1835
|
+
(l, i) => alreadyListed ? l.replace(/^(\d+\.\s|-\s\[ \]\s|-\s)/, "") : makePrefix(i) + l
|
|
1836
|
+
);
|
|
1837
|
+
const next = value.slice(0, from) + nextLines.join("\n") + value.slice(to);
|
|
1838
|
+
const delta = nextLines.join("\n").length - block.length;
|
|
1839
|
+
return { value: next, selectionStart: from, selectionEnd: to + delta };
|
|
1840
|
+
}
|
|
1841
|
+
__name(toggleListPrefix, "toggleListPrefix");
|
|
1842
|
+
function toggleCode(value, start, end) {
|
|
1843
|
+
const selected = value.slice(start, end);
|
|
1844
|
+
if (selected.includes("\n")) {
|
|
1845
|
+
const next = value.slice(0, start) + "```\n" + selected + "\n```" + value.slice(end);
|
|
1846
|
+
return { value: next, selectionStart: start + 4, selectionEnd: end + 4 };
|
|
1847
|
+
}
|
|
1848
|
+
return toggleWrap(value, start, end, "`");
|
|
1849
|
+
}
|
|
1850
|
+
__name(toggleCode, "toggleCode");
|
|
1851
|
+
function insertLink(value, start, end) {
|
|
1852
|
+
const selected = value.slice(start, end);
|
|
1853
|
+
const label = selected || "text";
|
|
1854
|
+
const snippet = `[${label}](url)`;
|
|
1855
|
+
const next = value.slice(0, start) + snippet + value.slice(end);
|
|
1856
|
+
const urlStart = start + label.length + 3;
|
|
1857
|
+
return { value: next, selectionStart: urlStart, selectionEnd: urlStart + 3 };
|
|
1858
|
+
}
|
|
1859
|
+
__name(insertLink, "insertLink");
|
|
1860
|
+
|
|
1861
|
+
// src/utils/env.ts
|
|
1862
|
+
function readProcessEnv() {
|
|
1863
|
+
try {
|
|
1864
|
+
return typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
|
|
1865
|
+
} catch {
|
|
1866
|
+
return void 0;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
__name(readProcessEnv, "readProcessEnv");
|
|
1870
|
+
function readImportMetaEnv() {
|
|
1871
|
+
try {
|
|
1872
|
+
return typeof import.meta !== "undefined" ? import.meta.env?.MODE : void 0;
|
|
1873
|
+
} catch {
|
|
1874
|
+
return void 0;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
__name(readImportMetaEnv, "readImportMetaEnv");
|
|
1878
|
+
function isDev() {
|
|
1879
|
+
const mode = readProcessEnv() ?? readImportMetaEnv();
|
|
1880
|
+
return mode !== void 0 && mode !== "production";
|
|
1881
|
+
}
|
|
1882
|
+
__name(isDev, "isDev");
|
|
1883
|
+
var TOOLBAR = [
|
|
1884
|
+
{
|
|
1885
|
+
label: "Heading",
|
|
1886
|
+
icon: Heading,
|
|
1887
|
+
action: /* @__PURE__ */ __name((v, s, e) => toggleLinePrefix(v, s, e, "### "), "action")
|
|
1888
|
+
},
|
|
1889
|
+
{
|
|
1890
|
+
label: "Bold",
|
|
1891
|
+
icon: Bold,
|
|
1892
|
+
action: /* @__PURE__ */ __name((v, s, e) => toggleWrap(v, s, e, "**"), "action")
|
|
1893
|
+
},
|
|
1894
|
+
{
|
|
1895
|
+
label: "Italic",
|
|
1896
|
+
icon: Italic,
|
|
1897
|
+
action: /* @__PURE__ */ __name((v, s, e) => toggleWrap(v, s, e, "_"), "action")
|
|
1898
|
+
},
|
|
1899
|
+
{
|
|
1900
|
+
label: "Ordered list",
|
|
1901
|
+
icon: ListOrdered,
|
|
1902
|
+
action: /* @__PURE__ */ __name((v, s, e) => toggleListPrefix(v, s, e, (i) => `${i + 1}. `), "action")
|
|
1903
|
+
},
|
|
1904
|
+
{
|
|
1905
|
+
label: "Checklist",
|
|
1906
|
+
icon: ClipboardList,
|
|
1907
|
+
action: /* @__PURE__ */ __name((v, s, e) => toggleListPrefix(v, s, e, () => "- [ ] "), "action")
|
|
1908
|
+
},
|
|
1909
|
+
{ label: "Code", icon: Code, action: toggleCode },
|
|
1910
|
+
{ label: "Link", icon: Link, action: insertLink }
|
|
1911
|
+
];
|
|
1912
|
+
var MarkdownEditor = forwardRef(
|
|
1913
|
+
({
|
|
1914
|
+
renderMarkdown,
|
|
1915
|
+
tab: tabProp,
|
|
1916
|
+
defaultTab = "write",
|
|
1917
|
+
onTabChange,
|
|
1918
|
+
hint = "Markdown is supported",
|
|
1919
|
+
value: valueProp,
|
|
1920
|
+
defaultValue,
|
|
1921
|
+
onValueChange,
|
|
1922
|
+
className,
|
|
1923
|
+
...textareaProps
|
|
1924
|
+
}, ref) => {
|
|
1925
|
+
const baseId = useId();
|
|
1926
|
+
const textareaRef = useRef(null);
|
|
1927
|
+
const [uncontrolledTab, setUncontrolledTab] = useState(
|
|
1928
|
+
defaultTab
|
|
1929
|
+
);
|
|
1930
|
+
const tab = tabProp ?? uncontrolledTab;
|
|
1931
|
+
const [draft, setDraft] = useState(() => valueProp ?? defaultValue ?? "");
|
|
1932
|
+
const value = valueProp ?? draft;
|
|
1933
|
+
function setTab(next) {
|
|
1934
|
+
if (tabProp === void 0) setUncontrolledTab(next);
|
|
1935
|
+
onTabChange?.(next);
|
|
1936
|
+
}
|
|
1937
|
+
__name(setTab, "setTab");
|
|
1938
|
+
function commit(next) {
|
|
1939
|
+
setDraft(next);
|
|
1940
|
+
onValueChange?.(next);
|
|
1941
|
+
}
|
|
1942
|
+
__name(commit, "commit");
|
|
1943
|
+
function runAction(action) {
|
|
1944
|
+
const el = textareaRef.current;
|
|
1945
|
+
if (!el) return;
|
|
1946
|
+
const { selectionStart, selectionEnd } = el;
|
|
1947
|
+
const edit = action(
|
|
1948
|
+
value,
|
|
1949
|
+
selectionStart ?? value.length,
|
|
1950
|
+
selectionEnd ?? value.length
|
|
1951
|
+
);
|
|
1952
|
+
commit(edit.value);
|
|
1953
|
+
el.focus();
|
|
1954
|
+
requestAnimationFrame(() => {
|
|
1955
|
+
el.setSelectionRange(edit.selectionStart, edit.selectionEnd);
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
__name(runAction, "runAction");
|
|
1959
|
+
const tablistId = `${baseId}-tablist`;
|
|
1960
|
+
const writePanelId = `${baseId}-write-panel`;
|
|
1961
|
+
const previewPanelId = `${baseId}-preview-panel`;
|
|
1962
|
+
const renderedPreview = useMemo(
|
|
1963
|
+
() => renderMarkdown ? renderMarkdown(value) : null,
|
|
1964
|
+
[renderMarkdown, value]
|
|
1965
|
+
);
|
|
1966
|
+
useEffect(() => {
|
|
1967
|
+
if (isDev() && !renderMarkdown) {
|
|
1968
|
+
console.warn(
|
|
1969
|
+
"[kreativ-ui/MarkdownEditor]: no `renderMarkdown` prop was provided, so the Preview tab is just showing plain text with no markdown formatting applied. Pass a `renderMarkdown={(value) => ReactNode}` function \u2014 e.g. using react-markdown \u2014 to enable a real preview:\n\n import ReactMarkdown from 'react-markdown';\n <Textarea allowMarkdown renderMarkdown={(v) => <ReactMarkdown>{v}</ReactMarkdown>} />"
|
|
1970
|
+
);
|
|
1971
|
+
}
|
|
1972
|
+
}, [renderMarkdown]);
|
|
1973
|
+
return /* @__PURE__ */ jsxs(
|
|
1974
|
+
"div",
|
|
1975
|
+
{
|
|
1976
|
+
className: cn(
|
|
1977
|
+
"rounded-(--kui-radii-md) border border-border",
|
|
1978
|
+
className
|
|
1979
|
+
),
|
|
1980
|
+
children: [
|
|
1981
|
+
/* @__PURE__ */ jsxs(
|
|
1982
|
+
"div",
|
|
1983
|
+
{
|
|
1984
|
+
role: "tablist",
|
|
1985
|
+
"aria-label": "Markdown editor mode",
|
|
1986
|
+
id: tablistId,
|
|
1987
|
+
className: "flex items-center gap-4 border-b border-border px-3",
|
|
1988
|
+
children: [
|
|
1989
|
+
["write", "preview"].map((t) => /* @__PURE__ */ jsx(
|
|
1990
|
+
"button",
|
|
1991
|
+
{
|
|
1992
|
+
type: "button",
|
|
1993
|
+
role: "tab",
|
|
1994
|
+
id: `${baseId}-${t}-tab`,
|
|
1995
|
+
"aria-selected": tab === t,
|
|
1996
|
+
"aria-controls": t === "write" ? writePanelId : previewPanelId,
|
|
1997
|
+
onClick: () => setTab(t),
|
|
1998
|
+
className: cn(
|
|
1999
|
+
"border-b-2 py-2.5 text-sm capitalize transition-colors",
|
|
2000
|
+
tab === t ? "border-brand text-text" : "border-transparent text-text-muted hover:text-text"
|
|
2001
|
+
),
|
|
2002
|
+
children: t
|
|
2003
|
+
},
|
|
2004
|
+
t
|
|
2005
|
+
)),
|
|
2006
|
+
tab === "write" && /* @__PURE__ */ jsx("div", { className: "ml-auto flex items-center gap-1 py-1.5", children: TOOLBAR.map(({ label, icon: Icon, action }) => /* @__PURE__ */ jsx(
|
|
2007
|
+
"button",
|
|
2008
|
+
{
|
|
2009
|
+
type: "button",
|
|
2010
|
+
"aria-label": label,
|
|
2011
|
+
onClick: () => runAction(action),
|
|
2012
|
+
className: "rounded-(--kui-radii-sm) p-1.5 text-text-muted transition-colors hover:bg-surface-raised hover:text-text",
|
|
2013
|
+
children: /* @__PURE__ */ jsx(Icon, { size: 15 })
|
|
2014
|
+
},
|
|
2015
|
+
label
|
|
2016
|
+
)) })
|
|
2017
|
+
]
|
|
2018
|
+
}
|
|
2019
|
+
),
|
|
2020
|
+
/* @__PURE__ */ jsx(
|
|
2021
|
+
"div",
|
|
2022
|
+
{
|
|
2023
|
+
id: writePanelId,
|
|
2024
|
+
role: "tabpanel",
|
|
2025
|
+
"aria-labelledby": `${baseId}-write-tab`,
|
|
2026
|
+
hidden: tab !== "write",
|
|
2027
|
+
children: /* @__PURE__ */ jsx(
|
|
2028
|
+
TextareaCore,
|
|
2029
|
+
{
|
|
2030
|
+
ref: (node) => {
|
|
2031
|
+
textareaRef.current = node;
|
|
2032
|
+
if (typeof ref === "function") ref(node);
|
|
2033
|
+
else if (ref)
|
|
2034
|
+
ref.current = node;
|
|
2035
|
+
},
|
|
2036
|
+
value,
|
|
2037
|
+
onValueChange: commit,
|
|
2038
|
+
resize: "vertical",
|
|
2039
|
+
variant: "ghost",
|
|
2040
|
+
className: "rounded-none border-0",
|
|
2041
|
+
...textareaProps
|
|
2042
|
+
}
|
|
2043
|
+
)
|
|
2044
|
+
}
|
|
2045
|
+
),
|
|
2046
|
+
/* @__PURE__ */ jsx(
|
|
2047
|
+
"div",
|
|
2048
|
+
{
|
|
2049
|
+
id: previewPanelId,
|
|
2050
|
+
role: "tabpanel",
|
|
2051
|
+
"aria-labelledby": `${baseId}-preview-tab`,
|
|
2052
|
+
hidden: tab !== "preview",
|
|
2053
|
+
className: "min-h-32 p-3 text-sm text-text",
|
|
2054
|
+
children: renderMarkdown ? renderedPreview : /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: "No renderMarkdown provided \u2014 showing raw text." })
|
|
2055
|
+
}
|
|
2056
|
+
),
|
|
2057
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 border-t border-border px-3 py-2 text-xs text-text-muted", children: hint })
|
|
2058
|
+
]
|
|
2059
|
+
}
|
|
2060
|
+
);
|
|
2061
|
+
}
|
|
2062
|
+
);
|
|
2063
|
+
MarkdownEditor.displayName = "MarkdownEditor";
|
|
2064
|
+
var Textarea = forwardRef(
|
|
2065
|
+
({ allowMarkdown, ...props }, ref) => {
|
|
2066
|
+
if (allowMarkdown) {
|
|
2067
|
+
return /* @__PURE__ */ jsx(MarkdownEditor, { ref, ...props });
|
|
2068
|
+
}
|
|
2069
|
+
return /* @__PURE__ */ jsx(TextareaCore, { ref, ...props });
|
|
2070
|
+
}
|
|
2071
|
+
);
|
|
2072
|
+
Textarea.displayName = "Textarea";
|
|
2073
|
+
var checkboxBoxVariants = cva(
|
|
2074
|
+
"flex shrink-0 items-center justify-center rounded-[calc(var(--kui-radii-md)-2px)] border transition-colors duration-[var(--kui-duration-fast)]",
|
|
2075
|
+
{
|
|
2076
|
+
variants: {
|
|
2077
|
+
size: {
|
|
2078
|
+
sm: "h-4 w-4",
|
|
2079
|
+
md: "h-5 w-5",
|
|
2080
|
+
lg: "h-6 w-6"
|
|
2081
|
+
},
|
|
2082
|
+
state: {
|
|
2083
|
+
none: "",
|
|
2084
|
+
error: "border-danger",
|
|
2085
|
+
success: "border-success"
|
|
2086
|
+
},
|
|
2087
|
+
checked: {
|
|
2088
|
+
true: "bg-brand border-brand text-brand-fg",
|
|
2089
|
+
false: "border-border bg-transparent"
|
|
2090
|
+
},
|
|
2091
|
+
disabled: {
|
|
2092
|
+
true: "cursor-not-allowed",
|
|
2093
|
+
false: "cursor-pointer"
|
|
2094
|
+
}
|
|
2095
|
+
},
|
|
2096
|
+
defaultVariants: {
|
|
2097
|
+
size: "md",
|
|
2098
|
+
state: "none",
|
|
2099
|
+
checked: false,
|
|
2100
|
+
disabled: false
|
|
2101
|
+
},
|
|
2102
|
+
compoundVariants: [
|
|
2103
|
+
{ checked: false, state: "error", class: "border-danger" },
|
|
2104
|
+
{ checked: false, state: "success", class: "border-success" }
|
|
2105
|
+
]
|
|
2106
|
+
}
|
|
2107
|
+
);
|
|
2108
|
+
var checkboxIconSizes = {
|
|
2109
|
+
sm: 10,
|
|
2110
|
+
md: 12,
|
|
2111
|
+
lg: 14
|
|
2112
|
+
};
|
|
2113
|
+
function DashIcon({ size }) {
|
|
2114
|
+
return /* @__PURE__ */ jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("line", { x1: "5", y1: "12", x2: "19", y2: "12" }) });
|
|
2115
|
+
}
|
|
2116
|
+
__name(DashIcon, "DashIcon");
|
|
2117
|
+
function mergeRefs3(...refs) {
|
|
2118
|
+
return (node) => {
|
|
2119
|
+
refs.forEach((r) => {
|
|
2120
|
+
if (!r) return;
|
|
2121
|
+
if (typeof r === "function") r(node);
|
|
2122
|
+
else r.current = node;
|
|
2123
|
+
});
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
2126
|
+
__name(mergeRefs3, "mergeRefs");
|
|
2127
|
+
var Checkbox = forwardRef(
|
|
2128
|
+
({
|
|
2129
|
+
className,
|
|
2130
|
+
checked: checkedProp,
|
|
2131
|
+
defaultChecked,
|
|
2132
|
+
onCheckedChange,
|
|
2133
|
+
indeterminate = false,
|
|
2134
|
+
size = "md",
|
|
2135
|
+
error,
|
|
2136
|
+
success,
|
|
2137
|
+
disabled,
|
|
2138
|
+
label,
|
|
2139
|
+
description,
|
|
2140
|
+
id: externalId,
|
|
2141
|
+
onChange: onChangeProp,
|
|
2142
|
+
required,
|
|
2143
|
+
...props
|
|
2144
|
+
}, ref) => {
|
|
2145
|
+
const autoId = useId();
|
|
2146
|
+
const field = useOptionalFormField();
|
|
2147
|
+
const id = field?.id ?? externalId ?? autoId;
|
|
2148
|
+
const internalRef = useRef(null);
|
|
2149
|
+
const [internalChecked, setInternalChecked] = useState(
|
|
2150
|
+
defaultChecked ?? false
|
|
2151
|
+
);
|
|
2152
|
+
const checked = checkedProp !== void 0 ? checkedProp : internalChecked;
|
|
2153
|
+
const hasWarned = useRef(false);
|
|
2154
|
+
useEffect(() => {
|
|
2155
|
+
if (process.env?.NODE_ENV === "production") return;
|
|
2156
|
+
if (hasWarned.current) return;
|
|
2157
|
+
if (label && field?.hasExternalLabel) {
|
|
2158
|
+
console.warn(
|
|
2159
|
+
"[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor. That renders two <label> elements pointing at the same input, which double-announces in screen readers. Use Checkbox's `label` prop instead of <FormField.Label> when the control is a checkbox."
|
|
2160
|
+
);
|
|
2161
|
+
hasWarned.current = true;
|
|
2162
|
+
}
|
|
2163
|
+
}, [label, field?.hasExternalLabel]);
|
|
2164
|
+
useEffect(() => {
|
|
2165
|
+
if (internalRef.current)
|
|
2166
|
+
internalRef.current.indeterminate = indeterminate;
|
|
2167
|
+
}, [indeterminate]);
|
|
2168
|
+
const isInvalid = error ?? field?.invalid ?? false;
|
|
2169
|
+
const isSuccess = success ?? false;
|
|
2170
|
+
const state = isInvalid ? "error" : isSuccess ? "success" : "none";
|
|
2171
|
+
function handleChange(e) {
|
|
2172
|
+
const next = e.target.checked;
|
|
2173
|
+
if (checkedProp === void 0) setInternalChecked(next);
|
|
2174
|
+
onCheckedChange?.(next);
|
|
2175
|
+
onChangeProp?.(e);
|
|
2176
|
+
}
|
|
2177
|
+
__name(handleChange, "handleChange");
|
|
2178
|
+
const descriptionId = description ? `${id}-description` : void 0;
|
|
2179
|
+
const describedBy = field?.describedBy ?? descriptionId;
|
|
2180
|
+
return /* @__PURE__ */ jsxs(
|
|
2181
|
+
"div",
|
|
2182
|
+
{
|
|
2183
|
+
className: cn(
|
|
2184
|
+
"flex gap-2.5",
|
|
2185
|
+
disabled && "cursor-not-allowed opacity-50",
|
|
2186
|
+
className
|
|
2187
|
+
),
|
|
2188
|
+
children: [
|
|
2189
|
+
/* @__PURE__ */ jsxs("div", { className: "relative mt-0.5 inline-flex", children: [
|
|
2190
|
+
/* @__PURE__ */ jsx(
|
|
2191
|
+
"input",
|
|
2192
|
+
{
|
|
2193
|
+
ref: mergeRefs3(internalRef, ref),
|
|
2194
|
+
type: "checkbox",
|
|
2195
|
+
id,
|
|
2196
|
+
checked,
|
|
2197
|
+
disabled,
|
|
2198
|
+
required: required ?? field?.required,
|
|
2199
|
+
onChange: handleChange,
|
|
2200
|
+
"aria-invalid": isInvalid || void 0,
|
|
2201
|
+
"aria-describedby": describedBy,
|
|
2202
|
+
className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
|
|
2203
|
+
"data-invalid": isInvalid || void 0,
|
|
2204
|
+
...props
|
|
2205
|
+
}
|
|
2206
|
+
),
|
|
2207
|
+
/* @__PURE__ */ jsx(
|
|
2208
|
+
"div",
|
|
2209
|
+
{
|
|
2210
|
+
"aria-hidden": "true",
|
|
2211
|
+
className: cn(
|
|
2212
|
+
checkboxBoxVariants({
|
|
2213
|
+
size,
|
|
2214
|
+
state,
|
|
2215
|
+
checked: checked || indeterminate,
|
|
2216
|
+
disabled: !!disabled
|
|
2217
|
+
}),
|
|
2218
|
+
"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
|
|
2219
|
+
),
|
|
2220
|
+
children: indeterminate ? /* @__PURE__ */ jsx(DashIcon, { size: checkboxIconSizes[size] }) : checked ? /* @__PURE__ */ jsx(Check, { size: checkboxIconSizes[size] }) : null
|
|
2221
|
+
}
|
|
2222
|
+
)
|
|
2223
|
+
] }),
|
|
2224
|
+
(label || description) && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
2225
|
+
label && /* @__PURE__ */ jsx(
|
|
2226
|
+
"label",
|
|
2227
|
+
{
|
|
2228
|
+
htmlFor: id,
|
|
2229
|
+
className: cn(
|
|
2230
|
+
"text-sm text-text",
|
|
2231
|
+
!disabled && "cursor-pointer"
|
|
2232
|
+
),
|
|
2233
|
+
children: label
|
|
2234
|
+
}
|
|
2235
|
+
),
|
|
2236
|
+
description && /* @__PURE__ */ jsx("p", { id: descriptionId, className: "text-xs text-text-muted", children: description })
|
|
2237
|
+
] })
|
|
2238
|
+
]
|
|
2239
|
+
}
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
);
|
|
2243
|
+
Checkbox.displayName = "Checkbox";
|
|
2244
|
+
var RadioGroupContext = createContext(null);
|
|
2245
|
+
function useRadioGroupContext() {
|
|
2246
|
+
const ctx = useContext(RadioGroupContext);
|
|
2247
|
+
if (!ctx) {
|
|
2248
|
+
throw new Error("<Radio /> must be rendered inside <RadioGroup>.");
|
|
2249
|
+
}
|
|
2250
|
+
return ctx;
|
|
2251
|
+
}
|
|
2252
|
+
__name(useRadioGroupContext, "useRadioGroupContext");
|
|
2253
|
+
function RadioGroup({
|
|
2254
|
+
value: valueProp,
|
|
2255
|
+
defaultValue,
|
|
2256
|
+
onValueChange,
|
|
2257
|
+
name: nameProp,
|
|
2258
|
+
disabled = false,
|
|
2259
|
+
required = false,
|
|
2260
|
+
orientation = "vertical",
|
|
2261
|
+
size = "md",
|
|
2262
|
+
error,
|
|
2263
|
+
success,
|
|
2264
|
+
className,
|
|
2265
|
+
children
|
|
2266
|
+
}) {
|
|
2267
|
+
const autoName = useId();
|
|
2268
|
+
const name = nameProp ?? autoName;
|
|
2269
|
+
const field = useOptionalFormField();
|
|
2270
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
2271
|
+
const value = valueProp !== void 0 ? valueProp : internalValue;
|
|
2272
|
+
const handleValueChange = useCallback(
|
|
2273
|
+
(next) => {
|
|
2274
|
+
if (valueProp === void 0) setInternalValue(next);
|
|
2275
|
+
onValueChange?.(next);
|
|
2276
|
+
},
|
|
2277
|
+
[valueProp, onValueChange]
|
|
2278
|
+
);
|
|
2279
|
+
const isInvalid = error ?? field?.invalid ?? false;
|
|
2280
|
+
const isSuccess = success ?? false;
|
|
2281
|
+
const state = isInvalid ? "error" : isSuccess ? "success" : "none";
|
|
2282
|
+
const groupRequired = required || !!field?.required;
|
|
2283
|
+
return /* @__PURE__ */ jsx(
|
|
2284
|
+
RadioGroupContext.Provider,
|
|
2285
|
+
{
|
|
2286
|
+
value: { name, value, onValueChange: handleValueChange, disabled, size, state, groupRequired },
|
|
2287
|
+
children: /* @__PURE__ */ jsx(
|
|
2288
|
+
"div",
|
|
2289
|
+
{
|
|
2290
|
+
role: "radiogroup",
|
|
2291
|
+
"aria-labelledby": field?.hasExternalLabel ? `${field.id}-label` : void 0,
|
|
2292
|
+
"aria-describedby": field?.describedBy,
|
|
2293
|
+
"aria-required": groupRequired || void 0,
|
|
2294
|
+
"aria-invalid": isInvalid || void 0,
|
|
2295
|
+
className: cn(
|
|
2296
|
+
"flex gap-3",
|
|
2297
|
+
orientation === "horizontal" ? "flex-row flex-wrap" : "flex-col",
|
|
2298
|
+
className
|
|
2299
|
+
),
|
|
2300
|
+
children
|
|
2301
|
+
}
|
|
2302
|
+
)
|
|
2303
|
+
}
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
__name(RadioGroup, "RadioGroup");
|
|
2307
|
+
var radioBubbleVariants = cva(
|
|
2308
|
+
"flex shrink-0 items-center justify-center rounded-full border transition-colors duration-[var(--kui-duration-fast)]",
|
|
2309
|
+
{
|
|
2310
|
+
variants: {
|
|
2311
|
+
size: {
|
|
2312
|
+
sm: "h-4 w-4",
|
|
2313
|
+
md: "h-5 w-5",
|
|
2314
|
+
lg: "h-6 w-6"
|
|
2315
|
+
},
|
|
2316
|
+
state: {
|
|
2317
|
+
none: "",
|
|
2318
|
+
error: "border-danger",
|
|
2319
|
+
success: "border-success"
|
|
2320
|
+
},
|
|
2321
|
+
checked: {
|
|
2322
|
+
true: "border-brand",
|
|
2323
|
+
false: "border-border bg-transparent"
|
|
2324
|
+
},
|
|
2325
|
+
disabled: {
|
|
2326
|
+
true: "cursor-not-allowed",
|
|
2327
|
+
false: "cursor-pointer"
|
|
2328
|
+
}
|
|
2329
|
+
},
|
|
2330
|
+
defaultVariants: { size: "md", state: "none", checked: false, disabled: false },
|
|
2331
|
+
compoundVariants: [
|
|
2332
|
+
{ checked: false, state: "error", class: "border-danger" },
|
|
2333
|
+
{ checked: false, state: "success", class: "border-success" }
|
|
2334
|
+
]
|
|
2335
|
+
}
|
|
2336
|
+
);
|
|
2337
|
+
var radioDotSizes = {
|
|
2338
|
+
sm: "h-1.5 w-1.5",
|
|
2339
|
+
md: "h-2 w-2",
|
|
2340
|
+
lg: "h-2.5 w-2.5"
|
|
2341
|
+
};
|
|
2342
|
+
function Radio({
|
|
2343
|
+
value,
|
|
2344
|
+
disabled: itemDisabled,
|
|
2345
|
+
label,
|
|
2346
|
+
description,
|
|
2347
|
+
className,
|
|
2348
|
+
...props
|
|
2349
|
+
}) {
|
|
2350
|
+
const group = useRadioGroupContext();
|
|
2351
|
+
const id = `${group.name}-${value}`;
|
|
2352
|
+
const checked = group.value === value;
|
|
2353
|
+
const disabled = itemDisabled || group.disabled;
|
|
2354
|
+
const descriptionId = description ? `${id}-description` : void 0;
|
|
2355
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex gap-2.5", disabled && "cursor-not-allowed opacity-50", className), children: [
|
|
2356
|
+
/* @__PURE__ */ jsxs("div", { className: "relative mt-0.5 inline-flex", children: [
|
|
2357
|
+
/* @__PURE__ */ jsx(
|
|
2358
|
+
"input",
|
|
2359
|
+
{
|
|
2360
|
+
type: "radio",
|
|
2361
|
+
id,
|
|
2362
|
+
name: group.name,
|
|
2363
|
+
value,
|
|
2364
|
+
checked,
|
|
2365
|
+
disabled,
|
|
2366
|
+
onChange: () => group.onValueChange(value),
|
|
2367
|
+
"aria-describedby": descriptionId,
|
|
2368
|
+
className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
|
|
2369
|
+
"data-invalid": group.state === "error" || void 0,
|
|
2370
|
+
...props
|
|
2371
|
+
}
|
|
2372
|
+
),
|
|
2373
|
+
/* @__PURE__ */ jsx(
|
|
2374
|
+
"div",
|
|
2375
|
+
{
|
|
2376
|
+
"aria-hidden": "true",
|
|
2377
|
+
className: cn(
|
|
2378
|
+
radioBubbleVariants({ size: group.size, state: group.state, checked, disabled }),
|
|
2379
|
+
"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
|
|
2380
|
+
),
|
|
2381
|
+
children: checked && /* @__PURE__ */ jsx("div", { className: cn("rounded-full bg-brand", radioDotSizes[group.size]) })
|
|
2382
|
+
}
|
|
2383
|
+
)
|
|
2384
|
+
] }),
|
|
2385
|
+
(label || description) && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
2386
|
+
label && /* @__PURE__ */ jsx("label", { htmlFor: id, className: cn("text-sm text-text", !disabled && "cursor-pointer", group.size === "sm" && "text-xs"), children: label }),
|
|
2387
|
+
description && /* @__PURE__ */ jsx("p", { id: descriptionId, className: cn("text-xs text-text-muted", group.size === "sm" && "text-[10px]"), children: description })
|
|
2388
|
+
] })
|
|
2389
|
+
] });
|
|
2390
|
+
}
|
|
2391
|
+
__name(Radio, "Radio");
|
|
2392
|
+
var switchTrackVariants = cva(
|
|
2393
|
+
"relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-colors duration-[var(--kui-duration-fast)]",
|
|
2394
|
+
{
|
|
2395
|
+
variants: {
|
|
2396
|
+
size: {
|
|
2397
|
+
sm: "h-4 w-7",
|
|
2398
|
+
md: "h-5 w-9",
|
|
2399
|
+
lg: "h-6 w-11"
|
|
2400
|
+
},
|
|
2401
|
+
checked: {
|
|
2402
|
+
true: "bg-brand",
|
|
2403
|
+
false: "bg-surface-raised"
|
|
2404
|
+
},
|
|
2405
|
+
disabled: {
|
|
2406
|
+
true: "cursor-not-allowed",
|
|
2407
|
+
false: "cursor-pointer"
|
|
2408
|
+
}
|
|
2409
|
+
},
|
|
2410
|
+
defaultVariants: { size: "md", checked: false, disabled: false }
|
|
2411
|
+
}
|
|
2412
|
+
);
|
|
2413
|
+
var switchThumbConfig = {
|
|
2414
|
+
sm: { thumb: "h-3 w-3", translate: "translate-x-3" },
|
|
2415
|
+
md: { thumb: "h-4 w-4", translate: "translate-x-4" },
|
|
2416
|
+
lg: { thumb: "h-5 w-5", translate: "translate-x-5" }
|
|
2417
|
+
};
|
|
2418
|
+
function Switch({
|
|
2419
|
+
checked: checkedProp,
|
|
2420
|
+
defaultChecked,
|
|
2421
|
+
onCheckedChange,
|
|
2422
|
+
size = "md",
|
|
2423
|
+
disabled,
|
|
2424
|
+
label,
|
|
2425
|
+
description,
|
|
2426
|
+
className,
|
|
2427
|
+
id: externalId,
|
|
2428
|
+
onChange: onChangeProp,
|
|
2429
|
+
...props
|
|
2430
|
+
}) {
|
|
2431
|
+
const autoId = useId();
|
|
2432
|
+
const field = useOptionalFormField();
|
|
2433
|
+
const id = field?.id ?? externalId ?? autoId;
|
|
2434
|
+
const [internalChecked, setInternalChecked] = useState(defaultChecked ?? false);
|
|
2435
|
+
const checked = checkedProp !== void 0 ? checkedProp : internalChecked;
|
|
2436
|
+
function handleChange(e) {
|
|
2437
|
+
const next = e.target.checked;
|
|
2438
|
+
if (checkedProp === void 0) setInternalChecked(next);
|
|
2439
|
+
onCheckedChange?.(next);
|
|
2440
|
+
onChangeProp?.(e);
|
|
2441
|
+
}
|
|
2442
|
+
__name(handleChange, "handleChange");
|
|
2443
|
+
const descriptionId = description ? `${id}-description` : void 0;
|
|
2444
|
+
const { thumb, translate } = switchThumbConfig[size];
|
|
2445
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex gap-2.5", disabled && "cursor-not-allowed opacity-50", className), children: [
|
|
2446
|
+
/* @__PURE__ */ jsxs("div", { className: "relative inline-flex", children: [
|
|
2447
|
+
/* @__PURE__ */ jsx(
|
|
2448
|
+
"input",
|
|
2449
|
+
{
|
|
2450
|
+
type: "checkbox",
|
|
2451
|
+
role: "switch",
|
|
2452
|
+
id,
|
|
2453
|
+
checked,
|
|
2454
|
+
disabled,
|
|
2455
|
+
onChange: handleChange,
|
|
2456
|
+
"aria-describedby": field?.describedBy ?? descriptionId,
|
|
2457
|
+
className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
|
|
2458
|
+
...props
|
|
2459
|
+
}
|
|
2460
|
+
),
|
|
2461
|
+
/* @__PURE__ */ jsx(
|
|
2462
|
+
"div",
|
|
2463
|
+
{
|
|
2464
|
+
"aria-hidden": "true",
|
|
2465
|
+
className: cn(
|
|
2466
|
+
switchTrackVariants({ size, checked, disabled: !!disabled }),
|
|
2467
|
+
"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
|
|
2468
|
+
),
|
|
2469
|
+
children: /* @__PURE__ */ jsx(
|
|
2470
|
+
"div",
|
|
2471
|
+
{
|
|
2472
|
+
className: cn(
|
|
2473
|
+
"absolute left-0.5 rounded-full bg-white shadow transition-transform duration-[var(--kui-duration-fast)]",
|
|
2474
|
+
thumb,
|
|
2475
|
+
checked && translate
|
|
2476
|
+
)
|
|
2477
|
+
}
|
|
2478
|
+
)
|
|
2479
|
+
}
|
|
2480
|
+
)
|
|
2481
|
+
] }),
|
|
2482
|
+
(label || description) && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
2483
|
+
label && /* @__PURE__ */ jsx("label", { htmlFor: id, className: cn("text-sm text-text", !disabled && "cursor-pointer"), children: label }),
|
|
2484
|
+
description && /* @__PURE__ */ jsx("p", { id: descriptionId, className: "text-xs text-text-muted", children: description })
|
|
2485
|
+
] })
|
|
2486
|
+
] });
|
|
2487
|
+
}
|
|
2488
|
+
__name(Switch, "Switch");
|
|
2489
|
+
var ComboboxContext = createContext(null);
|
|
2490
|
+
function useComboboxContext(componentName) {
|
|
2491
|
+
const ctx = useContext(ComboboxContext);
|
|
2492
|
+
if (!ctx) throw new Error(`<${componentName} /> must be rendered inside <Combobox>.`);
|
|
2493
|
+
return ctx;
|
|
2494
|
+
}
|
|
2495
|
+
__name(useComboboxContext, "useComboboxContext");
|
|
2496
|
+
var inputBase2 = [
|
|
2497
|
+
"flex",
|
|
2498
|
+
"items-center",
|
|
2499
|
+
"font-sans",
|
|
2500
|
+
"transition-colors",
|
|
2501
|
+
"duration-[var(--kui-duration-fast)]",
|
|
2502
|
+
"outline-none",
|
|
2503
|
+
"placeholder:text-text-muted",
|
|
2504
|
+
"disabled:opacity-50",
|
|
2505
|
+
"disabled:pointer-events-none",
|
|
2506
|
+
"disabled:cursor-not-allowed"
|
|
2507
|
+
].join(" ");
|
|
2508
|
+
var inputWrapperVariants = cva(
|
|
2509
|
+
"group relative inline-flex items-center gap-2 transition-colors",
|
|
2510
|
+
{
|
|
2511
|
+
variants: {
|
|
2512
|
+
variant: {
|
|
2513
|
+
outline: "border border-border bg-transparent text-text hover:border-brand",
|
|
2514
|
+
filled: "border border-transparent bg-surface-raised text-text hover:bg-surface",
|
|
2515
|
+
ghost: "border border-transparent bg-transparent text-text hover:bg-surface-raised"
|
|
2516
|
+
},
|
|
2517
|
+
state: {
|
|
2518
|
+
none: "focus-within:ring-2 focus-within:ring-brand/20",
|
|
2519
|
+
error: "border-danger focus-within:ring-2 focus-within:ring-danger/20",
|
|
2520
|
+
success: "border-success focus-within:ring-2 focus-within:ring-success/20"
|
|
2521
|
+
},
|
|
2522
|
+
rounded: {
|
|
2523
|
+
true: "rounded-full",
|
|
2524
|
+
false: "rounded-[var(--kui-radii-md)]"
|
|
2525
|
+
},
|
|
2526
|
+
fullWidth: {
|
|
2527
|
+
true: "w-full",
|
|
2528
|
+
false: ""
|
|
2529
|
+
},
|
|
2530
|
+
hasIcon: {
|
|
2531
|
+
true: "px-2",
|
|
2532
|
+
false: ""
|
|
2533
|
+
},
|
|
2534
|
+
disabled: {
|
|
2535
|
+
true: "pointer-events-none cursor-not-allowed opacity-50",
|
|
2536
|
+
false: ""
|
|
2537
|
+
}
|
|
2538
|
+
},
|
|
2539
|
+
defaultVariants: {
|
|
2540
|
+
variant: "outline",
|
|
2541
|
+
state: "none",
|
|
2542
|
+
rounded: false,
|
|
2543
|
+
fullWidth: true,
|
|
2544
|
+
hasIcon: false,
|
|
2545
|
+
disabled: false
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
);
|
|
2549
|
+
var inputSizeVariants = {
|
|
2550
|
+
sm: "h-8 px-2 text-xs",
|
|
2551
|
+
md: "h-10 px-3 text-sm",
|
|
2552
|
+
lg: "h-12 px-4 text-base"
|
|
2553
|
+
};
|
|
2554
|
+
function orderedFilteredValues(ctx, query) {
|
|
2555
|
+
const q = query.trim().toLowerCase();
|
|
2556
|
+
return [...ctx.items.entries()].filter(([, meta]) => !meta.disabled).filter(([, meta]) => !q || String(meta.label).toLowerCase().includes(q)).map(([val]) => val);
|
|
2557
|
+
}
|
|
2558
|
+
__name(orderedFilteredValues, "orderedFilteredValues");
|
|
2559
|
+
var ComboboxInput = forwardRef(
|
|
2560
|
+
({ variant = "outline", size = "md", placeholder, clearable = false, allowFreeText = false, className }, ref) => {
|
|
2561
|
+
const ctx = useComboboxContext("ComboboxInput");
|
|
2562
|
+
const state = ctx.isInvalid ? "error" : ctx.isSuccess ? "success" : "none";
|
|
2563
|
+
const showClear = clearable && ctx.inputValue.length > 0 && !ctx.disabled;
|
|
2564
|
+
useEffect(() => {
|
|
2565
|
+
console.log(ctx);
|
|
2566
|
+
if (ctx.value === void 0) return;
|
|
2567
|
+
const meta = ctx.items.get(ctx.value);
|
|
2568
|
+
if (meta && !ctx.open) {
|
|
2569
|
+
ctx.setInputValue(String(meta.label));
|
|
2570
|
+
}
|
|
2571
|
+
}, [ctx.value, ctx.open, ctx.items]);
|
|
2572
|
+
function handleChange(e) {
|
|
2573
|
+
ctx.setInputValue(e.target.value);
|
|
2574
|
+
if (!ctx.open) ctx.setOpen(true);
|
|
2575
|
+
ctx.setActiveValue(void 0);
|
|
2576
|
+
if (allowFreeText) ctx.onValueChange(e.target.value || void 0);
|
|
2577
|
+
}
|
|
2578
|
+
__name(handleChange, "handleChange");
|
|
2579
|
+
function handleKeyDown(e) {
|
|
2580
|
+
const order = orderedFilteredValues(ctx, ctx.inputValue);
|
|
2581
|
+
switch (e.key) {
|
|
2582
|
+
case "ArrowDown": {
|
|
2583
|
+
e.preventDefault();
|
|
2584
|
+
if (!ctx.open) {
|
|
2585
|
+
ctx.setOpen(true);
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
const i = ctx.activeValue ? order.indexOf(ctx.activeValue) : -1;
|
|
2589
|
+
ctx.setActiveValue(order[(i + 1) % order.length]);
|
|
2590
|
+
break;
|
|
2591
|
+
}
|
|
2592
|
+
case "ArrowUp": {
|
|
2593
|
+
e.preventDefault();
|
|
2594
|
+
if (!ctx.open) {
|
|
2595
|
+
ctx.setOpen(true);
|
|
2596
|
+
return;
|
|
2597
|
+
}
|
|
2598
|
+
const i = ctx.activeValue ? order.indexOf(ctx.activeValue) : -1;
|
|
2599
|
+
ctx.setActiveValue(order[(i - 1 + order.length) % order.length]);
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2602
|
+
case "Enter":
|
|
2603
|
+
e.preventDefault();
|
|
2604
|
+
if (ctx.activeValue !== void 0) ctx.onValueChange(ctx.activeValue);
|
|
2605
|
+
else if (allowFreeText) ctx.setOpen(false);
|
|
2606
|
+
break;
|
|
2607
|
+
case "Escape":
|
|
2608
|
+
if (ctx.open) {
|
|
2609
|
+
e.preventDefault();
|
|
2610
|
+
ctx.setOpen(false);
|
|
2611
|
+
}
|
|
2612
|
+
break;
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
__name(handleKeyDown, "handleKeyDown");
|
|
2616
|
+
function handleBlur() {
|
|
2617
|
+
if (!allowFreeText && ctx.value === void 0) ctx.setInputValue("");
|
|
2618
|
+
setTimeout(() => ctx.setOpen(false), 120);
|
|
2619
|
+
}
|
|
2620
|
+
__name(handleBlur, "handleBlur");
|
|
2621
|
+
return /* @__PURE__ */ jsxs(
|
|
2622
|
+
"div",
|
|
2623
|
+
{
|
|
2624
|
+
className: cn(
|
|
2625
|
+
inputWrapperVariants({ variant, state, fullWidth: true, disabled: ctx.disabled, rounded: ctx.rounded }),
|
|
2626
|
+
"px-2",
|
|
2627
|
+
className
|
|
2628
|
+
),
|
|
2629
|
+
children: [
|
|
2630
|
+
/* @__PURE__ */ jsx(
|
|
2631
|
+
"input",
|
|
2632
|
+
{
|
|
2633
|
+
ref: (node) => {
|
|
2634
|
+
ctx.triggerRef.current = node;
|
|
2635
|
+
if (typeof ref === "function") ref(node);
|
|
2636
|
+
else if (ref) ref.current = node;
|
|
2637
|
+
},
|
|
2638
|
+
id: ctx.triggerId,
|
|
2639
|
+
role: "combobox",
|
|
2640
|
+
"aria-autocomplete": "list",
|
|
2641
|
+
"aria-haspopup": "listbox",
|
|
2642
|
+
"aria-expanded": ctx.open,
|
|
2643
|
+
"aria-controls": ctx.contentId,
|
|
2644
|
+
"aria-activedescendant": ctx.open && ctx.activeValue ? ctx.optionId(ctx.activeValue) : void 0,
|
|
2645
|
+
"aria-invalid": ctx.isInvalid || void 0,
|
|
2646
|
+
"aria-describedby": ctx.describedBy,
|
|
2647
|
+
disabled: ctx.disabled,
|
|
2648
|
+
value: ctx.inputValue,
|
|
2649
|
+
placeholder,
|
|
2650
|
+
onChange: handleChange,
|
|
2651
|
+
onFocus: () => ctx.setOpen(true),
|
|
2652
|
+
onKeyDown: handleKeyDown,
|
|
2653
|
+
onBlur: handleBlur,
|
|
2654
|
+
"data-state": ctx.open ? "open" : "closed",
|
|
2655
|
+
className: cn(inputBase2, "flex-1 border-0 bg-transparent outline-none", inputSizeVariants[size], "px-0")
|
|
2656
|
+
}
|
|
2657
|
+
),
|
|
2658
|
+
showClear && /* @__PURE__ */ jsx(
|
|
2659
|
+
"button",
|
|
2660
|
+
{
|
|
2661
|
+
type: "button",
|
|
2662
|
+
tabIndex: -1,
|
|
2663
|
+
"aria-label": "Clear",
|
|
2664
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2665
|
+
onClick: () => {
|
|
2666
|
+
ctx.setInputValue("");
|
|
2667
|
+
ctx.onValueChange(void 0);
|
|
2668
|
+
},
|
|
2669
|
+
className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
|
|
2670
|
+
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
2671
|
+
}
|
|
2672
|
+
)
|
|
2673
|
+
]
|
|
2674
|
+
}
|
|
2675
|
+
);
|
|
2676
|
+
}
|
|
2677
|
+
);
|
|
2678
|
+
ComboboxInput.displayName = "ComboboxInput";
|
|
2679
|
+
function ComboboxItem({
|
|
2680
|
+
value,
|
|
2681
|
+
disabled = false,
|
|
2682
|
+
children,
|
|
2683
|
+
className
|
|
2684
|
+
}) {
|
|
2685
|
+
const ctx = useComboboxContext("ComboboxItem");
|
|
2686
|
+
const ref = useRef(null);
|
|
2687
|
+
const active = ctx.activeValue === value;
|
|
2688
|
+
const selected = ctx.value === value;
|
|
2689
|
+
useEffect(
|
|
2690
|
+
() => ctx.registerItem(value, { label: children, disabled, visible: true }),
|
|
2691
|
+
[value, disabled, children]
|
|
2692
|
+
);
|
|
2693
|
+
useEffect(() => {
|
|
2694
|
+
if (active) ref.current?.scrollIntoView({ block: "nearest" });
|
|
2695
|
+
}, [active]);
|
|
2696
|
+
const query = ctx.inputValue.trim().toLowerCase();
|
|
2697
|
+
const matches = !query || String(children).toLowerCase().includes(query);
|
|
2698
|
+
useEffect(() => {
|
|
2699
|
+
ctx.setItemVisibility(value, matches);
|
|
2700
|
+
}, [matches, value]);
|
|
2701
|
+
if (!matches) return null;
|
|
2702
|
+
return /* @__PURE__ */ jsx(
|
|
2703
|
+
"div",
|
|
2704
|
+
{
|
|
2705
|
+
ref,
|
|
2706
|
+
id: ctx.optionId(value),
|
|
2707
|
+
role: "option",
|
|
2708
|
+
"aria-selected": selected,
|
|
2709
|
+
"aria-disabled": disabled || void 0,
|
|
2710
|
+
onMouseEnter: () => !disabled && ctx.setActiveValue(value),
|
|
2711
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2712
|
+
onClick: () => !disabled && ctx.onValueChange(value),
|
|
2713
|
+
className: cn(
|
|
2714
|
+
"flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",
|
|
2715
|
+
active && "bg-brand/15 text-brand",
|
|
2716
|
+
selected && !active && "bg-surface-raised",
|
|
2717
|
+
disabled && "pointer-events-none cursor-not-allowed opacity-50",
|
|
2718
|
+
className
|
|
2719
|
+
),
|
|
2720
|
+
children
|
|
2721
|
+
}
|
|
2722
|
+
);
|
|
2723
|
+
}
|
|
2724
|
+
__name(ComboboxItem, "ComboboxItem");
|
|
2725
|
+
var VIEWPORT_PADDING2 = 8;
|
|
2726
|
+
function useFloatingSide(triggerRef, open) {
|
|
2727
|
+
const contentRef = useRef(null);
|
|
2728
|
+
const [side, setSide] = useState("bottom");
|
|
2729
|
+
useLayoutEffect(() => {
|
|
2730
|
+
if (!open) return;
|
|
2731
|
+
const trigger = triggerRef.current;
|
|
2732
|
+
const content = contentRef.current;
|
|
2733
|
+
if (!trigger || !content) return;
|
|
2734
|
+
function measure() {
|
|
2735
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
2736
|
+
const contentHeight = content.offsetHeight;
|
|
2737
|
+
const spaceBelow = window.innerHeight - triggerRect.bottom - VIEWPORT_PADDING2;
|
|
2738
|
+
const spaceAbove = triggerRect.top - VIEWPORT_PADDING2;
|
|
2739
|
+
setSide(contentHeight > spaceBelow && spaceAbove > spaceBelow ? "top" : "bottom");
|
|
2740
|
+
}
|
|
2741
|
+
__name(measure, "measure");
|
|
2742
|
+
measure();
|
|
2743
|
+
window.addEventListener("resize", measure);
|
|
2744
|
+
window.addEventListener("scroll", measure, true);
|
|
2745
|
+
return () => {
|
|
2746
|
+
window.removeEventListener("resize", measure);
|
|
2747
|
+
window.removeEventListener("scroll", measure, true);
|
|
2748
|
+
};
|
|
2749
|
+
}, [open, triggerRef]);
|
|
2750
|
+
return { contentRef, side };
|
|
2751
|
+
}
|
|
2752
|
+
__name(useFloatingSide, "useFloatingSide");
|
|
2753
|
+
function ComboboxContent({
|
|
2754
|
+
className,
|
|
2755
|
+
children
|
|
2756
|
+
}) {
|
|
2757
|
+
const ctx = useComboboxContext("ComboboxContent");
|
|
2758
|
+
const { contentRef, side } = useFloatingSide(ctx.triggerRef, ctx.open);
|
|
2759
|
+
if (!ctx.open) return null;
|
|
2760
|
+
return /* @__PURE__ */ jsx(
|
|
2761
|
+
"div",
|
|
2762
|
+
{
|
|
2763
|
+
ref: contentRef,
|
|
2764
|
+
id: ctx.contentId,
|
|
2765
|
+
role: "listbox",
|
|
2766
|
+
"aria-labelledby": ctx.triggerId,
|
|
2767
|
+
"data-side": side,
|
|
2768
|
+
className: cn(
|
|
2769
|
+
"animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",
|
|
2770
|
+
side === "bottom" ? "top-full mt-1" : "bottom-full mb-1",
|
|
2771
|
+
className
|
|
2772
|
+
),
|
|
2773
|
+
children
|
|
2774
|
+
}
|
|
2775
|
+
);
|
|
2776
|
+
}
|
|
2777
|
+
__name(ComboboxContent, "ComboboxContent");
|
|
2778
|
+
function ComboboxEmpty({ children }) {
|
|
2779
|
+
const ctx = useComboboxContext("ComboboxEmpty");
|
|
2780
|
+
const visibleCount = [...ctx.items.values()].filter((item) => item.visible && !item.disabled).length;
|
|
2781
|
+
if (visibleCount > 0) return null;
|
|
2782
|
+
return /* @__PURE__ */ jsx("div", { className: "px-2 py-3 text-center text-sm text-text-muted", children: children ?? "No results found" });
|
|
2783
|
+
}
|
|
2784
|
+
__name(ComboboxEmpty, "ComboboxEmpty");
|
|
2785
|
+
function ComboboxLoading({
|
|
2786
|
+
children = "Loading...",
|
|
2787
|
+
className
|
|
2788
|
+
}) {
|
|
2789
|
+
return /* @__PURE__ */ jsx(
|
|
2790
|
+
"div",
|
|
2791
|
+
{
|
|
2792
|
+
role: "status",
|
|
2793
|
+
"aria-live": "polite",
|
|
2794
|
+
className: cn(
|
|
2795
|
+
"px-2 py-3 text-center text-sm text-text-muted",
|
|
2796
|
+
className
|
|
2797
|
+
),
|
|
2798
|
+
children
|
|
2799
|
+
}
|
|
2800
|
+
);
|
|
2801
|
+
}
|
|
2802
|
+
__name(ComboboxLoading, "ComboboxLoading");
|
|
2803
|
+
function Combobox({
|
|
2804
|
+
value,
|
|
2805
|
+
onValueChange,
|
|
2806
|
+
inputValue: inputValueProp,
|
|
2807
|
+
defaultInputValue = "",
|
|
2808
|
+
onInputChange,
|
|
2809
|
+
disabled = false,
|
|
2810
|
+
name,
|
|
2811
|
+
error,
|
|
2812
|
+
success,
|
|
2813
|
+
rounded,
|
|
2814
|
+
className,
|
|
2815
|
+
children
|
|
2816
|
+
}) {
|
|
2817
|
+
const autoId = useId();
|
|
2818
|
+
const field = useOptionalFormField();
|
|
2819
|
+
const triggerId = field?.id ?? autoId;
|
|
2820
|
+
const contentId = `${triggerId}-listbox`;
|
|
2821
|
+
const isInvalid = error || field?.invalid || false;
|
|
2822
|
+
const isSuccess = success && !isInvalid ? true : false;
|
|
2823
|
+
const [internalInput, setInternalInput] = useState(defaultInputValue);
|
|
2824
|
+
const inputValue = inputValueProp !== void 0 ? inputValueProp : internalInput;
|
|
2825
|
+
function setInputValue(v) {
|
|
2826
|
+
if (inputValueProp === void 0) setInternalInput(v);
|
|
2827
|
+
onInputChange?.(v);
|
|
2828
|
+
}
|
|
2829
|
+
__name(setInputValue, "setInputValue");
|
|
2830
|
+
const [open, setOpen] = useState(false);
|
|
2831
|
+
const [activeValue, setActiveValue] = useState(void 0);
|
|
2832
|
+
const itemsRef = useRef(/* @__PURE__ */ new Map());
|
|
2833
|
+
const [items, setItems] = useState(/* @__PURE__ */ new Map());
|
|
2834
|
+
const registerItem = useCallback(
|
|
2835
|
+
(value2, meta) => {
|
|
2836
|
+
const item = {
|
|
2837
|
+
...meta,
|
|
2838
|
+
visible: true
|
|
2839
|
+
};
|
|
2840
|
+
itemsRef.current.set(value2, item);
|
|
2841
|
+
setItems((prev) => {
|
|
2842
|
+
const next = new Map(prev);
|
|
2843
|
+
next.set(value2, item);
|
|
2844
|
+
return next;
|
|
2845
|
+
});
|
|
2846
|
+
return () => unregisterItem(value2);
|
|
2847
|
+
},
|
|
2848
|
+
[]
|
|
2849
|
+
);
|
|
2850
|
+
function setItemVisibility(value2, visible) {
|
|
2851
|
+
setItems((prev) => {
|
|
2852
|
+
const item2 = prev.get(value2);
|
|
2853
|
+
if (!item2 || item2.visible === visible) {
|
|
2854
|
+
return prev;
|
|
2855
|
+
}
|
|
2856
|
+
const next = new Map(prev);
|
|
2857
|
+
next.set(value2, {
|
|
2858
|
+
...item2,
|
|
2859
|
+
visible
|
|
2860
|
+
});
|
|
2861
|
+
return next;
|
|
2862
|
+
});
|
|
2863
|
+
const item = itemsRef.current.get(value2);
|
|
2864
|
+
if (item) {
|
|
2865
|
+
itemsRef.current.set(value2, {
|
|
2866
|
+
...item,
|
|
2867
|
+
visible
|
|
2868
|
+
});
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
__name(setItemVisibility, "setItemVisibility");
|
|
2872
|
+
function unregisterItem(value2) {
|
|
2873
|
+
setItems((prev) => {
|
|
2874
|
+
if (!prev.has(value2)) return prev;
|
|
2875
|
+
const next = new Map(prev);
|
|
2876
|
+
next.delete(value2);
|
|
2877
|
+
return next;
|
|
2878
|
+
});
|
|
2879
|
+
itemsRef.current.delete(value2);
|
|
2880
|
+
}
|
|
2881
|
+
__name(unregisterItem, "unregisterItem");
|
|
2882
|
+
const triggerRef = useRef(null);
|
|
2883
|
+
const rootRef = useRef(null);
|
|
2884
|
+
useEffect(() => {
|
|
2885
|
+
if (!open) return;
|
|
2886
|
+
function handlePointerDown(e) {
|
|
2887
|
+
if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
|
|
2888
|
+
}
|
|
2889
|
+
__name(handlePointerDown, "handlePointerDown");
|
|
2890
|
+
document.addEventListener("mousedown", handlePointerDown);
|
|
2891
|
+
return () => document.removeEventListener("mousedown", handlePointerDown);
|
|
2892
|
+
}, [open]);
|
|
2893
|
+
const optionId = useCallback((val) => `${contentId}-option-${val}`, [contentId]);
|
|
2894
|
+
useEffect(() => {
|
|
2895
|
+
if (!value) {
|
|
2896
|
+
setInputValue("");
|
|
2897
|
+
return;
|
|
2898
|
+
}
|
|
2899
|
+
const item = itemsRef.current.get(value);
|
|
2900
|
+
if (item && !open) {
|
|
2901
|
+
setInputValue(String(item.label));
|
|
2902
|
+
}
|
|
2903
|
+
}, [value, open]);
|
|
2904
|
+
const ctxValue = useMemo(
|
|
2905
|
+
() => ({
|
|
2906
|
+
value,
|
|
2907
|
+
inputValue,
|
|
2908
|
+
setInputValue,
|
|
2909
|
+
onValueChange: /* @__PURE__ */ __name((v) => {
|
|
2910
|
+
onValueChange?.(v);
|
|
2911
|
+
const item = v ? itemsRef.current.get(v) : void 0;
|
|
2912
|
+
if (item) {
|
|
2913
|
+
setInputValue(String(item.label));
|
|
2914
|
+
}
|
|
2915
|
+
setOpen(false);
|
|
2916
|
+
}, "onValueChange"),
|
|
2917
|
+
disabled,
|
|
2918
|
+
open,
|
|
2919
|
+
setOpen,
|
|
2920
|
+
triggerId,
|
|
2921
|
+
contentId,
|
|
2922
|
+
triggerRef,
|
|
2923
|
+
isInvalid,
|
|
2924
|
+
isSuccess,
|
|
2925
|
+
describedBy: field?.describedBy,
|
|
2926
|
+
activeValue,
|
|
2927
|
+
setActiveValue,
|
|
2928
|
+
items,
|
|
2929
|
+
registerItem,
|
|
2930
|
+
rounded,
|
|
2931
|
+
optionId,
|
|
2932
|
+
setItemVisibility,
|
|
2933
|
+
unregisterItem
|
|
2934
|
+
}),
|
|
2935
|
+
[value, inputValue, onValueChange, disabled, open, triggerId, contentId, field?.invalid, field?.describedBy, activeValue, registerItem, optionId, success, rounded, items, setItemVisibility, unregisterItem]
|
|
2936
|
+
);
|
|
2937
|
+
return /* @__PURE__ */ jsx(ComboboxContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
|
|
2938
|
+
children,
|
|
2939
|
+
name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: value ?? "", disabled })
|
|
2940
|
+
] }) });
|
|
2941
|
+
}
|
|
2942
|
+
__name(Combobox, "Combobox");
|
|
2943
|
+
Combobox.Input = ComboboxInput;
|
|
2944
|
+
Combobox.Item = ComboboxItem;
|
|
2945
|
+
Combobox.Content = ComboboxContent;
|
|
2946
|
+
Combobox.Empty = ComboboxEmpty;
|
|
2947
|
+
Combobox.Loading = ComboboxLoading;
|
|
2948
|
+
var MultiSelectContext = createContext(null);
|
|
2949
|
+
function useMultiSelectContext(componentName) {
|
|
2950
|
+
const ctx = useContext(MultiSelectContext);
|
|
2951
|
+
if (!ctx) throw new Error(`<${componentName} /> must be rendered inside <MultiSelect>.`);
|
|
2952
|
+
return ctx;
|
|
2953
|
+
}
|
|
2954
|
+
__name(useMultiSelectContext, "useMultiSelectContext");
|
|
2955
|
+
var multiSelectSizeVariants = cva("", {
|
|
2956
|
+
variants: {
|
|
2957
|
+
size: {
|
|
2958
|
+
sm: "min-h-[2.25rem] py-1 px-2 text-xs gap-1",
|
|
2959
|
+
md: "min-h-[2.75rem] py-1.5 px-3 text-sm gap-1.5",
|
|
2960
|
+
lg: "min-h-[3.25rem] py-2 px-4 text-base gap-2"
|
|
2961
|
+
}
|
|
2962
|
+
},
|
|
2963
|
+
defaultVariants: {
|
|
2964
|
+
size: "md"
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
var chipSizeVariants = cva("inline-flex items-center rounded-full", {
|
|
2968
|
+
variants: {
|
|
2969
|
+
size: {
|
|
2970
|
+
sm: "text-[10px] px-1.5 py-0.5 gap-0.5",
|
|
2971
|
+
md: "text-xs px-2 py-0.5 gap-1",
|
|
2972
|
+
lg: "text-sm px-2.5 py-1 gap-1.5"
|
|
2973
|
+
}
|
|
2974
|
+
},
|
|
2975
|
+
defaultVariants: {
|
|
2976
|
+
size: "md"
|
|
2977
|
+
}
|
|
2978
|
+
});
|
|
2979
|
+
function orderedEnabledValues2(items) {
|
|
2980
|
+
return [...items.entries()].filter(([, meta]) => !meta.disabled).map(([val]) => val);
|
|
2981
|
+
}
|
|
2982
|
+
__name(orderedEnabledValues2, "orderedEnabledValues");
|
|
2983
|
+
var MultiSelectTrigger = forwardRef(
|
|
2984
|
+
({ className }, ref) => {
|
|
2985
|
+
const ctx = useMultiSelectContext("MultiSelectTrigger");
|
|
2986
|
+
const state = ctx.isInvalid ? "error" : ctx.isSuccess ? "success" : "none";
|
|
2987
|
+
const showClear = ctx.clearable && ctx.value.length > 0 && !ctx.disabled;
|
|
2988
|
+
const visible = ctx.maxVisibleChips ? ctx.value.slice(0, ctx.maxVisibleChips) : ctx.value;
|
|
2989
|
+
const overflow = ctx.value.length - visible.length;
|
|
2990
|
+
function move(delta) {
|
|
2991
|
+
const order = orderedEnabledValues2(ctx.items);
|
|
2992
|
+
if (!order.length) return;
|
|
2993
|
+
const i = ctx.activeValue ? order.indexOf(ctx.activeValue) : -1;
|
|
2994
|
+
ctx.setActiveValue(order[(i + delta + order.length) % order.length]);
|
|
2995
|
+
}
|
|
2996
|
+
__name(move, "move");
|
|
2997
|
+
function handleKeyDown(e) {
|
|
2998
|
+
switch (e.key) {
|
|
2999
|
+
case "ArrowDown":
|
|
3000
|
+
e.preventDefault();
|
|
3001
|
+
ctx.open ? move(1) : ctx.setOpen(true);
|
|
3002
|
+
break;
|
|
3003
|
+
case "ArrowUp":
|
|
3004
|
+
e.preventDefault();
|
|
3005
|
+
ctx.open ? move(-1) : ctx.setOpen(true);
|
|
3006
|
+
break;
|
|
3007
|
+
case "Enter":
|
|
3008
|
+
case " ":
|
|
3009
|
+
e.preventDefault();
|
|
3010
|
+
if (!ctx.open) ctx.setOpen(true);
|
|
3011
|
+
else if (ctx.activeValue) ctx.toggleValue(ctx.activeValue);
|
|
3012
|
+
break;
|
|
3013
|
+
case "Escape":
|
|
3014
|
+
if (ctx.open) {
|
|
3015
|
+
e.preventDefault();
|
|
3016
|
+
ctx.setOpen(false);
|
|
3017
|
+
}
|
|
3018
|
+
break;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
__name(handleKeyDown, "handleKeyDown");
|
|
3022
|
+
return /* @__PURE__ */ jsxs(
|
|
3023
|
+
"div",
|
|
3024
|
+
{
|
|
3025
|
+
ref: ctx.triggerRef,
|
|
3026
|
+
className: cn(
|
|
3027
|
+
inputWrapperVariants({ variant: ctx.variant, state, fullWidth: true, disabled: ctx.disabled, rounded: ctx.rounded }),
|
|
3028
|
+
multiSelectSizeVariants({ size: ctx.size }),
|
|
3029
|
+
"flex flex-wrap items-center gap-1",
|
|
3030
|
+
className
|
|
3031
|
+
),
|
|
3032
|
+
children: [
|
|
3033
|
+
/* @__PURE__ */ jsxs(
|
|
3034
|
+
"button",
|
|
3035
|
+
{
|
|
3036
|
+
ref,
|
|
3037
|
+
type: "button",
|
|
3038
|
+
id: ctx.triggerId,
|
|
3039
|
+
role: "combobox",
|
|
3040
|
+
"aria-haspopup": "listbox",
|
|
3041
|
+
"aria-expanded": ctx.open,
|
|
3042
|
+
"aria-controls": ctx.contentId,
|
|
3043
|
+
"aria-invalid": ctx.isInvalid || void 0,
|
|
3044
|
+
"aria-describedby": ctx.describedBy,
|
|
3045
|
+
"aria-required": ctx.required || void 0,
|
|
3046
|
+
disabled: ctx.disabled,
|
|
3047
|
+
onClick: () => !ctx.disabled && ctx.setOpen(!ctx.open),
|
|
3048
|
+
onKeyDown: handleKeyDown,
|
|
3049
|
+
className: "flex flex-1 flex-wrap items-center gap-1 bg-transparent text-left outline-none cursor-pointer disabled:cursor-not-allowed",
|
|
3050
|
+
children: [
|
|
3051
|
+
ctx.value.length === 0 && /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: ctx.placeholder }),
|
|
3052
|
+
visible.map((v) => {
|
|
3053
|
+
const meta = ctx.items.get(v);
|
|
3054
|
+
return /* @__PURE__ */ jsxs(
|
|
3055
|
+
"span",
|
|
3056
|
+
{
|
|
3057
|
+
className: cn(
|
|
3058
|
+
chipSizeVariants({ size: ctx.size }),
|
|
3059
|
+
"bg-brand/15 text-brand"
|
|
3060
|
+
),
|
|
3061
|
+
children: [
|
|
3062
|
+
meta?.label ?? v,
|
|
3063
|
+
/* @__PURE__ */ jsx(
|
|
3064
|
+
"span",
|
|
3065
|
+
{
|
|
3066
|
+
role: "button",
|
|
3067
|
+
tabIndex: -1,
|
|
3068
|
+
"aria-label": `Remove ${meta?.label ?? v}`,
|
|
3069
|
+
onClick: (e) => {
|
|
3070
|
+
e.stopPropagation();
|
|
3071
|
+
ctx.removeValue(v);
|
|
3072
|
+
},
|
|
3073
|
+
className: "hover:opacity-70",
|
|
3074
|
+
children: /* @__PURE__ */ jsx(
|
|
3075
|
+
X,
|
|
3076
|
+
{
|
|
3077
|
+
size: ctx.size === "sm" ? 8 : ctx.size === "md" ? 10 : 12
|
|
3078
|
+
}
|
|
3079
|
+
)
|
|
3080
|
+
}
|
|
3081
|
+
)
|
|
3082
|
+
]
|
|
3083
|
+
},
|
|
3084
|
+
v
|
|
3085
|
+
);
|
|
3086
|
+
}),
|
|
3087
|
+
overflow > 0 && /* @__PURE__ */ jsxs("span", { className: cn(
|
|
3088
|
+
"text-text-muted",
|
|
3089
|
+
ctx.size === "sm" ? "text-[10px]" : ctx.size === "md" ? "text-xs" : "text-sm"
|
|
3090
|
+
), children: [
|
|
3091
|
+
"+",
|
|
3092
|
+
overflow,
|
|
3093
|
+
" more"
|
|
3094
|
+
] })
|
|
3095
|
+
]
|
|
3096
|
+
}
|
|
3097
|
+
),
|
|
3098
|
+
showClear && /* @__PURE__ */ jsx(
|
|
3099
|
+
"button",
|
|
3100
|
+
{
|
|
3101
|
+
type: "button",
|
|
3102
|
+
tabIndex: -1,
|
|
3103
|
+
"aria-label": "Clear selection",
|
|
3104
|
+
onClick: (e) => {
|
|
3105
|
+
e.preventDefault();
|
|
3106
|
+
e.stopPropagation();
|
|
3107
|
+
ctx.onClear();
|
|
3108
|
+
},
|
|
3109
|
+
className: "flex h-4 w-4 shrink-0 items-center justify-center text-text-muted transition-colors hover:text-text",
|
|
3110
|
+
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
3111
|
+
}
|
|
3112
|
+
)
|
|
3113
|
+
]
|
|
3114
|
+
}
|
|
3115
|
+
);
|
|
3116
|
+
}
|
|
3117
|
+
);
|
|
3118
|
+
MultiSelectTrigger.displayName = "MultiSelectTrigger";
|
|
3119
|
+
function MultiSelectContent({
|
|
3120
|
+
className,
|
|
3121
|
+
children,
|
|
3122
|
+
...props
|
|
3123
|
+
}) {
|
|
3124
|
+
const ctx = useMultiSelectContext("MultiSelectContent");
|
|
3125
|
+
const { side, contentRef } = useFloatingSide(ctx.triggerRef, ctx.open);
|
|
3126
|
+
if (!ctx.open) return null;
|
|
3127
|
+
return /* @__PURE__ */ jsx(
|
|
3128
|
+
"div",
|
|
3129
|
+
{
|
|
3130
|
+
ref: contentRef,
|
|
3131
|
+
id: ctx.contentId,
|
|
3132
|
+
role: "listbox",
|
|
3133
|
+
"aria-labelledby": ctx.triggerId,
|
|
3134
|
+
"data-state": ctx.open ? "open" : "closed",
|
|
3135
|
+
"data-side": side,
|
|
3136
|
+
className: cn(
|
|
3137
|
+
"animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",
|
|
3138
|
+
side === "bottom" ? "top-full mt-1" : "bottom-full mb-1",
|
|
3139
|
+
className
|
|
3140
|
+
),
|
|
3141
|
+
...props,
|
|
3142
|
+
children
|
|
3143
|
+
}
|
|
3144
|
+
);
|
|
3145
|
+
}
|
|
3146
|
+
__name(MultiSelectContent, "MultiSelectContent");
|
|
3147
|
+
function CheckIcon() {
|
|
3148
|
+
return /* @__PURE__ */ jsx(
|
|
3149
|
+
"svg",
|
|
3150
|
+
{
|
|
3151
|
+
width: "12",
|
|
3152
|
+
height: "12",
|
|
3153
|
+
viewBox: "0 0 24 24",
|
|
3154
|
+
fill: "none",
|
|
3155
|
+
stroke: "currentColor",
|
|
3156
|
+
strokeWidth: 3,
|
|
3157
|
+
strokeLinecap: "round",
|
|
3158
|
+
strokeLinejoin: "round",
|
|
3159
|
+
children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" })
|
|
3160
|
+
}
|
|
3161
|
+
);
|
|
3162
|
+
}
|
|
3163
|
+
__name(CheckIcon, "CheckIcon");
|
|
3164
|
+
function MultiSelectItem({
|
|
3165
|
+
value,
|
|
3166
|
+
disabled = false,
|
|
3167
|
+
children,
|
|
3168
|
+
className
|
|
3169
|
+
}) {
|
|
3170
|
+
const ctx = useMultiSelectContext("MultiSelectItem");
|
|
3171
|
+
const ref = useRef(null);
|
|
3172
|
+
const selected = ctx.value.includes(value);
|
|
3173
|
+
const active = ctx.activeValue === value;
|
|
3174
|
+
useEffect(
|
|
3175
|
+
() => ctx.registerItem(value, { label: children, disabled }),
|
|
3176
|
+
[value, disabled, children]
|
|
3177
|
+
);
|
|
3178
|
+
useEffect(() => {
|
|
3179
|
+
if (active) ref.current?.scrollIntoView({ block: "nearest" });
|
|
3180
|
+
}, [active]);
|
|
3181
|
+
return /* @__PURE__ */ jsxs(
|
|
3182
|
+
"div",
|
|
3183
|
+
{
|
|
3184
|
+
ref,
|
|
3185
|
+
id: ctx.optionId(value),
|
|
3186
|
+
role: "option",
|
|
3187
|
+
"aria-selected": selected,
|
|
3188
|
+
"aria-disabled": disabled || void 0,
|
|
3189
|
+
onMouseEnter: () => !disabled && ctx.setActiveValue(value),
|
|
3190
|
+
onClick: () => !disabled && ctx.toggleValue(value),
|
|
3191
|
+
className: cn(
|
|
3192
|
+
"flex cursor-pointer items-center justify-between rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",
|
|
3193
|
+
active && "bg-brand/15 text-brand",
|
|
3194
|
+
disabled && "pointer-events-none cursor-not-allowed opacity-50",
|
|
3195
|
+
className
|
|
3196
|
+
),
|
|
3197
|
+
children: [
|
|
3198
|
+
/* @__PURE__ */ jsx("span", { children }),
|
|
3199
|
+
selected && /* @__PURE__ */ jsx(CheckIcon, {})
|
|
3200
|
+
]
|
|
3201
|
+
}
|
|
3202
|
+
);
|
|
3203
|
+
}
|
|
3204
|
+
__name(MultiSelectItem, "MultiSelectItem");
|
|
3205
|
+
function MultiSelect({
|
|
3206
|
+
value: valueProp,
|
|
3207
|
+
defaultValue = [],
|
|
3208
|
+
onValueChange,
|
|
3209
|
+
disabled = false,
|
|
3210
|
+
required,
|
|
3211
|
+
name,
|
|
3212
|
+
variant = "outline",
|
|
3213
|
+
size = "md",
|
|
3214
|
+
placeholder,
|
|
3215
|
+
maxVisibleChips,
|
|
3216
|
+
className,
|
|
3217
|
+
children,
|
|
3218
|
+
error,
|
|
3219
|
+
success,
|
|
3220
|
+
rounded,
|
|
3221
|
+
clearable
|
|
3222
|
+
}) {
|
|
3223
|
+
const autoId = useId();
|
|
3224
|
+
const field = useOptionalFormField();
|
|
3225
|
+
const triggerId = field?.id ?? autoId;
|
|
3226
|
+
const contentId = `${triggerId}-listbox`;
|
|
3227
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
3228
|
+
const value = valueProp !== void 0 ? valueProp : internalValue;
|
|
3229
|
+
const [open, setOpen] = useState(false);
|
|
3230
|
+
const [activeValue, setActiveValue] = useState(void 0);
|
|
3231
|
+
const itemsRef = useRef(/* @__PURE__ */ new Map());
|
|
3232
|
+
const [, forceUpdate] = useReducer((n) => n + 1, 0);
|
|
3233
|
+
const registerItem = useCallback((val, meta) => {
|
|
3234
|
+
itemsRef.current.set(val, meta);
|
|
3235
|
+
forceUpdate();
|
|
3236
|
+
return () => {
|
|
3237
|
+
itemsRef.current.delete(val);
|
|
3238
|
+
forceUpdate();
|
|
3239
|
+
};
|
|
3240
|
+
}, []);
|
|
3241
|
+
const commit = useCallback(
|
|
3242
|
+
(next) => {
|
|
3243
|
+
if (valueProp === void 0) setInternalValue(next);
|
|
3244
|
+
onValueChange?.(next);
|
|
3245
|
+
},
|
|
3246
|
+
[valueProp, onValueChange]
|
|
3247
|
+
);
|
|
3248
|
+
const toggleValue = useCallback(
|
|
3249
|
+
(v) => commit(value.includes(v) ? value.filter((x) => x !== v) : [...value, v]),
|
|
3250
|
+
[value, commit]
|
|
3251
|
+
);
|
|
3252
|
+
const removeValue = useCallback((v) => commit(value.filter((x) => x !== v)), [value, commit]);
|
|
3253
|
+
const handleClear = useCallback(() => {
|
|
3254
|
+
commit([]);
|
|
3255
|
+
}, [commit]);
|
|
3256
|
+
const triggerRef = useRef(null);
|
|
3257
|
+
const rootRef = useRef(null);
|
|
3258
|
+
useEffect(() => {
|
|
3259
|
+
if (!open) return;
|
|
3260
|
+
function handlePointerDown(e) {
|
|
3261
|
+
if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
|
|
3262
|
+
}
|
|
3263
|
+
__name(handlePointerDown, "handlePointerDown");
|
|
3264
|
+
document.addEventListener("mousedown", handlePointerDown);
|
|
3265
|
+
return () => document.removeEventListener("mousedown", handlePointerDown);
|
|
3266
|
+
}, [open]);
|
|
3267
|
+
const optionId = useCallback((val) => `${contentId}-option-${val}`, [contentId]);
|
|
3268
|
+
const ctxValue = useMemo(
|
|
3269
|
+
() => ({
|
|
3270
|
+
value,
|
|
3271
|
+
toggleValue,
|
|
3272
|
+
removeValue,
|
|
3273
|
+
disabled,
|
|
3274
|
+
variant,
|
|
3275
|
+
size,
|
|
3276
|
+
open,
|
|
3277
|
+
setOpen,
|
|
3278
|
+
triggerId,
|
|
3279
|
+
contentId,
|
|
3280
|
+
triggerRef,
|
|
3281
|
+
isInvalid: field?.invalid ?? error ?? false,
|
|
3282
|
+
describedBy: field?.describedBy,
|
|
3283
|
+
required: field?.required ?? required,
|
|
3284
|
+
placeholder,
|
|
3285
|
+
maxVisibleChips,
|
|
3286
|
+
activeValue,
|
|
3287
|
+
setActiveValue,
|
|
3288
|
+
items: itemsRef.current,
|
|
3289
|
+
registerItem,
|
|
3290
|
+
optionId,
|
|
3291
|
+
isSuccess: success,
|
|
3292
|
+
rounded,
|
|
3293
|
+
clearable,
|
|
3294
|
+
onClear: handleClear
|
|
3295
|
+
}),
|
|
3296
|
+
[value, toggleValue, removeValue, disabled, variant, size, open, triggerId, contentId, field?.invalid, field?.describedBy, field?.required, required, placeholder, maxVisibleChips, activeValue, registerItem, optionId, error, success, rounded, clearable, handleClear]
|
|
3297
|
+
);
|
|
3298
|
+
return /* @__PURE__ */ jsx(MultiSelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
|
|
3299
|
+
children,
|
|
3300
|
+
name && value.map((v) => /* @__PURE__ */ jsx("input", { type: "hidden", name: `${name}[]`, value: v, disabled }, v))
|
|
3301
|
+
] }) });
|
|
3302
|
+
}
|
|
3303
|
+
__name(MultiSelect, "MultiSelect");
|
|
3304
|
+
MultiSelect.Trigger = MultiSelectTrigger;
|
|
3305
|
+
MultiSelect.Content = MultiSelectContent;
|
|
3306
|
+
MultiSelect.Item = MultiSelectItem;
|
|
3307
|
+
|
|
3308
|
+
// src/theme/defaults/tokens.ts
|
|
3309
|
+
var defaultTokens = {
|
|
3310
|
+
colors: {
|
|
3311
|
+
blue: {
|
|
3312
|
+
300: { value: "#5EA6ED" },
|
|
3313
|
+
400: { value: "#4799EB" },
|
|
3314
|
+
500: { value: "#1A80E6" },
|
|
3315
|
+
600: { value: "#1773CF" }
|
|
3316
|
+
},
|
|
3317
|
+
red: {
|
|
3318
|
+
300: { value: "#EB4747" },
|
|
3319
|
+
400: { value: "#E83030" },
|
|
3320
|
+
500: { value: "#E61A1A" },
|
|
3321
|
+
600: { value: "#CF1717" }
|
|
3322
|
+
},
|
|
3323
|
+
green: {
|
|
3324
|
+
300: { value: "#26D997" },
|
|
3325
|
+
400: { value: "#22C388" },
|
|
3326
|
+
500: { value: "#16A249" },
|
|
3327
|
+
600: { value: "#12875C" }
|
|
3328
|
+
},
|
|
3329
|
+
amber: {
|
|
3330
|
+
300: { value: "#F7B23B" },
|
|
3331
|
+
400: { value: "#F6A823" },
|
|
3332
|
+
500: { value: "#F59F0A" },
|
|
3333
|
+
600: { value: "#D38909" }
|
|
3334
|
+
},
|
|
3335
|
+
cyan: {
|
|
3336
|
+
300: { value: "#6CC3EF" },
|
|
3337
|
+
400: { value: "#47B4EB" },
|
|
3338
|
+
500: { value: "#1791CF" },
|
|
3339
|
+
600: { value: "#137BAE" }
|
|
3340
|
+
},
|
|
3341
|
+
gray: {
|
|
3342
|
+
50: { value: "#FAFAFA" },
|
|
3343
|
+
100: { value: "#EBEBEB" },
|
|
3344
|
+
200: { value: "#D9D9D9" },
|
|
3345
|
+
300: { value: "#BDBDBD" },
|
|
3346
|
+
400: { value: "#999999" },
|
|
3347
|
+
500: { value: "#666666" },
|
|
3348
|
+
600: { value: "#4D4D4D" },
|
|
3349
|
+
700: { value: "#333333" },
|
|
3350
|
+
800: { value: "#2E2E2E" },
|
|
3351
|
+
900: { value: "#1F1F1F" },
|
|
3352
|
+
950: { value: "#141414" },
|
|
3353
|
+
1e3: { value: "#0A0A0A" }
|
|
3354
|
+
},
|
|
3355
|
+
white: {
|
|
3356
|
+
value: "#FFFFFF"
|
|
3357
|
+
},
|
|
3358
|
+
black: {
|
|
3359
|
+
value: "#000000"
|
|
3360
|
+
}
|
|
3361
|
+
},
|
|
3362
|
+
spacing: {
|
|
3363
|
+
1: { value: "0.25rem" },
|
|
3364
|
+
2: { value: "0.5rem" },
|
|
3365
|
+
3: { value: "0.75rem" },
|
|
3366
|
+
4: { value: "1rem" },
|
|
3367
|
+
5: { value: "1.25rem" },
|
|
3368
|
+
6: { value: "1.5rem" },
|
|
3369
|
+
8: { value: "2rem" },
|
|
3370
|
+
10: { value: "2.5rem" },
|
|
3371
|
+
12: { value: "3rem" },
|
|
3372
|
+
16: { value: "4rem" }
|
|
3373
|
+
},
|
|
3374
|
+
radii: {
|
|
3375
|
+
none: { value: "0" },
|
|
3376
|
+
sm: { value: "0.25rem" },
|
|
3377
|
+
md: { value: "0.5rem" },
|
|
3378
|
+
lg: { value: "0.75rem" },
|
|
3379
|
+
xl: { value: "1rem" },
|
|
3380
|
+
full: { value: "9999px" }
|
|
3381
|
+
},
|
|
3382
|
+
fonts: {
|
|
3383
|
+
body: {
|
|
3384
|
+
value: "Inter, sans-serif"
|
|
3385
|
+
},
|
|
3386
|
+
heading: {
|
|
3387
|
+
value: "Inter, sans-serif"
|
|
3388
|
+
},
|
|
3389
|
+
mono: {
|
|
3390
|
+
value: "ui-monospace, SFMono-Regular, Menlo, monospace"
|
|
3391
|
+
}
|
|
3392
|
+
},
|
|
3393
|
+
fontSizes: {
|
|
3394
|
+
xs: { value: "0.75rem" },
|
|
3395
|
+
sm: { value: "0.875rem" },
|
|
3396
|
+
md: { value: "1rem" },
|
|
3397
|
+
lg: { value: "1.125rem" },
|
|
3398
|
+
xl: { value: "1.25rem" },
|
|
3399
|
+
"2xl": { value: "1.5rem" },
|
|
3400
|
+
"3xl": { value: "1.875rem" },
|
|
3401
|
+
"4xl": { value: "2.25rem" }
|
|
3402
|
+
},
|
|
3403
|
+
fontWeights: {
|
|
3404
|
+
normal: { value: "400" },
|
|
3405
|
+
medium: { value: "500" },
|
|
3406
|
+
semibold: { value: "600" },
|
|
3407
|
+
bold: { value: "700" }
|
|
3408
|
+
},
|
|
3409
|
+
lineHeights: {
|
|
3410
|
+
tight: { value: "1.25" },
|
|
3411
|
+
normal: { value: "1.5" },
|
|
3412
|
+
relaxed: { value: "1.75" }
|
|
3413
|
+
},
|
|
3414
|
+
letterSpacings: {
|
|
3415
|
+
tighter: { value: "-0.025em" },
|
|
3416
|
+
tight: { value: "-0.01em" },
|
|
3417
|
+
normal: { value: "0" },
|
|
3418
|
+
wide: { value: "0.025em" }
|
|
3419
|
+
},
|
|
3420
|
+
animations: {
|
|
3421
|
+
"slide-in-right": {
|
|
3422
|
+
value: "slide-in-right 0.5s ease-in-out"
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
};
|
|
3426
|
+
|
|
3427
|
+
// src/theme/defaults/semanticTokens.ts
|
|
3428
|
+
var defaultSemanticTokens = {
|
|
3429
|
+
colors: {
|
|
3430
|
+
brand: {
|
|
3431
|
+
value: {
|
|
3432
|
+
light: "{colors.blue.500}",
|
|
3433
|
+
dark: "{colors.blue.400}"
|
|
3434
|
+
}
|
|
3435
|
+
},
|
|
3436
|
+
brandHover: {
|
|
3437
|
+
value: {
|
|
3438
|
+
light: "{colors.blue.600}",
|
|
3439
|
+
dark: "{colors.blue.300}"
|
|
3440
|
+
}
|
|
3441
|
+
},
|
|
3442
|
+
brandFg: {
|
|
3443
|
+
value: "{colors.white}"
|
|
3444
|
+
},
|
|
3445
|
+
surface: {
|
|
3446
|
+
value: {
|
|
3447
|
+
light: "{colors.gray.50}",
|
|
3448
|
+
dark: "{colors.gray.900}"
|
|
3449
|
+
}
|
|
3450
|
+
},
|
|
3451
|
+
surfaceRaised: {
|
|
3452
|
+
value: {
|
|
3453
|
+
light: "{colors.white}",
|
|
3454
|
+
dark: "{colors.gray.800}"
|
|
3455
|
+
}
|
|
3456
|
+
},
|
|
3457
|
+
surfaceSunken: {
|
|
3458
|
+
value: {
|
|
3459
|
+
light: "{colors.gray.100}",
|
|
3460
|
+
dark: "{colors.gray.950}"
|
|
3461
|
+
}
|
|
3462
|
+
},
|
|
3463
|
+
border: {
|
|
3464
|
+
value: {
|
|
3465
|
+
light: "{colors.gray.200}",
|
|
3466
|
+
dark: "{colors.gray.600}"
|
|
3467
|
+
}
|
|
3468
|
+
},
|
|
3469
|
+
text: {
|
|
3470
|
+
value: {
|
|
3471
|
+
light: "{colors.gray.900}",
|
|
3472
|
+
dark: "{colors.gray.50}"
|
|
3473
|
+
}
|
|
3474
|
+
},
|
|
3475
|
+
textMuted: {
|
|
3476
|
+
value: {
|
|
3477
|
+
light: "{colors.gray.500}",
|
|
3478
|
+
dark: "{colors.gray.400}"
|
|
3479
|
+
}
|
|
3480
|
+
},
|
|
3481
|
+
destructive: {
|
|
3482
|
+
value: {
|
|
3483
|
+
light: "{colors.red.500}",
|
|
3484
|
+
dark: "{colors.red.400}"
|
|
3485
|
+
}
|
|
3486
|
+
},
|
|
3487
|
+
destructiveFg: {
|
|
3488
|
+
value: "{colors.white}"
|
|
3489
|
+
},
|
|
3490
|
+
destructiveHover: {
|
|
3491
|
+
value: {
|
|
3492
|
+
light: "{colors.red.600}",
|
|
3493
|
+
dark: "{colors.red.300}"
|
|
3494
|
+
}
|
|
3495
|
+
},
|
|
3496
|
+
success: {
|
|
3497
|
+
value: {
|
|
3498
|
+
light: "{colors.green.500}",
|
|
3499
|
+
dark: "{colors.green.400}"
|
|
3500
|
+
}
|
|
3501
|
+
},
|
|
3502
|
+
successFg: {
|
|
3503
|
+
value: "{colors.white}"
|
|
3504
|
+
},
|
|
3505
|
+
successHover: {
|
|
3506
|
+
value: {
|
|
3507
|
+
light: "{colors.green.600}",
|
|
3508
|
+
dark: "{colors.green.300}"
|
|
3509
|
+
}
|
|
3510
|
+
},
|
|
3511
|
+
warning: {
|
|
3512
|
+
value: {
|
|
3513
|
+
light: "{colors.amber.500}",
|
|
3514
|
+
dark: "{colors.amber.400}"
|
|
3515
|
+
}
|
|
3516
|
+
},
|
|
3517
|
+
warningFg: {
|
|
3518
|
+
value: "{colors.black}"
|
|
3519
|
+
},
|
|
3520
|
+
warningHover: {
|
|
3521
|
+
value: {
|
|
3522
|
+
light: "{colors.amber.600}",
|
|
3523
|
+
dark: "{colors.amber.300}"
|
|
3524
|
+
}
|
|
3525
|
+
},
|
|
3526
|
+
info: {
|
|
3527
|
+
value: {
|
|
3528
|
+
light: "{colors.cyan.500}",
|
|
3529
|
+
dark: "{colors.cyan.400}"
|
|
3530
|
+
}
|
|
3531
|
+
},
|
|
3532
|
+
infoFg: {
|
|
3533
|
+
value: "{colors.white}"
|
|
3534
|
+
},
|
|
3535
|
+
infoHover: {
|
|
3536
|
+
value: {
|
|
3537
|
+
light: "{colors.cyan.600}",
|
|
3538
|
+
dark: "{colors.cyan.300}"
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
};
|
|
3543
|
+
|
|
3544
|
+
// src/theme/defaults/theme.ts
|
|
3545
|
+
var defaultSizes = {
|
|
3546
|
+
xs: {
|
|
3547
|
+
height: "1.75rem",
|
|
3548
|
+
paddingX: "0.5rem",
|
|
3549
|
+
fontSize: "0.75rem",
|
|
3550
|
+
gap: "0.25rem",
|
|
3551
|
+
iconSize: "0.875rem",
|
|
3552
|
+
radius: "0.65rem"
|
|
3553
|
+
},
|
|
3554
|
+
sm: {
|
|
3555
|
+
height: "2rem",
|
|
3556
|
+
paddingX: "0.75rem",
|
|
3557
|
+
fontSize: "0.8125rem",
|
|
3558
|
+
gap: "0.375rem",
|
|
3559
|
+
iconSize: "1rem",
|
|
3560
|
+
radius: "0.8rem"
|
|
3561
|
+
},
|
|
3562
|
+
md: {
|
|
3563
|
+
height: "2.5rem",
|
|
3564
|
+
paddingX: "1rem",
|
|
3565
|
+
fontSize: "0.875rem",
|
|
3566
|
+
gap: "0.5rem",
|
|
3567
|
+
iconSize: "1.125rem",
|
|
3568
|
+
radius: "1rem"
|
|
3569
|
+
},
|
|
3570
|
+
lg: {
|
|
3571
|
+
height: "3rem",
|
|
3572
|
+
paddingX: "1.5rem",
|
|
3573
|
+
fontSize: "1rem",
|
|
3574
|
+
gap: "0.625rem",
|
|
3575
|
+
iconSize: "1.25rem",
|
|
3576
|
+
radius: "1.15rem"
|
|
3577
|
+
}
|
|
3578
|
+
};
|
|
3579
|
+
var defaultTextStyles = {
|
|
3580
|
+
body: {
|
|
3581
|
+
fontFamily: "{fonts.body}",
|
|
3582
|
+
fontSize: "{fontSizes.md}",
|
|
3583
|
+
fontWeight: "{fontWeights.normal}",
|
|
3584
|
+
lineHeight: "{lineHeights.normal}"
|
|
3585
|
+
},
|
|
3586
|
+
bodySmall: {
|
|
3587
|
+
fontFamily: "{fonts.body}",
|
|
3588
|
+
fontSize: "{fontSizes.sm}",
|
|
3589
|
+
fontWeight: "{fontWeights.normal}",
|
|
3590
|
+
lineHeight: "{lineHeights.normal}"
|
|
3591
|
+
},
|
|
3592
|
+
heading: {
|
|
3593
|
+
fontFamily: "{fonts.heading}",
|
|
3594
|
+
fontSize: "{fontSizes.2xl}",
|
|
3595
|
+
fontWeight: "{fontWeights.bold}",
|
|
3596
|
+
lineHeight: "{lineHeights.tight}"
|
|
3597
|
+
},
|
|
3598
|
+
headingSmall: {
|
|
3599
|
+
fontFamily: "{fonts.heading}",
|
|
3600
|
+
fontSize: "{fontSizes.xl}",
|
|
3601
|
+
fontWeight: "{fontWeights.semibold}",
|
|
3602
|
+
lineHeight: "{lineHeights.tight}"
|
|
3603
|
+
},
|
|
3604
|
+
caption: {
|
|
3605
|
+
fontFamily: "{fonts.body}",
|
|
3606
|
+
fontSize: "{fontSizes.xs}",
|
|
3607
|
+
fontWeight: "{fontWeights.normal}",
|
|
3608
|
+
lineHeight: "{lineHeights.normal}"
|
|
3609
|
+
}
|
|
3610
|
+
};
|
|
3611
|
+
var defaultRecipes = {
|
|
3612
|
+
Button: buttonRecipe,
|
|
3613
|
+
FormControl: formControlRecipe,
|
|
3614
|
+
Input: inputRecipe
|
|
3615
|
+
};
|
|
3616
|
+
var defaultTheme = {
|
|
3617
|
+
tokens: defaultTokens,
|
|
3618
|
+
semanticTokens: defaultSemanticTokens,
|
|
3619
|
+
textStyles: defaultTextStyles,
|
|
3620
|
+
recipes: defaultRecipes,
|
|
3621
|
+
intensity: 50,
|
|
3622
|
+
sizes: defaultSizes
|
|
3623
|
+
};
|
|
3624
|
+
|
|
3625
|
+
// src/provider/cssVariables.ts
|
|
3626
|
+
function toKebabCase(str) {
|
|
3627
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
3628
|
+
}
|
|
3629
|
+
__name(toKebabCase, "toKebabCase");
|
|
3630
|
+
function colorToRgbChannels(value) {
|
|
3631
|
+
const trimmed = value.trim();
|
|
3632
|
+
const rgbMatch = trimmed.match(
|
|
3633
|
+
/^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i
|
|
3634
|
+
);
|
|
3635
|
+
if (rgbMatch) {
|
|
3636
|
+
return `${rgbMatch[1]} ${rgbMatch[2]} ${rgbMatch[3]}`;
|
|
3637
|
+
}
|
|
3638
|
+
if (trimmed.startsWith("#")) {
|
|
3639
|
+
const hex = trimmed.slice(1);
|
|
3640
|
+
if (hex.length === 3) {
|
|
3641
|
+
const r = parseInt(hex[0] + hex[0], 16);
|
|
3642
|
+
const g = parseInt(hex[1] + hex[1], 16);
|
|
3643
|
+
const b = parseInt(hex[2] + hex[2], 16);
|
|
3644
|
+
return `${r} ${g} ${b}`;
|
|
3645
|
+
}
|
|
3646
|
+
if (hex.length === 6) {
|
|
3647
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
3648
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
3649
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
3650
|
+
return `${r} ${g} ${b}`;
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
if (/^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
3654
|
+
return trimmed;
|
|
3655
|
+
}
|
|
3656
|
+
return value;
|
|
3657
|
+
}
|
|
3658
|
+
__name(colorToRgbChannels, "colorToRgbChannels");
|
|
3659
|
+
function getTokenValue(reference, tokens) {
|
|
3660
|
+
const path = reference.replace(/^\{/, "").replace(/\}$/, "").split(".");
|
|
3661
|
+
let current = tokens;
|
|
3662
|
+
for (const segment of path) {
|
|
3663
|
+
if (typeof current !== "object" || current === null || !(segment in current)) {
|
|
3664
|
+
return void 0;
|
|
3665
|
+
}
|
|
3666
|
+
current = current[segment];
|
|
3667
|
+
}
|
|
3668
|
+
if (typeof current === "object" && current !== null && "value" in current) {
|
|
3669
|
+
const value = current.value;
|
|
3670
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
3671
|
+
return value;
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
return void 0;
|
|
3675
|
+
}
|
|
3676
|
+
__name(getTokenValue, "getTokenValue");
|
|
3677
|
+
function resolveReference(reference, tokens, seen = /* @__PURE__ */ new Set()) {
|
|
3678
|
+
if (seen.has(reference)) {
|
|
3679
|
+
console.error(
|
|
3680
|
+
`[kreativ-ui] Circular token reference detected: ${reference}`
|
|
3681
|
+
);
|
|
3682
|
+
return void 0;
|
|
3683
|
+
}
|
|
3684
|
+
const nextSeen = new Set(seen);
|
|
3685
|
+
nextSeen.add(reference);
|
|
3686
|
+
const value = getTokenValue(reference, tokens);
|
|
3687
|
+
if (value === void 0) {
|
|
3688
|
+
console.warn(
|
|
3689
|
+
`[kreativ-ui] Unable to resolve token reference: ${reference}`
|
|
3690
|
+
);
|
|
3691
|
+
return void 0;
|
|
3692
|
+
}
|
|
3693
|
+
if (typeof value === "number") {
|
|
3694
|
+
return String(value);
|
|
3695
|
+
}
|
|
3696
|
+
if (value.startsWith("{") && value.endsWith("}")) {
|
|
3697
|
+
return resolveReference(value, tokens, nextSeen);
|
|
3698
|
+
}
|
|
3699
|
+
return value;
|
|
3700
|
+
}
|
|
3701
|
+
__name(resolveReference, "resolveReference");
|
|
3702
|
+
function resolveValue(value, tokens) {
|
|
3703
|
+
if (typeof value === "number") {
|
|
3704
|
+
return String(value);
|
|
3705
|
+
}
|
|
3706
|
+
if (typeof value !== "string") {
|
|
3707
|
+
return void 0;
|
|
3708
|
+
}
|
|
3709
|
+
if (value.startsWith("{") && value.endsWith("}")) {
|
|
3710
|
+
return resolveReference(value, tokens);
|
|
3711
|
+
}
|
|
3712
|
+
return value;
|
|
3713
|
+
}
|
|
3714
|
+
__name(resolveValue, "resolveValue");
|
|
3715
|
+
function flattenTokens(value, path, result, tokens) {
|
|
3716
|
+
if (typeof value !== "object" || value === null) {
|
|
3717
|
+
return;
|
|
3718
|
+
}
|
|
3719
|
+
if ("value" in value) {
|
|
3720
|
+
const tokenValue = value.value;
|
|
3721
|
+
const resolved = resolveValue(tokenValue, tokens);
|
|
3722
|
+
if (resolved !== void 0) {
|
|
3723
|
+
result[path.join(".")] = resolved;
|
|
3724
|
+
}
|
|
3725
|
+
return;
|
|
3726
|
+
}
|
|
3727
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3728
|
+
flattenTokens(child, [...path, key], result, tokens);
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
__name(flattenTokens, "flattenTokens");
|
|
3732
|
+
function resolveSemanticValue(value, mode, tokens) {
|
|
3733
|
+
if (typeof value === "object" && value !== null && "light" in value && "dark" in value) {
|
|
3734
|
+
const modeValue = value[mode];
|
|
3735
|
+
return resolveValue(modeValue, tokens);
|
|
3736
|
+
}
|
|
3737
|
+
return resolveValue(value, tokens);
|
|
3738
|
+
}
|
|
3739
|
+
__name(resolveSemanticValue, "resolveSemanticValue");
|
|
3740
|
+
function resolveSemanticTokens(semanticTokens, tokens, mode) {
|
|
3741
|
+
const result = {};
|
|
3742
|
+
function walk(value, path) {
|
|
3743
|
+
if (typeof value !== "object" || value === null) {
|
|
3744
|
+
return;
|
|
3745
|
+
}
|
|
3746
|
+
if ("value" in value) {
|
|
3747
|
+
const semanticValue = value.value;
|
|
3748
|
+
const resolved = resolveSemanticValue(semanticValue, mode, tokens);
|
|
3749
|
+
if (resolved !== void 0) {
|
|
3750
|
+
result[path.join(".")] = resolved;
|
|
3751
|
+
}
|
|
3752
|
+
return;
|
|
3753
|
+
}
|
|
3754
|
+
for (const [key, child] of Object.entries(
|
|
3755
|
+
value
|
|
3756
|
+
)) {
|
|
3757
|
+
walk(child, [...path, key]);
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
__name(walk, "walk");
|
|
3761
|
+
walk(semanticTokens, []);
|
|
3762
|
+
return result;
|
|
3763
|
+
}
|
|
3764
|
+
__name(resolveSemanticTokens, "resolveSemanticTokens");
|
|
3765
|
+
function resolveTokens(tokens, semanticTokens, mode) {
|
|
3766
|
+
const primitiveTokens = {};
|
|
3767
|
+
flattenTokens(tokens, [], primitiveTokens, tokens);
|
|
3768
|
+
const resolvedSemanticTokens = resolveSemanticTokens(
|
|
3769
|
+
semanticTokens,
|
|
3770
|
+
tokens,
|
|
3771
|
+
mode
|
|
3772
|
+
);
|
|
3773
|
+
return {
|
|
3774
|
+
...primitiveTokens,
|
|
3775
|
+
...resolvedSemanticTokens
|
|
3776
|
+
};
|
|
3777
|
+
}
|
|
3778
|
+
__name(resolveTokens, "resolveTokens");
|
|
3779
|
+
function tokensToCssVars(tokens, mode, intensity) {
|
|
3780
|
+
const cssVars = {};
|
|
3781
|
+
for (const [path, value] of Object.entries(tokens)) {
|
|
3782
|
+
const parts = path.split(".");
|
|
3783
|
+
const isSemanticColor = parts.length === 2 && parts[0] === "colors";
|
|
3784
|
+
const isPrimitiveColor = parts.length >= 3 && parts[0] === "colors";
|
|
3785
|
+
const varName = isSemanticColor ? `--kui-${toKebabCase(parts[1])}` : `--kui-${parts.map(toKebabCase).join("-")}`;
|
|
3786
|
+
const outputValue = isSemanticColor || isPrimitiveColor ? colorToRgbChannels(value) : value;
|
|
3787
|
+
cssVars[varName] = outputValue;
|
|
3788
|
+
}
|
|
3789
|
+
return {
|
|
3790
|
+
...cssVars,
|
|
3791
|
+
"--kui-mode": mode,
|
|
3792
|
+
"--kui-intensity": String(intensity)
|
|
3793
|
+
};
|
|
3794
|
+
}
|
|
3795
|
+
__name(tokensToCssVars, "tokensToCssVars");
|
|
3796
|
+
|
|
3797
|
+
// src/theme/mergeTheme.ts
|
|
3798
|
+
var CSS_SIZE = /^-?\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr)$|^(auto|min-content|max-content|fit-content)$/;
|
|
3799
|
+
var CSS_KEYWORDS = /* @__PURE__ */ new Set([
|
|
3800
|
+
"auto",
|
|
3801
|
+
"min-content",
|
|
3802
|
+
"max-content",
|
|
3803
|
+
"fit-content"
|
|
3804
|
+
]);
|
|
3805
|
+
var SIZE_FIELDS = [
|
|
3806
|
+
"height",
|
|
3807
|
+
"width",
|
|
3808
|
+
"paddingX",
|
|
3809
|
+
"paddingY",
|
|
3810
|
+
"fontSize",
|
|
3811
|
+
"gap",
|
|
3812
|
+
"iconSize",
|
|
3813
|
+
"radius"
|
|
3814
|
+
];
|
|
3815
|
+
function isCssKeyword(value) {
|
|
3816
|
+
return CSS_KEYWORDS.has(value);
|
|
3817
|
+
}
|
|
3818
|
+
__name(isCssKeyword, "isCssKeyword");
|
|
3819
|
+
function toPx(value) {
|
|
3820
|
+
if (isCssKeyword(value)) return void 0;
|
|
3821
|
+
const num = parseFloat(value);
|
|
3822
|
+
if (Number.isNaN(num)) return void 0;
|
|
3823
|
+
if (value.endsWith("px")) return num;
|
|
3824
|
+
if (value.endsWith("rem") || value.endsWith("em")) {
|
|
3825
|
+
return num * 16;
|
|
3826
|
+
}
|
|
3827
|
+
return void 0;
|
|
3828
|
+
}
|
|
3829
|
+
__name(toPx, "toPx");
|
|
3830
|
+
function validateSizeToken(key, token) {
|
|
3831
|
+
SIZE_FIELDS.forEach((field) => {
|
|
3832
|
+
const value = token[field];
|
|
3833
|
+
if (value === void 0) return;
|
|
3834
|
+
if (!CSS_SIZE.test(value)) {
|
|
3835
|
+
console.error(
|
|
3836
|
+
`[kreativ-ui] Invalid size "${key}.${field}": "${value}" is not a valid CSS size.`
|
|
3837
|
+
);
|
|
3838
|
+
return;
|
|
3839
|
+
}
|
|
3840
|
+
if (isCssKeyword(value)) return;
|
|
3841
|
+
const num = parseFloat(value);
|
|
3842
|
+
if (num < 0) {
|
|
3843
|
+
console.error(
|
|
3844
|
+
`[kreativ-ui] Invalid size "${key}.${field}": "${value}" is negative.`
|
|
3845
|
+
);
|
|
3846
|
+
}
|
|
3847
|
+
});
|
|
3848
|
+
if (token.height && token.fontSize) {
|
|
3849
|
+
const heightPx = toPx(token.height);
|
|
3850
|
+
const fontSizePx = toPx(token.fontSize);
|
|
3851
|
+
if (heightPx !== void 0 && fontSizePx !== void 0 && fontSizePx >= heightPx) {
|
|
3852
|
+
console.warn(
|
|
3853
|
+
`[kreativ-ui] Size "${key}" has conflicting dimensions: height=${token.height} (${heightPx}px), fontSize=${token.fontSize} (${fontSizePx}px).
|
|
3854
|
+
Font size meets or exceeds the box height \u2014 text may clip or overflow.`
|
|
3855
|
+
);
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3859
|
+
__name(validateSizeToken, "validateSizeToken");
|
|
3860
|
+
function isPlainObject(value) {
|
|
3861
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3862
|
+
}
|
|
3863
|
+
__name(isPlainObject, "isPlainObject");
|
|
3864
|
+
function deepMerge(base, override) {
|
|
3865
|
+
if (override === void 0) {
|
|
3866
|
+
return base;
|
|
3867
|
+
}
|
|
3868
|
+
if (!isPlainObject(base) || !isPlainObject(override)) {
|
|
3869
|
+
return override;
|
|
3870
|
+
}
|
|
3871
|
+
const result = {
|
|
3872
|
+
...base
|
|
3873
|
+
};
|
|
3874
|
+
for (const [key, value] of Object.entries(override)) {
|
|
3875
|
+
const existing = result[key];
|
|
3876
|
+
if (isPlainObject(existing) && isPlainObject(value)) {
|
|
3877
|
+
result[key] = deepMerge(existing, value);
|
|
3878
|
+
} else {
|
|
3879
|
+
result[key] = value;
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
return result;
|
|
3883
|
+
}
|
|
3884
|
+
__name(deepMerge, "deepMerge");
|
|
3885
|
+
function mergeDesignTokens(base, override) {
|
|
3886
|
+
return deepMerge(base, override);
|
|
3887
|
+
}
|
|
3888
|
+
__name(mergeDesignTokens, "mergeDesignTokens");
|
|
3889
|
+
function mergeSemanticTokens(base, override) {
|
|
3890
|
+
return deepMerge(base, override);
|
|
3891
|
+
}
|
|
3892
|
+
__name(mergeSemanticTokens, "mergeSemanticTokens");
|
|
3893
|
+
function mergeTextStyles(base, override) {
|
|
3894
|
+
return deepMerge(base, override);
|
|
3895
|
+
}
|
|
3896
|
+
__name(mergeTextStyles, "mergeTextStyles");
|
|
3897
|
+
function mergeSizes(base, override) {
|
|
3898
|
+
if (!override) {
|
|
3899
|
+
return base;
|
|
3900
|
+
}
|
|
3901
|
+
const merged = {
|
|
3902
|
+
...base
|
|
3903
|
+
};
|
|
3904
|
+
for (const [key, overrideToken] of Object.entries(override)) {
|
|
3905
|
+
const next = {
|
|
3906
|
+
...merged[key],
|
|
3907
|
+
...overrideToken
|
|
3908
|
+
};
|
|
3909
|
+
validateSizeToken(key, next);
|
|
3910
|
+
merged[key] = next;
|
|
3911
|
+
}
|
|
3912
|
+
return merged;
|
|
3913
|
+
}
|
|
3914
|
+
__name(mergeSizes, "mergeSizes");
|
|
3915
|
+
function mergeTheme(base, override) {
|
|
3916
|
+
if (!override) {
|
|
3917
|
+
return base;
|
|
3918
|
+
}
|
|
3919
|
+
return {
|
|
3920
|
+
tokens: mergeDesignTokens(base.tokens, override.tokens),
|
|
3921
|
+
semanticTokens: mergeSemanticTokens(
|
|
3922
|
+
base.semanticTokens,
|
|
3923
|
+
override.semanticTokens
|
|
3924
|
+
),
|
|
3925
|
+
textStyles: mergeTextStyles(base.textStyles, override.textStyles),
|
|
3926
|
+
recipes: mergeRecipes(base.recipes, override.recipes),
|
|
3927
|
+
intensity: override.intensity ?? base.intensity,
|
|
3928
|
+
sizes: mergeSizes(base.sizes, override.sizes)
|
|
3929
|
+
};
|
|
3930
|
+
}
|
|
3931
|
+
__name(mergeTheme, "mergeTheme");
|
|
3932
|
+
function useSystemPrefersDark() {
|
|
3933
|
+
const [prefersDark, setPrefersDark] = useState(
|
|
3934
|
+
() => typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
3935
|
+
);
|
|
3936
|
+
useEffect(() => {
|
|
3937
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
3938
|
+
const handleChange = /* @__PURE__ */ __name((event) => {
|
|
3939
|
+
setPrefersDark(event.matches);
|
|
3940
|
+
}, "handleChange");
|
|
3941
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
3942
|
+
return () => {
|
|
3943
|
+
mediaQuery.removeEventListener("change", handleChange);
|
|
3944
|
+
};
|
|
3945
|
+
}, []);
|
|
3946
|
+
return prefersDark;
|
|
3947
|
+
}
|
|
3948
|
+
__name(useSystemPrefersDark, "useSystemPrefersDark");
|
|
3949
|
+
function UIProvider({
|
|
3950
|
+
children,
|
|
3951
|
+
theme: themeOverride,
|
|
3952
|
+
defaultMode = "system",
|
|
3953
|
+
as = "div",
|
|
3954
|
+
fallbackSize = "md"
|
|
3955
|
+
}) {
|
|
3956
|
+
const [mode, setMode] = useState(defaultMode);
|
|
3957
|
+
const systemPrefersDark = useSystemPrefersDark();
|
|
3958
|
+
const resolvedMode = mode === "system" ? systemPrefersDark ? "dark" : "light" : mode;
|
|
3959
|
+
const theme = useMemo(
|
|
3960
|
+
() => mergeTheme(defaultTheme, themeOverride),
|
|
3961
|
+
[themeOverride]
|
|
3962
|
+
);
|
|
3963
|
+
const resolvedTokens = useMemo(
|
|
3964
|
+
() => resolveTokens(theme.tokens, theme.semanticTokens, resolvedMode),
|
|
3965
|
+
[theme.tokens, theme.semanticTokens, resolvedMode]
|
|
3966
|
+
);
|
|
3967
|
+
const cssVars = useMemo(
|
|
3968
|
+
() => tokensToCssVars(resolvedTokens, resolvedMode, theme.intensity),
|
|
3969
|
+
[resolvedTokens, resolvedMode, theme.intensity]
|
|
3970
|
+
);
|
|
3971
|
+
useEffect(() => {
|
|
3972
|
+
if (isDev() && !theme.sizes[fallbackSize]) {
|
|
3973
|
+
console.error(
|
|
3974
|
+
`[kreativ-ui] fallbackSize="${fallbackSize}" is not a registered size in theme.sizes. Components requesting an unknown size may render without size styles.`
|
|
3975
|
+
);
|
|
3976
|
+
}
|
|
3977
|
+
}, [theme.sizes, fallbackSize]);
|
|
3978
|
+
const contextValue = useMemo(
|
|
3979
|
+
() => ({
|
|
3980
|
+
theme,
|
|
3981
|
+
mode,
|
|
3982
|
+
resolvedMode,
|
|
3983
|
+
setMode,
|
|
3984
|
+
fallbackSize,
|
|
3985
|
+
tokens: resolvedTokens
|
|
3986
|
+
}),
|
|
3987
|
+
[theme, mode, resolvedMode, fallbackSize, resolvedTokens]
|
|
3988
|
+
);
|
|
3989
|
+
const Tag = as;
|
|
3990
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
3991
|
+
Tag,
|
|
3992
|
+
{
|
|
3993
|
+
"data-kreativ-theme": resolvedMode,
|
|
3994
|
+
className: resolvedMode === "dark" ? "dark" : void 0,
|
|
3995
|
+
style: cssVars,
|
|
3996
|
+
children
|
|
3997
|
+
}
|
|
3998
|
+
) });
|
|
3999
|
+
}
|
|
4000
|
+
__name(UIProvider, "UIProvider");
|
|
4001
|
+
|
|
4002
|
+
export { Button, Checkbox, Combobox, ComboboxContent, ComboboxInput, ComboboxItem, FormField, FormFieldControl, FormFieldDescription, FormFieldLabel, FormFieldMessage, Input, MarkdownEditor, MultiSelect, MultiSelectContent, MultiSelectContext, MultiSelectItem, MultiSelectTrigger, Radio, RadioGroup, Select, SelectContent, SelectContext, SelectGroup, SelectGroupContext, SelectItem, SelectTrigger, SelectValue, Switch, Textarea, TextareaCore, ThemeContext, ThemeToggler, UIProvider, cn, defaultRecipes, defaultSizes, defaultTextStyles, defaultTheme, hexToRgbString, inputKindDefaults, rgbToHex, tokensToCssVars, useBreakpoint, useMultiSelectContext, useSelectContext, useSizeStyle, useTheme };
|
|
4003
|
+
//# sourceMappingURL=index.js.map
|
|
6
4004
|
//# sourceMappingURL=index.js.map
|