pre-installations and preparations

This commit is contained in:
MuhammadKhalilzadeh committed 2024-05-05 11:21:00 +03:30
1 parent 3e5a0329cb
commit 201d621ac3
6977 files changed
+742826

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { MenuTypeMap } from './Menu.types';
/**
*
* Demos:
*
* - [Menu](https://mui.com/base-ui/react-menu/)
*
* API:
*
* - [Menu API](https://mui.com/base-ui/react-menu/components-api/#menu)
*/
declare const Menu: PolymorphicComponent<MenuTypeMap<{}, "div">>;
export { Menu };
+161
View File
@@ -0,0 +1,161 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["actions", "anchor", "children", "onItemsChange", "slotProps", "slots"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { HTMLElementType, refType } from '@mui/utils';
import { getMenuUtilityClass } from './menuClasses';
import { useMenu } from '../useMenu';
import { MenuProvider } from '../useMenu/MenuProvider';
import { unstable_composeClasses as composeClasses } from '../composeClasses';
import { Unstable_Popup as Popup } from '../Unstable_Popup';
import { useSlotProps } from '../utils/useSlotProps';
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
import { ListActionTypes } from '../useList';
import { jsx as _jsx } from "react/jsx-runtime";
function useUtilityClasses(ownerState) {
const {
open
} = ownerState;
const slots = {
root: ['root', open && 'expanded'],
listbox: ['listbox', open && 'expanded']
};
return composeClasses(slots, useClassNamesOverride(getMenuUtilityClass));
}
/**
*
* Demos:
*
* - [Menu](https://mui.com/base-ui/react-menu/)
*
* API:
*
* - [Menu API](https://mui.com/base-ui/react-menu/components-api/#menu)
*/
const Menu = /*#__PURE__*/React.forwardRef(function Menu(props, forwardedRef) {
var _slots$root, _slots$listbox;
const {
actions,
anchor: anchorProp,
children,
onItemsChange,
slotProps = {},
slots = {}
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const {
contextValue,
getListboxProps,
dispatch,
open,
triggerElement
} = useMenu({
onItemsChange,
componentName: 'Menu'
});
const anchor = anchorProp != null ? anchorProp : triggerElement;
React.useImperativeHandle(actions, () => ({
dispatch,
resetHighlight: () => dispatch({
type: ListActionTypes.resetHighlight,
event: null
})
}), [dispatch]);
const ownerState = _extends({}, props, {
open
});
const classes = useUtilityClasses(ownerState);
const Root = (_slots$root = slots.root) != null ? _slots$root : 'div';
const rootProps = useSlotProps({
elementType: Root,
externalSlotProps: slotProps.root,
externalForwardedProps: other,
additionalProps: {
ref: forwardedRef,
role: undefined
},
className: classes.root,
ownerState
});
const Listbox = (_slots$listbox = slots.listbox) != null ? _slots$listbox : 'ul';
const listboxProps = useSlotProps({
elementType: Listbox,
getSlotProps: getListboxProps,
externalSlotProps: slotProps.listbox,
className: classes.listbox,
ownerState
});
if (open === true && anchor == null) {
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
children: /*#__PURE__*/_jsx(Listbox, _extends({}, listboxProps, {
children: /*#__PURE__*/_jsx(MenuProvider, {
value: contextValue,
children: children
})
}))
}));
}
return /*#__PURE__*/_jsx(Popup, _extends({
keepMounted: true
}, rootProps, {
open: open,
anchor: anchor,
slots: {
root: Root
},
children: /*#__PURE__*/_jsx(Listbox, _extends({}, listboxProps, {
children: /*#__PURE__*/_jsx(MenuProvider, {
value: contextValue,
children: children
})
}))
}));
});
process.env.NODE_ENV !== "production" ? Menu.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* A ref with imperative actions that can be performed on the menu.
*/
actions: refType,
/**
* The element based on which the menu is positioned.
*/
anchor: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([HTMLElementType, PropTypes.object, PropTypes.func]),
/**
* @ignore
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Function called when the items displayed in the menu change.
*/
onItemsChange: PropTypes.func,
/**
* The props used for each slot inside the Menu.
* @default {}
*/
slotProps: PropTypes.shape({
listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside the Menu.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
root: PropTypes.elementType
})
} : void 0;
export { Menu };
+81
View File
@@ -0,0 +1,81 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { PolymorphicProps, SlotComponentProps } from '../utils';
import { UseMenuListboxSlotProps } from '../useMenu';
import { ListAction } from '../useList';
import { PopupProps } from '../Unstable_Popup';
export interface MenuRootSlotPropsOverrides {
}
export interface MenuListboxSlotPropsOverrides {
}
export interface MenuActions {
/**
* Dispatches an action that can cause a change to the menu's internal state.
*/
dispatch: (action: ListAction<string>) => void;
/**
* Resets the highlighted item.
*/
resetHighlight: () => void;
}
export interface MenuOwnProps {
/**
* A ref with imperative actions that can be performed on the menu.
*/
actions?: React.Ref<MenuActions>;
/**
* The element based on which the menu is positioned.
*/
anchor?: PopupProps['anchor'];
children?: React.ReactNode;
className?: string;
/**
* Function called when the items displayed in the menu change.
*/
onItemsChange?: (items: string[]) => void;
/**
* The props used for each slot inside the Menu.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'div', MenuRootSlotPropsOverrides & PopupProps, MenuOwnerState>;
listbox?: SlotComponentProps<'ul', MenuListboxSlotPropsOverrides, MenuOwnerState>;
};
/**
* The components used for each slot inside the Menu.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: MenuSlots;
}
export interface MenuSlots {
/**
* The component that renders the popup element.
* @default 'div'
*/
root?: React.ElementType;
/**
* The component that renders the listbox.
* @default 'ul'
*/
listbox?: React.ElementType;
}
export interface MenuTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
props: MenuOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type MenuProps<RootComponentType extends React.ElementType = MenuTypeMap['defaultComponent']> = PolymorphicProps<MenuTypeMap<{}, RootComponentType>, RootComponentType>;
export type MenuOwnerState = Simplify<MenuOwnProps & {
open: boolean;
}>;
export type MenuRootSlotProps = {
children?: React.ReactNode;
className?: string;
ownerState: MenuOwnerState;
ref: React.Ref<any>;
};
export type MenuListboxSlotProps = UseMenuListboxSlotProps & {
children?: React.ReactNode;
className?: string;
ownerState: MenuOwnerState;
};
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export { Menu } from './Menu';
export * from './menuClasses';
export * from './Menu.types';
+3
View File
@@ -0,0 +1,3 @@
export { Menu } from './Menu';
export * from './menuClasses';
export * from './Menu.types';
+11
View File
@@ -0,0 +1,11 @@
export interface MenuClasses {
/** Class name applied to the root element. */
root: string;
/** Class name applied to the listbox element. */
listbox: string;
/** State class applied to the root element if `open={true}`. */
expanded: string;
}
export type MenuClassKey = keyof MenuClasses;
export declare function getMenuUtilityClass(slot: string): string;
export declare const menuClasses: MenuClasses;
+7
View File
@@ -0,0 +1,7 @@
import { generateUtilityClass } from '../generateUtilityClass';
import { generateUtilityClasses } from '../generateUtilityClasses';
const COMPONENT_NAME = 'Menu';
export function getMenuUtilityClass(slot) {
return generateUtilityClass(COMPONENT_NAME, slot);
}
export const menuClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'listbox', 'expanded']);
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Menu/index.js",
"types": "./index.d.ts"
}