mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-16 23:21:00 +08:00

* chore: upgrade RC component dependencies
* chore: trigger CI build
* chore: update deps and import path
* chore: update deps
* test: update snapshot
* test: update snapshot
* fix: lint fix
* chore: migrate Drawer to @rc-component/drawer
* chore: migrate Image to @rc-component/image
* test: update snapshot
* chore: replace api
* fix cascader dropdown api and snap, popupAlign
* fix ci test
* fix key
* test: update snapshot
* Revert "test: update snapshot"
This reverts commit 66a993332b
.
* chore: fix logic
* test: update snapshot
* chore: revert part logic
---------
Signed-off-by: Jony J <1844749591@qq.com>
Co-authored-by: thinkasany <480968828@qq.com>
Co-authored-by: 二货机器人 <smith3816@gmail.com>
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import * as React from 'react';
|
|
import { forwardRef, useImperativeHandle, useRef } from 'react';
|
|
import type { MenuRef as RcMenuRef } from '@rc-component/menu';
|
|
import { ItemGroup } from '@rc-component/menu';
|
|
|
|
import { SiderContext } from '../layout/Sider';
|
|
import type { ItemType, MenuItemType } from './interface';
|
|
import type { MenuProps } from './menu';
|
|
import InternalMenu from './menu';
|
|
import type { MenuTheme } from './MenuContext';
|
|
import MenuDivider from './MenuDivider';
|
|
import Item from './MenuItem';
|
|
import type { MenuItemProps } from './MenuItem';
|
|
import SubMenu from './SubMenu';
|
|
import type { SubMenuProps } from './SubMenu';
|
|
|
|
export type { MenuItemGroupProps } from '@rc-component/menu';
|
|
export type { MenuDividerProps } from './MenuDivider';
|
|
export type { MenuItemProps, MenuProps, MenuTheme, SubMenuProps };
|
|
|
|
export type MenuRef = {
|
|
menu: RcMenuRef | null;
|
|
focus: (options?: FocusOptions) => void;
|
|
};
|
|
|
|
type ComponentProps = MenuProps & React.RefAttributes<MenuRef>;
|
|
|
|
type GenericItemType<T = unknown> = T extends infer U extends MenuItemType
|
|
? unknown extends U
|
|
? ItemType
|
|
: ItemType<U>
|
|
: ItemType;
|
|
|
|
type GenericComponentProps<T = unknown> = Omit<ComponentProps, 'items'> & {
|
|
items?: GenericItemType<T>[];
|
|
};
|
|
|
|
type CompoundedComponent = React.ForwardRefExoticComponent<GenericComponentProps> & {
|
|
Item: typeof Item;
|
|
SubMenu: typeof SubMenu;
|
|
Divider: typeof MenuDivider;
|
|
ItemGroup: typeof ItemGroup;
|
|
};
|
|
|
|
type GenericComponent = Omit<CompoundedComponent, ''> &
|
|
(<T extends MenuItemType>(props: GenericComponentProps<T>) => ReturnType<CompoundedComponent>);
|
|
|
|
const Menu = forwardRef<MenuRef, MenuProps>((props, ref) => {
|
|
const menuRef = useRef<RcMenuRef>(null);
|
|
const context = React.useContext(SiderContext);
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
menu: menuRef.current,
|
|
focus: (options) => {
|
|
menuRef.current?.focus(options);
|
|
},
|
|
}));
|
|
return <InternalMenu ref={menuRef} {...props} {...context} />;
|
|
}) as GenericComponent;
|
|
|
|
Menu.Item = Item;
|
|
Menu.SubMenu = SubMenu;
|
|
Menu.Divider = MenuDivider;
|
|
Menu.ItemGroup = ItemGroup;
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
Menu.displayName = 'Menu';
|
|
}
|
|
|
|
export default Menu;
|