scm-ui: new repository layout

This commit is contained in:
Sebastian Sdorra
2019-10-07 10:57:09 +02:00
parent 09c7def874
commit c05798e254
417 changed files with 3620 additions and 52971 deletions

View File

@@ -0,0 +1,26 @@
//@flow
import React from "react";
import type { Me } from "@scm-manager/ui-types";
import {Link} from "react-router-dom";
type Props = {
me?: Me
};
class Footer extends React.Component<Props> {
render() {
const { me } = this.props;
if (!me) {
return "";
}
return (
<footer className="footer">
<div className="container is-centered">
<p className="has-text-centered"><Link to={"/me"}>{me.displayName}</Link></p>
</div>
</footer>
);
}
}
export default Footer;

View File

@@ -0,0 +1,31 @@
//@flow
import * as React from "react";
import Logo from "./../Logo";
type Props = {
children?: React.Node
};
class Header extends React.Component<Props> {
render() {
const { children } = this.props;
return (
<section className="hero is-dark is-small">
<div className="hero-body">
<div className="container">
<div className="columns is-vcentered">
<div className="column">
<Logo />
</div>
</div>
</div>
</div>
<div className="hero-foot">
<div className="container">{children}</div>
</div>
</section>
);
}
}
export default Header;

View File

@@ -0,0 +1,114 @@
//@flow
import * as React from "react";
import injectSheet from "react-jss";
import classNames from "classnames";
import Loading from "./../Loading";
import ErrorNotification from "./../ErrorNotification";
import Title from "./Title";
import Subtitle from "./Subtitle";
import PageActions from "./PageActions";
import ErrorBoundary from "../ErrorBoundary";
type Props = {
title?: string,
subtitle?: string,
loading?: boolean,
error?: Error,
showContentOnError?: boolean,
children: React.Node,
// context props
classes: Object
};
const styles = {
actions: {
display: "flex",
justifyContent: "flex-end"
}
};
class Page extends React.Component<Props> {
render() {
const { error } = this.props;
return (
<section className="section">
<div className="container">
{this.renderPageHeader()}
<ErrorBoundary>
<ErrorNotification error={error} />
{this.renderContent()}
</ErrorBoundary>
</div>
</section>
);
}
isPageAction(node: any) {
return node.displayName === PageActions.displayName
|| (node.type && node.type.displayName === PageActions.displayName);
}
renderPageHeader() {
const { error, title, subtitle, children, classes } = this.props;
let pageActions = null;
let pageActionsExists = false;
React.Children.forEach(children, child => {
if (child && !error) {
if (this.isPageAction(child)) {
pageActions = (
<div
className={classNames(
classes.actions,
"column is-three-fifths is-mobile-action-spacing"
)}
>
{child}
</div>
);
pageActionsExists = true;
}
}
});
let underline = pageActionsExists ? (
<hr className="header-with-actions" />
) : null;
return (
<>
<div className="columns">
<div className="column">
<Title title={title} />
<Subtitle subtitle={subtitle} />
</div>
{pageActions}
</div>
{underline}
</>
);
}
renderContent() {
const { loading, children, showContentOnError, error } = this.props;
if (error && !showContentOnError) {
return null;
}
if (loading) {
return <Loading />;
}
let content = [];
React.Children.forEach(children, child => {
if (child) {
if (!this.isPageAction(child)) {
content.push(child);
}
}
});
return content;
}
}
export default injectSheet(styles)(Page);

View File

@@ -0,0 +1,28 @@
//@flow
import * as React from "react";
import Loading from "./../Loading";
type Props = {
loading?: boolean,
error?: Error,
children: React.Node
};
export default class PageActions extends React.Component<Props> {
static displayName = "PageActions";
render() {
return <>{this.renderContent()}</>;
}
renderContent() {
const { loading, children, error } = this.props;
if (error) {
return null;
}
if (loading) {
return <Loading />;
}
return children;
}
}

View File

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

View File

@@ -0,0 +1,18 @@
// @flow
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;

View File

@@ -0,0 +1,9 @@
// @create-index
export { default as Footer } from "./Footer.js";
export { default as Header } from "./Header.js";
export { default as Page } from "./Page.js";
export { default as PageActions } from "./PageActions.js";
export { default as Subtitle } from "./Subtitle.js";
export { default as Title } from "./Title.js";