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