mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
* Initial * Calendar initial * Extract EventCalendar * Events list initial * Winners * SQL fixes * List events by series * Leaderboards * Series leaderboard * Own entry peek * Edit page skeleton * RHF initial test * RHF stuff * Form etc. progress * Fix tournament series description * Fix tabs layout * Fix socials insert * Check for not removing admin * Adding series * TODOs * Allow updating org with no series * FormFieldset * Allow series without events * TextAreaFormfield accepting array syntax * Input form array field * ToggleFormField * SelectFormField * UserSearchFormField * Fetch badgeOptions * Badge editing * Progress * Use native preventScrollReset * Rename func * Fix sticky scroll * Fix translation * i18n errors * handle,meta in edit * Add ref to user search * TODOs * Done
34 lines
801 B
TypeScript
34 lines
801 B
TypeScript
import * as React from "react";
|
|
import {
|
|
type FieldPath,
|
|
type FieldValues,
|
|
get,
|
|
useFormContext,
|
|
} from "react-hook-form";
|
|
import { FormMessage } from "~/components/FormMessage";
|
|
import { Label } from "~/components/Label";
|
|
|
|
export function TextFormField<T extends FieldValues>({
|
|
label,
|
|
name,
|
|
bottomText,
|
|
}: { label: string; name: FieldPath<T>; bottomText?: string }) {
|
|
const methods = useFormContext();
|
|
const id = React.useId();
|
|
|
|
const error = get(methods.formState.errors, name);
|
|
|
|
return (
|
|
<div>
|
|
<Label htmlFor={id}>{label}</Label>
|
|
<input id={id} {...methods.register(name)} />
|
|
{error && (
|
|
<FormMessage type="error">{error.message as string}</FormMessage>
|
|
)}
|
|
{bottomText && !error ? (
|
|
<FormMessage type="info">{bottomText}</FormMessage>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|