From 820c00def4967a90b3811cbcaad964012d110a36 Mon Sep 17 00:00:00 2001 From: louistiti Date: Sat, 10 Aug 2024 12:44:11 +0800 Subject: [PATCH] feat(form): introduce Form component --- src/App.tsx | 97 +++++++++++++++++++++++------------ src/components/form/form.sass | 4 ++ src/components/form/form.tsx | 26 ++++++++++ src/components/form/index.ts | 1 + src/index.ts | 1 + 5 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 src/components/form/form.sass create mode 100644 src/components/form/form.tsx create mode 100644 src/components/form/index.ts diff --git a/src/App.tsx b/src/App.tsx index 66464de..c099c7b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import { Checkbox, CircularProgress, Flexbox, + Form, Icon, IconButton, Image, @@ -101,16 +102,6 @@ export const App: React.FC = () => { const [isPlayButtonActivated, setIsPlayButtonActivated] = useState(false) const [isPlayButton2Activated, setIsPlayButton2Activated] = useState(false) - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault() - - // get form value - const form = e.currentTarget - const formData = new FormData(form) - const data = Object.fromEntries(formData) - console.log(data) - } - return ( <>
@@ -285,6 +276,50 @@ export const App: React.FC = () => {
+
+ +
{ + alert(JSON.stringify(data)) + }} + > + + + + + + + + + + + + + + + +
+
+
@@ -900,28 +935,26 @@ export const App: React.FC = () => {
-
- - - -
+ + +
diff --git a/src/components/form/form.sass b/src/components/form/form.sass new file mode 100644 index 0000000..14de4bf --- /dev/null +++ b/src/components/form/form.sass @@ -0,0 +1,4 @@ +@import '../../styles/main.sass' + +.aurora-form + position: relative diff --git a/src/components/form/form.tsx b/src/components/form/form.tsx new file mode 100644 index 0000000..21b6cad --- /dev/null +++ b/src/components/form/form.tsx @@ -0,0 +1,26 @@ +import './form.sass' + +export interface FormProps { + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + children?: any + // children?: React.ReactNode + onSubmit: (data: Record) => void +} + +export function Form({ children, onSubmit }: FormProps) { + const handleSubmit = (event: React.FormEvent) => { + event.preventDefault() + + const form = event.currentTarget + const formData = new FormData(form) + const data = Object.fromEntries(formData) + + onSubmit(data) + } + + return ( +
+ {children} +
+ ) +} diff --git a/src/components/form/index.ts b/src/components/form/index.ts new file mode 100644 index 0000000..5415177 --- /dev/null +++ b/src/components/form/index.ts @@ -0,0 +1 @@ +export * from './form' diff --git a/src/index.ts b/src/index.ts index 142cfed..d5268a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ export * from './components/card' export * from './components/checkbox' export * from './components/circular-progress' export * from './components/flexbox' +export * from './components/form' export * from './components/icon' export * from './components/icon-button' export * from './components/image'