To add a timeline with circles to the left of each experience element, you can structure your Experience component using Flexbox. The idea is to have a vertical line representing the timeline and place a circle for each experience item aligned with this line. Here's how you can achieve this using Tailwind CSS:
-
Structure the Layout:
- Timeline Column: This will contain the vertical line and the circles for each experience.
- Content Column: This will contain the experience cards.
-
Style the Timeline:
- Use a
div with a fixed width for the timeline column.
- Add a vertical line using a bordered
div.
- Place circles (
div elements) at the appropriate positions for each experience item.
-
Style the Experience Cards:
- Use the existing styling for the experience cards, ensuring they align properly with the timeline.
Here's the updated Experience component implementing the timeline:
import React from 'react';
// Assuming ExperienceData and the Experience type are defined and imported appropriately
// import ExperienceData from './path-to-your-data';
// interface Experience {
// title: string;
// company: string;
// date: string;
// country: string;
// body: string;
// }
const Experience = () => {
return (
<div className="mt-8 flex">
{/* Timeline Column */}
<div className="relative w-6 flex flex-col items-center">
{/* Vertical Line */}
<div className="absolute left-3 top-0 w-0.5 h-full bg-gray-300"></div>
{ExperienceData.map((item, index) => (
<div key={index} className="relative flex flex-col items-center">
{/* Circle */}
<div className="z-10 w-6 h-6 bg-blue-500 rounded-full"></div>
{/* Optional: Add connector lines between circles */}
{index < ExperienceData.length - 1 && (
<div className="w-0.5 h-8 bg-gray-300"></div>
)}
</div>
))}
</div>
{/* Content Column */}
<div className="flex-1 ml-4">
{ExperienceData.map((item, index) => (
<div
key={index}
className="max-w-[900px] h-auto py-4 px-6 bg-white shadow-md rounded-[15px] flex flex-col mt-4"
>
<div className="flex justify-between ">
<div>
<div className="text-[18px] font-bold text-header">
{item.title}
</div>
<div className="text-[16px]">{item.company}</div>
</div>
<div>
<div className="text-[14px] font-semibold flex items-center">
{item.date}
</div>
<div className="flex justify-end text-[14px]">
{item.country}
</div>
</div>
</div>
<div className="my-4 text-[14px]">{item.body}</div>
</div>
))}
</div>
</div>
);
};
export default Experience;
Explanation of the Changes:
-
Parent Container (div with flex):
- The parent
div uses flex to place the timeline and content columns side by side.
-
Timeline Column:
- Width: Set to a fixed width (
w-6) to accommodate the circles and the vertical line.
- Relative Positioning: This allows the vertical line and circles to be positioned correctly.
- Vertical Line: An absolutely positioned
div with a narrow width (w-0.5) and full height (h-full) to create the vertical line.
- Circles:
- Each experience item has a
div representing the circle.
- Positioned centrally using
flex and items-center.
- The circles are given a background color (
bg-blue-500) and rounded to appear circular (rounded-full).
- Connector Lines (Optional):
- Between each circle (except the last one), a smaller vertical line (
h-8) is added to connect the circles, enhancing the timeline visualization.
-
Content Column:
- Flex-1 (
flex-1): Allows the content column to take up the remaining space.
- Margin Left (
ml-4): Adds space between the timeline and the content.
- Experience Cards: Retains the existing structure and styling for each experience card, ensuring they appear aligned next to the timeline.
Additional Enhancements:
- Responsiveness: Ensure that the layout remains responsive on different screen sizes. Tailwind's responsive utility classes can help adjust the layout for mobile devices if needed.
- Active States: You can add active states or animations to the circles to highlight the current experience or on hover interactions.
- Icons Inside Circles: Instead of plain circles, you can include icons representing each experience or role.
Final Thoughts
This approach cleanly separates the timeline from the content, making it easy to maintain and customize. Tailwind CSS provides the flexibility to adjust spacing, colors, and other styles as needed. Feel free to further customize the timeline's appearance to match your design preferences.