import React, { Children, type ReactNode } from "react"; import SelectDropdown from "../SelectDropdown"; import SelectOption from "../SelectOption"; import type { SelectOptionData } from "./SelectInput.types"; export interface SelectInputViewProps { label?: string; placeholder: string; size: "small" | "medium" | "large"; state: "default" | "hover" | "focus"; disabled: boolean; error: boolean; labelVariant: "default" | "horizontal"; className: string; options?: SelectOptionData[]; children?: ReactNode; // Computed props from container selectId: string; labelId: string; isOpen: boolean; selectedValue: string; displayText: string; selectClasses: string; labelClasses: string; containerClasses: string; chevronClasses: string; // Callbacks onButtonClick: () => void; onButtonKeyDown: (_e: React.KeyboardEvent) => void; onOptionClick: (_value: string, _text: string) => void; // Refs selectRef: React.RefObject; menuRef: React.RefObject; // Additional props ariaLabelledby?: string; ariaInvalid?: boolean; } export function SelectInputView({ label, placeholder: _placeholder, size, disabled, error: _error, labelVariant: _labelVariant, options, children, selectId, labelId, isOpen, selectedValue, displayText, selectClasses, labelClasses, containerClasses, chevronClasses, onButtonClick, onButtonKeyDown, onOptionClick, selectRef, menuRef, ariaLabelledby, ariaInvalid, ...props }: SelectInputViewProps) { return (
{label && ( )}
{isOpen && (
{options && Array.isArray(options) ? options.map((option) => ( onOptionClick(option.value, option.label)} > {option.label} )) : Children.map(children, (child) => { if ( React.isValidElement(child) && child.type === "option" ) { const optionProps = child.props as { value: string; children: ReactNode; }; return ( onOptionClick( optionProps.value, String(optionProps.children), ) } > {optionProps.children} ); } return child; })}
)}
); }