1
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
import * as React from 'react';
|
||||
export declare const IdContext: React.Context<string>;
|
||||
export declare function getMenuId(uuid: string, eventKey: string): string;
|
||||
/**
|
||||
* Get `data-menu-id`
|
||||
*/
|
||||
export declare function useMenuId(eventKey: string): string;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import * as React from 'react';
|
||||
export const IdContext = /*#__PURE__*/React.createContext(null);
|
||||
export function getMenuId(uuid, eventKey) {
|
||||
return `${uuid}-${eventKey}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get `data-menu-id`
|
||||
*/
|
||||
export function useMenuId(eventKey) {
|
||||
const id = React.useContext(IdContext);
|
||||
return getMenuId(id, eventKey);
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import * as React from 'react';
|
||||
import type { CSSMotionProps } from '@rc-component/motion';
|
||||
import type { BuiltinPlacements, MenuClickEventHandler, MenuMode, RenderIconType, TriggerSubMenuAction, PopupRender } from '../interface';
|
||||
import { SubMenuProps } from '..';
|
||||
export interface MenuContextProps {
|
||||
prefixCls: string;
|
||||
classNames?: SubMenuProps['classNames'];
|
||||
styles?: SubMenuProps['styles'];
|
||||
rootClassName?: string;
|
||||
openKeys: string[];
|
||||
rtl?: boolean;
|
||||
mode: MenuMode;
|
||||
disabled?: boolean;
|
||||
overflowDisabled?: boolean;
|
||||
activeKey: string;
|
||||
onActive: (key: string) => void;
|
||||
onInactive: (key: string) => void;
|
||||
selectedKeys: string[];
|
||||
inlineIndent: number;
|
||||
motion?: CSSMotionProps;
|
||||
defaultMotions?: Partial<{
|
||||
[key in MenuMode | 'other']: CSSMotionProps;
|
||||
}>;
|
||||
subMenuOpenDelay: number;
|
||||
subMenuCloseDelay: number;
|
||||
forceSubMenuRender?: boolean;
|
||||
builtinPlacements?: BuiltinPlacements;
|
||||
triggerSubMenuAction?: TriggerSubMenuAction;
|
||||
popupRender?: PopupRender;
|
||||
itemIcon?: RenderIconType;
|
||||
expandIcon?: RenderIconType;
|
||||
onItemClick: MenuClickEventHandler;
|
||||
onOpenChange: (key: string, open: boolean) => void;
|
||||
getPopupContainer: (node: HTMLElement) => HTMLElement;
|
||||
}
|
||||
export declare const MenuContext: React.Context<MenuContextProps>;
|
||||
export interface InheritableContextProps extends Partial<MenuContextProps> {
|
||||
children?: React.ReactNode;
|
||||
locked?: boolean;
|
||||
}
|
||||
export default function InheritableContextProvider({ children, locked, ...restProps }: InheritableContextProps): React.JSX.Element;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import * as React from 'react';
|
||||
import useMemo from "@rc-component/util/es/hooks/useMemo";
|
||||
import isEqual from "@rc-component/util/es/isEqual";
|
||||
export const MenuContext = /*#__PURE__*/React.createContext(null);
|
||||
function mergeProps(origin, target) {
|
||||
const clone = {
|
||||
...origin
|
||||
};
|
||||
Object.keys(target).forEach(key => {
|
||||
const value = target[key];
|
||||
if (value !== undefined) {
|
||||
clone[key] = value;
|
||||
}
|
||||
});
|
||||
return clone;
|
||||
}
|
||||
export default function InheritableContextProvider({
|
||||
children,
|
||||
locked,
|
||||
...restProps
|
||||
}) {
|
||||
const context = React.useContext(MenuContext);
|
||||
const inheritableContext = useMemo(() => mergeProps(context, restProps), [context, restProps], (prev, next) => !locked && (prev[0] !== next[0] || !isEqual(prev[1], next[1], true)));
|
||||
return /*#__PURE__*/React.createElement(MenuContext.Provider, {
|
||||
value: inheritableContext
|
||||
}, children);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import * as React from 'react';
|
||||
export interface PathRegisterContextProps {
|
||||
registerPath: (key: string, keyPath: string[]) => void;
|
||||
unregisterPath: (key: string, keyPath: string[]) => void;
|
||||
}
|
||||
export declare const PathRegisterContext: React.Context<PathRegisterContextProps>;
|
||||
export declare function useMeasure(): PathRegisterContextProps;
|
||||
export declare const PathTrackerContext: React.Context<string[]>;
|
||||
export declare function useFullPath(eventKey?: string): string[];
|
||||
export interface PathUserContextProps {
|
||||
isSubPathKey: (pathKeys: string[], eventKey: string) => boolean;
|
||||
}
|
||||
export declare const PathUserContext: React.Context<PathUserContextProps>;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import * as React from 'react';
|
||||
const EmptyList = [];
|
||||
|
||||
// ========================= Path Register =========================
|
||||
|
||||
export const PathRegisterContext = /*#__PURE__*/React.createContext(null);
|
||||
export function useMeasure() {
|
||||
return React.useContext(PathRegisterContext);
|
||||
}
|
||||
|
||||
// ========================= Path Tracker ==========================
|
||||
export const PathTrackerContext = /*#__PURE__*/React.createContext(EmptyList);
|
||||
export function useFullPath(eventKey) {
|
||||
const parentKeyPath = React.useContext(PathTrackerContext);
|
||||
return React.useMemo(() => eventKey !== undefined ? [...parentKeyPath, eventKey] : parentKeyPath, [parentKeyPath, eventKey]);
|
||||
}
|
||||
|
||||
// =========================== Path User ===========================
|
||||
|
||||
export const PathUserContext = /*#__PURE__*/React.createContext(null);
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import type { MenuProps } from '../Menu';
|
||||
export interface PrivateContextProps {
|
||||
_internalRenderMenuItem?: MenuProps['_internalRenderMenuItem'];
|
||||
_internalRenderSubMenuItem?: MenuProps['_internalRenderSubMenuItem'];
|
||||
}
|
||||
declare const PrivateContext: React.Context<PrivateContextProps>;
|
||||
export default PrivateContext;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import * as React from 'react';
|
||||
const PrivateContext = /*#__PURE__*/React.createContext({});
|
||||
export default PrivateContext;
|
||||
Reference in New Issue
Block a user