diff --git a/src/components/EnquiryFormSimple.css b/src/components/EnquiryForm.css
similarity index 84%
rename from src/components/EnquiryFormSimple.css
rename to src/components/EnquiryForm.css
index 772f0bb..f3003c0 100644
--- a/src/components/EnquiryFormSimple.css
+++ b/src/components/EnquiryForm.css
@@ -18,8 +18,7 @@
flex-wrap: wrap;
}
-.EnquiryForm--Input,
-.EnquiryForm--Textarea {
+.EnquiryForm--Input {
font-family: inherit;
font-weight: 400;
flex-grow: 1;
@@ -38,8 +37,7 @@
-webkit-box-shadow: 0 0 0 1000px var(--lightGrey) inset !important;
}
-.EnquiryForm--Input:focus,
-.EnquiryForm--Textarea:focus {
+.EnquiryForm--Input:focus {
outline: none;
border-color: black;
}
@@ -50,8 +48,7 @@
cursor: progress;
}
-.EnquiryForm--Input::placeholder,
-.EnquiryForm--Textarea {
+.EnquiryForm--Input::placeholder {
text-transform: none;
}
diff --git a/src/components/EnquiryFormControlled.css b/src/components/EnquiryFormControlled.css
new file mode 100644
index 0000000..fede56c
--- /dev/null
+++ b/src/components/EnquiryFormControlled.css
@@ -0,0 +1,43 @@
+.EnquiryForm-controlled .EnquiryForm--Input {
+ border: none;
+}
+
+.EnquiryForm--Line {
+ width: 100%;
+ height: 1px;
+ stroke: #bababa;
+ stroke-width: 2px;
+}
+
+.EnquiryForm--Line .focus,
+.EnquiryForm--Line .valid,
+.EnquiryForm--Line .invalid {
+ transition: all 0.2s;
+ stroke-dasharray: 0, 20;
+ stroke-dashoffset: -20;
+}
+
+.EnquiryForm--Line .focus {
+ stroke: black;
+}
+
+.EnquiryForm--Line .valid {
+ stroke: hsl(166, 72%, 40%);
+}
+
+.EnquiryForm--Line .invalid {
+ stroke: var(--danger);
+}
+
+.EnquiryForm--Input:focus ~ .EnquiryForm--Line .focus,
+.EnquiryForm--Input:valid ~ .EnquiryForm--Line .valid,
+.EnquiryForm--Input[data-touched]:invalid ~ .EnquiryForm--Line .invalid {
+ stroke-dasharray: 40, 0;
+ stroke-dashoffset: 0;
+}
+
+.EnquiryForm--Alert {
+ background: whitesmoke;
+ width: 100%;
+ padding: 2rem;
+}
diff --git a/src/components/EnquiryFormControlled.js b/src/components/EnquiryFormControlled.js
new file mode 100644
index 0000000..f6f20fa
--- /dev/null
+++ b/src/components/EnquiryFormControlled.js
@@ -0,0 +1,190 @@
+import React, { Component } from 'react'
+import { stringify } from 'qs'
+
+import './EnquiryForm.css'
+import './EnquiryFormControlled.css'
+
+const fetch = window.fetch
+
+class Form extends Component {
+ static defaultProps = {
+ name: 'Controlled Form'
+ }
+
+ state = {
+ name: '',
+ email: '',
+ message: '',
+ subject: `New Submission from ${this.props.siteTitle}!`,
+ _gotcha: '',
+ disabled: false,
+ alert: '',
+ action: '/contact/',
+ 'form-name': this.props.name
+ }
+
+ form = null
+
+ componentDidMount () {
+ if (!this.form) return
+ const inputs = this.form.querySelectorAll('input')
+ inputs.forEach(input => {
+ input.addEventListener('invalid', () => {
+ console.log(input)
+ input.dataset.touched = true
+ })
+ input.addEventListener('blur', () => {
+ if (input.value !== '') input.dataset.touched = true
+ })
+ })
+ }
+
+ handleSubmit = e => {
+ e.preventDefault()
+ const data = {
+ name: this.state.name,
+ email: this.state.email,
+ message: this.state.message,
+ subject: this.state.subject,
+ _gotcha: this.state._gotcha,
+ 'form-name': this.state['form-name']
+ }
+ this.setState({ disabled: true })
+ fetch(this.state.action + '?' + stringify(data), {
+ method: 'POST'
+ })
+ .then(res => {
+ if (res.ok) {
+ return res
+ } else {
+ throw new Error('Network error')
+ }
+ })
+ .then(res => {
+ this.setState({
+ disabled: false,
+ alert: 'Thanks for your enquiry, we will get back to you soon.',
+ name: '',
+ email: '',
+ message: '',
+ subject: `New Submission from ${this.props.siteTitle}!`,
+ _gotcha: ''
+ })
+ })
+ .catch(err => {
+ console.log(err)
+ this.setState({
+ disabled: false,
+ alert:
+ '❗️ There is a problem, your message has not been sent, please try contacting us via email'
+ })
+ })
+ }
+
+ handleChange = e =>
+ this.setState({
+ [e.target.name]: e.target.value
+ })
+
+ render () {
+ return (
+
+ )
+ }
+}
+
+const LineGroup = () => (
+
+)
+
+export default Form
diff --git a/src/components/EnquiryFormSimple.js b/src/components/EnquiryFormSimple.js
index af4bd4c..225c1d7 100644
--- a/src/components/EnquiryFormSimple.js
+++ b/src/components/EnquiryFormSimple.js
@@ -1,6 +1,6 @@
import React from 'react'
-import './EnquiryFormSimple.css'
+import './EnquiryForm.css'
export default ({
name = 'Simple Form',
@@ -34,7 +34,7 @@ export default ({