@styleless-ui/react
Version:
Completely unstyled, headless and accessible React UI components.
1 lines • 2.67 kB
JavaScript
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)},t=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r};import{jsx as r}from"react/jsx-runtime";import*as n from"react";import{disableUserSelectCSSProperties as i}from"../../internals";import{componentWithForwardedRef as o,useEventCallback as u,useForkedRefs as l}from"../../utils";import s from"../context";import{ItemRoot as c}from"../slots";import a from"../useMenuItem";import f from"./context";var v=o((function(o,v){var d,m=o.children,p=o.className,b=o.disabled,h=void 0!==b&&b,g=o.onClick,y=o.onMouseEnter,M=o.onMouseLeave,O=o.onSelect,x=o.style,A=t(o,["children","className","disabled","onClick","onMouseEnter","onMouseLeave","onSelect","style"]),S=n.useContext(s),E=n.useRef(null),I=l(v,E),j=function(){return null!=E.current&&(null==S?void 0:S.activeSubTrigger)===E.current},C=!(!S||!E.current)&&S.activeElement===E.current,k={disabled:h,active:C,isSubMenuOpen:j()},L="function"==typeof m?m(k):m,P="function"==typeof p?p(k):p,w=n.useRef(),R=(d=w,function(e,t){d.current={ref:e,id:t}}),T=a({disabled:h,isActive:C,onClick:g,onMouseEnter:u((function(e){var t;if(e.currentTarget!==E.current||!S)return null==y?void 0:y(e);S.setActiveElement(E.current),S.shouldActivateFirstSubItemRef.current=!1,S.setIsMenuActive(!0),w.current&&(S.setActiveSubTrigger(E.current),null===(t=w.current.ctx)||void 0===t||t.setIsMenuActive(!1)),null==y||y(e)})),onMouseLeave:u((function(e){var t;null==S||S.setActiveElement(null),w.current&&(null==S||S.setActiveSubTrigger(null),null===(t=w.current.ctx)||void 0===t||t.setIsMenuActive(!0)),null==M||M(e)})),changeEmitter:u((function(e){null==O||O(e)}))});return r("div",e({},A,{ref:function(e){if(I(e),e&&(null==S||S.registerItem(E),w.current)){var t=w.current.id;e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded",String(j())),t&&e.setAttribute("aria-controls",t)}},className:P,onClick:T.handleClick,onMouseEnter:T.handleMouseEnter,onMouseLeave:T.handleMouseLeave,style:x?e(e({},x),i):i,tabIndex:-1,role:"menuitem","data-slot":c,"data-active":C?"":void 0,"aria-disabled":h},{children:r(f.Provider,e({value:{ref:E,isSubMenuOpen:j,registerSubMenu:R}},{children:L}))}))}));export default v;