mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
refactoring: change title and subtitle to independent components
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
17
scm-ui/src/components/layout/Subtitle.js
Normal file
17
scm-ui/src/components/layout/Subtitle.js
Normal 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;
|
||||||
17
scm-ui/src/components/layout/Title.js
Normal file
17
scm-ui/src/components/layout/Title.js
Normal 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;
|
||||||
Reference in New Issue
Block a user