diff --git a/examples/custom.tsx b/examples/custom.tsx new file mode 100644 index 0000000..5fe6ac3 --- /dev/null +++ b/examples/custom.tsx @@ -0,0 +1,35 @@ +import React from 'react' +import ReactDOM from 'react-dom' + +import { useForm } from '../dist' + +const Index: React.FC = () => { + + const { auto, form, errors } = useForm({ + awesome: true, + }) + + return ( +
{ + e.preventDefault() + console.log(form) + }}> + +

Custom

+ + + + + +
+ ) +} + +ReactDOM.render(, document.getElementById('custom')) \ No newline at end of file diff --git a/examples/errorsAndValidation.tsx b/examples/errorsAndValidation.tsx new file mode 100644 index 0000000..476ebf6 --- /dev/null +++ b/examples/errorsAndValidation.tsx @@ -0,0 +1,31 @@ +import React from 'react' +import ReactDOM from 'react-dom' + +import { useForm } from '../' + +const Index: React.FC = () => { + + const { auto, form, errors } = useForm({ + username: '', + password: '' + }, { + username: value => value.length > 3, + password: /[\d]{1,}/ + }) + + return ( +
+ +

Errors & Validation

+ + + {errors.username && 'Must be longer than 3'} + + + {errors.password && 'Must contain a number'} + +
+ ) +} + +ReactDOM.render(, document.getElementById('errors')) \ No newline at end of file diff --git a/examples/index.html b/examples/index.html new file mode 100644 index 0000000..b712881 --- /dev/null +++ b/examples/index.html @@ -0,0 +1,67 @@ + + + + + + Form Hero + + + + +
+

Open the console to see the submitted data

+
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/examples/select.tsx b/examples/select.tsx new file mode 100644 index 0000000..6a5534b --- /dev/null +++ b/examples/select.tsx @@ -0,0 +1,33 @@ +import React from 'react' +import ReactDOM from 'react-dom' + +import { useForm } from '../dist' + +const Index: React.FC = () => { + + const { auto, form, errors } = useForm({ + type: 'formhero', + }) + + return ( +
{ + e.preventDefault() + console.log(form) + }}> + +

Select

+ + + + + +
+ ) +} + +ReactDOM.render(, document.getElementById('select')) \ No newline at end of file diff --git a/examples/simple.tsx b/examples/simple.tsx new file mode 100644 index 0000000..f8449d9 --- /dev/null +++ b/examples/simple.tsx @@ -0,0 +1,30 @@ +import React from 'react' +import ReactDOM from 'react-dom' + +import { useForm } from '../dist' + +const Index: React.FC = () => { + + const { auto, form, errors } = useForm({ + username: 'unicorn', + password: '', + }) + + return ( +
{ + e.preventDefault() + console.log(form) + }}> + +

Simple

+ + + + + + +
+ ) +} + +ReactDOM.render(, document.getElementById('simple')) \ No newline at end of file