| 1 | import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; |
| 2 | import { ComponentType, useState } from "react"; |
| 3 | import { lightGray, vscBackground } from "."; |
| 4 | |
| 5 | interface ToggleProps { |
| 6 | children: React.ReactNode; |
| 7 | title: React.ReactNode; |
| 8 | icon?: ComponentType<React.SVGProps<SVGSVGElement>>; |
| 9 | } |
| 10 | |
| 11 | function ToggleDiv({ children, title, icon: Icon }: ToggleProps) { |
| 12 | const [open, setOpen] = useState(false); |
| 13 | const [isHovered, setIsHovered] = useState(false); |
| 14 | |
| 15 | return ( |
| 16 | <div |
| 17 | className={`pl-2 pt-2`} |
| 18 | style={{ |
| 19 | backgroundColor: vscBackground, |
| 20 | }} |
| 21 | > |
| 22 | <div |
| 23 | className="flex cursor-pointer items-center justify-start text-xs text-gray-300" |
| 24 | onClick={() => setOpen((prev) => !prev)} |
| 25 | onMouseEnter={() => setIsHovered(true)} |
| 26 | onMouseLeave={() => setIsHovered(false)} |
| 27 | data-testid="context-items-peek" |
| 28 | > |
| 29 | <div className="relative mr-1 h-4 w-4"> |
| 30 | {Icon && !isHovered && !open ? ( |
| 31 | <Icon className={`absolute h-4 w-4 text-[${lightGray}]`} /> |
| 32 | ) : ( |
| 33 | <> |
| 34 | <ChevronRightIcon |
| 35 | className={`absolute h-4 w-4 transition-all duration-200 ease-in-out text-[${lightGray}] ${ |
| 36 | open ? "rotate-90 opacity-0" : "rotate-0 opacity-100" |
| 37 | }`} |
| 38 | /> |
| 39 | <ChevronDownIcon |
| 40 | className={`absolute h-4 w-4 transition-all duration-200 ease-in-out text-[${lightGray}] ${ |
| 41 | open ? "rotate-0 opacity-100" : "-rotate-90 opacity-0" |
| 42 | }`} |
| 43 | /> |
| 44 | </> |
| 45 | )} |
| 46 | </div> |
| 47 | <span |
| 48 | className="ml-1 text-xs text-gray-400 transition-colors duration-200" |
| 49 | data-testid="toggle-div-title" |
| 50 | > |
| 51 | {title} |
| 52 | </span> |
| 53 | </div> |
| 54 | |
| 55 | <div |
| 56 | className={`mt-2 overflow-y-auto transition-all duration-300 ease-in-out ${ |
| 57 | open ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0" |
| 58 | }`} |
| 59 | > |
| 60 | {children} |
| 61 | </div> |
| 62 | </div> |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | export default ToggleDiv; |