import { callHandler } from "@kobalte/utils"; import { type Component, type JSX, type ValidComponent, splitProps, } from "solid-js"; import { FormControlLabel, type FormControlLabelCommonProps, type FormControlLabelRenderProps, } from "../form-control"; import type { ElementOf, PolymorphicProps } from "../polymorphic"; import { useSelectContext } from "./select-context"; export interface SelectLabelOptions {} export interface SelectLabelCommonProps extends FormControlLabelCommonProps { onClick: JSX.EventHandlerUnion; } export interface SelectLabelRenderProps extends SelectLabelCommonProps, FormControlLabelRenderProps {} export type SelectLabelProps< T extends ValidComponent | HTMLElement = HTMLElement, > = SelectLabelOptions & Partial>>; /** * The label that gives the user information on the select. */ export function SelectLabel( props: PolymorphicProps>, ) { const context = useSelectContext(); const [local, others] = splitProps(props as SelectLabelProps, ["onClick"]); const onClick: JSX.EventHandlerUnion = (e) => { callHandler(e, local.onClick); if (!context.isDisabled()) { context.triggerRef()?.focus(); } }; return ( > > as="span" onClick={onClick} {...others} /> ); }