fix(components): refine tabs component

This commit is contained in:
hexxa 2021-11-27 10:59:29 +08:00 committed by Hexxa
parent 7156c22a56
commit 6881d2449e
3 changed files with 71 additions and 28 deletions

View file

@ -18,7 +18,7 @@ const defaultIconProps: IconProps = {
}; };
export interface Props { export interface Props {
targetSwitch: string; targetControl: string;
tabIcons: Map<string, IconProps>; // option name -> icon name tabIcons: Map<string, IconProps>; // option name -> icon name
login: LoginProps; login: LoginProps;
admin: AdminProps; admin: AdminProps;
@ -33,18 +33,18 @@ export class Tabs extends React.Component<Props, State, {}> {
super(p); super(p);
} }
setTab = (targetSwitch: string, targetOption: string) => { setTab = (targetControl: string, targetOption: string) => {
if (!updater().setControlOption(targetSwitch, targetOption)) { if (!updater().setControlOption(targetControl, targetOption)) {
alertMsg(this.props.msg.pkg.get("op.fail")); alertMsg(this.props.msg.pkg.get("op.fail"));
} }
}; };
render() { render() {
const displaying = this.props.ui.control.controls.get( const displaying = this.props.ui.control.controls.get(
this.props.targetSwitch this.props.targetControl
); );
const options = this.props.ui.control.options.get(this.props.targetSwitch); const options = this.props.ui.control.options.get(this.props.targetControl);
const tabs = options.map((option: string, targetSwitch: string) => { const tabs = options.map((option: string, targetControl: string) => {
const iconProps = this.props.tabIcons.has(option) const iconProps = this.props.tabIcons.has(option)
? this.props.tabIcons.get(option) ? this.props.tabIcons.get(option)
: defaultIconProps; : defaultIconProps;
@ -54,9 +54,9 @@ export class Tabs extends React.Component<Props, State, {}> {
return ( return (
<button <button
key={`${targetSwitch}-${option}`} key={`${targetControl}-${option}`}
onClick={() => { onClick={() => {
this.setTab(targetSwitch, option); this.setTab(targetControl, option);
}} }}
className="float" className="float"
> >
@ -64,7 +64,7 @@ export class Tabs extends React.Component<Props, State, {}> {
children={List([ children={List([
<span className="margin-r-s">{icon}</span>, <span className="margin-r-s">{icon}</span>,
<span> <span>
{this.props.msg.pkg.get(`switch.${targetSwitch}.${option}`)} {this.props.msg.pkg.get(`switch.${targetControl}.${option}`)}
</span>, </span>,
])} ])}
childrenStyles={List([{ flex: "30%" }, { flex: "70%" }])} childrenStyles={List([{ flex: "30%" }, { flex: "70%" }])}
@ -74,7 +74,7 @@ export class Tabs extends React.Component<Props, State, {}> {
}); });
return ( return (
<div className={`tabs control-${this.props.targetSwitch}`}>{tabs}</div> <div className={`tabs control-${this.props.targetControl}`}>{tabs}</div>
); );
} }
} }

View file

@ -1,16 +1,20 @@
import * as React from "react"; import * as React from "react";
import { Map } from "immutable";
import { ICoreState, MsgProps, UIProps } from "./core_state"; import { ICoreState, MsgProps, UIProps } from "./core_state";
import { FilesPanel, FilesProps } from "./panel_files"; import { FilesPanel, FilesProps } from "./panel_files";
import { UploadingsPanel, UploadingsProps } from "./panel_uploadings"; import { UploadingsPanel, UploadingsProps } from "./panel_uploadings";
import { SharingsPanel, SharingsProps } from "./panel_sharings"; import { SharingsPanel, SharingsProps } from "./panel_sharings";
import { IconProps } from "./visual/icons";
import { Tabs } from "./control/tabs";
import { LoginProps } from "./pane_login"; import { LoginProps } from "./pane_login";
import { Panes, PanesProps } from "./panes"; import { Panes, PanesProps } from "./panes";
import { AdminProps } from "./pane_admin"; import { AdminProps } from "./pane_admin";
import { TopBar } from "./topbar"; import { TopBar } from "./topbar";
import { roleVisitor } from "../client"; import { roleVisitor } from "../client";
const controlName = "panel-tabs";
export interface Props { export interface Props {
filesInfo: FilesProps; filesInfo: FilesProps;
uploadingsInfo: UploadingsProps; uploadingsInfo: UploadingsProps;
@ -54,6 +58,11 @@ export class RootFrame extends React.Component<Props, State, {}> {
? "hidden" ? "hidden"
: ""; : "";
const displaying = this.props.ui.control.controls.get(controlName);
const filesPanelClass = displaying === "files" ? "" : "none";
const uploadingsPanelClass = displaying === "uploadings" ? "" : "none";
const sharingsPanelClass = displaying === "sharings" ? "" : "none";
return ( return (
<div id="root-frame" className={`${theme} ${fontSizeClass}`}> <div id="root-frame" className={`${theme} ${fontSizeClass}`}>
<div id="bg" style={bgStyle}> <div id="bg" style={bgStyle}>
@ -81,6 +90,33 @@ export class RootFrame extends React.Component<Props, State, {}> {
ui={this.props.ui} ui={this.props.ui}
update={this.props.update} update={this.props.update}
/> */} /> */}
<Tabs
targetControl={controlName}
tabIcons={Map<string, IconProps>({
filesPanel: {
name: "RiFolder2Fill",
size: "1.6rem",
color: "cyan0",
},
uploadingsPanel: {
name: "RiFolder2Fill",
size: "1.6rem",
color: "cyan0",
},
sharingsPanel: {
name: "RiFolder2Fill",
size: "1.6rem",
color: "cyan0",
},
})}
login={this.props.login}
admin={this.props.admin}
ui={this.props.ui}
msg={this.props.msg}
/>
<span className={filesPanelClass}>
<FilesPanel <FilesPanel
filesInfo={this.props.filesInfo} filesInfo={this.props.filesInfo}
msg={this.props.msg} msg={this.props.msg}
@ -88,6 +124,9 @@ export class RootFrame extends React.Component<Props, State, {}> {
ui={this.props.ui} ui={this.props.ui}
update={this.props.update} update={this.props.update}
/> />
</span>
<span className={uploadingsPanelClass}>
<UploadingsPanel <UploadingsPanel
uploadingsInfo={this.props.uploadingsInfo} uploadingsInfo={this.props.uploadingsInfo}
msg={this.props.msg} msg={this.props.msg}
@ -95,6 +134,9 @@ export class RootFrame extends React.Component<Props, State, {}> {
ui={this.props.ui} ui={this.props.ui}
update={this.props.update} update={this.props.update}
/> />
</span>
<span className={sharingsPanelClass}>
<SharingsPanel <SharingsPanel
sharingsInfo={this.props.sharingsInfo} sharingsInfo={this.props.sharingsInfo}
msg={this.props.msg} msg={this.props.msg}
@ -102,6 +144,7 @@ export class RootFrame extends React.Component<Props, State, {}> {
ui={this.props.ui} ui={this.props.ui}
update={this.props.update} update={this.props.update}
/> />
</span>
</div> </div>
<div id="tail" className="container-center"> <div id="tail" className="container-center">

View file

@ -1,4 +1,4 @@
import { Set, Map } from "immutable"; import { Set } from "immutable";
export const colors = Set<string>([ export const colors = Set<string>([
"blue0", "blue0",