@royyanbach-mhg-test/material-tailwind-react
Version:
@material-tailwind/react is an easy-to-use components library for ReactJS & Tailwind CSS inspired by Material Design.
1 lines • 7.24 kB
JavaScript
function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}import React from"react";import PropTypes from"prop-types";import{useFloating,useFloatingTree,useFloatingNodeId,useFloatingParentNodeId,FloatingNode,useInteractions,offset as fuiOffset,flip,shift,useHover,useClick,useRole,useDismiss,safePolygon,useListNavigation,useTypeahead,useMergeRefs,autoUpdate}from"@floating-ui/react";import merge from"deepmerge";import{useTheme}from"../../context/theme";import{MenuContextProvider}from"./MenuContext";import{propTypesOpen,propTypesHandler,propTypesPlacement,propTypesOffset,propTypesDismiss,propTypesAnimate,propTypesLockScroll,propTypesChildren}from"../../types/components/menu";export var MenuCore=React.forwardRef(function(param,ref){var open=param.open,handler=param.handler,placement=param.placement,offset=param.offset,dismiss=param.dismiss,animate=param.animate,lockScroll=param.lockScroll,allowHover=param.allowHover,children=param.children;var menu=useTheme().menu;var defaultProps=menu.defaultProps;var _React_useState=_slicedToArray(React.useState(false),2),internalOpen=_React_useState[0],setInternalOpen=_React_useState[1];var _React_useState1=_slicedToArray(React.useState(false),2),internalAllowHover=_React_useState1[0],setInternalAllowHover=_React_useState1[1];open=open!==null&&open!==void 0?open:internalOpen;handler=handler!==null&&handler!==void 0?handler:setInternalOpen;placement=placement!==null&&placement!==void 0?placement:defaultProps.placement;offset=offset!==null&&offset!==void 0?offset:defaultProps.offset;dismiss=dismiss!==null&&dismiss!==void 0?dismiss:defaultProps.dismiss;animate=animate!==null&&animate!==void 0?animate:defaultProps.animate;lockScroll=lockScroll!==null&&lockScroll!==void 0?lockScroll:defaultProps.lockScroll;var animation={unmount:{opacity:0,transformOrigin:"top",transform:"scale(0.95)",transition:{duration:.2,times:[.4,0,.2,1]}},mount:{opacity:1,transformOrigin:"top",transform:"scale(1)",transition:{duration:.2,times:[.4,0,.2,1]}}};var appliedAnimation=merge(animation,animate);var _React_useState2=_slicedToArray(React.useState(null),2),activeIndex=_React_useState2[0],setActiveIndex=_React_useState2[1];var listItemsRef=React.useRef([]);var listContentRef=React.useRef(React.Children.map(children,function(child){return React.isValidElement(child)?child.props.label:null}));var tree=useFloatingTree();var nodeId=useFloatingNodeId();var parentId=useFloatingParentNodeId();var nested=parentId!=null;var _useFloating=useFloating({open:open,nodeId:nodeId,placement:placement,onOpenChange:handler,middleware:[fuiOffset(offset),flip(),shift()],whileElementsMounted:autoUpdate}),x=_useFloating.x,y=_useFloating.y,strategy=_useFloating.strategy,refs=_useFloating.refs,context=_useFloating.context;var _useInteractions=useInteractions([useHover(context,{handleClose:safePolygon({restMs:25,blockPointerEvents:true}),enabled:allowHover||nested&&internalAllowHover,delay:{open:75}}),useClick(context,{toggle:!nested||!internalAllowHover,event:"mousedown",ignoreMouse:nested}),useRole(context,{role:"menu"}),useDismiss(context,dismiss),useListNavigation(context,{listRef:listItemsRef,activeIndex:activeIndex,nested:nested,onNavigate:setActiveIndex}),useTypeahead(context,{listRef:listContentRef,onMatch:open?setActiveIndex:undefined,activeIndex:activeIndex})]),getReferenceProps=_useInteractions.getReferenceProps,getFloatingProps=_useInteractions.getFloatingProps,getItemProps=_useInteractions.getItemProps;React.useEffect(function(){var handleTreeClick=function handleTreeClick(){if(dismiss.itemPress)handler(false)};var onSubMenuOpen=function onSubMenuOpen(event){if(event.nodeId!==nodeId&&event.parentId===parentId){handler(false)}};tree===null||tree===void 0?void 0:tree.events.on("click",handleTreeClick);tree===null||tree===void 0?void 0:tree.events.on("menuopen",onSubMenuOpen);return function(){tree===null||tree===void 0?void 0:tree.events.off("click",handleTreeClick);tree===null||tree===void 0?void 0:tree.events.off("menuopen",onSubMenuOpen)}},[tree,nodeId,parentId,handler,dismiss]);React.useEffect(function(){if(open){tree===null||tree===void 0?void 0:tree.events.emit("menuopen",{parentId:parentId,nodeId:nodeId})}},[tree,open,nodeId,parentId]);React.useEffect(function(){var onPointerMove=function onPointerMove(param){var pointerType=param.pointerType;if(pointerType!=="touch"){setInternalAllowHover(true)}};var onKeyDown=function onKeyDown(){setInternalAllowHover(false)};window.addEventListener("pointermove",onPointerMove,{once:true,capture:true});window.addEventListener("keydown",onKeyDown,true);return function(){window.removeEventListener("pointermove",onPointerMove,{capture:true});window.removeEventListener("keydown",onKeyDown,true)}},[internalAllowHover]);var referenceRef=useMergeRefs([refs.setReference,ref]);var contextValue=React.useMemo(function(){return{open:open,handler:handler,setInternalOpen:setInternalOpen,strategy:strategy,x:x,y:y,reference:referenceRef,floating:refs.setFloating,listItemsRef:listItemsRef,getReferenceProps:getReferenceProps,getFloatingProps:getFloatingProps,getItemProps:getItemProps,appliedAnimation:appliedAnimation,lockScroll:lockScroll,context:context,activeIndex:activeIndex,tree:tree,allowHover:allowHover,internalAllowHover:internalAllowHover,nested:nested,setActiveIndex:setActiveIndex}},[open,handler,setInternalOpen,strategy,x,y,referenceRef,refs,getReferenceProps,getFloatingProps,getItemProps,appliedAnimation,lockScroll,context,activeIndex,tree,allowHover,internalAllowHover,nested,setActiveIndex]);return React.createElement(MenuContextProvider,{value:contextValue},React.createElement(FloatingNode,{id:nodeId},children))});MenuCore.propTypes={open:propTypesOpen,handler:propTypesHandler,placement:PropTypes.oneOf(propTypesPlacement),offset:propTypesOffset,dismiss:propTypesDismiss,animate:propTypesAnimate,lockScroll:propTypesLockScroll,children:propTypesChildren};MenuCore.displayName="MaterialTailwind.MenuCore";export default MenuCore;