2023-05-06 15:49:37 +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
|
|
|
}
|
|
|
|
|
|
|
|
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-11-21 09:52:33 +08:00
|
|
|
export const OverrideProvider: React.FC<OverrideContextProps & { children: React.ReactNode }> = (
|
|
|
|
props,
|
|
|
|
) => {
|
|
|
|
const { children, ...restProps } = props;
|
2022-06-17 14:37:18 +08:00
|
|
|
const override = React.useContext(OverrideContext);
|
|
|
|
|
2022-11-21 09:52:33 +08:00
|
|
|
const context = React.useMemo<OverrideContextProps>(
|
|
|
|
() => ({ ...override, ...restProps }),
|
2022-06-17 14:37:18 +08:00
|
|
|
[
|
|
|
|
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>;
|
|
|
|
};
|
|
|
|
|
2023-04-26 14:53:23 +08:00
|
|
|
/** @internal Only used for Dropdown component. Do not use this in your production. */
|
2022-06-17 14:37:18 +08:00
|
|
|
export default OverrideContext;
|