@@ -24,8 +24,7 @@ export const TextFieldInput = <A, R, O extends boolean = false>(options: {
|
||||
optional: true,
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
...yield* useOptionalInput({
|
||||
schema: options.schema,
|
||||
equivalence: options.equivalence,
|
||||
...options,
|
||||
...props as TextFieldOptionalInputProps<A, R>,
|
||||
}),
|
||||
}
|
||||
@@ -33,8 +32,7 @@ export const TextFieldInput = <A, R, O extends boolean = false>(options: {
|
||||
optional: false,
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
...yield* useInput({
|
||||
schema: options.schema,
|
||||
equivalence: options.equivalence,
|
||||
...options,
|
||||
...props as TextFieldInputProps<A, R>,
|
||||
})
|
||||
}
|
||||
@@ -49,21 +47,20 @@ export const TextFieldInput = <A, R, O extends boolean = false>(options: {
|
||||
<Flex direction="row" align="center" gap="1">
|
||||
{input.optional &&
|
||||
<Checkbox
|
||||
checked={!input.disabled}
|
||||
onCheckedChange={checked => input.setDisabled(!checked)}
|
||||
checked={input.enabled}
|
||||
onCheckedChange={checked => input.setEnabled(checked !== "indeterminate" && checked)}
|
||||
/>
|
||||
}
|
||||
|
||||
<TextField.Root
|
||||
{...input.optional
|
||||
? Struct.pick(input, "value", "onChange", "disabled")
|
||||
: Struct.pick(input, "value", "onChange")
|
||||
}
|
||||
value={input.value}
|
||||
onChange={e => input.setValue(e.target.value)}
|
||||
disabled={input.optional ? !input.enabled : undefined}
|
||||
{...Struct.omit(props as TextFieldOptionalInputProps<A, R> | TextFieldInputProps<A, R>, "ref")}
|
||||
/>
|
||||
</Flex>
|
||||
|
||||
{(!(input.optional && input.disabled) && Option.isSome(issue)) &&
|
||||
{(!(input.optional && !input.enabled) && Option.isSome(issue)) &&
|
||||
<Callout.Root color="red" role="alert">
|
||||
<Callout.Text>{issue.value.message}</Callout.Text>
|
||||
</Callout.Root>
|
||||
|
||||
Reference in New Issue
Block a user