Rename component added and set
This commit is contained in:
parent
2a6c8ae92e
commit
886a938b98
2 changed files with 102 additions and 2 deletions
84
src/frontend/src/components/ui/rename-label.tsx
Normal file
84
src/frontend/src/components/ui/rename-label.tsx
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
import { useState, useEffect, useRef } from "react";
|
||||||
|
import { cn } from "../../utils";
|
||||||
|
|
||||||
|
export default function RenameLabel(props) {
|
||||||
|
const [internalState, setInternalState] = useState(false);
|
||||||
|
const [isRename, setIsRename] = props.rename
|
||||||
|
? [props.rename, props.setRename]
|
||||||
|
: [internalState, setInternalState];
|
||||||
|
|
||||||
|
const [myValue, setMyValue] = useState(props.value);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isRename) {
|
||||||
|
document.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
setIsRename(false);
|
||||||
|
props.setValue("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (inputRef.current) {
|
||||||
|
setTimeout(() => {
|
||||||
|
inputRef.current.focus();
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resizeInput();
|
||||||
|
}, [isRename]);
|
||||||
|
|
||||||
|
const inputRef = useRef(null);
|
||||||
|
|
||||||
|
const resizeInput = () => {
|
||||||
|
const input = inputRef.current;
|
||||||
|
if (input) {
|
||||||
|
const span = document.createElement("span");
|
||||||
|
span.style.position = "absolute";
|
||||||
|
span.style.visibility = "hidden";
|
||||||
|
span.style.whiteSpace = "pre";
|
||||||
|
span.style.font = window.getComputedStyle(input).font;
|
||||||
|
span.textContent = input.value;
|
||||||
|
|
||||||
|
document.body.appendChild(span);
|
||||||
|
const textWidth = span.getBoundingClientRect().width;
|
||||||
|
document.body.removeChild(span);
|
||||||
|
|
||||||
|
input.style.width = `${textWidth + 16}px`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{isRename ? (
|
||||||
|
<input
|
||||||
|
autoFocus
|
||||||
|
ref={inputRef}
|
||||||
|
onInput={resizeInput}
|
||||||
|
className={cn(
|
||||||
|
"px-2 bg-transparent focus:border-none active:outline hover:outline focus:outline outline-gray-300 rounded-md",
|
||||||
|
props.className
|
||||||
|
)}
|
||||||
|
onBlur={() => {
|
||||||
|
setIsRename(false);
|
||||||
|
if (props.value !== "") {
|
||||||
|
props.setValue(myValue);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
value={myValue}
|
||||||
|
onChange={(e) => {
|
||||||
|
setMyValue(e.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className={cn("px-2 text-left truncate", props.className)}
|
||||||
|
onDoubleClick={() => {
|
||||||
|
setIsRename(true);
|
||||||
|
setMyValue(props.value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{props.value}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -21,6 +21,7 @@ import {
|
||||||
ChevronDownIcon,
|
ChevronDownIcon,
|
||||||
CodeBracketSquareIcon,
|
CodeBracketSquareIcon,
|
||||||
GlobeAltIcon,
|
GlobeAltIcon,
|
||||||
|
PencilSquareIcon,
|
||||||
PlusIcon,
|
PlusIcon,
|
||||||
TrashIcon,
|
TrashIcon,
|
||||||
} from "@heroicons/react/24/outline";
|
} from "@heroicons/react/24/outline";
|
||||||
|
|
@ -47,6 +48,7 @@ import {
|
||||||
CardHeader,
|
CardHeader,
|
||||||
CardTitle,
|
CardTitle,
|
||||||
} from "../../components/ui/card";
|
} from "../../components/ui/card";
|
||||||
|
import RenameLabel from "../../components/ui/rename-label";
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const {
|
const {
|
||||||
|
|
@ -63,6 +65,7 @@ export default function HomePage() {
|
||||||
const AlertWidth = 384;
|
const AlertWidth = 384;
|
||||||
const { dark, setDark } = useContext(darkContext);
|
const { dark, setDark } = useContext(darkContext);
|
||||||
const [activeTab, setActiveTab] = useState("myflow");
|
const [activeTab, setActiveTab] = useState("myflow");
|
||||||
|
const [rename, setRename] = useState(false);
|
||||||
const { notificationCenter, setNotificationCenter } =
|
const { notificationCenter, setNotificationCenter } =
|
||||||
useContext(alertContext);
|
useContext(alertContext);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -84,13 +87,26 @@ export default function HomePage() {
|
||||||
<span className="text-2xl ml-4">⛓️</span>
|
<span className="text-2xl ml-4">⛓️</span>
|
||||||
<div className="flex gap-2 p-2">
|
<div className="flex gap-2 p-2">
|
||||||
<TabsTrigger value="myflow" className="flex items-center gap-2">
|
<TabsTrigger value="myflow" className="flex items-center gap-2">
|
||||||
{flows[tabIndex].name}
|
<RenameLabel
|
||||||
|
value={flows[tabIndex].name}
|
||||||
|
setValue={() => {}}
|
||||||
|
rename={rename}
|
||||||
|
setRename={setRename}
|
||||||
|
/>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger>
|
<DropdownMenuTrigger>
|
||||||
<ChevronDownIcon className="w-3" />
|
<ChevronDownIcon className="w-3" />
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="w-40">
|
<DropdownMenuContent className="w-40">
|
||||||
<DropdownMenuLabel>Current Flow</DropdownMenuLabel>
|
<DropdownMenuLabel>Current Flow</DropdownMenuLabel>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setRename(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PencilSquareIcon className="w-4 h-4 mr-2" />
|
||||||
|
Rename
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
openPopUp(<ImportModal />);
|
openPopUp(<ImportModal />);
|
||||||
|
|
@ -126,7 +142,7 @@ export default function HomePage() {
|
||||||
{flows.map((flow, idx) => {
|
{flows.map((flow, idx) => {
|
||||||
return (
|
return (
|
||||||
<DropdownMenuRadioItem value={idx.toString()}>
|
<DropdownMenuRadioItem value={idx.toString()}>
|
||||||
<span onDoubleClick={() => {}}>{flow.name}</span>
|
{flow.name}
|
||||||
</DropdownMenuRadioItem>
|
</DropdownMenuRadioItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue