diff --git a/docs/data/base/components/menu/MenuSimple/tailwind/index.js b/docs/data/base/components/menu/MenuSimple/tailwind/index.js index 1497c91f85cec5..7dfa9d0f74b465 100644 --- a/docs/data/base/components/menu/MenuSimple/tailwind/index.js +++ b/docs/data/base/components/menu/MenuSimple/tailwind/index.js @@ -1,5 +1,7 @@ import * as React from 'react'; -import { Menu } from '@mui/base/Menu'; +import PropTypes from 'prop-types'; +import clsx from 'clsx'; +import { Menu as BaseMenu } from '@mui/base/Menu'; import { MenuButton } from '@mui/base/MenuButton'; import { MenuItem } from '@mui/base/MenuItem'; import { Dropdown } from '@mui/base/Dropdown'; @@ -27,17 +29,7 @@ export default function MenuSimple() { Dashboard - + ); } + +const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn); + +const Menu = React.forwardRef((props, ref) => { + // Replace this with your app logic for determining dark modes + const isDarkMode = useIsDarkMode(); + + return ( + { + const resolvedSlotProps = resolveSlotProps( + props.slotProps?.root, + ownerState, + ); + return { + ...resolvedSlotProps, + className: clsx( + `${isDarkMode ? 'dark' : ''} z-10`, + resolvedSlotProps?.className, + ), + }; + }, + listbox: (ownerState) => { + const resolvedSlotProps = resolveSlotProps( + props.slotProps?.listbox, + ownerState, + ); + return { + ...resolvedSlotProps, + className: clsx( + 'text-sm box-border font-sans p-1.5 my-3 mx-0 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 min-w-listbox shadow-md dark:shadow-slate-900', + resolvedSlotProps?.className, + ), + }; + }, + }} + /> + ); +}); + +Menu.propTypes = { + /** + * 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]), + }), +}; diff --git a/docs/data/base/components/menu/MenuSimple/tailwind/index.tsx b/docs/data/base/components/menu/MenuSimple/tailwind/index.tsx index 22fdf714067046..c6f09f53248184 100644 --- a/docs/data/base/components/menu/MenuSimple/tailwind/index.tsx +++ b/docs/data/base/components/menu/MenuSimple/tailwind/index.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; -import { Menu } from '@mui/base/Menu'; +import clsx from 'clsx'; +import { Menu as BaseMenu, MenuProps } from '@mui/base/Menu'; import { MenuButton } from '@mui/base/MenuButton'; import { MenuItem } from '@mui/base/MenuItem'; import { Dropdown } from '@mui/base/Dropdown'; @@ -27,17 +28,7 @@ export default function MenuSimple() { Dashboard - + ); } + +const resolveSlotProps = (fn: any, args: any) => + typeof fn === 'function' ? fn(args) : fn; + +const Menu = React.forwardRef((props, ref) => { + // Replace this with your app logic for determining dark modes + const isDarkMode = useIsDarkMode(); + + return ( + { + const resolvedSlotProps = resolveSlotProps( + props.slotProps?.root, + ownerState, + ); + return { + ...resolvedSlotProps, + className: clsx( + `${isDarkMode ? 'dark' : ''} z-10`, + resolvedSlotProps?.className, + ), + }; + }, + listbox: (ownerState) => { + const resolvedSlotProps = resolveSlotProps( + props.slotProps?.listbox, + ownerState, + ); + return { + ...resolvedSlotProps, + className: clsx( + 'text-sm box-border font-sans p-1.5 my-3 mx-0 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 min-w-listbox shadow-md dark:shadow-slate-900', + resolvedSlotProps?.className, + ), + }; + }, + }} + /> + ); +});