Portfolio/front/ScrollComponent.ts

21 lines
524 B
TypeScript
Raw Normal View History

import { newLine } from ".";
interface ScrollComponentProps {
text: string;
width: number;
height: number;
scrollPosition: number;
}
const ScrollComponent = ({ text, width, height, scrollPosition }: ScrollComponentProps) => {
const lines = text.split(newLine);
const totalLines = lines.length;
const startLine = scrollPosition;
const endLine = Math.min(startLine + height, totalLines);
const visibleLines = lines.slice(startLine, endLine);
return visibleLines.join(newLine);
};
export default ScrollComponent;