0.1.3 #4
@@ -1,30 +1,32 @@
|
|||||||
import { TextField } from "@radix-ui/themes"
|
import { TextField } from "@radix-ui/themes"
|
||||||
import { Duration, Equivalence, Record, Schema } from "effect"
|
import { type ParseResult, Schema } from "effect"
|
||||||
import { Component } from "effect-fc"
|
import { Component } from "effect-fc"
|
||||||
import { useInput } from "effect-fc/hooks"
|
import { useInput } from "effect-fc/hooks"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
|
|
||||||
export interface TextInputProps<A, R> extends Omit<useInput.Options<A, R>, "schema"> {
|
export interface TextInputProps<A, R> extends Omit<useInput.Options<A, R>, "schema"> {
|
||||||
readonly textFieldRootProps: TextField.RootProps
|
readonly textFieldRootProps: Omit<TextField.RootProps, "children">
|
||||||
|
readonly children?: React.ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TextInputPropsEquivalence: Equivalence.Equivalence<TextInputProps<unknown, unknown>> = Equivalence.struct({
|
export const TextInput = <A, R>(
|
||||||
ref: Equivalence.strict(),
|
schema: Schema.Schema<A, string, R>
|
||||||
debounce: (self?: Duration.Duration, that?: Duration.Duration) => (self === undefined || that === undefined)
|
): Component.Component<
|
||||||
? self === that
|
TextInputProps<A, R>,
|
||||||
: Duration.Equivalence(self, that),
|
React.JSX.Element,
|
||||||
textFieldRootProps: Record.getEquivalence(Equivalence.strict()),
|
ParseResult.ParseError,
|
||||||
})
|
R
|
||||||
|
> => Component.makeUntraced(function* TextInput(props: TextInputProps<A, R>) {
|
||||||
|
|
||||||
export const TextInput = <A, R>(schema: Schema.Schema<A, string, R>) => Component.makeUntraced(
|
|
||||||
function* TextInput(props: TextInputProps<A, R>) {
|
|
||||||
const input = yield* useInput({ ...props, schema })
|
const input = yield* useInput({ ...props, schema })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TextField.Root {...props.textFieldRootProps}>
|
<TextField.Root
|
||||||
|
value={input.value}
|
||||||
|
onChange={input.onChange}
|
||||||
|
{...props.textFieldRootProps}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
</TextField.Root>
|
</TextField.Root>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user