UNPKG

@styleless-ui/react

Version:

Completely unstyled, headless and accessible React UI components.

1 lines 2.1 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 i}from"../utils";import o from"./context";import*as s from"./slots";var c=t((function(t,c){var b=t.label,u=t.children,d=t.id,p=t.classes,f=t.defaultValue,v=t.value,y=t.onChange,h=t.orientation,g=void 0===h?"vertical":h,m=l(t,["label","children","id","classes","defaultValue","value","onChange","orientation"]),O=i(d,"styleless-ui__check-group"),j=O?"".concat(O,"__label"):void 0,L=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][CheckGroup]: 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}(b),_=n(v,f,[]),x=_[0],w=_[1];return r("div",e({},m,{id:O,ref:c,className:null==p?void 0:p.root,"data-slot":s.Root},{children:a(o.Provider,e({value:{value:x,onChange:function(e,l){var r=e?x.concat(l):x.filter((function(e){return e!==l}));w(r),null==y||y(r)}}},{children:[L.visibleLabel&&r("span",e({id:j,"data-slot":s.Label,className:null==p?void 0:p.label},{children:L.visibleLabel})),r("div",e({role:"group","data-slot":s.Group,className:null==p?void 0:p.group,"aria-label":L.srOnlyLabel,"aria-orientation":g,"aria-labelledby":L.visibleLabel?j:L.labelledBy},{children:u}))]}))}))}));export default c;