aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/LabelBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/LabelBox.tsx')
-rw-r--r--src/client/views/nodes/LabelBox.tsx65
1 files changed, 59 insertions, 6 deletions
diff --git a/src/client/views/nodes/LabelBox.tsx b/src/client/views/nodes/LabelBox.tsx
index e39caecb6..bcf55fbe8 100644
--- a/src/client/views/nodes/LabelBox.tsx
+++ b/src/client/views/nodes/LabelBox.tsx
@@ -1,8 +1,12 @@
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { Tooltip } from '@mui/material';
import { Property } from 'csstype';
-import { action, computed, makeObservable } from 'mobx';
+import { action, computed, makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import * as textfit from 'textfit';
+import { returnFalse, setupMoveUpEvents } from '../../../ClientUtils';
+import { emptyFunction } from '../../../Utils';
import { Field, FieldType } from '../../../fields/Doc';
import { BoolCast, NumCast, StrCast } from '../../../fields/Types';
import { TraceMobx } from '../../../fields/util';
@@ -22,6 +26,7 @@ export class LabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
}
private dropDisposer?: DragManager.DragDropDisposer;
private _timeout: NodeJS.Timeout | undefined;
+ @observable private _editLabel = false;
_divRef: HTMLDivElement | null = null;
constructor(props: FieldViewProps) {
@@ -44,6 +49,48 @@ export class LabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
return this._props.styleProvider?.(this.Document, this._props, StyleProp.BackgroundColor) as string;
}
+ @computed get answerIcon() {
+ return (
+ <Tooltip
+ title={
+ <div className="answer-tooltip" style={{ minWidth: '150px' }}>
+ {StrCast(this.Document.quiz)}
+ </div>
+ }>
+ <div className="answer-tool-tip">
+ <FontAwesomeIcon className="q-icon" icon="circle" color="white" />
+ <FontAwesomeIcon className="answer-icon" icon="question" />
+ </div>
+ </Tooltip>
+ );
+ }
+
+ @computed get editAnswer() {
+ return (
+ <Tooltip
+ title={
+ <div className="answer-tooltip" style={{ minWidth: '150px' }}>
+ {this._editLabel ? 'save' : 'edit correct answer'}
+ </div>
+ }>
+ <div className="answer-tool-tip" onPointerDown={e => setupMoveUpEvents(e.target, e, returnFalse, emptyFunction, () => this.editLabelAnswer())}>
+ <FontAwesomeIcon className="edit-icon" color={this._editLabel ? 'white' : 'black'} icon="pencil" size="sm" />
+ </div>
+ </Tooltip>
+ );
+ }
+
+ editLabelAnswer = () => {
+ // when click the pencil, set the text to the quiz content. when click off, set the quiz text to that and set textbox to nothing.
+ if (!this._editLabel) {
+ this.dataDoc.title = StrCast(this.Document.quiz);
+ } else {
+ this.Document.quiz = this.Title;
+ this.dataDoc.title = '';
+ }
+ this._editLabel = !this._editLabel;
+ };
+
componentDidMount() {
this._props.setContentViewBox?.(this);
}
@@ -122,7 +169,11 @@ export class LabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
width: this._props.PanelWidth(),
height: this._props.PanelHeight(),
whiteSpace: 'multiLine' in boxParams && boxParams.multiLine ? 'pre-wrap' : 'pre',
- }}>
+ }}
+ // onMouseLeave={() => {
+ // this.hoverFlip(undefined);
+ // }}
+ >
<div
style={{
width: this._props.PanelWidth() - 2 * NumCast(this.layoutDoc._xPadding),
@@ -134,10 +185,10 @@ export class LabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
})}
onKeyUp={action(e => {
e.stopPropagation();
- if (e.key === 'Enter') {
- this.dataDoc[this.fieldKey] = this._divRef?.innerText ?? '';
- setTimeout(() => this._props.select(false));
- }
+ // if (e.key === 'Enter') {
+ this.dataDoc[this.fieldKey] = this._divRef?.innerText ?? '';
+ setTimeout(() => this._props.select(false));
+ // }
})}
onBlur={() => {
this.dataDoc[this.fieldKey] = this._divRef?.innerText ?? '';
@@ -158,6 +209,8 @@ export class LabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
{label}
</div>
</div>
+ {this.Document.showQuiz ? this.answerIcon : null}
+ {this.Document.showQuiz ? this.editAnswer : null}
</div>
);
}