UNPKG

@styleless-ui/react

Version:

Completely unstyled, headless and accessible React UI components.

1 lines 1.95 kB
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var l,r=1,a=arguments.length;r<a;r++)for(var t in l=arguments[r])Object.prototype.hasOwnProperty.call(l,t)&&(e[t]=l[t]);return e},e.apply(this,arguments)},l=this&&this.__rest||function(e,l){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&l.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var t=0;for(a=Object.getOwnPropertySymbols(e);t<a.length;t++)l.indexOf(a[t])<0&&Object.prototype.propertyIsEnumerable.call(e,a[t])&&(r[a[t]]=e[a[t]])}return r};import{jsx as r,jsxs as a}from"react/jsx-runtime";import{componentWithForwardedRef as t,useControlledProp as n,useDeterministicId as o}from"../../utils";import{RadioGroupLabel as i,RadioGroupRoot as s}from"../slots";import u from"./context";var b=t((function(t,b){var d=t.children,c=t.classes,p=t.value,f=t.defaultValue,y=t.onValueChange,v=t.label,h=t.id,m=l(t,["children","classes","value","defaultValue","onValueChange","label","id"]),g=o(h,"styleless-ui__menu-radio-group"),O=g?"".concat(g,"__label"):void 0,j=function(e){var l={};if("string"==typeof e)l.visibleLabel=e;else if("screenReaderLabel"in e)l.srOnlyLabel=e.screenReaderLabel;else{if(!("labelledBy"in e))throw new Error(["[StylelessUI][Menu.RadioGroup]: Invalid `label` property.","The `label` property must be either a `string` or in shape of `{ screenReaderLabel: string; } | { labelledBy: string; }`"].join("\n"));l.labelledBy=e.labelledBy}return l}(v),L=n(p,f,""),x=L[0],_=L[1];return a("div",e({},m,{id:g,ref:b,className:null==c?void 0:c.root,role:"group",tabIndex:-1,"data-slot":s,"aria-label":j.srOnlyLabel,"aria-labelledby":j.visibleLabel?O:j.labelledBy},{children:[j.visibleLabel&&r("span",e({id:O,"data-slot":i,className:null==c?void 0:c.label},{children:j.visibleLabel})),r(u.Provider,e({value:{value:x,onValueChange:function(e){_(e),null==y||y(e)}}},{children:d}))]}))}));export default b;