From 77e9b7ff8d7c5d729b04e37ea847f1df8fa7fb9a Mon Sep 17 00:00:00 2001
From: geireann <60007097+geireann@users.noreply.github.com>
Date: Sat, 21 Aug 2021 12:31:29 -0400
Subject: added num range button

---
 src/client/views/nodes/button/FontIconBox.tsx | 71 ++++++++++++++++-----------
 1 file changed, 42 insertions(+), 29 deletions(-)

(limited to 'src/client/views/nodes/button/FontIconBox.tsx')

diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx
index 4f52e90b7..bc4b56a2d 100644
--- a/src/client/views/nodes/button/FontIconBox.tsx
+++ b/src/client/views/nodes/button/FontIconBox.tsx
@@ -1,3 +1,4 @@
+import { IconProp } from '@fortawesome/fontawesome-svg-core';
 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
 import { Tooltip } from '@material-ui/core';
 import { action, computed, observable } from 'mobx';
@@ -7,12 +8,16 @@ import { ColorState, SketchPicker } from 'react-color';
 import { Doc, StrListCast } from '../../../../fields/Doc';
 import { createSchema, makeInterface } from '../../../../fields/Schema';
 import { ScriptField } from '../../../../fields/ScriptField';
-import { BoolCast, Cast, StrCast, ScriptCast } from '../../../../fields/Types';
+import { BoolCast, Cast, StrCast } from '../../../../fields/Types';
+import { DocumentType } from '../../../documents/DocumentTypes';
+import { Scripting } from "../../../util/Scripting";
 import { SelectionManager } from '../../../util/SelectionManager';
 import { ColorScheme } from '../../../util/SettingsManager';
-import { undoBatch, UndoManager } from '../../../util/UndoManager';
+import { UndoManager } from '../../../util/UndoManager';
+import { CollectionViewType } from '../../collections/CollectionView';
 import { ContextMenu } from '../../ContextMenu';
 import { DocComponent } from '../../DocComponent';
+import { Colors } from '../../global/globalEnums';
 import { StyleProp } from '../../StyleProvider';
 import { FieldView, FieldViewProps } from '.././FieldView';
 import './FontIconBox.scss';
@@ -28,7 +33,14 @@ export enum ButtonType {
     DoubleButton = "dblBtn",
     ToggleButton = "tglBtn",
     ColorButton = "colorBtn",
-    ToolButton = "toolBtn"
+    ToolButton = "toolBtn",
+    NumberButton = "numBtn"
+}
+
+export enum NumButtonType {
+    Slider = "slider",
+    DropdownOptions = "dropdown",
+    Inline = "inline"
 }
 
 export interface ButtonProps extends FieldViewProps {
@@ -60,7 +72,6 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
     @observable private label = StrCast(this.rootDoc.label, StrCast(this.rootDoc.title));
     @observable private icon = StrCast(this.dataDoc.icon, "user") as any;
     @observable private dropdown: boolean = BoolCast(this.rootDoc.dropDownOpen);
-    @observable private dropdownDirection: string = StrCast(this.rootDoc.dropDownDirection);
     @observable private buttonList: string[] = StrListCast(this.rootDoc.btnList);
     @observable private type = StrCast(this.rootDoc.btnType);
 
@@ -74,8 +85,23 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
      * - Dropdown button 
      * - Color button
      * - Dropdown list
+     * - Number button
     **/
 
+    /**
+     * Number button
+     */
+    @computed get numberButton() {
+        const numType: string = StrCast(this.rootDoc.numButtonType);
+
+        return (
+            <div className={`menuButton ${this.type}`}
+            >
+
+            </div>
+        );
+    }
+
     /**
      * Dropdown button
      */
@@ -120,9 +146,9 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
         let icon: IconProp = "caret-down";
 
 
-        if (script == 'changeView') {
+        if (script === 'changeView') {
             const selected = SelectionManager.Views().length ? SelectionManager.Views()[0] : undefined;
-            if (selected && StrCast(selected.Document.type) == DocumentType.COL) {
+            if (selected && StrCast(selected.Document.type) === DocumentType.COL) {
                 text = StrCast(selected.Document._viewType);
             } else if (selected) {
                 dropdown = false;
@@ -130,9 +156,9 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
                 icon = Doc.toIcon(selected.Document);
             }
             noviceList = [CollectionViewType.Freeform, CollectionViewType.Schema, CollectionViewType.Stacking];
-        } else if (script == 'changeFont') {
+        } else if (script === 'changeFont') {
             const selected = SelectionManager.Views().length ? SelectionManager.Views()[0] : undefined;
-            if (selected && StrCast(selected.Document.type) == DocumentType.RTF) {
+            if (selected && StrCast(selected.Document.type) === DocumentType.RTF) {
                 text = StrCast(selected.Document._fontFamily);
             } else {
                 text = StrCast(Doc.UserDoc()._fontFamily);
@@ -152,7 +178,7 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
                 if (s) {
                     s.script.run().result;
                 }
-            }
+            };
             return <div className="list-item" key={`${value}`}
                 style={{
                     fontFamily: script === 'changeFont' ? value : undefined,
@@ -194,15 +220,6 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
         );
     }
 
-
-    @computed get rangeButton() {
-        return (
-            <div>
-
-            </div>
-        )
-    }
-
     /**
      * Colour button
      */
@@ -264,7 +281,8 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
         const selectedDoc = numSelected > 0 ? SelectionManager.Views()[0].Document : undefined;
 
         const script: string = StrCast(this.rootDoc.script) + "(true)";
-        const boolResult = ScriptField.MakeScript(script)?.script.run().result;
+        console.log(script);
+        const boolResult = ScriptField.MakeScript(script)?.script.run().success;
         if (script.includes("toggleOverlay")) {
             console.log("boolResult: " + boolResult);
         }
@@ -280,7 +298,7 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
                 <FontAwesomeIcon className={`fontIconBox-icon-${this.type}`} icon={this.icon} color={boolResult ? Colors.LIGHT_GRAY : Colors.LIGHT_GRAY} />
                 {label}
             </div>
-        )
+        );
     }
 
 
@@ -298,10 +316,9 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
                 <div className="menuButton-wrap">
                     <FontAwesomeIcon className={`menuButton-icon-${this.type}`} icon={this.icon} color={"black"} size={"sm"} />
                     {!this.label || !Doc.UserDoc()._showLabel ? (null) : <div className="fontIconBox-label" style={{ color: color, backgroundColor: backgroundColor }}> {this.label} </div>}
-                    {/* <FontIconBadge collection={Cast(this.rootDoc.watchedDocuments, Doc, null)} /> */}
                 </div>
             </div>
-        )
+        );
     }
 
 
@@ -332,6 +349,9 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
         let button = this.defaultButton;
 
         switch (this.type) {
+            case ButtonType.NumberButton:
+                button = this.numberButton;
+                break;
             case ButtonType.DropdownButton:
                 button = this.dropdownButton;
                 break;
@@ -387,13 +407,6 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
     }
 }
 
-// SCRIPTING BUTTONS
-
-import { Scripting } from "../../../util/Scripting";
-import { CollectionViewType } from '../../collections/CollectionView';
-import { DocumentType } from '../../../documents/DocumentTypes';
-import { Colors } from '../../global/globalEnums';
-import { IconProp } from '@fortawesome/fontawesome-svg-core';
 
 // toggle: Set overlay status of selected document
 Scripting.addGlobal(function changeView(view: string) {
-- 
cgit v1.2.3-70-g09d2

