diff --git a/components/FormContainer.js b/components/FormContainer.js index 38b1c96..e286bad 100644 --- a/components/FormContainer.js +++ b/components/FormContainer.js @@ -1,9 +1,11 @@ import React, { useState } from 'react'; import FormField from './FormField'; +import FormPreview from './FormPreview'; export default function FormContainer() { const [formContent, setFormContent] = useState([]); const [option, setOption] = useState(""); + const [showPreview, setShowPreview] = useState(false); const addFormField = () => { const field = { @@ -64,31 +66,55 @@ export default function FormContainer() { setFormContent(formField); } + const togglePreview = () => { + setShowPreview(!showPreview); + }; + return ( -
- {formContent.map((field) => ( - - ))} -
-
- +
+
+
+
+

Form Editor

+ +
+ + {formContent.map((field) => ( + + ))} +
+
+ +
+
+ + {showPreview && ( +
+ +
+ )}
); } \ No newline at end of file diff --git a/components/FormField.js b/components/FormField.js index dcc1c03..24f56e3 100644 --- a/components/FormField.js +++ b/components/FormField.js @@ -32,9 +32,9 @@ export default function FormField({
- {field.type === "text" && } - {field.type === "number" && } - {field.type === "date" && } + {field.type === "text" && } + {field.type === "number" && } + {field.type === "date" && } {(field.type === "checkbox" || field.type === "radio") && (
@@ -53,7 +53,7 @@ export default function FormField({ className="text-red-600 hover:text-red-900" onClick={() => onDeleteOption(field.id, opt)} > - Eliminar opcion + Delete option
))} @@ -67,7 +67,7 @@ export default function FormField({ className="text-blue-900 hover:text-blue-600" onClick={() => onAddOption(field.id, option)} > - Añadir opción + Add option
@@ -101,7 +101,7 @@ export default function FormField({ className="text-blue-900 hover:text-blue-600" onClick={() => onAddOption(field.id, option)} > - Añadir opción + Add option @@ -112,7 +112,7 @@ export default function FormField({ className="bg-red-700 hover:bg-red-200 text-neutral-100 rounded-md px-3 py-1" onClick={() => onDelete(field.id)} > - Eliminar campo + Delete field diff --git a/components/FormPreview.js b/components/FormPreview.js new file mode 100644 index 0000000..38602d6 --- /dev/null +++ b/components/FormPreview.js @@ -0,0 +1,102 @@ +import React from 'react'; + +export default function FormPreview({ formContent }) { + return ( +
+

Form Preview

+
+ {formContent.map((field) => ( +
+ + + {field.type === "text" && ( + + )} + + {field.type === "number" && ( + + )} + + {field.type === "date" && ( + + )} + + {field.type === "checkbox" && ( +
+ {field.options.map((opt) => ( +
+ + +
+ ))} +
+ )} + + {field.type === "radio" && ( +
+ {field.options.map((opt) => ( +
+ + +
+ ))} +
+ )} + + {field.type === "select" && ( + + )} +
+ ))} + + {formContent.length > 0 && ( + + )} +
+
+ ); +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9da4486..281f4b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "adestos-forms", "version": "0.1.0", "dependencies": { "@tailwindcss/forms": "^0.5.3", @@ -431,7 +432,6 @@ "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", - "fsevents": "~2.3.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -745,19 +745,6 @@ "integrity": "sha512-l7bvmSeIwX5lp07WtIiP9u2ytZMv7jIeB8iacR28PuUEFG5j0HGAPnMqyG5kbZNBG2H7tRsrQ4HCjuMOPnANZw==", "dependencies": { "@next/env": "12.3.1", - "@next/swc-android-arm-eabi": "12.3.1", - "@next/swc-android-arm64": "12.3.1", - "@next/swc-darwin-arm64": "12.3.1", - "@next/swc-darwin-x64": "12.3.1", - "@next/swc-freebsd-x64": "12.3.1", - "@next/swc-linux-arm-gnueabihf": "12.3.1", - "@next/swc-linux-arm64-gnu": "12.3.1", - "@next/swc-linux-arm64-musl": "12.3.1", - "@next/swc-linux-x64-gnu": "12.3.1", - "@next/swc-linux-x64-musl": "12.3.1", - "@next/swc-win32-arm64-msvc": "12.3.1", - "@next/swc-win32-ia32-msvc": "12.3.1", - "@next/swc-win32-x64-msvc": "12.3.1", "@swc/helpers": "0.4.11", "caniuse-lite": "^1.0.30001406", "postcss": "8.4.14", diff --git a/package.json b/package.json index e90d039..3ffd5fe 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev", + "dev": "next dev -p 3001", "build": "next build", "start": "next start", "lint": "next lint" diff --git a/pages/index.js b/pages/index.js index 16c2e49..d758cf7 100644 --- a/pages/index.js +++ b/pages/index.js @@ -6,13 +6,13 @@ export default function Home() { return ( <> - Adestos Forms - + Forms + -
-
-

Adestos-Forms

-

Crea tu formulario

+
+
+

Forms

+

Create your form