UNPKG

ivt

Version:

Ivt Components Library

3 lines (2 loc) 4.93 kB
import*as e from"react";import{c as r}from"../chunks/index-DVnblQ-a.mjs";import{u as a}from"../chunks/index-C-j8pU3U.mjs";import{c as o}from"../chunks/index-Dr5ObK3L.mjs";import{P as t}from"../chunks/index-DiPp8h7C.mjs";import{c as i,R as n,I as s}from"../chunks/index-9IZ9Aw1I.mjs";import{u as d}from"../chunks/index-BOUg6o32.mjs";import{u as c}from"../chunks/index-DBjm5RwN.mjs";import{u}from"../chunks/index-CnLJ482V.mjs";import{u as l}from"../chunks/index-DzFekr2h.mjs";import{P as m}from"../chunks/index-1xuBLrml.mjs";import{jsx as p,jsxs as f}from"react/jsx-runtime";import{c as h}from"../chunks/utils-C-nkZ_Ir.mjs";import{C as b}from"../chunks/circle-Dt7_dwrq.mjs";import"react-dom";import"@radix-ui/react-slot";import"@radix-ui/react-collection";import"../chunks/index-UQBMY2z8.mjs";import"../chunks/index-0-u0cdz8.mjs";import"../chunks/index-DSUHCtxx.mjs";import"../chunks/bundle-mjs-DHbvkKp4.mjs";import"../chunks/createLucideIcon-D1jKv6AP.mjs";var k="Radio",[v,y]=o(k),[x,R]=v(k),g=e.forwardRef((o,i)=>{const{__scopeRadio:n,name:s,checked:d=!1,required:c,disabled:u,value:l="on",onCheck:m,form:h,...b}=o,[k,v]=e.useState(null),y=a(i,e=>v(e)),R=e.useRef(!1),g=!k||(h||!!k.closest("form"));return f(x,{scope:n,checked:d,disabled:u,children:[p(t.button,{type:"button",role:"radio","aria-checked":d,"data-state":C(d),"data-disabled":u?"":void 0,disabled:u,value:l,...b,ref:y,onClick:r(o.onClick,e=>{d||m?.(),g&&(R.current=e.isPropagationStopped(),R.current||e.stopPropagation())})}),g&&p(E,{control:k,bubbles:!R.current,name:s,value:l,checked:d,required:c,disabled:u,form:h,style:{transform:"translateX(-100%)"}})]})});g.displayName=k;var j="RadioIndicator",w=e.forwardRef((e,r)=>{const{__scopeRadio:a,forceMount:o,...i}=e,n=R(j,a);return p(m,{present:o||n.checked,children:p(t.span,{"data-state":C(n.checked),"data-disabled":n.disabled?"":void 0,...i,ref:r})})});w.displayName=j;var E=e.forwardRef(({__scopeRadio:r,control:o,checked:i,bubbles:n=!0,...s},d)=>{const c=e.useRef(null),m=a(c,d),f=l(i),h=u(o);return e.useEffect(()=>{const e=c.current;if(!e)return;const r=window.HTMLInputElement.prototype,a=Object.getOwnPropertyDescriptor(r,"checked").set;if(f!==i&&a){const r=new Event("click",{bubbles:n});a.call(e,i),e.dispatchEvent(r)}},[f,i,n]),p(t.input,{type:"radio","aria-hidden":!0,defaultChecked:i,...s,tabIndex:-1,ref:m,style:{...s.style,...h,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});function C(e){return e?"checked":"unchecked"}E.displayName="RadioBubbleInput";var N=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],_="RadioGroup",[q,I]=o(_,[i,y]),L=i(),G=y(),[P,A]=q(_),D=e.forwardRef((e,r)=>{const{__scopeRadioGroup:a,name:o,defaultValue:i,value:s,required:u=!1,disabled:l=!1,orientation:m,dir:f,loop:h=!0,onValueChange:b,...k}=e,v=L(a),y=c(f),[x,R]=d({prop:s,defaultProp:i??null,onChange:b,caller:_});return p(P,{scope:a,name:o,required:u,disabled:l,value:x,onValueChange:R,children:p(n,{asChild:!0,...v,orientation:m,dir:y,loop:h,children:p(t.div,{role:"radiogroup","aria-required":u,"aria-orientation":m,"data-disabled":l?"":void 0,dir:y,...k,ref:r})})})});D.displayName=_;var V="RadioGroupItem",M=e.forwardRef((o,t)=>{const{__scopeRadioGroup:i,disabled:n,...d}=o,c=A(V,i),u=c.disabled||n,l=L(i),m=G(i),f=e.useRef(null),h=a(t,f),b=c.value===d.value,k=e.useRef(!1);return e.useEffect(()=>{const e=e=>{N.includes(e.key)&&(k.current=!0)},r=()=>k.current=!1;return document.addEventListener("keydown",e),document.addEventListener("keyup",r),()=>{document.removeEventListener("keydown",e),document.removeEventListener("keyup",r)}},[]),p(s,{asChild:!0,...l,focusable:!u,active:b,children:p(g,{disabled:u,required:c.required,checked:b,...m,...d,name:c.name,ref:h,onCheck:()=>c.onValueChange(d.value),onKeyDown:r(e=>{"Enter"===e.key&&e.preventDefault()}),onFocus:r(d.onFocus,()=>{k.current&&f.current?.click()})})})});M.displayName=V;var z=e.forwardRef((e,r)=>{const{__scopeRadioGroup:a,...o}=e,t=G(a);return p(w,{...t,...o,ref:r})});z.displayName="RadioGroupIndicator";var F=D,K=M,O=z;function S({className:r,...a}){return e.createElement(F,{"data-slot":"radio-group",className:h("grid gap-3",r),...a})}function B({className:r,...a}){return e.createElement(K,{"data-slot":"radio-group-item",className:h("border-input text-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 aspect-square size-4 shrink-0 rounded-full border shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",r),...a},e.createElement(O,{"data-slot":"radio-group-indicator",className:"relative flex items-center justify-center"},e.createElement(b,{className:"fill-primary absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2"})))}export{S as RadioGroup,B as RadioGroupItem}; //# sourceMappingURL=index.mjs.map