added page component

This commit is contained in:
Sebastian Sdorra
2018-07-20 08:28:36 +02:00
parent 9ab231477c
commit e383eb250a
4 changed files with 67 additions and 37 deletions

View File

@@ -0,0 +1,46 @@
//@flow
import * as React from "react";
import Loading from "./Loading";
import ErrorNotification from "./ErrorNotification";
type Props = {
title: string,
subtitle?: string,
loading?: boolean,
error?: Error,
children: React.Node
};
class Page extends React.Component<Props> {
render() {
const { title, error } = this.props;
return (
<section className="section">
<div className="container">
<h1 className="title">{title}</h1>
{this.renderSubtitle()}
<ErrorNotification error={error} />
{this.renderContent()}
</div>
</section>
);
}
renderSubtitle() {
const { subtitle } = this.props;
if (subtitle) {
return <h2 className="subtitle">Users</h2>;
}
return null;
}
renderContent() {
const { loading, children } = this.props;
if (loading) {
return <Loading />;
}
return children;
}
}
export default Page;