From 70eba32b345839a1b642b809610e01192642a01b Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sun, 31 Oct 2021 22:56:42 -0400 Subject: [PATCH] added foundation for tooltip --- .../automation/StateManager/ScriptService.tsx | 10 +- .../AutomationEditor/NewNodeModal.tsx | 1 - web/src/components/InputText.tsx | 31 ++++- web/src/router.tsx | 33 +++-- web/src/styles/common.scss | 97 +++++++++++++++ web/src/styles/index.scss | 115 +----------------- web/src/styles/tooltip.scss | 30 +++++ web/src/tooltip/context.ts | 41 +++++++ web/src/tooltip/index.tsx | 40 ++++++ 9 files changed, 267 insertions(+), 131 deletions(-) create mode 100644 web/src/styles/common.scss create mode 100644 web/src/styles/tooltip.scss create mode 100644 web/src/tooltip/context.ts create mode 100644 web/src/tooltip/index.tsx diff --git a/web/src/automation/StateManager/ScriptService.tsx b/web/src/automation/StateManager/ScriptService.tsx index f2de323..9e28302 100644 --- a/web/src/automation/StateManager/ScriptService.tsx +++ b/web/src/automation/StateManager/ScriptService.tsx @@ -18,15 +18,19 @@ export default class ScriptCallServiceState extends BaseState { } renderOptionList(state: ServiceScript): JSX.Element { return
- this.setState({...state, alias})} /> - this.setState({...state, service})} /> - this.setState({...state, target})} /> diff --git a/web/src/components/AutomationEditor/NewNodeModal.tsx b/web/src/components/AutomationEditor/NewNodeModal.tsx index 50697e2..030765b 100644 --- a/web/src/components/AutomationEditor/NewNodeModal.tsx +++ b/web/src/components/AutomationEditor/NewNodeModal.tsx @@ -2,7 +2,6 @@ import { useState, useEffect } from "react"; import StateManager from "../../automation/StateManager"; import { AutomationNodeType, AutomationNodeTypes, NodeSubType, typeList } from "../../automation/types"; import InputList from "../InputList"; -import InputWrapper from "../InputWrapper"; export interface Props { node_type: T, diff --git a/web/src/components/InputText.tsx b/web/src/components/InputText.tsx index 8938668..89637e7 100644 --- a/web/src/components/InputText.tsx +++ b/web/src/components/InputText.tsx @@ -1,18 +1,37 @@ +import { useToolTip } from "../tooltip/context"; import InputWrapper from "./InputWrapper"; - export interface Props { + textBoxFor?: string; label: string; value: string; onChange: (v: string) => void; + additionalTooltipFilters?: Record; } export default function InputText({ - label, value, onChange + label, + textBoxFor, + value="", + onChange, + additionalTooltipFilters={}, }: Props) { + const tooltip = useToolTip(); return - { - e.preventDefault(); - onChange(e.target.value) - }}/> + { + e.preventDefault(); + onChange(e.target.value) + }} + onFocus={e => textBoxFor && tooltip.setFocus( + e.target.getBoundingClientRect(), + { + searchObject: textBoxFor, + textInput: value, + filterObjects: additionalTooltipFilters, + }, + onChange + )} + /> } \ No newline at end of file diff --git a/web/src/router.tsx b/web/src/router.tsx index 16b4d1f..48da619 100644 --- a/web/src/router.tsx +++ b/web/src/router.tsx @@ -1,17 +1,34 @@ -import React from "react"; +import React, { useState } from "react"; import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom"; +import NewNodeModal from "./components/AutomationEditor/NewNodeModal"; import { Home } from "./pages/Home"; +import Tooltip from "./tooltip"; +import { TooltipContext, TooltipState } from "./tooltip/context"; export default function App() { + const [tooltipState, updateState] = useState({ + updateState(s) { updateState(s) }, + searchResults: [ + "Option #1" + ], + }); return ( -
- - - - - -
+ +
+ + + {/* */} + {}} + onCreate={()=>{}} + /> + + +
+ +
); } diff --git a/web/src/styles/common.scss b/web/src/styles/common.scss new file mode 100644 index 0000000..1a34a50 --- /dev/null +++ b/web/src/styles/common.scss @@ -0,0 +1,97 @@ +html, +body, +#app { + margin: 0; + padding: 0; + height: 100vh; + width: 100vw; + overflow: hidden; + font-family: Tahoma, Geneva, sans-serif; + background-color: $primary; + display: grid; + align-items: center; + justify-items: center; + color: $font-color-primary; +} + +h1, +h2, +h3, +h4, +h5 { + justify-content: center; + align-items: center; + display: flex; + text-align: center; +} + +/* width */ +::-webkit-scrollbar { + width: 10px; +} + +/* Track */ +::-webkit-scrollbar-track { + background: $secondary; +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: $secondary-accent; +} + +/* Handle on hover */ +::-webkit-scrollbar-thumb:hover { + background: $primary-accent; +} + +:root { + touch-action: pan-x pan-y; + height: 100%; +} + +button { + background-color: $secondary; + color: $primary-accent; + border-color: $primary-accent; + + &:hover { + background-color: $primary; + border-color: $secondary-accent; + } + + &:disabled { + background-color: $gray; + border-color: $gray; + color: darken($gray, 50); + cursor: not-allowed; + } + + &.secondary { + background-color: $primary; + color: $secondary-accent; + border-color: $secondary-accent; + &:hover { + background-color: $secondary; + border-color: $primary-accent; + } + } + + border-style: solid; + border-width: 1px; + padding: 2.5%; + margin-left: 5%; + margin-right: 5%; + border-radius: 5px; + cursor: pointer; +} + +select { + @extend button; + margin: 0; +} +input { + @extend button; + margin: 0; + cursor: text; +} diff --git a/web/src/styles/index.scss b/web/src/styles/index.scss index 45815da..e0db30e 100644 --- a/web/src/styles/index.scss +++ b/web/src/styles/index.scss @@ -1,117 +1,6 @@ @import "./colors.scss"; @import "./pages/index.scss"; @import "./utils.scss"; +@import "./common.scss"; @import "./components/index.scss"; - -html, -body, -#app { - margin: 0; - padding: 0; - height: 100vh; - width: 100vw; - overflow: hidden; - font-family: Tahoma, Geneva, sans-serif; - background-color: $primary; - display: grid; - align-items: center; - justify-items: center; - color: $font-color-primary; -} - -.row { - display: flex; - flex-direction: row; -} - -.col { - display: flex; - flex-direction: column; -} - -.center { - display: flex; - justify-content: center; - align-items: center; -} - -h1, -h2, -h3, -h4, -h5 { - justify-content: center; - align-items: center; - display: flex; - text-align: center; -} - -/* width */ -::-webkit-scrollbar { - width: 10px; -} - -/* Track */ -::-webkit-scrollbar-track { - background: $secondary; -} - -/* Handle */ -::-webkit-scrollbar-thumb { - background: $secondary-accent; -} - -/* Handle on hover */ -::-webkit-scrollbar-thumb:hover { - background: $primary-accent; -} - -:root { - touch-action: pan-x pan-y; - height: 100%; -} - -button { - background-color: $secondary; - color: $primary-accent; - border-color: $primary-accent; - &:hover { - background-color: $primary; - border-color: $secondary-accent; - } - - &:disabled { - background-color: $gray; - border-color: $gray; - color: darken($gray, 50); - cursor: not-allowed; - } - - &.secondary { - background-color: $primary; - color: $secondary-accent; - border-color: $secondary-accent; - &:hover { - background-color: $secondary; - border-color: $primary-accent; - } - } - - border-style: solid; - border-width: 1px; - padding: 2.5%; - margin-left: 5%; - margin-right: 5%; - border-radius: 5px; - cursor: pointer; -} - -select { - @extend button; - margin: 0; -} -input { - @extend button; - margin: 0; - cursor: text; -} +@import "./tooltip.scss"; diff --git a/web/src/styles/tooltip.scss b/web/src/styles/tooltip.scss new file mode 100644 index 0000000..38eadb0 --- /dev/null +++ b/web/src/styles/tooltip.scss @@ -0,0 +1,30 @@ +.tooltip { + &.hide { + width: 0; + height: 0; + display: none; + } + &-bg { + position: absolute; + left: 0; + top: 0; + width: 100vw; + height: 100vh; + z-index: 9; + } + ul { + position: absolute; + left: 0; + top: 0; + + list-style: none; + margin: 0; + padding: 0; + z-index: 10; + + li { + @extend button; + margin: 0; + } + } +} diff --git a/web/src/tooltip/context.ts b/web/src/tooltip/context.ts new file mode 100644 index 0000000..eff2e5e --- /dev/null +++ b/web/src/tooltip/context.ts @@ -0,0 +1,41 @@ +import { createContext, useContext } from "react" + +export interface TooltipSearchOption { + searchObject: string; + textInput: string; + filterObjects: Record; +} +export interface TooltipState { + domrect?: DOMRect; + searchOptions?: TooltipSearchOption; + onSelected?: (s: string) => void; + searchResults: string[]; + updateState: (s: TooltipState) => void; +} +export const TooltipContext = createContext({ + updateState(s) {}, + searchResults: [], +}) + +export const useToolTip = () => { + const state = useContext(TooltipContext); + + return { + setFocus( + domrect: DOMRect, + searchOptions: TooltipSearchOption, + onSelected: (s: string) => void + ){ + state.updateState({ + ...state, + domrect, searchOptions, onSelected + }) + }, + setSearchResults(searchResults: string[]){ + state.updateState({ + ...state, + searchResults + }) + }, + } +}; \ No newline at end of file diff --git a/web/src/tooltip/index.tsx b/web/src/tooltip/index.tsx new file mode 100644 index 0000000..4ad983e --- /dev/null +++ b/web/src/tooltip/index.tsx @@ -0,0 +1,40 @@ +import { TooltipState } from "./context"; + +export default function Tooltip({ + domrect, + searchOptions, + searchResults=[], + onSelected=()=>{}, + updateState, +}: TooltipState) { + + // state alias + const rootClassName = !!domrect && !!searchOptions ? "tooltip show" : "tooltip hide"; + let tooltipStyle = {}; + if (domrect) { + const {left=0, top=0, height=0, width=0} = domrect; + tooltipStyle = { + top: `${top + height}px`, + left: `${left}px`, + width: `${width}px`, + } + } + const unFocus = () => updateState({ + updateState, + onSelected, + searchResults: [], + }); + + return
+
unFocus()}>
+
    + {searchResults.map((r, i) =>
  • { + onSelected(r); + unFocus(); + }}> + {r} +
  • )} + {searchResults.length === 0 ?
  • unFocus()}>No Options...
  • : ""} +
+
+} \ No newline at end of file