Compare commits

...

2 Commits

Author SHA1 Message Date
b2eff20b6e Add label picker 2022-03-12 21:11:09 +08:00
f832a5af00 Add label picker 2022-03-12 16:33:46 +08:00
14 changed files with 368 additions and 19 deletions

View File

@ -5,10 +5,11 @@ import "./ErrorMessage.scss";
interface IErrorMessageProps {
i18nKey: AllI18nKeys;
options?: Record<string, string>;
className?: string;
}
const ErrorMessage: FunctionComponent<IErrorMessageProps> = (props) => {
return <div className="panel-error-message">
return <div className={["panel-error-message", props.className].filter(c => !!c).join(" ")}>
<Localization i18nKey={props.i18nKey} options={props.options}/>
</div>
}

View File

@ -1,5 +1,9 @@
@import "../Theme/Theme.scss";
div.label-list-root {
margin: -5px;
}
div.label {
width: auto;
height: auto;

View File

@ -1,4 +1,4 @@
import { Component } from "react";
import { Component, RefObject } from "react";
import { Label } from "@Model/Label";
import { Icon } from "@fluentui/react";
import { useSetting, IMixinSettingProps, Themes } from "@Context/Setting";
@ -10,6 +10,7 @@ interface ILabelListProps {
maxWidth?: number;
width?: number;
labels: Label[];
addRef?: RefObject<HTMLDivElement>;
focusLabel?: Label;
clickLabel?: (label: Label) => any;
deleteLabel?: (label: Label) => any;
@ -34,6 +35,7 @@ class LabelList extends Component<ILabelListProps & IMixinSettingProps> {
classList.push("one-line");
}
const colorCss = `rgb(${label.color.join(",")})`;
const isDelete = label.isDeleted();
return <div
style={{
@ -53,7 +55,13 @@ class LabelList extends Component<ILabelListProps & IMixinSettingProps> {
backgroundColor: colorCss,
borderRadius: isFocus ? 0 : 3
}}/>
<div className="label-name">
<div
className="label-name"
style={{
textDecoration: isDelete ? "line-through" : undefined,
opacity: isDelete ? ".6" : undefined
}}
>
<div>{label.name}</div>
</div>
{
@ -79,17 +87,17 @@ class LabelList extends Component<ILabelListProps & IMixinSettingProps> {
});
}
private renderAddButton(isNoMargin: boolean = false) {
private renderAddButton() {
const theme = this.props.setting?.themes ?? Themes.dark;
const classList: string[] = ["label", "add-button"];
classList.push( theme === Themes.dark ? "dark" : "light" );
return <div
className={classList.join(" ")}
ref={this.props.addRef}
style={{
minHeight: this.props.minHeight,
minWidth: this.props.minHeight,
marginLeft: isNoMargin ? "0" : undefined
minWidth: this.props.minHeight
}}
onClick={() => {
this.props.addLabel ? this.props.addLabel() : null
@ -100,17 +108,10 @@ class LabelList extends Component<ILabelListProps & IMixinSettingProps> {
}
public render() {
if (this.props.labels.length > 0) {
return <>
{this.renderAllLabels()}
{this.props.addLabel ? this.renderAddButton() : null}
</>;
} else {
return <>
<ErrorMessage i18nKey="Panel.Info.Label.List.Error.Nodata"/>
{this.props.addLabel ? this.renderAddButton(true) : null}
</>;
}
return <div className="label-list-root">
{this.renderAllLabels()}
{this.props.addLabel ? this.renderAddButton() : null}
</div>;
}
}

View File

@ -0,0 +1,31 @@
@import "../Theme/Theme.scss";
$line-min-height: 26px;
div.label-picker-root {
width: 100%;
display: flex;
flex-wrap: wrap;
min-height: $line-min-height;
padding: 5px 0;
div.input-intro {
width: 50%;
height: 100%;
max-width: 220px;
display: flex;
align-items: center;
padding-right: 5px;
box-sizing: border-box;
}
div.root-content {
width: 50%;
height: 100%;
max-width: 180px;
min-height: $line-min-height;
border-radius: 3px;
overflow: hidden;
display: flex;
}
}

View File

@ -0,0 +1,93 @@
import { AllI18nKeys, Localization } from "@Component/Localization/Localization";
import { PickerList } from "../PickerList/PickerList";
import { Label } from "@Model/Label";
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
import { Component, ReactNode, createRef } from "react";
import { LabelList } from "../LabelList/LabelList";
import "./LabelPicker.scss"
interface ILabelPickerProps {
keyI18n: AllI18nKeys;
infoI18n?: AllI18nKeys;
labels: Label[];
labelAdd?: (label: Label) => any;
labelDelete?: (label: Label) => any;
}
interface ILabelPickerState {
isPickerVisible: boolean;
}
@useStatusWithEvent("labelAttrChange", "labelChange")
class LabelPicker extends Component<ILabelPickerProps & IMixinStatusProps, ILabelPickerState> {
public constructor(props: ILabelPickerProps) {
super(props);
this.state = {
isPickerVisible: false
}
}
private addButtonRef = createRef<HTMLDivElement>();
private getOtherLabel() {
let res: Label[] = [];
let nowLabel: Label[] = this.props.labels ?? [];
if (this.props.status) {
this.props.status.model.labelPool.forEach((aLabel) => {
let isHas = false;
nowLabel.forEach((nLabel) => {
if (aLabel.equal(nLabel)) isHas = true;
})
if (!isHas) {
res.push(aLabel);
}
})
}
return res;
}
public render(): ReactNode {
return <div
className="label-picker-root"
>
<div className="input-intro">
<Localization i18nKey={this.props.keyI18n}/>
</div>
<div className="root-content">
<LabelList
addRef={this.addButtonRef}
labels={this.props.labels}
minHeight={26}
deleteLabel={(label) => {
this.props.labelDelete ? this.props.labelDelete(label) : 0;
}}
addLabel={() => {
this.setState({
isPickerVisible: true
});
}}
/>
{this.state.isPickerVisible ? <PickerList
objectList={this.getOtherLabel()}
dismiss={() => {
this.setState({
isPickerVisible: false
});
}}
click={(label) => {
if (label instanceof Label && this.props.labelAdd) {
this.props.labelAdd(label)
}
this.setState({
isPickerVisible: false
});
}}
target={this.addButtonRef}
/> : null}
</div>
</div>
}
}
export { LabelPicker }

View File

@ -0,0 +1,12 @@
import { Component, ReactNode } from "react";
interface IObjectPickerProps {}
class ObjectPicker extends Component<IObjectPickerProps> {
public render(): ReactNode {
return <div></div>
}
}
export { ObjectPicker }

View File

@ -0,0 +1,72 @@
div.picker-list-root {
max-width: 200px;
padding: 0px;
margin: 0px;
overflow-y: auto;
div.picker-list-item {
width: 200px;
height: 36px;
display: flex;
justify-content: center;
align-items: center;
vertical-align: middle;
cursor: pointer;
user-select: none;
border-radius: 3px;
overflow: hidden;
div.list-item-color {
width: 3px;
height: calc( 100% - 6px );
margin: 3px 0 3px 3px;
flex-shrink: 0;
border-radius: 1000px;
overflow: hidden;
background-color: black;
}
div.list-item-icon {
width: 30px;
flex-shrink: 0;
display: flex;
justify-content: center;
align-items: center;
}
div.list-item-name {
width: 100%;
}
}
div.picker-list-item:hover {
background-color: rgba($color: #000000, $alpha: .1);
}
span.picker-list-nodata {
display: inline-block;
padding: 5px;
}
}
div.picker-list-root::-webkit-scrollbar {
width : 0; /*高宽分别对应横竖滚动条的尺寸*/
height: 0;
}
div.picker-list-root::-webkit-scrollbar {
width : 8px; /*高宽分别对应横竖滚动条的尺寸*/
height: 0;
}
div.picker-list-root::-webkit-scrollbar-thumb {
/*滚动条里面小方块*/
border-radius: 8px;
background-color: rgba($color: #000000, $alpha: .1);
}
div.picker-list-root::-webkit-scrollbar-track {
/*滚动条里面轨道*/
border-radius: 8px;
background-color: rgba($color: #000000, $alpha: 0);
}

View File

@ -0,0 +1,87 @@
import { Localization } from "@Component/Localization/Localization";
import { Callout, DirectionalHint, Icon } from "@fluentui/react";
import { CtrlObject } from "@Model/CtrlObject";
import { Group } from "@Model/Group";
import { Label } from "@Model/Label";
import { Range } from "@Model/Range";
import { Component, ReactNode, RefObject } from "react";
import "./PickerList.scss";
type IPickerListItem = CtrlObject | Label;
interface IPickerListProps {
objectList?: IPickerListItem[];
target?: RefObject<any>;
dismiss?: () => any;
click?: (item: IPickerListItem) => any;
}
class PickerList extends Component<IPickerListProps> {
private renderItem(item: IPickerListItem) {
let color: number[] = [];
let icon: string = "tag";
let name: string = "";
if (item instanceof Range) {
icon = "CubeShape"
}
if (item instanceof Group) {
icon = "WebAppBuilderFragment"
}
if (item instanceof CtrlObject) {
color[0] = Math.round(item.color[0] * 255);
color[1] = Math.round(item.color[1] * 255);
color[2] = Math.round(item.color[2] * 255);
name = item.displayName;
}
if (item instanceof Label) {
icon = "tag";
color = item.color.concat([]);
name = item.name;
}
return <div
className="picker-list-item"
key={item.id}
onClick={() => {
if (this.props.click) {
this.props.click(item)
}
}}
>
<div className="list-item-color"
style={{
backgroundColor: `rgb(${color[0]},${color[1]},${color[2]})`
}}
></div>
<div className="list-item-icon">
<Icon iconName={icon}/>
</div>
<div className="list-item-name">
{name}
</div>
</div>;
}
public render(): ReactNode {
return <Callout
onDismiss={this.props.dismiss}
target={this.props.target}
directionalHint={DirectionalHint.topAutoEdge}
>
<div className="picker-list-root">
{this.props.objectList ? this.props.objectList.map((item) => {
return this.renderItem(item);
}) : null}
{!this.props.objectList || (this.props.objectList && this.props.objectList.length <= 0) ?
<Localization className="picker-list-nodata" i18nKey="Common.Attr.Key.Label.Picker.Nodata"/>
: null
}
</div>
</Callout>
}
}
export { PickerList }

View File

@ -30,6 +30,7 @@ interface IStatusEvent {
focusObjectChange: void;
focusLabelChange: void;
objectChange: void;
rangeLabelChange: void;
labelChange: void;
rangeAttrChange: void;
labelAttrChange: void;
@ -121,6 +122,22 @@ class Status extends Emitter<IStatusEvent> {
}
}
public addRangeLabel(id: ObjectID, val: Label) {
const range = this.model.getObjectById(id);
if (range && range instanceof Range) {
range.addLabel(val);
this.emit("rangeLabelChange");
}
}
public deleteRangeLabel(id: ObjectID, val: Label) {
const range = this.model.getObjectById(id);
if (range && range instanceof Range) {
range.removeLabel(val);
this.emit("rangeLabelChange");
}
}
/**
*
*/
@ -137,7 +154,7 @@ class Status extends Emitter<IStatusEvent> {
findLabel[key] = val;
this.emit("labelAttrChange");
}
}
}
/**
*

View File

@ -51,7 +51,9 @@ const EN_US = {
"Common.Attr.Key.Display": "Display",
"Common.Attr.Key.Update": "Update",
"Common.Attr.Key.Delete": "Delete",
"Common.Attr.Key.Label": "Label",
"Common.Attr.Key.Error.Multiple": "Multiple values",
"Common.Attr.Key.Label.Picker.Nodata": "No tags can be added",
"Panel.Info.Range.Details.Attr.Error.Not.Range": "Object is not a Range",
"Panel.Info.Range.Details.Attr.Error.Unspecified": "Unspecified range object",
"Panel.Info.Label.Details.Error.Unspecified": "Label object not specified",

View File

@ -51,7 +51,9 @@ const ZH_CN = {
"Common.Attr.Key.Display": "显示",
"Common.Attr.Key.Update": "更新",
"Common.Attr.Key.Delete": "删除",
"Common.Attr.Key.Label": "标签",
"Common.Attr.Key.Error.Multiple": "多重数值",
"Common.Attr.Key.Label.Picker.Nodata": "没有可以被添加的标签",
"Panel.Info.Range.Details.Attr.Error.Not.Range": "对象不是一个范围",
"Panel.Info.Range.Details.Attr.Error.Unspecified": "未指定范围对象",
"Panel.Info.Label.Details.Error.Unspecified": "未指定标签对象",

View File

@ -6,3 +6,7 @@ div.label-list-panel-root {
padding: 10px;
box-sizing: border-box;
}
div.label-list-pabel-err-msg {
padding-bottom: 5px;
}

View File

@ -3,6 +3,7 @@ import { Component } from "react";
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
import { useSetting, IMixinSettingProps } from "@Context/Setting";
import { Label } from "@Model/Label";
import { ErrorMessage } from "@Component/ErrorMessage/ErrorMessage";
import "./LabelList.scss";
interface ILabelListProps {
@ -29,6 +30,12 @@ class LabelList extends Component<ILabelListProps & IMixinStatusProps & IMixinSe
this.labelInnerClick = false;
}}
>
{labels.length <=0 ?
<ErrorMessage
className="label-list-pabel-err-msg"
i18nKey="Panel.Info.Label.List.Error.Nodata"
/> : null
}
<LabelListComponent
labels={labels}
focusLabel={this.props.status ? this.props.status.focusLabel : undefined}

View File

@ -7,13 +7,15 @@ import { Range } from "@Model/Range";
import { ObjectID } from "@Model/Renderer";
import { ColorInput } from "@Component/ColorInput/ColorInput";
import { TogglesInput } from "@Component/TogglesInput/TogglesInput";
import { LabelPicker } from "@Component/LabelPicker/LabelPicker";
import "./RangeDetails.scss";
@useStatusWithEvent("rangeAttrChange", "focusObjectChange")
@useStatusWithEvent("rangeAttrChange", "focusObjectChange", "rangeLabelChange")
class RangeDetails extends Component<IMixinStatusProps> {
public readonly AttrI18nKey: AllI18nKeys[] = [
"Common.Attr.Key.Display.Name",
"Common.Attr.Key.Label",
"Common.Attr.Key.Display",
"Common.Attr.Key.Update",
"Common.Attr.Key.Color",
@ -59,6 +61,20 @@ class RangeDetails extends Component<IMixinStatusProps> {
status.changeRangeAttrib(range.id, "displayName", val);
})}
<LabelPicker keyI18n={this.AttrI18nKey[keyIndex ++]}
labels={range.allLabels()}
labelAdd={(label) => {
if (this.props.status) {
this.props.status.addRangeLabel(range.id, label);
}
}}
labelDelete={(label) => {
if (this.props.status) {
this.props.status.deleteRangeLabel(range.id, label);
}
}}
/>
<TogglesInput keyI18n={this.AttrI18nKey[keyIndex ++]} value={range.display} valueChange={(val) => {
if (this.props.status) {
this.props.status.changeRangeAttrib(range.id, "display", val);