ant-design/components/config-provider/DisabledContext.tsx
黑雨 b0a652580a
feat: Form disabled (#35210)
* feat: add form disabled

* feat: add form disabled

* feat: add radio disabled

* feat: update snap

* feat: add test case
2022-04-29 20:48:10 +08:00

22 lines
582 B
TypeScript

import * as React from 'react';
export type DisabledType = true | false | undefined;
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 (
<DisabledContext.Provider value={disabled || originDisabled}>
{children}
</DisabledContext.Provider>
);
};
export default DisabledContext;