import { Section } from "./section" import { H2, H3, H4, H5, Text, SmallText } from "./text" import "hono/jsx" import type { JSX, FC } from "hono/jsx" import { VStack, HStack } from "./stack" export type SelectOption = { value: string label: string disabled?: boolean } export type SelectProps = Omit & { options: SelectOption[] placeholder?: string labelPosition?: "above" | "left" | "right" children?: any } export const Select: FC = (props) => { const { options, placeholder, labelPosition = "above", children, style, ...selectProps } = props // If a label is provided but no id, generate a random id so the label can be clicked if (children && !selectProps.id) { selectProps.id = `random-${Math.random().toString(36)}` } const selectStyle: JSX.CSSProperties = { height: "40px", padding: "8px 32px 8px 12px", borderRadius: "6px", border: "1px solid #d1d5db", backgroundColor: "white", fontSize: "14px", outline: "none", appearance: "none", backgroundImage: `url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQgNkw4IDEwTDEyIDYiIHN0cm9rZT0iIzZCNzI4MCIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+")`, backgroundRepeat: "no-repeat", backgroundPosition: "right 8px center", backgroundSize: "16px 16px", ...style, } const selectElement = ( ) if (!children) { return selectElement } const labelStyle: JSX.CSSProperties = { fontSize: "14px", fontWeight: "500", color: "#111827", } const labelElement = ( ) if (labelPosition === "above") { return (
{labelElement} {selectElement}
) } if (labelPosition === "left") { return (
{labelElement}
) } if (labelPosition === "right") { return (
{labelElement}
) } return null } export const Test = () => { const options = [{ value: "1", label: "Option 1" }, { value: "2", label: "Option 2" }] const months = [ { value: "01", label: "January" }, { value: "02", label: "February" }, { value: "03", label: "March" }, { value: "04", label: "April" }, { value: "05", label: "May" }, { value: "06", label: "June" }, { value: "07", label: "July" }, { value: "08", label: "August" }, { value: "09", label: "September" }, { value: "10", label: "October" }, { value: "11", label: "November" }, { value: "12", label: "December" }, ] const years = Array.from({ length: 10 }, (_, i) => ({ value: String(2024 + i), label: String(2024 + i), })) const countries = [ { value: "us", label: "United States" }, { value: "ca", label: "Canada" }, { value: "uk", label: "United Kingdom" }, { value: "de", label: "Germany" }, { value: "fr", label: "France" }, { value: "au", label: "Australia", disabled: true }, ] return (
{/* API Usage Examples */}
<Select options={options} />
<Select options={options} placeholder="Choose" />
<Select options={options}>Label</Select>
<Select options={options} labelPosition="left">Label</Select>
{/* Basic selects */}

Basic Selects

Birth Month
{/* Label to the left */}

Label Left

{/* Label to the right */}

Label Right

{/* Horizontal layout (like card form) */}

Horizontal Layout

) }