update the previous code with the next instructions and return me the full updated code;
import React from 'react'
import { ChevronLeft, ChevronRight } from 'lucide-react'
import { Trade, DayStats } from '@/types/trade'
Certainly! Below is the fully updated DayTradesModal.tsx component that incorporates the navigation buttons (ChevronLeft and ChevronRight) as per your instructions. The navigation buttons allow users to navigate between different days by invoking the onNavigate callback with -1 or 1 to decrement or increment the day, respectively.
Changes Implemented:
Added Imports:
Imported ChevronLeft and ChevronRight from lucide-react for navigation buttons.
Updated DayTradesModalProps Interface:
Included the onNavigate prop to handle navigation between days.
Integrated Navigation Buttons:
Positioned the navigation buttons absolutely within the DialogContent.
Styled the buttons to align vertically centered on the left and right sides of the modal.
Maintained Existing Functionality:
Preserved all existing features such as charts, trade tables, and stats display.
Responsive and Accessible Design:
Ensured buttons have appropriate hover effects and accessibility considerations like aria-label.
Positioning: The navigation buttons are absolutely positioned within the DialogContent to appear on the left and right sides of the modal, vertically centered.
Accessibility: Added aria-label attributes to the buttons for better accessibility.
Styling: Applied classes to ensure the buttons have a consistent appearance with hover effects and are easily clickable.
Date Formatting:
Utilized JavaScript's toLocaleDateString to display a more readable and formatted date in the DialogDescription.
Responsive Handling:
Ensured that the modal remains responsive by maintaining the existing flex and grid layouts, making sure the navigation buttons do not interfere with the modal's main content.
Z-Index Management:
Set a higher z-index for the navigation buttons to ensure they appear above other modal elements.
Conditional Rendering:
Maintained checks to ensure the modal only renders when isOpen is true and a selectedDay is provided.
Consistent Data Handling:
Continued to sort and display trades, charts, and statistics as per the original implementation, ensuring that the added navigation does not disrupt existing functionalities.
Usage:
To utilize the updated DayTradesModal, ensure that you pass the required props including the new onNavigate function. Here's an example of how you might implement it:
tsx
import React, { useState } from 'react';
import { DayTradesModal } from '@/components/DayTradesModal';
import { Trade, DayStats } from '@/types/trade';
const ExampleParentComponent = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [selectedDay, setSelectedDay] = useState<{
day: number;
trades: Trade[];
stats: DayStats | null;
} | null>(null);
const currentDate = new Date();
const handleNewTrade = (newTrade: Trade) => {
// Handle new trade addition
};
const handleNavigate = (increment: number) => {
// Logic to navigate between days
// For example:
setSelectedDay((prev) => {
if (!prev) return prev;
const newDay = prev.day + increment;
// Fetch or update trades and stats for the newDay
return {
...prev,
day: newDay,
// Update trades and stats accordingly
};
});
};
return (
<>
<Button onClick={() => setIsModalOpen(true)}>Open Day Trades Modal</Button>
<DayTradesModal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
selectedDay={selectedDay}
currentDate={currentDate}
onNewTrade={handleNewTrade}
onNavigate={handleNavigate} // Pass the navigation handler
/>
</>
);
};
export default ExampleParentComponent;
Conclusion
The updated DayTradesModal now includes intuitive navigation controls, enhancing the user experience by allowing easy traversal between different trading days. All existing functionalities related to displaying trades, charts, and statistics remain intact and are seamlessly integrated with the new navigation features.