refactoring: change title and subtitle to independent components

This commit is contained in:
Maren Süwer
2018-08-09 11:33:08 +02:00
parent 4edf5d6f35
commit 52eaafa549
3 changed files with 40 additions and 12 deletions

View File

@@ -2,9 +2,11 @@
import * as React from "react"; import * as React from "react";
import Loading from "./../Loading"; import Loading from "./../Loading";
import ErrorNotification from "./../ErrorNotification"; import ErrorNotification from "./../ErrorNotification";
import Title from "./Title";
import Subtitle from "./Subtitle";
type Props = { type Props = {
title: string, title?: string,
subtitle?: string, subtitle?: string,
loading?: boolean, loading?: boolean,
error?: Error, error?: Error,
@@ -14,12 +16,12 @@ type Props = {
class Page extends React.Component<Props> { class Page extends React.Component<Props> {
render() { render() {
const { title, error } = this.props; const { title, error, subtitle } = this.props;
return ( return (
<section className="section"> <section className="section">
<div className="container"> <div className="container">
<h1 className="title">{title}</h1> <Title title={title} />
{this.renderSubtitle()} <Subtitle subtitle={subtitle} />
<ErrorNotification error={error} /> <ErrorNotification error={error} />
{this.renderContent()} {this.renderContent()}
</div> </div>
@@ -27,14 +29,6 @@ class Page extends React.Component<Props> {
); );
} }
renderSubtitle() {
const { subtitle } = this.props;
if (subtitle) {
return <h2 className="subtitle">{subtitle}</h2>;
}
return null;
}
renderContent() { renderContent() {
const { loading, children, showContentOnError, error } = this.props; const { loading, children, showContentOnError, error } = this.props;
if (error && !showContentOnError) { if (error && !showContentOnError) {

View File

@@ -0,0 +1,17 @@
import React from "react";
type Props = {
subtitle?: string
};
class Subtitle extends React.Component<Props> {
render() {
const { subtitle } = this.props;
if (subtitle) {
return <h1 className="subtitle">{subtitle}</h1>;
}
return null;
}
}
export default Subtitle;

View File

@@ -0,0 +1,17 @@
import React from "react";
type Props = {
title?: string
};
class Title extends React.Component<Props> {
render() {
const { title } = this.props;
if (title) {
return <h1 className="title">{title}</h1>;
}
return null;
}
}
export default Title;