feat(UI): Adding linter and prettier for UI (#3156)

This commit is contained in:
Francisco Arceo 2025-08-14 15:58:43 -06:00 committed by GitHub
parent 61582f327c
commit e69acbafbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
73 changed files with 1452 additions and 1226 deletions

View file

@ -1,10 +1,10 @@
import { useLayoutEffect, useRef } from "react"
import { useLayoutEffect, useRef } from "react";
interface UseAutosizeTextAreaProps {
ref: React.RefObject<HTMLTextAreaElement | null>
maxHeight?: number
borderWidth?: number
dependencies: React.DependencyList
ref: React.RefObject<HTMLTextAreaElement | null>;
maxHeight?: number;
borderWidth?: number;
dependencies: React.DependencyList;
}
export function useAutosizeTextArea({
@ -13,27 +13,27 @@ export function useAutosizeTextArea({
borderWidth = 0,
dependencies,
}: UseAutosizeTextAreaProps) {
const originalHeight = useRef<number | null>(null)
const originalHeight = useRef<number | null>(null);
useLayoutEffect(() => {
if (!ref.current) return
if (!ref.current) return;
const currentRef = ref.current
const borderAdjustment = borderWidth * 2
const currentRef = ref.current;
const borderAdjustment = borderWidth * 2;
if (originalHeight.current === null) {
originalHeight.current = currentRef.scrollHeight - borderAdjustment
originalHeight.current = currentRef.scrollHeight - borderAdjustment;
}
currentRef.style.removeProperty("height")
const scrollHeight = currentRef.scrollHeight
currentRef.style.removeProperty("height");
const scrollHeight = currentRef.scrollHeight;
// Make sure we don't go over maxHeight
const clampedToMax = Math.min(scrollHeight, maxHeight)
const clampedToMax = Math.min(scrollHeight, maxHeight);
// Make sure we don't go less than the original height
const clampedToMin = Math.max(clampedToMax, originalHeight.current)
const clampedToMin = Math.max(clampedToMax, originalHeight.current);
currentRef.style.height = `${clampedToMin + borderAdjustment}px`
currentRef.style.height = `${clampedToMin + borderAdjustment}px`;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [maxHeight, ref, ...dependencies])
}, [maxHeight, ref, ...dependencies]);
}