From 012eeb3b8e241b207794c5ddf4598693e7de8073 Mon Sep 17 00:00:00 2001 From: Hadeed Ahmad Date: Sat, 8 Jun 2024 11:52:17 +0400 Subject: [PATCH] Finish mobile form --- package-lock.json | 16 ++++ package.json | 1 + src/app.jsx | 179 ++++++++++++++++++++++++++++----------- src/components/input.jsx | 2 +- 4 files changed, 147 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6bf8867..87b564a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "clsx": "^2.1.1", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-hook-form": "^7.51.5", "tailwind-merge": "^2.3.0" }, "devDependencies": { @@ -2489,6 +2490,21 @@ "react": "^18.3.1" } }, + "node_modules/react-hook-form": { + "version": "7.51.5", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.51.5.tgz", + "integrity": "sha512-J2ILT5gWx1XUIJRETiA7M19iXHlG74+6O3KApzvqB/w8S5NQR7AbU8HVZrMALdmDgWpRPYiZJl0zx8Z4L2mP6Q==", + "engines": { + "node": ">=12.22.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/react-hook-form" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", diff --git a/package.json b/package.json index 5443c36..297e75b 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "clsx": "^2.1.1", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-hook-form": "^7.51.5", "tailwind-merge": "^2.3.0" }, "devDependencies": { diff --git a/src/app.jsx b/src/app.jsx index 9bfb69f..db320e3 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -2,6 +2,7 @@ import * as Checkbox from "@radix-ui/react-checkbox"; import * as RadioGroup from "@radix-ui/react-radio-group"; import * as Toast from "@radix-ui/react-toast"; import { useState } from "react"; +import { Controller, useForm } from "react-hook-form"; import icon_checkbox_checked from "../assets/icon-checkbox-checked.svg"; import icon_checkbox_unchecked from "../assets/icon-checkbox-unchecked.svg"; @@ -10,24 +11,42 @@ import icon_check from "../assets/check.svg"; import { Button } from "./components/button"; import { Input } from "./components/input"; -const InputField = ({ label, type = "text", required = false, ...props }) => { +const InputField = ({ + label, + type = "text", + required = false, + register, + errors, + ...props +}) => { + const _label = label.toLowerCase().replace(/ /g, "_"); + const error = errors[_label]?.type == "required"; + return ( -