Add checkbox handel func

This commit is contained in:
MrKBear 2022-03-05 11:37:35 +08:00
parent ca3a19f5b0
commit 86c840443c
8 changed files with 120 additions and 10 deletions

View File

@ -19,9 +19,18 @@ div.details-list {
div.details-list-checkbox { div.details-list-checkbox {
display: flex; display: flex;
width: 30px;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
padding: 0 10px; opacity: 0;
}
}
div.details-list-item.active,
div.details-list-item:hover {
div.details-list-checkbox {
opacity: 1;
} }
} }
} }
@ -35,15 +44,33 @@ div.light.details-list {
div.details-list-item:hover { div.details-list-item:hover {
background-color: $lt-bg-color-lvl3-light; background-color: $lt-bg-color-lvl3-light;
} }
div.details-list-item.active {
background-color: $lt-bg-color-lvl2-light;
color: rgba(0, 0, 0, 0.95);
}
// div.details-list-checkbox:hover {
// background-color: rgba($lt-bg-color-lvl1-light, .4);
// }
} }
div.dark.details-list { div.dark.details-list {
div.details-list-item:nth-child(2n) { div.details-list-item:nth-child(2n) {
background-color: rgba($lt-bg-color-lvl5-dark, .4); background-color: rgba($lt-bg-color-lvl5-dark, .8);
} }
div.details-list-item:hover { div.details-list-item:hover {
background-color: $lt-bg-color-lvl3-dark; background-color: $lt-bg-color-lvl3-dark;
} }
div.details-list-item.active {
background-color: $lt-bg-color-lvl2-dark;
color: rgba(255, 255, 255, 0.85);
}
// div.details-list-checkbox:hover {
// background-color: rgba($lt-bg-color-lvl1-dark, .8);
// }
} }

View File

