aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Form
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2021-12-16 13:40:12 +0100
committerArmand Philippot <git@armandphilippot.com>2021-12-16 13:40:12 +0100
commiteb459cc248a5940a14193b20d263ffee3d345026 (patch)
tree92ea7b91d4481b4b61f86bef5299227e0bca1c3d /src/components/Form
parent94f1c1fbea903e677476a167e51b549bb0c53330 (diff)
chore: create contact page
Diffstat (limited to 'src/components/Form')
-rw-r--r--src/components/Form/Form.module.scss31
-rw-r--r--src/components/Form/Form.tsx16
-rw-r--r--src/components/Form/FormItem/FormItem.tsx7
-rw-r--r--src/components/Form/Input/Input.tsx47
-rw-r--r--src/components/Form/TextArea/TextArea.tsx42
-rw-r--r--src/components/Form/index.tsx6
6 files changed, 149 insertions, 0 deletions
diff --git a/src/components/Form/Form.module.scss b/src/components/Form/Form.module.scss
new file mode 100644
index 0000000..f23dfde
--- /dev/null
+++ b/src/components/Form/Form.module.scss
@@ -0,0 +1,31 @@
+@use "@styles/abstracts/functions" as fun;
+
+.wrapper {
+ width: 100%;
+}
+
+.item {
+ margin: var(--spacing-xs) 0;
+ max-width: 45ch;
+}
+
+.label {
+ display: block;
+ font-size: var(--font-size-sm);
+ font-variant: small-caps;
+ font-weight: 600;
+}
+
+.field {
+ border: fun.convert-px(1) solid var(--color-border);
+ width: 100%;
+ padding: var(--spacing-2xs) var(--spacing-xs);
+
+ &:focus {
+ border-color: var(--color-primary);
+ }
+}
+
+.textarea {
+ min-height: fun.convert-px(200);
+}
diff --git a/src/components/Form/Form.tsx b/src/components/Form/Form.tsx
new file mode 100644
index 0000000..cc97526
--- /dev/null
+++ b/src/components/Form/Form.tsx
@@ -0,0 +1,16 @@
+import { FormEvent } from 'react';
+import styles from './Form.module.scss';
+
+const Form: React.FunctionComponent = ({ children }) => {
+ const submitForm = (e: FormEvent) => {
+ e.preventDefault();
+ };
+
+ return (
+ <form onSubmit={submitForm} className={styles.wrapper}>
+ {children}
+ </form>
+ );
+};
+
+export default Form;
diff --git a/src/components/Form/FormItem/FormItem.tsx b/src/components/Form/FormItem/FormItem.tsx
new file mode 100644
index 0000000..0f12e64
--- /dev/null
+++ b/src/components/Form/FormItem/FormItem.tsx
@@ -0,0 +1,7 @@
+import styles from '../Form.module.scss';
+
+const FormItem: React.FunctionComponent = ({ children }) => {
+ return <div className={styles.item}>{children}</div>;
+};
+
+export default FormItem;
diff --git a/src/components/Form/Input/Input.tsx b/src/components/Form/Input/Input.tsx
new file mode 100644
index 0000000..901b9ab
--- /dev/null
+++ b/src/components/Form/Input/Input.tsx
@@ -0,0 +1,47 @@
+import { ChangeEvent, SetStateAction } from 'react';
+import styles from '../Form.module.scss';
+
+type InputType = 'text' | 'number';
+
+const Input = ({
+ id,
+ name,
+ value,
+ setValue,
+ type = 'text',
+ required = false,
+ label,
+}: {
+ id: string;
+ name: string;
+ value: string;
+ setValue: (value: SetStateAction<string>) => void;
+ type?: InputType;
+ required?: boolean;
+ label?: string;
+}) => {
+ const updateValue = (e: ChangeEvent<HTMLInputElement>) => {
+ setValue(e.target.value);
+ };
+
+ return (
+ <>
+ {label && (
+ <label htmlFor={id} className={styles.label}>
+ {label}
+ {required && <span> *</span>}
+ </label>
+ )}
+ <input
+ type={type}
+ id={id}
+ name={name}
+ value={value}
+ onChange={updateValue}
+ className={styles.field}
+ />
+ </>
+ );
+};
+
+export default Input;
diff --git a/src/components/Form/TextArea/TextArea.tsx b/src/components/Form/TextArea/TextArea.tsx
new file mode 100644
index 0000000..729ef6d
--- /dev/null
+++ b/src/components/Form/TextArea/TextArea.tsx
@@ -0,0 +1,42 @@
+import { ChangeEvent, SetStateAction } from 'react';
+import styles from '../Form.module.scss';
+
+const TextArea = ({
+ id,
+ name,
+ value,
+ setValue,
+ required = false,
+ label,
+}: {
+ id: string;
+ name: string;
+ value: string;
+ setValue: (value: SetStateAction<string>) => void;
+ required?: boolean;
+ label?: string;
+}) => {
+ const updateValue = (e: ChangeEvent<HTMLTextAreaElement>) => {
+ setValue(e.target.value);
+ };
+
+ return (
+ <>
+ {label && (
+ <label htmlFor={id} className={styles.label}>
+ {label}
+ {required && <span> *</span>}
+ </label>
+ )}
+ <textarea
+ id={id}
+ name={name}
+ value={value}
+ onChange={updateValue}
+ className={`${styles.field} ${styles.textarea}`}
+ />
+ </>
+ );
+};
+
+export default TextArea;
diff --git a/src/components/Form/index.tsx b/src/components/Form/index.tsx
new file mode 100644
index 0000000..987e013
--- /dev/null
+++ b/src/components/Form/index.tsx
@@ -0,0 +1,6 @@
+import Form from './Form';
+import FormItem from './FormItem/FormItem';
+import Input from './Input/Input';
+import TextArea from './TextArea/TextArea';
+
+export { Form, FormItem, Input, TextArea };