Farmbot-Web-App/frontend/farm_designer/designer_panel.tsx

121 lines
3.4 KiB
TypeScript
Raw Normal View History

import * as React from "react";
2019-12-10 13:09:52 -07:00
import { history as routeHistory } from "../history";
2018-12-03 20:05:45 -07:00
import { last, trim } from "lodash";
2019-12-10 13:09:52 -07:00
import { Link } from "../link";
import { Panel, TAB_COLOR, PanelColor } from "./panel_header";
import { t } from "../i18next_wrapper";
2019-12-26 13:20:10 -07:00
import { ErrorBoundary } from "../error_boundary";
interface DesignerPanelProps {
panelName: string;
2019-10-25 09:33:33 -06:00
panel?: Panel;
panelColor?: PanelColor;
children?: React.ReactNode;
}
2019-10-25 09:33:33 -06:00
export const DesignerPanel = (props: DesignerPanelProps) => {
const color = props.panel ? TAB_COLOR[props.panel] : props.panelColor;
return <div
className={[
"panel-container",
2019-10-25 09:33:33 -06:00
`${color || PanelColor.gray}-panel`,
`${props.panelName}-panel`].join(" ")}>
2019-12-26 13:20:10 -07:00
<ErrorBoundary>
{props.children}
</ErrorBoundary>
</div>;
2019-10-25 09:33:33 -06:00
};
interface DesignerPanelHeaderProps {
panelName: string;
2019-10-25 09:33:33 -06:00
panel?: Panel;
panelColor?: PanelColor;
title?: string;
blackText?: boolean;
description?: string;
descriptionElement?: JSX.Element;
backTo?: string;
onBack?: () => void;
style?: React.CSSProperties;
children?: React.ReactNode;
}
2018-12-03 20:05:45 -07:00
const backToText = (to: string | undefined): string => {
const lastPathName = last(trim(to, "/").split("/"));
const s = (lastPathName || "").replace("_", " ");
return s ? ` ${t("to")} ${s}` : "";
};
2019-10-25 09:33:33 -06:00
export const DesignerPanelHeader = (props: DesignerPanelHeaderProps) => {
const color = props.panel ? TAB_COLOR[props.panel] : props.panelColor;
const textColor = props.blackText ? "black" : "white";
return <div className={`panel-header ${color || PanelColor.gray}-panel`}
style={props.style || {}}>
<p className="panel-title">
2019-10-25 09:33:33 -06:00
<i className={`fa fa-arrow-left back-arrow ${textColor}-text`}
2018-12-03 20:05:45 -07:00
title={t("go back") + backToText(props.backTo)}
onClick={() => {
props.backTo ? routeHistory.push(props.backTo) : history.back();
2020-01-03 13:04:45 -07:00
props.onBack?.();
}} />
{props.title &&
2019-10-25 09:33:33 -06:00
<span className={`title ${textColor}-text`}>
{t(props.title)}
</span>}
{props.children}
</p>
{(props.description || props.descriptionElement) &&
<div
2019-10-25 09:33:33 -06:00
className={trim(`panel-header-description ${props.panelName}-description
${textColor}-text`)}>
{props.description && t(props.description)}
{props.descriptionElement}
</div>}
</div>;
2019-10-25 09:33:33 -06:00
};
2019-03-05 11:59:22 -07:00
interface DesignerPanelTopProps {
2019-10-25 09:33:33 -06:00
panel: Panel;
2019-03-05 11:59:22 -07:00
linkTo?: string;
title?: string;
children?: React.ReactNode;
noIcon?: boolean;
}
export const DesignerPanelTop = (props: DesignerPanelTopProps) => {
return <div className={`panel-top ${props.linkTo ? "with-button" : ""}`}>
<div className="thin-search-wrapper">
<div className="text-input-wrapper">
2019-03-05 11:59:22 -07:00
{!props.noIcon &&
<i className="fa fa-search"></i>}
2019-12-26 13:20:10 -07:00
<ErrorBoundary>
{props.children}
</ErrorBoundary>
</div>
</div>
2019-03-05 11:59:22 -07:00
{props.linkTo &&
<Link to={props.linkTo}>
2019-10-25 09:33:33 -06:00
<div className={`fb-button panel-${TAB_COLOR[props.panel]}`}>
2019-04-11 21:17:18 -06:00
<i className="fa fa-plus" title={props.title} />
2019-03-05 11:59:22 -07:00
</div>
</Link>}
</div>;
2019-03-05 11:59:22 -07:00
};
interface DesignerPanelContentProps {
panelName: string;
children?: React.ReactNode;
2019-03-05 11:59:22 -07:00
className?: string;
}
export const DesignerPanelContent = (props: DesignerPanelContentProps) =>
2019-12-26 13:20:10 -07:00
<div className={[
"panel-content",
`${props.panelName}-panel-content`,
props.className || ""].join(" ")}>
<ErrorBoundary>
{props.children}
</ErrorBoundary>
</div>;