added foundation for tooltip

This commit is contained in:
Ari Sosnovsky committed 2021-10-31 22:56:42 -04:00
1 parent 53ec0d417b
commit 70eba32b34
9 files changed
+267 -131

No files matched your search

@@ -18,15 +18,19 @@ export default class ScriptCallServiceState extends BaseState<ServiceScript> {
}
renderOptionList(state: ServiceScript): JSX.Element {
return <div className="state-manager-options">
<InputText label="Description"
<InputText
label="Description"
value={state.alias}
onChange={alias => this.setState({...state, alias})}
/>
<InputText label="Service"
<InputText
textBoxFor="service"
label="Service"
value={state.service}
onChange={service => this.setState({...state, service})}
/>
<InputText label="Target"
<InputText
label="Target"
value={state.target}
onChange={target => this.setState({...state, target})}
/>
@@ -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<T extends AutomationNodeType> {
node_type: T,
+25 -6
View File
@@ -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<string, string>;
}
export default function InputText({
label, value, onChange
label,
textBoxFor,
value="",
onChange,
additionalTooltipFilters={},
}: Props) {
const tooltip = useToolTip();
return <InputWrapper label={label}>
<input value={value} onChange={e => {
e.preventDefault();
onChange(e.target.value)
}}/>
<input
value={value}
onChange={e => {
e.preventDefault();
onChange(e.target.value)
}}
onFocus={e => textBoxFor && tooltip.setFocus(
e.target.getBoundingClientRect(),
{
searchObject: textBoxFor,
textInput: value,
filterObjects: additionalTooltipFilters,
},
onChange
)}
/>
</InputWrapper>
}
+25 -8
View File
@@ -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<TooltipState>({
updateState(s) { updateState(s) },
searchResults: [
"Option #1"
],
});
return (
<Router>
<div>
<Switch>
<Route path="/">
<Home />
</Route>
</Switch>
</div>
<TooltipContext.Provider value={tooltipState}>
<div>
<Switch>
<Route path="/">
{/* <Home /> */}
<NewNodeModal
node_type="action"
onClose={()=>{}}
onCreate={()=>{}}
/>
</Route>
</Switch>
</div>
<Tooltip {...tooltipState}/>
</TooltipContext.Provider>
</Router>
);
}
+97
View File
@@ -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;
}
+2 -113
View File
@@ -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";
+30
View File
@@ -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;
}
}
}
+41
View File
@@ -0,0 +1,41 @@
import { createContext, useContext } from "react"
export interface TooltipSearchOption {
searchObject: string;
textInput: string;
filterObjects: Record<string, string>;
}
export interface TooltipState {
domrect?: DOMRect;
searchOptions?: TooltipSearchOption;
onSelected?: (s: string) => void;
searchResults: string[];
updateState: (s: TooltipState) => void;
}
export const TooltipContext = createContext<TooltipState>({
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
})
},
}
};
+40
View File
@@ -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 <div className={rootClassName}>
<div className="tooltip-bg" onClick={() => unFocus()}></div>
<ul style={tooltipStyle}>
{searchResults.map((r, i) => <li key={i} onClick={() => {
onSelected(r);
unFocus();
}}>
{r}
</li>)}
{searchResults.length === 0 ? <li onClick={() => unFocus()}>No Options...</li> : ""}
</ul>
</div>
}