@mui/joy
Version:
Joy UI is an open-source React component library that implements MUI's own design principles. It's comprehensive and can be used in production out of the box.
191 lines (190 loc) • 6.72 kB
JavaScript
'use client';
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["actions", "id", "component", "children", "size", "variant", "color", "onItemsChange", "slots", "slotProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_capitalize as capitalize, refType } from '@mui/utils';
import { unstable_composeClasses as composeClasses } from '@mui/base/composeClasses';
import { useMenu, MenuProvider } from '@mui/base/useMenu';
import { ListActionTypes } from '@mui/base/useList';
import { styled, useThemeProps } from '../styles';
import { StyledList } from '../List/List';
import ListProvider, { scopedVariables } from '../List/ListProvider';
import GroupListContext from '../List/GroupListContext';
import { getMenuListUtilityClass } from './menuListClasses';
import useSlot from '../utils/useSlot';
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
variant,
color,
size
} = ownerState;
const slots = {
root: ['root', variant && `variant${capitalize(variant)}`, color && `color${capitalize(color)}`, size && `size${capitalize(size)}`]
};
return composeClasses(slots, getMenuListUtilityClass, {});
};
const MenuListRoot = styled(StyledList, {
name: 'JoyMenuList',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
})(({
theme,
ownerState
}) => {
var _theme$variants;
const variantStyle = (_theme$variants = theme.variants[ownerState.variant]) == null ? void 0 : _theme$variants[ownerState.color];
return _extends({
'--focus-outline-offset': `calc(${theme.vars.focus.thickness} * -1)`,
// to prevent the focus outline from being cut by overflow
'--ListItem-stickyBackground': (variantStyle == null ? void 0 : variantStyle.backgroundColor) || (variantStyle == null ? void 0 : variantStyle.background) || theme.vars.palette.background.surface,
'--ListItem-stickyTop': 'calc(var(--List-padding, var(--ListDivider-gap)) * -1)'
}, scopedVariables, {
borderRadius: `var(--List-radius, ${theme.vars.radius.sm})`,
overflow: 'auto'
}, !(variantStyle != null && variantStyle.backgroundColor) && {
backgroundColor: theme.vars.palette.background.surface
});
});
/**
*
* Demos:
*
* - [Menu](https://mui.com/joy-ui/react-menu/)
*
* API:
*
* - [MenuList API](https://mui.com/joy-ui/api/menu-list/)
*/
const MenuList = /*#__PURE__*/React.forwardRef(function MenuList(inProps, ref) {
const props = useThemeProps({
props: inProps,
name: 'JoyMenuList'
});
const {
actions,
id: idProp,
component,
children,
size = 'md',
variant = 'outlined',
color = 'neutral',
onItemsChange,
slots = {},
slotProps = {}
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const {
contextValue: menuContextValue,
getListboxProps,
dispatch
} = useMenu({
listboxRef: ref,
id: idProp,
onItemsChange
});
React.useImperativeHandle(actions, () => ({
dispatch,
resetHighlight: () => dispatch({
type: ListActionTypes.resetHighlight,
event: null
})
}), [dispatch]);
const ownerState = _extends({}, props, {
variant,
color,
size,
nesting: false,
row: false
});
const classes = useUtilityClasses(ownerState);
const externalForwardedProps = _extends({}, other, {
component,
slots,
slotProps
});
const [SlotRoot, rootProps] = useSlot('root', {
ref,
elementType: MenuListRoot,
getSlotProps: getListboxProps,
externalForwardedProps,
ownerState,
className: classes.root
});
return /*#__PURE__*/_jsx(SlotRoot, _extends({}, rootProps, {
children: /*#__PURE__*/_jsx(MenuProvider, {
value: menuContextValue,
children: /*#__PURE__*/_jsx(GroupListContext.Provider, {
value: "menu",
children: /*#__PURE__*/_jsx(ListProvider, {
nested: true,
children: children
})
})
})
}));
});
process.env.NODE_ENV !== "production" ? MenuList.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.
* It allows to select the first or last menu item.
*/
actions: refType,
/**
* @ignore
*/
children: PropTypes.node,
/**
* The color of the component. It supports those theme colors that make sense for this component.
* @default 'neutral'
*/
color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']), PropTypes.string]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* @ignore
*/
id: PropTypes.string,
/**
* Function called when the items displayed in the menu change.
*/
onItemsChange: PropTypes.func,
/**
* The size of the component (affect other nested list* components because the `Menu` inherits `List`).
* @default 'md'
*/
size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['sm', 'md', 'lg']), PropTypes.string]),
/**
* The props used for each slot inside.
* @default {}
*/
slotProps: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside.
* @default {}
*/
slots: PropTypes.shape({
root: PropTypes.elementType
}),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
/**
* The [global variant](https://mui.com/joy-ui/main-features/global-variants/) to use.
* @default 'outlined'
*/
variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['outlined', 'plain', 'soft', 'solid']), PropTypes.string])
} : void 0;
export default MenuList;