From fd36cf889a7b7a0395cf6e6dad7aa83d1f5152f7 Mon Sep 17 00:00:00 2001 From: rajun Date: Tue, 27 Oct 2026 16:28:50 +0530 Subject: [PATCH] feat: add form field wrapper with label and error --- app/components/ui/field.tsx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/components/ui/field.tsx diff --git a/app/components/ui/field.tsx b/app/components/ui/field.tsx new file mode 100644 index 0000000..e047405 --- /dev/null +++ b/app/components/ui/field.tsx @@ -0,0 +1,32 @@ +import type { ReactNode } from 'react'; +import { InlineMessage } from '~/components/ui/inline-message'; +import { Label } from '~/components/ui/label'; +import { Text } from '~/components/ui/text'; + +interface FieldProps { + label: string; + htmlFor?: string; + required?: boolean; + hint?: string; + error?: string; + // Shown on the right of the label: "Optional" / "Required" + requirement?: 'optional' | 'required'; + action?: ReactNode; + children?: ReactNode; +} + +export function Field({ label, htmlFor, required, hint, error, requirement, action, children }: FieldProps) { + return ( +
+
+ + {action ?? (requirement && {requirement === 'optional' ? 'Optional' : 'Required'})} +
+ {children} + {error ? {error} : hint && {hint}} +
+ ); +}