UNPKG

@stanfordspezi/spezi-web-design-system

Version:

Stanford Biodesign Digital Health Spezi Web Design System

2 lines (1 loc) 4.45 kB
"use strict";const i=require("react/jsx-runtime"),F=require("./index-DwV9MiDB.js"),$=require("react"),y=require("./index-Df0u7aLq.js"),P=require("./index-k79m3Yno.js"),h=require("./index-4XkuMsix.js"),g=require("./index-BlAHgGSW.js"),L=require("./index-BsBb8abU.js"),B=require("./index-CHmT0J_P.js"),T=require("./index-DYxWvftI.js"),z=require("./index-CldYjOhY.js");function K(o){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>o[e]})}}return t.default=o,Object.freeze(t)}const d=K($);var _="Radio",[U,E]=y.createContextScope(_),[V,H]=U(_),w=d.forwardRef((o,t)=>{const{__scopeRadio:e,name:n,checked:r=!1,required:a,disabled:c,value:f="on",onCheck:u,form:R,...v}=o,[p,m]=d.useState(null),s=P.useComposedRefs(t,b=>m(b)),l=d.useRef(!1),x=p?R||!!p.closest("form"):!0;return i.jsxs(V,{scope:e,checked:r,disabled:c,children:[i.jsx(h.Primitive.button,{type:"button",role:"radio","aria-checked":r,"data-state":k(r),"data-disabled":c?"":void 0,disabled:c,value:f,...v,ref:s,onClick:y.composeEventHandlers(o.onClick,b=>{r||u==null||u(),x&&(l.current=b.isPropagationStopped(),l.current||b.stopPropagation())})}),x&&i.jsx(j,{control:p,bubbles:!l.current,name:n,value:f,checked:r,required:a,disabled:c,form:R,style:{transform:"translateX(-100%)"}})]})});w.displayName=_;var S="RadioIndicator",I=d.forwardRef((o,t)=>{const{__scopeRadio:e,forceMount:n,...r}=o,a=H(S,e);return i.jsx(z.Presence,{present:n||a.checked,children:i.jsx(h.Primitive.span,{"data-state":k(a.checked),"data-disabled":a.disabled?"":void 0,...r,ref:t})})});I.displayName=S;var W="RadioBubbleInput",j=d.forwardRef(({__scopeRadio:o,control:t,checked:e,bubbles:n=!0,...r},a)=>{const c=d.useRef(null),f=P.useComposedRefs(c,a),u=T.usePrevious(e),R=B.useSize(t);return d.useEffect(()=>{const v=c.current;if(!v)return;const p=window.HTMLInputElement.prototype,s=Object.getOwnPropertyDescriptor(p,"checked").set;if(u!==e&&s){const l=new Event("click",{bubbles:n});s.call(v,e),v.dispatchEvent(l)}},[u,e,n]),i.jsx(h.Primitive.input,{type:"radio","aria-hidden":!0,defaultChecked:e,...r,tabIndex:-1,ref:f,style:{...r.style,...R,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});j.displayName=W;function k(o){return o?"checked":"unchecked"}var X=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],C="RadioGroup",[Y,ne]=y.createContextScope(C,[g.createRovingFocusGroupScope,E]),G=g.createRovingFocusGroupScope(),N=E(),[J,Q]=Y(C),q=d.forwardRef((o,t)=>{const{__scopeRadioGroup:e,name:n,defaultValue:r,value:a,required:c=!1,disabled:f=!1,orientation:u,dir:R,loop:v=!0,onValueChange:p,...m}=o,s=G(e),l=L.useDirection(R),[x,b]=y.useControllableState({prop:a,defaultProp:r??null,onChange:p,caller:C});return i.jsx(J,{scope:e,name:n,required:c,disabled:f,value:x,onValueChange:b,children:i.jsx(g.Root,{asChild:!0,...s,orientation:u,dir:l,loop:v,children:i.jsx(h.Primitive.div,{role:"radiogroup","aria-required":c,"aria-orientation":u,"data-disabled":f?"":void 0,dir:l,...m,ref:t})})})});q.displayName=C;var A="RadioGroupItem",D=d.forwardRef((o,t)=>{const{__scopeRadioGroup:e,disabled:n,...r}=o,a=Q(A,e),c=a.disabled||n,f=G(e),u=N(e),R=d.useRef(null),v=P.useComposedRefs(t,R),p=a.value===r.value,m=d.useRef(!1);return d.useEffect(()=>{const s=x=>{X.includes(x.key)&&(m.current=!0)},l=()=>m.current=!1;return document.addEventListener("keydown",s),document.addEventListener("keyup",l),()=>{document.removeEventListener("keydown",s),document.removeEventListener("keyup",l)}},[]),i.jsx(g.Item,{asChild:!0,...f,focusable:!c,active:p,children:i.jsx(w,{disabled:c,required:a.required,checked:p,...u,...r,name:a.name,ref:v,onCheck:()=>a.onValueChange(r.value),onKeyDown:y.composeEventHandlers(s=>{s.key==="Enter"&&s.preventDefault()}),onFocus:y.composeEventHandlers(r.onFocus,()=>{var s;m.current&&((s=R.current)==null||s.click())})})})});D.displayName=A;var Z="RadioGroupIndicator",O=d.forwardRef((o,t)=>{const{__scopeRadioGroup:e,...n}=o,r=N(e);return i.jsx(I,{...r,...n,ref:t})});O.displayName=Z;var M=q,ee=D,oe=O;const re=M,te=({className:o,...t})=>i.jsx(ee,{className:F.cn("focus-ring flex-center border-input size-4 shrink-0 rounded-full border disabled:cursor-not-allowed disabled:opacity-50",o),...t,children:i.jsx(oe,{className:"flex-center bg-primary size-2 rounded-full"})});exports.Radio=te;exports.RadioRoot=re;exports.Root2=M;