Skip to content

Commit

Permalink
refactorVolumeItem
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny1q committed Dec 3, 2024
1 parent 3b08eec commit 3b28c56
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions src/components/resumeSection/VolumeItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// src/components/ResumeSection/VolumeItem.tsx
import React, { useState, useRef, useEffect } from 'react';
import React, { useState } from 'react';
import ToggleButton from './ToggleButton';

interface VolumeItemProps {
Expand All @@ -10,8 +10,6 @@ interface VolumeItemProps {

const VolumeItem: React.FC<VolumeItemProps> = ({ title, description, isSkill = false }) => {
const [isOpen, setIsOpen] = useState(false);
const contentRef = useRef<HTMLDivElement>(null);
const [height, setHeight] = useState(0);

const isArray = Array.isArray(title);

Expand All @@ -30,41 +28,26 @@ const VolumeItem: React.FC<VolumeItemProps> = ({ title, description, isSkill = f
<span className={labelStyle}>{title}</span>
);

const toggleDescription = () => {
if (contentRef.current) {
setHeight(isOpen ? 0 : contentRef.current.scrollHeight);
}
setIsOpen(!isOpen);
};

useEffect(() => {
if (isOpen && contentRef.current) {
setHeight(contentRef.current.scrollHeight);
}
}, [isOpen]);

return (
<div className="mb-4">
<ToggleButton
label={label}
isOpen={isOpen}
onClick={toggleDescription}
onClick={()=>setIsOpen(!isOpen)}
className="w-full flex justify-between items-center py-2"
/>

<div
ref={contentRef}
style={{ height: isOpen ? `${height}px` : '0px' }}
className="overflow-hidden transition-all duration-500 ease-in-out"
>
<div className="mt-2 text-gray-600">
{description.map((desc, index) => (
<p key={index} className="mb-2">
{desc}
</p>
))}
{isOpen && (
<div className="overflow-hidden transition-all duration-500 ease-in-out">
<div className="mt-2 text-gray-600">
{description.map((desc, index) => (
<p key={index} className="mb-2">
{desc}
</p>
))}
</div>
</div>
</div>
)}
</div>
);
};
Expand Down

0 comments on commit 3b28c56

Please sign in to comment.