2020-11-05 16:22:21 +08:00
|
|
|
import * as React from 'react';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ScreenSizeMap } from '../_util/responsiveObserve';
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export const SizeContextProvider: React.FC<SizeContextProps> = ({ children, size }) => (
|
|
|
|
<SizeContext.Consumer>
|
2022-11-19 13:47:33 +08:00
|
|
|
{(originSize) => (
|
2020-11-05 16:22:21 +08:00
|
|
|
<SizeContext.Provider value={size || originSize}>{children}</SizeContext.Provider>
|
|
|
|
)}
|
|
|
|
</SizeContext.Consumer>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default SizeContext;
|