import { Callout, Flex, Spinner, Switch, TextField } from "@radix-ui/themes" import { Array, Option } from "effect" import { Component, Form, Hooks } from "effect-fc" interface Props extends TextField.RootProps, Form.useInput.Options { readonly optional?: false readonly field: Form.FormField } interface OptionalProps extends Omit, Form.useOptionalInput.Options { readonly optional: true readonly field: Form.FormField> } export type TextFieldFormInputProps = Props | OptionalProps export class TextFieldFormInput extends Component.makeUntraced("TextFieldFormInput")( function*(props: TextFieldFormInputProps) { const input: ( | { readonly optional: true } & Form.useOptionalInput.Result | { readonly optional: false } & Form.useInput.Result ) = props.optional // biome-ignore lint/correctness/useHookAtTopLevel: "optional" reactivity not supported ? { optional: true, ...yield* Form.useOptionalInput(props.field, props) } // biome-ignore lint/correctness/useHookAtTopLevel: "optional" reactivity not supported : { optional: false, ...yield* Form.useInput(props.field, props) } const [issues, isValidating, isSubmitting] = yield* Hooks.useSubscribables( props.field.issuesSubscribable, props.field.isValidatingSubscribable, props.field.isSubmittingSubscribable, ) return ( input.setValue(e.target.value)} disabled={(input.optional && !input.enabled) || isSubmitting} {...props} > {input.optional && } {isValidating && } {props.children} {Option.match(Array.head(issues), { onSome: issue => ( {issue.message} ), onNone: () => <>, })} ) } ) {}