import { observable, action, computed } from "mobx"; import { CirclePicker, ColorResult } from 'react-color'; import React = require("react"); import { observer } from "mobx-react"; import "./InkingControl.scss"; import { library } from '@fortawesome/fontawesome-svg-core'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faPen, faHighlighter, faEraser, faBan } from '@fortawesome/free-solid-svg-icons'; import { SelectionManager } from "../util/SelectionManager"; import { InkTool } from "../../new_fields/InkField"; import { Doc } from "../../new_fields/Doc"; library.add(faPen, faHighlighter, faEraser, faBan); @observer export class InkingControl extends React.Component { static Instance: InkingControl = new InkingControl({}); @observable private _selectedTool: InkTool = InkTool.None; @observable private _selectedColor: string = "rgb(244, 67, 54)"; @observable private _selectedWidth: string = "25"; @observable private _open: boolean = false; @observable private _colorPickerDisplay = false; constructor(props: Readonly<{}>) { super(props); InkingControl.Instance = this; } @action switchTool = (tool: InkTool): void => { this._selectedTool = tool; } @action switchColor = (color: ColorResult): void => { this._selectedColor = color.hex; if (SelectionManager.SelectedDocuments().length === 1) { var sdoc = SelectionManager.SelectedDocuments()[0]; if (sdoc.props.ContainingCollectionView) { Doc.SetOnPrototype(sdoc.props.Document, "backgroundColor", color.hex); } } } @action switchWidth = (width: string): void => { this._selectedWidth = width; } @computed get selectedTool() { return this._selectedTool; } @computed get selectedColor() { return this._selectedColor; } @computed get selectedWidth() { return this._selectedWidth; } selected = (tool: InkTool) => { if (this._selectedTool === tool) { return { color: "#61aaa3" }; } return {}; } @action toggleDisplay = () => { this._open = !this._open; } @action toggleColorPicker = () => { this._colorPickerDisplay = !this._colorPickerDisplay; } render() { return ( ); } }