2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2022-04-29 20:48:10 +08:00
|
|
|
|
2023-01-16 09:55:52 +08:00
|
|
|
export type DisabledType = boolean | undefined;
|
2022-04-29 20:48:10 +08:00
|
|
|
|
|
|
|
const DisabledContext = React.createContext<DisabledType>(false);
|
|
|
|
|
|
|
|
export interface DisabledContextProps {
|
|
|
|
disabled?: DisabledType;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const DisabledContextProvider: React.FC<DisabledContextProps> = ({ children, disabled }) => {
|
|
|
|
const originDisabled = React.useContext(DisabledContext);
|
|
|
|
return (
|
2022-11-23 11:04:23 +08:00
|
|
|
<DisabledContext.Provider value={disabled ?? originDisabled}>
|
2022-04-29 20:48:10 +08:00
|
|
|
{children}
|
|
|
|
</DisabledContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DisabledContext;
|