improve fields for contact and add send icon

This commit is contained in:
2026-06-04 21:29:44 +02:00
parent 38fc389776
commit 40541d3da2
+37 -14
View File
@@ -1,12 +1,13 @@
import { useActionState } from "react"; import { useActionState } from "react";
import { LuSend } from "react-icons/lu";
import Section from "#/components/Section.tsx"; import Section from "#/components/Section.tsx";
interface IFormField { interface IFormField {
fieldName: string; fieldName: string;
type: "text" | "email" | "textarea"; type: "text" | "email" | "textarea";
placeholder: string; placeholder: string;
label: string; required?: boolean;
required: boolean; textarea?: boolean;
} }
type IProps = { type IProps = {
@@ -20,18 +21,36 @@ const FormField = ({
type, type,
fieldName, fieldName,
placeholder, placeholder,
label, required = false,
required, textarea = false,
}: IFormField) => ( }: IFormField) => (
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<label htmlFor={fieldName}>{label}</label> <label
htmlFor={fieldName}
className="capitalize text-(--neutral-content) text-left"
>
{fieldName}
{required && <span>*</span>}
</label>
{textarea ? (
<textarea
id={fieldName}
name={fieldName}
placeholder={placeholder}
required={required}
rows={5}
className="text-(--base-content) w-full rounded-md border border-neutral-300 px-3 py-2 placeholder:text-neutral-400/50 outline-hidden transition-all duration-200 focus:border-(--accent) focus:outline-3 focus:outline-offset-2 focus:outline-(--accent)/50 resize-y"
/>
) : (
<input <input
type={type} type={type}
id={fieldName} id={fieldName}
name={fieldName} name={fieldName}
placeholder={placeholder} placeholder={placeholder}
required={required} required={required}
className="text-(--base-content) w-full rounded-md border border-neutral-300 px-3 py-2 placeholder:text-neutral-400/50 outline-hidden transition-all duration-200 focus:border-(--accent) focus:outline-3 focus:outline-offset-2 focus:outline-(--accent)/50"
/> />
)}
</div> </div>
); );
@@ -44,41 +63,45 @@ const Contact = ({ handleSubmit }: IProps) => {
title="Contact Us" title="Contact Us"
description="Do you have suggestions on how to improve this service? Would you like to get involved with this project? Ask us anything you like." description="Do you have suggestions on how to improve this service? Would you like to get involved with this project? Ask us anything you like."
> >
<form action={formAction}> <form
action={formAction}
className="col-span-3 flex flex-col gap-6 w-full max-w-(--breakpoint-sm)"
>
<FormField <FormField
type="text" type="text"
fieldName="name" fieldName="name"
placeholder="Your name" placeholder="Your name"
label="Name"
required required
/> />
<FormField <FormField
fieldName="email" fieldName="email"
type="text" type="email"
placeholder="name@example.com" placeholder="name@example.com"
label="Email"
required required
/> />
<input <FormField
fieldName="subject"
type="text" type="text"
name="subject"
placeholder="Reason for contacting us" placeholder="Reason for contacting us"
/> />
<textarea <FormField
name="message" fieldName="message"
type="text"
placeholder="Your message here..." placeholder="Your message here..."
required required
textarea
/> />
<button <button
type="submit" type="submit"
disabled={isPending} disabled={isPending}
className="btn btn-primary" className="btn btn-primary flex items-center justify-center gap-2"
> >
{isPending ? "Sending..." : "Send"} {isPending ? "Sending..." : "Send"}
<LuSend className="w-5 h-5" />
</button> </button>
{state && <p>{state.message}</p>} {state && <p>{state.message}</p>}
</form> </form>