import * as React from 'react'
import { FieldLabel, FieldHint, FieldError } from './field'
import { cn } from '@/lib/utils'
/**
* SingleSelect — native <select> wrapped в label/hint/error chrome.
* Замена @nstart/ui SingleSelect (тот же API: options, value, onChange).
*
*
Native select работает на mobile out-of-box, screen readers OK, по
* Enter/space открывается. Custom dropdown UI можно сделать через Radix
* Select (Stage 3.8b refinement) если потребуется branded look.
*/
/** nstart-compat shape: {id, label}. New code may prefer the more standard
* {value, label} — both keys accepted (id wins if both). */
export type SelectOption = {
id: string
label: React.ReactNode
/** Alias of `id` для совместимости с HTML option convention. */
value?: string
}
export type SingleSelectProps = {
label?: React.ReactNode
hint?: React.ReactNode
error?: React.ReactNode
required?: boolean
options: ReadonlyArray
value: string
onChange: (value: string) => void
placeholder?: string
disabled?: boolean
id?: string
rootClassName?: string
selectClassName?: string
}
export function SingleSelect({
label,
hint,
error,
required,
options,
value,
onChange,
placeholder,
disabled,
id,
rootClassName,
selectClassName,
}: SingleSelectProps) {
const autoId = React.useId()
const selectId = id ?? autoId
const hintId = hint ? `${selectId}-hint` : undefined
const errorId = error ? `${selectId}-error` : undefined
return (
{label && (
{label}
)}
{hint && !error && {hint}}
{error && {error}}
)
}