-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathindex.js
109 lines (104 loc) · 2.75 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { h, Component } from "preact";
function formatError(error) {
return (
(error.json && error.json.error_description) ||
error.message ||
error.toString()
);
}
export default class Modal extends Component {
handleClose = (e) => {
e.preventDefault();
this.props.onClose();
};
blockEvent = (e) => {
e.stopPropagation();
};
linkHandler = (page) => (e) => {
e.preventDefault();
this.props.onPage(page);
};
render() {
const {
page,
error,
loading,
showHeader,
showSignup,
devSettings,
isOpen,
children,
logo,
t
} = this.props;
const hidden = loading || !isOpen;
return (
<div
className="modalContainer"
role="dialog"
aria-hidden={`${hidden}`}
onClick={this.handleClose}
>
<div
className={`modalDialog${loading ? " visuallyHidden" : ""}`}
onClick={this.blockEvent}
>
<div className="modalContent">
<button onclick={this.handleClose} className="btn btnClose">
<span className="visuallyHidden">Close</span>
</button>
{showHeader && (
<div className="header">
{showSignup && (
<button
className={`btn btnHeader ${page.signup ? "active" : ""}`}
onclick={this.linkHandler("signup")}
>
{t("sign_up")}
</button>
)}
{!devSettings && (
<button
className={`btn btnHeader ${page.login ? "active" : ""}`}
onclick={this.linkHandler("login")}
>
{t("log_in")}
</button>
)}
</div>
)}
{page.title && (
<div className="header">
<button className="btn btnHeader active">
{t(page.title)}
</button>
</div>
)}
{devSettings && (
<div className="header">
<button className="btn btnHeader active">
{t("site_url_title")}
</button>
</div>
)}
{error && (
<div className="flashMessage error">
<span>{t(formatError(error))}</span>
</div>
)}
{children}
</div>
</div>
{logo && (
<a
href="https://www.netlify.com"
className={`callOut${loading ? " visuallyHidden" : ""}`}
>
<span className="netlifyLogo" />
{t("coded_by")}
</a>
)}
</div>
);
}
}