33 lines
954 B
TypeScript
33 lines
954 B
TypeScript
import { TextField } from "@radix-ui/themes"
|
|
import { type ParseResult, Schema } from "effect"
|
|
import { Component } from "effect-fc"
|
|
import { useInput } from "effect-fc/hooks"
|
|
import type * as React from "react"
|
|
|
|
|
|
export interface TextInputProps<A, R> extends Omit<useInput.Options<A, R>, "schema"> {
|
|
readonly textFieldRootProps: Omit<TextField.RootProps, "children">
|
|
readonly children?: React.ReactNode
|
|
}
|
|
|
|
export const TextInput = <A, R>(
|
|
schema: Schema.Schema<A, string, R>
|
|
): Component.Component<
|
|
TextInputProps<A, R>,
|
|
React.JSX.Element,
|
|
ParseResult.ParseError,
|
|
R
|
|
> => Component.makeUntraced(function* TextInput(props: TextInputProps<A, R>) {
|
|
const input = yield* useInput({ ...props, schema })
|
|
|
|
return (
|
|
<TextField.Root
|
|
value={input.value}
|
|
onChange={input.onChange}
|
|
{...props.textFieldRootProps}
|
|
>
|
|
{props.children}
|
|
</TextField.Root>
|
|
)
|
|
})
|