diff --git a/client/components/instructions/InstructionsAccordion/DisplayAccordion.tsx b/client/components/instructions/InstructionsAccordion/DisplayAccordion.tsx index 4bc84dd..5c2e7fe 100644 --- a/client/components/instructions/InstructionsAccordion/DisplayAccordion.tsx +++ b/client/components/instructions/InstructionsAccordion/DisplayAccordion.tsx @@ -12,41 +12,59 @@ import InstructionsCarousel from "./InstructionsCarousel"; import { InstructionsTag } from "./InstructionsTag"; import { useState } from "react"; -const DisplayAccordion = ({ items, handleAccordionClick, recyclable }: AccordionDisplayProps) => { +const DisplayAccordion = ({ items, recyclable }: AccordionDisplayProps) => { const { getItemCategory } = useSheetyData(); const lastIndex = items.length - 1; - const [isExpanded, setIsExpanded] = useState(false); - const [isHovered, setIsHovered] = useState(false); + + // Use an array of state variables to track hover and expanded state for each accordion + const [accordionStates, setAccordionStates] = useState( + items.map(() => ({ isHovered: false, isExpanded: false })), + ); + // Function to handle accordion hover + const handleAccordionHover = (index: number, isHovered: boolean, isExpanded: boolean) => { + setAccordionStates((prevState) => + prevState.map((state, i) => ({ + ...state, + isHovered: i === index ? isHovered : state.isHovered, + isExpanded: i === index ? isExpanded : state.isExpanded, + })), + ); + }; return ( {items.map((item, index) => { const category = getItemCategory(item.title); + const { isHovered, isExpanded } = accordionStates[index]; return (

{ - handleAccordionClick(index); - setIsExpanded(!isExpanded); + handleAccordionHover(index, true, !isExpanded); }} _hover={{ bg: "teal", color: "white" }} - onMouseEnter={() => setIsHovered(true)} - onMouseLeave={() => setIsHovered(false)} + onMouseEnter={() => handleAccordionHover(index, true, isExpanded)} + onMouseLeave={() => handleAccordionHover(index, false, isExpanded)} + style={{ + boxShadow: + index === 0 && index !== lastIndex + ? "0px -5px 6px -6px rgba(0, 0, 0, 0.25), -5px 0px 6px -6px rgba(0, 0, 0, 0.25), 5px 0px 6px -6px rgba(0, 0, 0, 0.25)" + : "1px 2px 6px 0px rgb(0,0,0, 0.25)", + }} >

) : ( - <> + Why cannot recycle? {item.reason} How to dispose properly? {item.suggestion} - + )} diff --git a/client/components/instructions/InstructionsAccordion/index.tsx b/client/components/instructions/InstructionsAccordion/index.tsx index 33c912f..7b80915 100644 --- a/client/components/instructions/InstructionsAccordion/index.tsx +++ b/client/components/instructions/InstructionsAccordion/index.tsx @@ -5,7 +5,6 @@ import DisplayAccordion from "./DisplayAccordion"; export type AccordionDisplayProps = { items: AccordionProps[]; - handleAccordionClick: (index: number) => void; recyclable: boolean; }; @@ -22,12 +21,6 @@ export type AccordionsProps = { }; export const AccordionComp: React.FC = ({ items }) => { - const [activeIndex, setActiveIndex] = useState(null); - - const handleAccordionClick = (index: number) => { - setActiveIndex((prevIndex) => (prevIndex === index ? null : index)); - }; - const unrecyclableItems = [] as AccordionProps[]; const recyclableItems = items.filter((item) => { if (item.method === Methods.THROW) { @@ -46,11 +39,7 @@ export const AccordionComp: React.FC = ({ items }) => { {/* Non-recyclable accordion */} - + )} {recyclableItems.length > 0 && ( @@ -60,11 +49,7 @@ export const AccordionComp: React.FC = ({ items }) => { {/* Recyclable accordion */} - + )} diff --git a/client/public/icons/GENERAL_WASTE.png b/client/public/icons/GENERAL_WASTE.png new file mode 100644 index 0000000..0ff05cb Binary files /dev/null and b/client/public/icons/GENERAL_WASTE.png differ diff --git a/client/public/whiteicons/GENERAL_WASTE.png b/client/public/whiteicons/GENERAL_WASTE.png new file mode 100644 index 0000000..0ff05cb Binary files /dev/null and b/client/public/whiteicons/GENERAL_WASTE.png differ