import { mergeRefs } from "@kobalte/utils"; import { type Component, type ValidComponent, createSignal, splitProps, } from "solid-js"; import type { ElementOf, PolymorphicProps } from "../polymorphic"; import { createFormResetListener } from "../primitives"; import { RadioGroup, type RadioGroupItemInputCommonProps, type RadioGroupItemInputOptions, type RadioGroupItemInputRenderProps, } from "../radio-group"; import { useRadioGroupItemContext } from "../radio-group/radio-group-item-context"; export interface SegmentedControlItemInputOptions extends RadioGroupItemInputOptions {} export interface SegmentedControlItemInputCommonProps< T extends HTMLElement = HTMLInputElement, > extends RadioGroupItemInputCommonProps {} export interface SegmentedControlItemInputRenderProps extends RadioGroupItemInputRenderProps {} export type SegmentedControlItemInputProps< T extends ValidComponent | HTMLElement = HTMLElement, > = SegmentedControlItemInputOptions & Partial>>; export const SegmentedControlItemInput = ( props: PolymorphicProps>, ) => { const radioGroupItemContext = useRadioGroupItemContext(); const [localProps, otherProps] = splitProps(props, ["ref"]); const [ref, setRef] = createSignal(); createFormResetListener(ref, () => { requestAnimationFrame(() => { if (radioGroupItemContext.isDefault()) { radioGroupItemContext.select(); } }); }); return ( > > ref={mergeRefs(setRef, localProps.ref)} {...otherProps} /> ); };