@@ -1,8 +1,7 @@
|
||||
import { Callout, Flex, TextField } from "@radix-ui/themes"
|
||||
import { Option, ParseResult, Schema, Struct, SubscriptionRef } from "effect"
|
||||
import { Callout, Flex, Switch, TextField } from "@radix-ui/themes"
|
||||
import { Option, ParseResult, Schema, Struct } from "effect"
|
||||
import { Component } from "effect-fc"
|
||||
import { useInput, useOptionalInput } from "effect-fc/hooks"
|
||||
import { SubscriptionSubRef } from "effect-fc/types"
|
||||
import * as React from "react"
|
||||
|
||||
|
||||
@@ -18,19 +17,21 @@ export const TextFieldInput: {
|
||||
readonly optional?: false
|
||||
readonly schema: Schema.Schema<A, string, R>
|
||||
}): Component.Component<TextFieldInputProps<A, R>, React.JSX.Element, ParseResult.ParseError, R>
|
||||
} = <A, R>(options:
|
||||
{
|
||||
readonly optional: true
|
||||
}
|
||||
): Component.Component<
|
||||
TextFieldOptionalInputProps<A, R> | TextFieldInputProps<A, R>,
|
||||
React.JSX.Element,
|
||||
ParseResult.ParseError,
|
||||
R
|
||||
> => Component.makeUntraced(function* TextFieldInput(props) {
|
||||
} = <A, R>(options: {
|
||||
readonly optional?: boolean
|
||||
readonly schema: Schema.Schema<A, string, R>
|
||||
}) => Component.makeUntraced(function* TextFieldInput(props: TextFieldOptionalInputProps<A, R> | TextFieldInputProps<A, R>) {
|
||||
const input = options.optional
|
||||
? yield* useOptionalInput({ schema, ...props })
|
||||
: yield* useInput({ schema, ...props })
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
? yield* useOptionalInput({
|
||||
schema: options.schema,
|
||||
...props as TextFieldOptionalInputProps<A, R>,
|
||||
})
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
: yield* useInput({
|
||||
schema: options.schema,
|
||||
...props as TextFieldInputProps<A, R>,
|
||||
})
|
||||
|
||||
const issues = React.useMemo(() => Option.map(
|
||||
input.error,
|
||||
@@ -47,11 +48,18 @@ export const TextFieldInput: {
|
||||
</Callout.Root>
|
||||
}
|
||||
|
||||
<Flex direction="row" align="center" gap="1">
|
||||
{options.optional &&
|
||||
<Switch
|
||||
|
||||
/>
|
||||
}
|
||||
|
||||
<TextField.Root
|
||||
value={input.value}
|
||||
onChange={input.onChange}
|
||||
{...input}
|
||||
{...Struct.omit(props, "ref")}
|
||||
/>
|
||||
</Flex>
|
||||
</Flex>
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user