import React, { useState, useRef, useEffect } from "react";
function Section({ title, children }: { title: string; children: React.ReactNode }) {
return (
);
}
const labelClass = "block text-sm font-medium text-[var(--flux-black)] mb-1";
interface CustomSelectProps {
label: string;
options: string[];
placeholder?: string;
disabled?: boolean;
error?: string;
defaultValue?: string;
}
function CustomSelect({
label,
options,
placeholder = "Select an option...",
disabled = false,
error,
defaultValue,
}: CustomSelectProps) {
const [open, setOpen] = useState(false);
const [selected, setSelected] = useState(defaultValue || "");
const ref = useRef(null);
useEffect(() => {
function handleClick(e: MouseEvent) {
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
}
document.addEventListener("mousedown", handleClick);
return () => document.removeEventListener("mousedown", handleClick);
}, []);
const borderColor = error
? "border-[var(--flux-error)]"
: open
? "border-[var(--flux-primary-400)]"
: "border-[var(--flux-grey-200)]";
const ringClass = open
? error
? "ring-1 ring-[var(--flux-error)]"
: "ring-1 ring-[var(--flux-primary-300)]"
: "";
return (
{open && (
{options.map((opt) => (
-
))}
)}
{error &&
{error}
}
);
}
const serviceTypes = ["Departure", "Accommodation", "Activity", "Transfer"];
export default function SelectDemo() {
return (
);
}