/** * ╔══════════════════════════════════════════════════════════════════╗ * ║ ║ * ║ +-+-+-+-+-+-+-+-+ ║ * ║ |H|e|x|a|H|o|s|t| ║ * ║ +-+-+-+-+-+-+-+-+ ║ * ║ ║ * ║ © 2026 HexaHost — All Rights Reserved ║ * ║ ║ * ║ discord ── https://discord.gg/hexahost ║ * ║ github ── https://github.com/theoneandonlymace ║ * ║ ║ * ╚══════════════════════════════════════════════════════════════════╝ */ "use client" import * as React from "react" import { ChevronDown, Check } from "lucide-react" import { cn } from "@/lib/utils" // Context for sub-components const SelectContext = React.createContext<{ value: string onValueChange: (value: string) => void isOpen: boolean setIsOpen: (open: boolean) => void } | null>(null) export interface SelectOption { value: string label: string } interface SelectProps { children?: React.ReactNode value: string onValueChange: (value: string) => void // Legacy props compatibility options?: SelectOption[] placeholder?: string className?: string disabled?: boolean } const Select = ({ children, value, onValueChange, options, placeholder, className, disabled }: SelectProps) => { const [isOpen, setIsOpen] = React.useState(false) const containerRef = React.useRef(null) React.useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (containerRef.current && !containerRef.current.contains(event.target as Node)) { setIsOpen(false) } } document.addEventListener("mousedown", handleClickOutside) return () => document.removeEventListener("mousedown", handleClickOutside) }, []) // If options are provided, use the legacy rendering if (options) { const selectedOption = options.find((opt) => opt.value === value) return (
{isOpen && (
{options.map((option) => ( ))}
)}
) } // Otherwise, use the sub-component pattern return (
{children}
) } const SelectTrigger = React.forwardRef< HTMLButtonElement, React.ButtonHTMLAttributes >(({ className, children, ...props }, ref) => { const context = React.useContext(SelectContext) if (!context) return null return ( ) }) SelectTrigger.displayName = "SelectTrigger" const SelectValue = ({ placeholder, className }: { placeholder?: string, className?: string }) => { const context = React.useContext(SelectContext) if (!context) return null return {context.value || placeholder} } const SelectContent = ({ children, className }: { children: React.ReactNode, className?: string }) => { const context = React.useContext(SelectContext) if (!context || !context.isOpen) return null return (
{children}
) } const SelectItem = React.forwardRef< HTMLButtonElement, React.ButtonHTMLAttributes & { value: string } >(({ className, children, value, ...props }, ref) => { const context = React.useContext(SelectContext) if (!context) return null const isSelected = context.value === value return ( ) }) SelectItem.displayName = "SelectItem" export { Select, SelectTrigger, SelectValue, SelectContent, SelectItem }