aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/FontIconBox.tsx
diff options
context:
space:
mode:
authorStanley Yip <stanley_yip@brown.edu>2020-02-09 14:58:57 -0500
committerStanley Yip <stanley_yip@brown.edu>2020-02-09 14:58:57 -0500
commitf6179334d6f2942631caa17b7c8ae2531d87c7c4 (patch)
tree091da0ef7bedb900c958c28cebe4058fade644cf /src/client/views/nodes/FontIconBox.tsx
parent07141291bee793955d7061f4e479942d7aceda67 (diff)
parent87167fd126e161b29d8d798a5f04e3cf159aae16 (diff)
recommender system works
Diffstat (limited to 'src/client/views/nodes/FontIconBox.tsx')
-rw-r--r--src/client/views/nodes/FontIconBox.tsx32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/client/views/nodes/FontIconBox.tsx b/src/client/views/nodes/FontIconBox.tsx
index 83ecc4657..a191ac4f4 100644
--- a/src/client/views/nodes/FontIconBox.tsx
+++ b/src/client/views/nodes/FontIconBox.tsx
@@ -5,10 +5,11 @@ import { createSchema, makeInterface } from '../../../new_fields/Schema';
import { DocComponent } from '../DocComponent';
import './FontIconBox.scss';
import { FieldView, FieldViewProps } from './FieldView';
-import { StrCast } from '../../../new_fields/Types';
+import { StrCast, Cast } from '../../../new_fields/Types';
import { Utils } from "../../../Utils";
import { runInAction, observable, reaction, IReactionDisposer } from 'mobx';
import { Doc } from '../../../new_fields/Doc';
+import { ContextMenu } from '../ContextMenu';
const FontIconSchema = createSchema({
icon: "string"
});
@@ -25,21 +26,36 @@ export class FontIconBox extends DocComponent<FieldViewProps, FontIconDocument>(
this._backgroundReaction = reaction(() => this.props.Document.backgroundColor,
() => {
if (this._ref && this._ref.current) {
- let col = Utils.fromRGBAstr(getComputedStyle(this._ref.current).backgroundColor);
- let colsum = (col.r + col.g + col.b);
+ const col = Utils.fromRGBAstr(getComputedStyle(this._ref.current).backgroundColor);
+ const colsum = (col.r + col.g + col.b);
if (colsum / col.a > 600 || col.a < 0.25) runInAction(() => this._foregroundColor = "black");
else if (colsum / col.a <= 600 || col.a >= .25) runInAction(() => this._foregroundColor = "white");
}
}, { fireImmediately: true });
}
+
+ showTemplate = (): void => {
+ const dragFactory = Cast(this.props.Document.dragFactory, Doc, null);
+ dragFactory && this.props.addDocTab(dragFactory, undefined, "onRight");
+ }
+
+ specificContextMenu = (): void => {
+ const cm = ContextMenu.Instance;
+ cm.addItem({ description: "Show Template", event: this.showTemplate, icon: "tag" });
+ }
+
componentWillUnmount() {
- this._backgroundReaction && this._backgroundReaction();
+ this._backgroundReaction?.();
}
+
render() {
- let referenceDoc = (this.props.Document.dragFactory instanceof Doc ? this.props.Document.dragFactory : this.props.Document);
- let referenceLayout = Doc.Layout(referenceDoc);
- return <button className="fontIconBox-outerDiv" title={StrCast(this.props.Document.title)} ref={this._ref}
- style={{ background: StrCast(referenceLayout.backgroundColor), boxShadow: this.props.Document.unchecked ? undefined : `4px 4px 12px black` }}>
+ const referenceDoc = (this.props.Document.dragFactory instanceof Doc ? this.props.Document.dragFactory : this.props.Document);
+ const referenceLayout = Doc.Layout(referenceDoc);
+ return <button className="fontIconBox-outerDiv" title={StrCast(this.props.Document.title)} ref={this._ref} onContextMenu={this.specificContextMenu}
+ style={{
+ background: StrCast(referenceLayout.backgroundColor),
+ boxShadow: this.props.Document.ischecked ? `4px 4px 12px black` : undefined
+ }}>
<FontAwesomeIcon className="fontIconBox-icon" icon={this.Document.icon as any} color={this._foregroundColor} size="sm" />
</button>;
}