mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
502dac12aa
* docs: fix code * feat: lint * feat: prettier * feat: test * feat: review * feat: format html * feat: format html
24 lines
604 B
TypeScript
24 lines
604 B
TypeScript
import React from 'react';
|
|
|
|
import type { SizeType } from '../SizeContext';
|
|
import SizeContext from '../SizeContext';
|
|
|
|
const useSize = <T>(customSize?: T | ((ctxSize: SizeType) => T)): T => {
|
|
const size = React.useContext<SizeType>(SizeContext);
|
|
const mergedSize = React.useMemo<T>(() => {
|
|
if (!customSize) {
|
|
return size as T;
|
|
}
|
|
if (typeof customSize === 'string') {
|
|
return customSize ?? size;
|
|
}
|
|
if (customSize instanceof Function) {
|
|
return customSize(size);
|
|
}
|
|
return size as T;
|
|
}, [customSize, size]);
|
|
return mergedSize;
|
|
};
|
|
|
|
export default useSize;
|