Overengineering for big image text

This commit is contained in:
Daniel Schädler 2025-03-16 16:22:12 +01:00
parent cd06ab4747
commit 030cc12544
1 changed files with 20 additions and 2 deletions

View File

@ -1,9 +1,27 @@
import React from 'react';
import React, {useEffect} from 'react';
export function BigImage(props) {
useEffect(() => {
const handleResize = () => {
const element = document.querySelector('.dynamically-resizing-h1');
if (element) {
const parentWidth = element.parentElement.offsetWidth;
const fontSize = parentWidth / 16; // Adjust the divisor as needed
element.style.fontSize = `${fontSize}px`;
}
};
window.addEventListener('resize', handleResize);
handleResize(); // Initial call to set the font size
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
return (
<div className="big-image">
<h1 className="display-1">{props.text}</h1>
<h1 className="text-truncate overflow-hidden dynamically-resizing-h1">{props.text}</h1>
</div>
);
}