2022-06-17 14:37:18 +08:00
|
|
|
import * as React from 'react';
|
2022-07-28 20:33:10 +08:00
|
|
|
import type { MenuProps } from './menu';
|
2022-06-17 14:37:18 +08:00
|
|
|
|
|
|
|
// Used for Dropdown only
|
|
|
|
export interface OverrideContextProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
expandIcon?: React.ReactNode;
|
|
|
|
mode?: MenuProps['mode'];
|
|
|
|
selectable?: boolean;
|
|
|
|
validator?: (menuProps: Pick<MenuProps, 'mode'>) => void;
|
2022-06-21 15:48:29 +08:00
|
|
|
onClick?: () => void;
|
2022-06-17 14:37:18 +08:00
|
|
|
}
|
|
|
|
|
2022-09-30 14:26:41 +08:00
|
|
|
/** @internal Only used for Dropdown component. Do not use this in your production. */
|
2022-06-17 14:37:18 +08:00
|
|
|
const OverrideContext = React.createContext<OverrideContextProps | null>(null);
|
|
|
|
|
2022-09-30 14:26:41 +08:00
|
|
|
/** @internal Only used for Dropdown component. Do not use this in your production. */
|
2022-06-17 14:37:18 +08:00
|
|
|
export const OverrideProvider = ({
|
|
|
|
children,
|
|
|
|
...restProps
|
|
|
|
}: OverrideContextProps & { children: React.ReactNode }) => {
|
|
|
|
const override = React.useContext(OverrideContext);
|
|
|
|
|
|
|
|
const context = React.useMemo(
|
|
|
|
() => ({
|
|
|
|
...override,
|
|
|
|
...restProps,
|
|
|
|
}),
|
|
|
|
[
|
|
|
|
override,
|
|
|
|
restProps.prefixCls,
|
|
|
|
// restProps.expandIcon, Not mark as deps since this is a ReactNode
|
|
|
|
restProps.mode,
|
|
|
|
restProps.selectable,
|
|
|
|
// restProps.validator, Not mark as deps since this is a function
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
return <OverrideContext.Provider value={context}>{children}</OverrideContext.Provider>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default OverrideContext;
|