@ -16,9 +16,13 @@ interface IColumns<D extends IItems, K extends keyof D> {
interface IDetailsListProps { interface IDetailsListProps {
items: IItems[]; items: IItems[];
className?: string;
columns: IColumns<this["items"][number], keyof this["items"][number]>[]; columns: IColumns<this["items"][number], keyof this["items"][number]>[];
hideCheckBox?: boolean; hideCheckBox?: boolean;
checkboxClassName?: string; checkboxClassName?: string;
click?: () => void;
clickLine?: (item: IItems) => any;
checkBox?: (data: IItems) => any;
} }
class DetailsList extends Component<IDetailsListProps> { class DetailsList extends Component<IDetailsListProps> {
@ -41,13 +45,27 @@ class DetailsList extends Component<IDetailsListProps> {
public render(): ReactNode { public render(): ReactNode {
return <Theme return <Theme
className="details-list" className={"details-list" + (this.props.className ? ` ${this.props.className}` : "")}
onClick={this.props.click}
backgroundLevel={BackgroundLevel.Level4} backgroundLevel={BackgroundLevel.Level4}
fontLevel={FontLevel.normal} fontLevel={FontLevel.normal}
>{ >{
this.props.items.map((item) => { this.props.items.map((item) => {
const { checkboxClassName } = this.props; const { checkboxClassName } = this.props;
return <div className="details-list-item" key={item.key}> const classList: string[] = ["details-list-item"];
if (item.select) {
classList.push("active");
}
return <div
className={classList.join(" ")}
key={item.key}
onClick={(e) => {
if (this.props.clickLine) {
e.stopPropagation();
this.props.clickLine(item);
}
}}
>
{ {
this.props.columns.map((column) => { this.props.columns.map((column) => {
if (column.beforeCheckbox) { if (column.beforeCheckbox) {
@ -59,6 +77,12 @@ class DetailsList extends Component<IDetailsListProps> {
this.props.hideCheckBox ? null : this.props.hideCheckBox ? null :
<div <div
className={"details-list-checkbox" + (checkboxClassName ? ` ${checkboxClassName}` : "")} className={"details-list-checkbox" + (checkboxClassName ? ` ${checkboxClassName}` : "")}
onClick={(e) => {
if (this.props.checkBox) {
e.stopPropagation();
this.props.checkBox(item);
}
}}
> >
<Icon iconName="CheckMark"></Icon> <Icon iconName="CheckMark"></Icon>
</div> </div>
@ -76,4 +100,4 @@ class DetailsList extends Component<IDetailsListProps> {
} }
} }
export { DetailsList }; export { DetailsList, IItems };

View File

@ -1,7 +1,8 @@
import { createContext, Component, FunctionComponent } from "react"; import { createContext, Component, FunctionComponent } from "react";
import { Emitter } from "@Model/Emitter"; import { Emitter } from "@Model/Emitter";
import { Model } from "@Model/Model"; import { Model, ObjectID } from "@Model/Model";
import { Archive } from "@Model/Archive"; import { Archive } from "@Model/Archive";
import { CtrlObject } from "@Model/CtrlObject";
import { AbstractRenderer } from "@Model/Renderer"; import { AbstractRenderer } from "@Model/Renderer";
import { ClassicRenderer, MouseMod } from "@GLRender/ClassicRenderer"; import { ClassicRenderer, MouseMod } from "@GLRender/ClassicRenderer";
import { Setting } from "./Setting"; import { Setting } from "./Setting";
@ -16,7 +17,8 @@ function randomColor() {
} }
class Status extends Emitter<{ class Status extends Emitter<{
mouseModChange: MouseMod mouseModChange: MouseMod,
focusObjectChange: Set<ObjectID>
}> { }> {
public setting: Setting = undefined as any; public setting: Setting = undefined as any;
@ -41,6 +43,19 @@ class Status extends Emitter<{
*/ */
public model: Model = new Model(); public model: Model = new Model();
/**
*
*/
public focusObject: Set<ObjectID> = new Set();
/**
*
*/
public setFocusObject(focusObject: Set<ObjectID>) {
this.focusObject = focusObject;
this.emit("focusObjectChange", this.focusObject);
}
/** /**
* *
*/ */

View File

@ -37,6 +37,14 @@ class Model extends Emitter<ModelEvent> {
*/ */
public objectPool: CtrlObject[] = []; public objectPool: CtrlObject[] = [];
public getObjectById(id: ObjectID): CtrlObject | undefined {
for (let i = 0; i < this.objectPool.length; i++) {
if (this.objectPool[i].id === id) {
return this.objectPool[i];
}
}
}
/** /**
* *
*/ */

View File

@ -73,7 +73,7 @@ class SimulatorWeb extends Component {
}, },
{ {
items: [{ items: [{
panles: ["ObjectList"] panles: ["ObjectList", "Test tab"]
}, { }, {
items: [{panles: ["Label e", "ee"]}, {panles: ["F"]}], items: [{panles: ["Label e", "ee"]}, {panles: ["F"]}],
layout: LayoutDirection.Y layout: LayoutDirection.Y

View File

@ -4,4 +4,8 @@ div.object-list-color-value {
margin-left: 3px; margin-left: 3px;
border-radius: 1000px; border-radius: 1000px;
width: 3px; width: 3px;
}
div.object-list {
min-height: 100%;
} }

View File

@ -2,6 +2,7 @@ import { Component, ReactNode } from "react";
import { DetailsList } from "@Component/DetailsList/DetailsList"; import { DetailsList } from "@Component/DetailsList/DetailsList";
import { useStatus, IMixinStatusProps } from "@Context/Status"; import { useStatus, IMixinStatusProps } from "@Context/Status";
import { Localization } from "@Component/Localization/Localization"; import { Localization } from "@Component/Localization/Localization";
import { ObjectID } from "@Model/Renderer";
import "./ObjectList.scss"; import "./ObjectList.scss";
@useStatus @useStatus
@ -14,12 +15,14 @@ class ObjectList extends Component<IMixinStatusProps> {
public componentDidMount(){ public componentDidMount(){
if (this.props.status) { if (this.props.status) {
this.props.status.model.on("objectChange", this.handelChange); this.props.status.model.on("objectChange", this.handelChange);
this.props.status.on("focusObjectChange", this.handelChange);
} }
} }
public componentWillUnmount(){ public componentWillUnmount(){
if (this.props.status) { if (this.props.status) {
this.props.status.model.off("objectChange", this.handelChange); this.props.status.model.off("objectChange", this.handelChange);
this.props.status.off("focusObjectChange", this.handelChange);
} }
} }
@ -34,15 +37,44 @@ class ObjectList extends Component<IMixinStatusProps> {
} }
return <DetailsList return <DetailsList
className="object-list"
items={objList.concat([]).map((object => { items={objList.concat([]).map((object => {
return { return {
key: object.id.toString(), key: object.id.toString(),
name: object.displayName, name: object.displayName,
color: object.color, color: object.color,
display: object.display, display: object.display,
update: object.update update: object.update,
select: this.props.status ?
this.props.status.focusObject.has(object.id.toString()) ||
this.props.status.focusObject.has(object.id) :
false
} }
}))} }))}
clickLine={(item) => {
if (this.props.status) {
this.props.status.setFocusObject(new Set<ObjectID>().add(item.key));
}
}}
checkBox={(item) => {
if (this.props.status) {
if (
this.props.status.focusObject.has(item.key.toString()) ||
this.props.status.focusObject.has(item.key)
) {
this.props.status.focusObject.delete(item.key);
this.props.status.focusObject.delete(item.key.toString());
this.props.status.setFocusObject(this.props.status.focusObject);
} else {
this.props.status.setFocusObject(this.props.status.focusObject.add(item.key));
}
}
}}
click={() => {
if (this.props.status) {
this.props.status.setFocusObject(new Set<ObjectID>());
}
}}
columns={[ columns={[
{ {
key: "color", key: "color",

View File

@ -28,7 +28,7 @@ class RenderView extends Component<IMixinStatusProps & IMixinSettingProps> {
public componentDidMount() { public componentDidMount() {
let div = this.rootEle.current; let div = this.rootEle.current;
console.log(div, div?.childNodes, this.props.status, this.props.status?.renderer.dom) // console.log(div, div?.childNodes, this.props.status, this.props.status?.renderer.dom)
if (div && (!div.childNodes || div.childNodes.length <= 0) && this.props.status) { if (div && (!div.childNodes || div.childNodes.length <= 0) && this.props.status) {
div.appendChild(this.props.status.renderer.dom); div.appendChild(this.props.status.renderer.dom);
} }