From 9df97141c15f32e20f09e903e16e3b5c68604b3e Mon Sep 17 00:00:00 2001 From: emaicorp Date: Sun, 21 Jul 2024 17:28:53 +0100 Subject: [PATCH 01/15] testing branch --- .../ui/formComponents/form.module.css | 11 +++ .../ui/formComponents/formComponent.tsx | 86 +++++++++++++++++++ .../ui/formComponents/formSchema.tsx | 8 ++ .../ui/formComponents/formSubmit.tsx | 17 ++++ .../ui/formComponents/handleImageUpload.tsx | 15 ++++ .../ui/formComponents/uploadPicture.tsx | 46 ++++++++++ 6 files changed, 183 insertions(+) create mode 100644 app/components/ui/formComponents/form.module.css create mode 100644 app/components/ui/formComponents/formComponent.tsx create mode 100644 app/components/ui/formComponents/formSchema.tsx create mode 100644 app/components/ui/formComponents/formSubmit.tsx create mode 100644 app/components/ui/formComponents/handleImageUpload.tsx create mode 100644 app/components/ui/formComponents/uploadPicture.tsx diff --git a/app/components/ui/formComponents/form.module.css b/app/components/ui/formComponents/form.module.css new file mode 100644 index 00000000..de2f733d --- /dev/null +++ b/app/components/ui/formComponents/form.module.css @@ -0,0 +1,11 @@ +/* InputForm.module.css */ +.placeholderCustom::placeholder { + font-size: 16px; + font-weight: 400; + line-height: 24px; + text-align: left; + + } + + + \ No newline at end of file diff --git a/app/components/ui/formComponents/formComponent.tsx b/app/components/ui/formComponents/formComponent.tsx new file mode 100644 index 00000000..3314f52c --- /dev/null +++ b/app/components/ui/formComponents/formComponent.tsx @@ -0,0 +1,86 @@ +"use client"; + +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; + +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, +} from "~/components/ui/for"; +import { Input } from "~/components/ui/input"; +import { toast } from "~/components/ui/use-toast"; +import { Button } from "../button"; +import { FormSchema } from "./formSchema"; + +export function InputForm() { + const form = useForm>({ + resolver: zodResolver(FormSchema), + defaultValues: { + name: "", + email: "", + number: "", + }, + }); + + function onSubmit(data: z.infer) { + console.log(data); + toast({ + title: "You submitted the following values:", + description: ( +
+          
+            {JSON.stringify(data, undefined, 2)}
+          
+        
+ ), + }); + } + + return ( +
+ + ( + + name + + + + + )} + /> + ( + + Email + + + + + )} + /> + ( + + Phone Number + + + + + )} + /> + + + + ); +} diff --git a/app/components/ui/formComponents/formSchema.tsx b/app/components/ui/formComponents/formSchema.tsx new file mode 100644 index 00000000..dc4560d3 --- /dev/null +++ b/app/components/ui/formComponents/formSchema.tsx @@ -0,0 +1,8 @@ +import { z } from "zod"; + +const phoneRegex = new RegExp(/^(\+?[\d\s]+)?(\d{3}|\(?\d+\))?(-?\s?\d)+$/); +export const FormSchema = z.object({ + name: z.string().min(2), + email: z.string().email(), + number: z.string().regex(phoneRegex, "Invalid Number!"), +}); diff --git a/app/components/ui/formComponents/formSubmit.tsx b/app/components/ui/formComponents/formSubmit.tsx new file mode 100644 index 00000000..f0017918 --- /dev/null +++ b/app/components/ui/formComponents/formSubmit.tsx @@ -0,0 +1,17 @@ +import z from "zod"; + +import { FormSchema } from "./formSchema"; + +// import { toast } from "./use-toast" + +export function submit(data: z.infer) { + console.log("submited", data); + // toast({ + // title: "You submitted the following values:", + // description: ( + //
+  //       {JSON.stringify(data, null, 2)}
+  //     
+ // ), + // }) +} diff --git a/app/components/ui/formComponents/handleImageUpload.tsx b/app/components/ui/formComponents/handleImageUpload.tsx new file mode 100644 index 00000000..d77a316d --- /dev/null +++ b/app/components/ui/formComponents/handleImageUpload.tsx @@ -0,0 +1,15 @@ +import { ChangeEvent } from "react"; + +export const handleImageUpload = ( + event: ChangeEvent, + setBackgroundImage: (image: string | null) => void, +) => { + const file = event.target.files?.[0]; + if (file && file.type.startsWith("image/")) { + const reader = new FileReader(); + reader.addEventListener("load", () => { + setBackgroundImage(reader.result as string); + }); + reader.readAsDataURL(file); + } +}; diff --git a/app/components/ui/formComponents/uploadPicture.tsx b/app/components/ui/formComponents/uploadPicture.tsx new file mode 100644 index 00000000..a0aefbc2 --- /dev/null +++ b/app/components/ui/formComponents/uploadPicture.tsx @@ -0,0 +1,46 @@ +import clsx from "clsx"; +import { ChangeEvent, useState } from "react"; + +import { Input } from "~/components/ui/input"; +import { Label } from "~/components/ui/label"; +import { handleImageUpload } from "./handleImageUpload"; + +export function UploadPicture() { + const [backgroundImage, setBackgroundImage] = useState< + string | null | undefined + >(); + return ( +
+
+
+ + + ) => + handleImageUpload(event, setBackgroundImage) + } + /> +
+
+ ); +} From ac6b33e8fed381018ba6690ae19931be07929935 Mon Sep 17 00:00:00 2001 From: emaicorp Date: Sun, 21 Jul 2024 17:18:56 +0100 Subject: [PATCH 02/15] merging and rebasing branch --- app/components/addUserModel/addUserModal.tsx | 18 ++ app/components/ui/form.tsx | 178 +++++++++++++++++ app/components/ui/toast.tsx | 129 ++++++++++++ app/components/ui/toaster.tsx | 35 ++++ app/components/ui/use-toast.ts | 194 +++++++++++++++++++ app/routes/_index.tsx | 74 +++++++ package.json | 1 + pnpm-lock.yaml | 45 +++++ 8 files changed, 674 insertions(+) create mode 100644 app/components/addUserModel/addUserModal.tsx create mode 100644 app/components/ui/form.tsx create mode 100644 app/components/ui/toast.tsx create mode 100644 app/components/ui/toaster.tsx create mode 100644 app/components/ui/use-toast.ts diff --git a/app/components/addUserModel/addUserModal.tsx b/app/components/addUserModel/addUserModal.tsx new file mode 100644 index 00000000..104c091a --- /dev/null +++ b/app/components/addUserModel/addUserModal.tsx @@ -0,0 +1,18 @@ +import { InputForm } from "../ui/formComponents/formComponent"; +import { UploadPicture } from "../ui/formComponents/uploadPicture"; + +const AddUserModal = () => { + return ( +
+
+

Add new user

+

Create New User

+ + + +
+
+ ); +}; + +export default AddUserModal; diff --git a/app/components/ui/form.tsx b/app/components/ui/form.tsx new file mode 100644 index 00000000..a00a8e12 --- /dev/null +++ b/app/components/ui/form.tsx @@ -0,0 +1,178 @@ +"use client" + +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" +import { Slot } from "@radix-ui/react-slot" +import { + Controller, + ControllerProps, + FieldPath, + FieldValues, + FormProvider, + useFormContext, +} from "react-hook-form" + +import { cn } from "app/lib/utils/cn" +import { Label } from "app/components/ui/label" + +const Form = FormProvider + +type FormFieldContextValue< + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath +> = { + name: TName +} + +const FormFieldContext = React.createContext( + {} as FormFieldContextValue +) + +const FormField = < + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath +>({ + ...props +}: ControllerProps) => { + return ( + + + + ) +} + +const useFormField = () => { + const fieldContext = React.useContext(FormFieldContext) + const itemContext = React.useContext(FormItemContext) + const { getFieldState, formState } = useFormContext() + + const fieldState = getFieldState(fieldContext.name, formState) + + if (!fieldContext) { + throw new Error("useFormField should be used within ") + } + + const { id } = itemContext + + return { + id, + name: fieldContext.name, + formItemId: `${id}-form-item`, + formDescriptionId: `${id}-form-item-description`, + formMessageId: `${id}-form-item-message`, + ...fieldState, + } +} + +type FormItemContextValue = { + id: string +} + +const FormItemContext = React.createContext( + {} as FormItemContextValue +) + +const FormItem = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => { + const id = React.useId() + + return ( + +
+ + ) +}) +FormItem.displayName = "FormItem" + +const FormLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + const { error, formItemId } = useFormField() + + return ( +
); } diff --git a/package.json b/package.json index 92e29012..d560fb67 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-switch": "^1.1.0", "@radix-ui/react-tabs": "^1.1.0", + "@radix-ui/react-toast": "^1.2.1", "@react-email/components": "^0.0.21", "@remix-run/css-bundle": "^2.10.3", "@remix-run/node": "^2.10.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c79f1b07..b3b3292a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ importers: '@radix-ui/react-tabs': specifier: ^1.1.0 version: 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-toast': + specifier: ^1.2.1 + version: 1.2.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@react-email/components': specifier: ^0.0.21 version: 0.0.21(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -1255,6 +1258,19 @@ packages: '@types/react-dom': optional: true + '@radix-ui/react-toast@1.2.1': + resolution: {integrity: sha512-5trl7piMXcZiCq7MW6r8YYmu0bK5qDpTWz+FdEPdKyft2UixkspheYbjbrLXVN5NGKHFbOP7lm8eD0biiSqZqg==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-toggle-group@1.1.0': resolution: {integrity: sha512-PpTJV68dZU2oqqgq75Uzto5o/XfOVgkrJ9rulVmfTKxWp3HfUjHE6CP/WLRR4AzPX9HWxw7vFow2me85Yu+Naw==} peerDependencies: @@ -6369,6 +6385,26 @@ snapshots: '@types/react': 18.3.3 '@types/react-dom': 18.3.0 + '@radix-ui/react-toast@1.2.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + dependencies: + '@radix-ui/primitive': 1.1.0 + '@radix-ui/react-collection': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.3)(react@18.3.1) + '@radix-ui/react-context': 1.1.0(@types/react@18.3.3)(react@18.3.1) + '@radix-ui/react-dismissable-layer': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-portal': 1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-presence': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-use-callback-ref': 1.1.0(@types/react@18.3.3)(react@18.3.1) + '@radix-ui/react-use-controllable-state': 1.1.0(@types/react@18.3.3)(react@18.3.1) + '@radix-ui/react-use-layout-effect': 1.1.0(@types/react@18.3.3)(react@18.3.1) + '@radix-ui/react-visually-hidden': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + optionalDependencies: + '@types/react': 18.3.3 + '@types/react-dom': 18.3.0 + '@radix-ui/react-toggle-group@1.1.0(@types/react-dom@18.3.0)(@types/react@18.2.47)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: '@radix-ui/primitive': 1.1.0 @@ -6503,6 +6539,15 @@ snapshots: '@types/react': 18.2.47 '@types/react-dom': 18.3.0 + '@radix-ui/react-visually-hidden@1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + dependencies: + '@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + optionalDependencies: + '@types/react': 18.3.3 + '@types/react-dom': 18.3.0 + '@radix-ui/rect@1.1.0': {} '@react-email/body@0.0.8(react@18.3.1)': From 91ce7e3f5f584e31be3e0d5de9a0d3594edc69ba Mon Sep 17 00:00:00 2001 From: emaicorp Date: Sun, 21 Jul 2024 17:32:05 +0100 Subject: [PATCH 03/15] rebased my branch to master --- app/components/ui/formComponents/formComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/ui/formComponents/formComponent.tsx b/app/components/ui/formComponents/formComponent.tsx index 3314f52c..0f9ddabf 100644 --- a/app/components/ui/formComponents/formComponent.tsx +++ b/app/components/ui/formComponents/formComponent.tsx @@ -10,7 +10,7 @@ import { FormField, FormItem, FormLabel, -} from "~/components/ui/for"; +} from "~/components/ui/form"; import { Input } from "~/components/ui/input"; import { toast } from "~/components/ui/use-toast"; import { Button } from "../button"; From 78177e719e847e164a8e04a03b0b75144a53be16 Mon Sep 17 00:00:00 2001 From: emaicorp Date: Sun, 21 Jul 2024 19:32:13 +0100 Subject: [PATCH 04/15] finished work on the responsiveness --- app/components/addUserModel/addUserModal.tsx | 7 +- .../ui/formComponents/form.module.css | 1 + .../ui/formComponents/formComponent.tsx | 76 +++++++++++++++++-- .../ui/formComponents/formSubmit.tsx | 19 +++-- .../ui/formComponents/uploadPicture.tsx | 8 +- tailwind.config.ts | 4 + 6 files changed, 90 insertions(+), 25 deletions(-) diff --git a/app/components/addUserModel/addUserModal.tsx b/app/components/addUserModel/addUserModal.tsx index 104c091a..a2ecaa5a 100644 --- a/app/components/addUserModel/addUserModal.tsx +++ b/app/components/addUserModel/addUserModal.tsx @@ -4,11 +4,10 @@ import { UploadPicture } from "../ui/formComponents/uploadPicture"; const AddUserModal = () => { return (
-
-

Add new user

-

Create New User

+
+

Add new user

+

Create New User

-
diff --git a/app/components/ui/formComponents/form.module.css b/app/components/ui/formComponents/form.module.css index de2f733d..ad6dc3c7 100644 --- a/app/components/ui/formComponents/form.module.css +++ b/app/components/ui/formComponents/form.module.css @@ -4,6 +4,7 @@ font-weight: 400; line-height: 24px; text-align: left; + color: #94A3B8; } diff --git a/app/components/ui/formComponents/formComponent.tsx b/app/components/ui/formComponents/formComponent.tsx index 0f9ddabf..5e89c30c 100644 --- a/app/components/ui/formComponents/formComponent.tsx +++ b/app/components/ui/formComponents/formComponent.tsx @@ -1,6 +1,7 @@ "use client"; import { zodResolver } from "@hookform/resolvers/zod"; +import clsx from "clsx"; import { useForm } from "react-hook-form"; import { z } from "zod"; @@ -14,6 +15,7 @@ import { import { Input } from "~/components/ui/input"; import { toast } from "~/components/ui/use-toast"; import { Button } from "../button"; +import styles from "./form.module.css"; import { FormSchema } from "./formSchema"; export function InputForm() { @@ -42,15 +44,33 @@ export function InputForm() { return (
- + ( - name + + name + - + )} @@ -60,9 +80,27 @@ export function InputForm() { name="email" render={({ field }) => ( - Email + + Email + - + )} @@ -72,14 +110,36 @@ export function InputForm() { name="number" render={({ field }) => ( - Phone Number + + Phone Number + - + )} /> - +
+ +
); diff --git a/app/components/ui/formComponents/formSubmit.tsx b/app/components/ui/formComponents/formSubmit.tsx index f0017918..17951458 100644 --- a/app/components/ui/formComponents/formSubmit.tsx +++ b/app/components/ui/formComponents/formSubmit.tsx @@ -1,17 +1,16 @@ import z from "zod"; +import { toast } from "~/components/ui/use-toast"; import { FormSchema } from "./formSchema"; -// import { toast } from "./use-toast" - export function submit(data: z.infer) { console.log("submited", data); - // toast({ - // title: "You submitted the following values:", - // description: ( - //
-  //       {JSON.stringify(data, null, 2)}
-  //     
- // ), - // }) + toast({ + title: "You submitted the following values:", + description: ( +
+        {JSON.stringify(data, undefined, 2)}
+      
+ ), + }); } diff --git a/app/components/ui/formComponents/uploadPicture.tsx b/app/components/ui/formComponents/uploadPicture.tsx index a0aefbc2..0c925013 100644 --- a/app/components/ui/formComponents/uploadPicture.tsx +++ b/app/components/ui/formComponents/uploadPicture.tsx @@ -10,10 +10,10 @@ export function UploadPicture() { string | null | undefined >(); return ( -
+
- +
- +