diff --git a/frontend/components/dashboard/DashboardInputField.js b/frontend/components/dashboard/DashboardInputField.js index eb4934c08..bba626207 100644 --- a/frontend/components/dashboard/DashboardInputField.js +++ b/frontend/components/dashboard/DashboardInputField.js @@ -1,9 +1,11 @@ -import React from "react"; +import React, { useRef } from "react"; import { faCircle } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import guidGenerator from "../utilities/randomId"; +const REGEX = /([$]{.*?})/g; + /** * This function splits the input of a dashboard field into the parts that are inside and outside of ${...} * @param {string} text - the value of the input in the Dashboard Input Field @@ -73,55 +75,53 @@ const DashboardInputField = ({ ); } else if (type === "value") { + const ref = useRef(null); + + const syncScroll = (e) => { + ref.current.scrollTop = e.target.scrollTop; + ref.current.scrollLeft = e.target.scrollLeft; + }; + return (
onChangeHandler(e.target.value, index)} - type={type} value={value} + onChange={(e) => setValue(e.target.value)} + onScroll={syncScroll} className={`${ blurred ? "text-transparent group-hover:text-transparent focus:text-transparent active:text-transparent" : "" } asolute z-10 peer font-mono ph-no-capture bg-transparent rounded-md caret-white text-transparent text-md px-2 py-1.5 w-full min-w-16 outline-none focus:ring-2 focus:ring-primary/50 duration-200`} spellCheck="false" + placeholder="This is a placeholder!" /> -
- {findReferences(value).map((texts, id) => { - if (id % 2 == 0 || texts.length <= 2) { - return ( - - {texts} - - ); - } - return ( - - {texts.slice(0, 2)} - - {texts.slice(2, texts.length - 1)} - - {texts.slice(texts.length - 1, texts.length) == "}" ? ( - - {texts.slice(texts.length - 1, texts.length)}{" "} + { + value + .split(REGEX) + .map((word, i) => { + if (word.match(REGEX) !== null) { + return ( + + {word} - ) : ( - - {texts.slice(texts.length - 1, texts.length)}{" "} - - )} - - ); - })} + ); + } else { + return {word}; + } + }) + }
{blurred && (
@@ -137,7 +137,7 @@ const DashboardInputField = ({ /> ))}
- )} + )}
);