Spaces:
Paused
Paused
Download frontend/apps/internal/src/components/Dropdown.tsx from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/internal/src/components/Dropdown.tsx
- Command line
-
hf download hf://spaces/TeamError404/nexus/frontend/apps/internal/src/components/Dropdown.tsx
-
curl -L -o Dropdown.tsx https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/internal/src/components/Dropdown.tsx
2.46 kB
| import React, { useState, useRef, useEffect } from 'react'; | |
| import { motion, AnimatePresence } from 'framer-motion'; | |
| import styles from './Dropdown.module.css'; | |
| interface Option { | |
| id: string; | |
| label: string; | |
| } | |
| interface DropdownProps { | |
| label: string; | |
| options: Option[]; | |
| value: string; | |
| onChange: (value: string) => void; | |
| width?: string; | |
| } | |
| export const Dropdown: React.FC<DropdownProps> = ({ | |
| label, | |
| options, | |
| value, | |
| onChange, | |
| width = '180px' | |
| }) => { | |
| const [isOpen, setIsOpen] = useState(false); | |
| const containerRef = useRef<HTMLDivElement>(null); | |
| const selectedOption = options.find(o => o.id === value) || options[0]; | |
| useEffect(() => { | |
| const handleClickOutside = (e: MouseEvent) => { | |
| if (containerRef.current && !containerRef.current.contains(e.target as Node)) { | |
| setIsOpen(false); | |
| } | |
| }; | |
| document.addEventListener('mousedown', handleClickOutside); | |
| return () => document.removeEventListener('mousedown', handleClickOutside); | |
| }, []); | |
| return ( | |
| <div className={styles.container} ref={containerRef} style={{ width }}> | |
| <label className={styles.label}>{label}</label> | |
| <div | |
| className={`${styles.trigger} ${isOpen ? styles.triggerActive : ''}`} | |
| onClick={() => setIsOpen(!isOpen)} | |
| > | |
| <span className={styles.currentValue}>{selectedOption?.label}</span> | |
| <span className={`${styles.arrow} ${isOpen ? styles.arrowOpen : ''}`}>▾</span> | |
| </div> | |
| <AnimatePresence> | |
| {isOpen && ( | |
| <motion.div | |
| initial={{ opacity: 0, y: 10, scale: 0.95 }} | |
| animate={{ opacity: 1, y: 5, scale: 1 }} | |
| exit={{ opacity: 0, y: 5, scale: 0.95 }} | |
| transition={{ duration: 0.15, ease: "easeOut" }} | |
| className={styles.menu} | |
| > | |
| <div className={styles.menuInner}> | |
| {options.map((opt) => ( | |
| <div | |
| key={opt.id} | |
| className={`${styles.option} ${value === opt.id ? styles.optionSelected : ''}`} | |
| onClick={() => { | |
| onChange(opt.id); | |
| setIsOpen(false); | |
| }} | |
| > | |
| {opt.label} | |
| {value === opt.id && <span className={styles.check}>✓</span>} | |
| </div> | |
| ))} | |
| </div> | |
| </motion.div> | |
| )} | |
| </AnimatePresence> | |
| </div> | |
| ); | |
| }; | |