@ant-design/x
Version:
Craft AI-driven interfaces effortlessly
25 lines • 977 B
JavaScript
import useToken from "../../theme/useToken";
const SENDER_INPUT_PADDING_HEIGHT = 4.35;
const useInputHeight = (styles, autoSize, editableRef) => {
const {
token
} = useToken();
const computedStyle = editableRef.current ? window.getComputedStyle(editableRef.current) : {};
const lineHeight = parseFloat(`${styles.lineHeight || token.lineHeight}`);
const fontSize = parseFloat(`${computedStyle?.fontSize || styles.fontSize || token.fontSize}`);
const height = computedStyle?.lineHeight ? parseFloat(`${computedStyle?.lineHeight}`) : lineHeight * fontSize;
if (autoSize === false || !autoSize) {
return {};
}
if (autoSize === true) {
return {
height: 'auto'
};
}
return {
minHeight: autoSize.minRows ? (height + SENDER_INPUT_PADDING_HEIGHT) * autoSize.minRows : 'auto',
maxHeight: autoSize.maxRows ? (height + SENDER_INPUT_PADDING_HEIGHT) * autoSize.maxRows : 'auto',
overflowY: 'auto'
};
};
export default useInputHeight;