Skip to content

Commit

Permalink
feat: make auto margin fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Sep 13, 2023
1 parent 584af57 commit f8e8542
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/organisms/projects/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,22 @@ const ProjectCard = ({ project }: ProjectCardProps) => {
setActiveDiv(activeDiv === 'first' ? 'second' : 'first');
};

const [autoMarginHeight, setAutoMarginHeight] = useState('auto');
const autoMarginRef: RefObject<HTMLDivElement> = useRef(null);

useEffect(() => {
if (cardRef.current) {
// Calculate and set the initial height of the card content
setCardHeight(cardRef.current.clientHeight + 'px');
}

if (autoMarginRef.current) {
const computedStyle = window.getComputedStyle(autoMarginRef.current);
const mbValue = computedStyle.marginBottom;
const mbNumeric = parseFloat(mbValue);

setAutoMarginHeight(`${mbNumeric}px`);
}
}, []);

const iconColor = theme === 'dark' ? 'white' : 'black';
Expand All @@ -87,8 +98,10 @@ const ProjectCard = ({ project }: ProjectCardProps) => {
</h3>

<div
className='text-justify md:font-light md:text-sm mb-auto'
ref={autoMarginRef}
className='text-justify md:font-light md:text-sm'
aria-label='Project short description'
style={{ marginBottom: autoMarginHeight }}
>
<ReactMarkdown>{project.shortDescription}</ReactMarkdown>
</div>
Expand Down

0 comments on commit f8e8542

Please sign in to comment.