mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-08-21 09:23:13 +00:00
feat(UI): Adding linter and prettier for UI (#3156)
This commit is contained in:
parent
61582f327c
commit
e69acbafbf
73 changed files with 1452 additions and 1226 deletions
|
@ -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]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue