forked from revolunet/react-mailchimp-subscribe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (83 loc) · 2.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, { Component } from "react";
import { render } from "react-dom";
import GithubCorner from "react-github-corner";
import MailchimpSubscribe from "../../src";
// a basic form
const CustomForm = ({ status, message, onValidated }) => {
let email, name;
const submit = () =>
email &&
name &&
email.value.indexOf("@") > -1 &&
onValidated({
EMAIL: email.value,
NAME: name.value
});
return (
<div
style={{
background: "#efefef",
borderRadius: 2,
padding: 10,
display: "inline-block"
}}
>
{status === "sending" && <div style={{ color: "blue" }}>sending...</div>}
{status === "error" && (
<div
style={{ color: "red" }}
dangerouslySetInnerHTML={{ __html: message }}
/>
)}
{status === "success" && (
<div
style={{ color: "green" }}
dangerouslySetInnerHTML={{ __html: message }}
/>
)}
<input
style={{ fontSize: "2em", padding: 5 }}
ref={node => (name = node)}
type="text"
placeholder="Your name"
/>
<br />
<input
style={{ fontSize: "2em", padding: 5 }}
ref={node => (email = node)}
type="email"
placeholder="Your email"
/>
<br />
<button style={{ fontSize: "2em", padding: 5 }} onClick={submit}>
Submit
</button>
</div>
);
};
class Demo extends Component {
render() {
const url =
"https://sachagreif.us2.list-manage.com/subscribe/post?u=b5af47765edbd2fc173dbf27a&id=d8282e7e96";
return (
<div>
<h1>react-mailchimp-subscribe Demo</h1>
<GithubCorner href="https://github.com/revolunet/react-mailchimp-subscribe" />
<h2>Default Form</h2>
<MailchimpSubscribe url={url} />
<h2>Custom Form</h2>
<MailchimpSubscribe
url={url}
render={({ subscribe, status, message }) => (
<CustomForm
status={status}
message={message}
onValidated={formData => subscribe(formData)}
/>
)}
/>
</div>
);
}
}
render(<Demo />, document.querySelector("#demo"));