ant-design/components/avatar/SizeContext.tsx
lijianan 59a332bf47
chore: use React.useContext() replace <Context.Provider /> (#39950)
* chore: use React.useContext() replace <Context.Provider />

* fix

* fix

* fix

* fix

* fix
2023-01-01 21:17:05 +08:00

19 lines
614 B
TypeScript

import * as React from 'react';
import type { ScreenSizeMap } from '../_util/responsiveObserver';
export type AvatarSize = 'large' | 'small' | 'default' | number | ScreenSizeMap;
const SizeContext = React.createContext<AvatarSize>('default');
export interface SizeContextProps {
size?: AvatarSize;
children?: React.ReactNode;
}
export const SizeContextProvider: React.FC<SizeContextProps> = ({ children, size }) => {
const originSize = React.useContext<AvatarSize>(SizeContext);
return <SizeContext.Provider value={size || originSize}>{children}</SizeContext.Provider>;
};
export default SizeContext;