fix(striker-ui): expose callback to control whether to disable menu item

main
Tsu-ba-me 1 year ago
parent 6532fe84fe
commit ef969fe056
  1. 4
      striker-ui/components/Menu.tsx
  2. 1
      striker-ui/types/Menu.d.ts

@ -5,6 +5,7 @@ import MenuItem from './MenuItem';
const Menu: FC<MenuProps> = (props) => {
const {
getItemDisabled,
items = {},
muiMenuProps: menuProps,
onItemClick,
@ -18,6 +19,7 @@ const Menu: FC<MenuProps> = (props) => {
() =>
pairs.map(([key, value]) => (
<MenuItem
disabled={getItemDisabled?.call(null, key, value)}
onClick={(...parent) =>
onItemClick?.call(null, key, value, ...parent)
}
@ -28,7 +30,7 @@ const Menu: FC<MenuProps> = (props) => {
{renderItem?.call(null, key, value)}
</MenuItem>
)),
[onItemClick, pairs, renderItem],
[getItemDisabled, onItemClick, pairs, renderItem],
);
return (

@ -1,6 +1,7 @@
type MuiMenuProps = import('@mui/material').MenuProps;
type MenuOptionalProps<T = unknown> = Pick<MuiMenuProps, 'open'> & {
getItemDisabled?: (key: string, value: T) => boolean;
items?: Record<string, T>;
muiMenuProps?: Partial<MuiMenuProps>;
onItemClick?: (

Loading…
Cancel
Save