@styleless-ui/react
Version:
Completely unstyled, headless and accessible React UI components.
1 lines • 1.99 kB
JavaScript
var t=this&&this.__assign||function(){return t=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)},e=this&&this.__rest||function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r};import{jsx as r}from"react/jsx-runtime";import*as n from"react";import{componentWithForwardedRef as o,useControlledProp as i,useForkedRefs as a,useIsMounted as l}from"../utils";import c from"./context";import{Root as s}from"./slots";var u=o((function(o,u){var f=o.children,d=o.className,v=o.onChange,h=o.defaultActiveTab,p=o.activeTab,b=o.keyboardActivationBehavior,m=void 0===b?"manual":b,y=o.orientation,O=void 0===y?"horizontal":y,g=e(o,["children","className","onChange","defaultActiveTab","activeTab","keyboardActivationBehavior","orientation"]),j=l(),x=n.useRef(),T=a(u,x),A=i(p,h,0),w=A[0],E=A[1],P=n.Children.map(f,(function(t){return n.isValidElement(t)?t:null})),C=[],I=[];return n.useEffect((function(){var t,e=null===(t=x.current)||void 0===t?void 0:t.querySelectorAll('[role="tab"]');if(e){var r=e[w];if(r&&(r.disabled||r.hasAttribute("disabled")))throw new Error("[StylelessUI][TabGroup.Root]: The selected tab is `disabled`.")}}),[]),r("div",t({},g,{className:d,ref:T,"data-slot":s},{children:r(c.Provider,t({value:{activeTab:w,tabs:C,panels:I,register:function(t){t.current&&(t.current instanceof HTMLDivElement?I.findIndex((function(e){return e.current===t.current}))<0&&I.push(t):C.findIndex((function(e){return e.current===t.current}))<0&&C.push(t))},orientation:O,keyboardActivationBehavior:m,onChange:function(t){j()&&(E(t),null==v||v(t))}}},{children:P}))}))}));export default u;