2020-11-05 16:22:21 +08:00
|
|
|
import * as React from 'react';
|
2022-12-22 10:11:08 +08:00
|
|
|
import type { ScreenSizeMap } from '../_util/responsiveObserver';
|
2020-11-05 16:22:21 +08:00
|
|
|
|
|
|
|
export type AvatarSize = 'large' | 'small' | 'default' | number | ScreenSizeMap;
|
|
|
|
|
|
|
|
const SizeContext = React.createContext<AvatarSize>('default');
|
|
|
|
|
|
|
|
export interface SizeContextProps {
|
|
|
|
size?: AvatarSize;
|
2022-04-08 22:55:42 +08:00
|
|
|
children?: React.ReactNode;
|
2020-11-05 16:22:21 +08:00
|
|
|
}
|
|
|
|
|
2023-01-01 21:17:05 +08:00
|
|
|
export const SizeContextProvider: React.FC<SizeContextProps> = ({ children, size }) => {
|
|
|
|
const originSize = React.useContext<AvatarSize>(SizeContext);
|
|
|
|
return <SizeContext.Provider value={size || originSize}>{children}</SizeContext.Provider>;
|
|
|
|
};
|
2020-11-05 16:22:21 +08:00
|
|
|
|
|
|
|
export default SizeContext;
|