Github
Twitter
Discord
Playground
Search…
English
👋
Atomico
🚀
Getting started with Atomico
Api
🧬
Props(Properties)
🧩
VirtualDOM
🎣
Hooks
🔬
Testing
Guides
🧠
Atomico design patterns
🗺
Atomico style guide
🛡
Atomico with Typescript
🤝
Atomico and React
🔀
Slot
🗃
Archives
@atomico
@atomico/store
@atomico/design-tokens
@atomico/router
@atomico/react
@atomico/hooks
@atomico/components
@atomico/exports
@atomico/magic-form
MagicFormProvider | <magic-form-provider>
MagicForm | <magic-form>
MagicForm Hooks
MagicForm in React and Preact
MagicForm in Microfrontend
MagicForm Patterns
Support
Discord
Github
Twitter
Powered By
GitBook
@atomico/magic-form
Improves the form development experience thanks to the use of webcomponents to centralize submission
GitHub - atomicojs/magic-form
GitHub
A powerful form submission manager created with Atomicojs webcomponents, with MagicForm you can:
1.
Simplify the sending of forms by centralizing the sending actions through a provider.
2.
Know at all times the forms that are being provided and show their status.
3.
Isolate a group of actions according to provider, this means that if a provider does not register the action it will bubble to the parent provider.
Installation and import
Instalation
Module webcomponents
Module hooks
1
npm install @atomico/magic-form
Copied!
1
import
{
2
MagicForm
,
3
MagicFormProvider
4
}
from
"@atomico/magic-form"
;
Copied!
1
import
{
2
useMagicForm
,
3
useMagicFormProvider
4
}
from
"@atomico/magic-form/hooks"
;
Copied!
Usage
HTML
JSX Atomico
1
<
magic-form-provider
>
2
<
magic-form
>
3
<
form
action
=
"
user
"
>
4
<
input
type
=
"
text
"
name
=
"
name
"
/>
5
<
input
type
=
"
text
"
name
=
"
email
"
/>
6
<
button
>
Create user
</
button
>
7
</
form
>
8
</
magic-form
>
9
</
magic-form-provider
>
10
<
script
>
11
document
.
querySelector
(
"magic-form-provider"
).
actions
=
{
12
async
add
(
form
)
{
13
return
fetch
(
"./my-api"
,
{
14
method
:
"post"
,
15
body
:
new
FormData
(
form
),
16
}).
then
((
res
)
=>
res
.
json
());
17
},
18
};
19
</
script
>
Copied!
1
import
{
MagicForm
,
MagicFormProvider
}
from
"@atomico/magic-form"
;
2
3
function
component
()
{
4
return
(
5
<
host
>
6
<
MagicFormProvider
7
actions
=
{{
8
async
add
(
form
)
{
9
return
fetch
(
"./my-api"
,
{
10
method
:
"post"
,
11
body
:
new
FormData
(
form
),
12
}).
then
((
res
)
=>
res
.
json
());
13
},
14
}}
15
>
16
<
MagicForm
>
17
<
form
action
=
"
user
"
>
18
<
input
type
=
"
text
"
name
=
"
name
"
/>
19
<
input
type
=
"
text
"
name
=
"
email
"
/>
20
<
button
>
Create user
</
button
>
21
</
form
>
22
</
MagicForm
>
23
</
MagicFormProvider
>
24
</
host
>
25
);
26
}
Copied!
magic-form-provider
captures all the forms nested in
magic-form
when executing the submit event by the form and distributes them according to the definition of the action attribute to each method of the actions object
Api
MagicFormProvider | <magic-form-provider>
MagicForm | <magic-form>
MagicForm Hooks
MagicForm in React and Preact
Previous
Wrapper for React
Next
MagicFormProvider | <magic-form-provider>
Last modified
1mo ago
Copy link
Edit on GitHub
Contents
Installation and import
Usage
Api