Prevent scenario from dragging when input is hovered (#8)

* Prevent scenario from dragging when input is hovered

* Prevent VariantHeader from dragging when input is hovered
This commit is contained in:
arcticfly
2023-07-01 10:23:04 -07:00
committed by GitHub
parent 3f6ef5adcf
commit c2c512d751
2 changed files with 8 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ export default function ScenarioEditor({
const savedValues = scenario.variableValues as Record<string, string>; const savedValues = scenario.variableValues as Record<string, string>;
const utils = api.useContext(); const utils = api.useContext();
const [isDragTarget, setIsDragTarget] = useState(false); const [isDragTarget, setIsDragTarget] = useState(false);
const [variableInputHovered, setVariableInputHovered] = useState(false);
const [values, setValues] = useState<Record<string, string>>(savedValues); const [values, setValues] = useState<Record<string, string>>(savedValues);
@@ -72,7 +73,7 @@ export default function ScenarioEditor({
pr={cellPadding.x} pr={cellPadding.x}
py={cellPadding.y} py={cellPadding.y}
height="100%" height="100%"
draggable draggable={!variableInputHovered}
onDragStart={(e) => { onDragStart={(e) => {
e.dataTransfer.setData("text/plain", scenario.id); e.dataTransfer.setData("text/plain", scenario.id);
e.currentTarget.style.opacity = "0.4"; e.currentTarget.style.opacity = "0.4";
@@ -154,6 +155,8 @@ export default function ScenarioEditor({
borderColor={hasChanged ? "blue.300" : "transparent"} borderColor={hasChanged ? "blue.300" : "transparent"}
_hover={{ borderColor: "gray.300" }} _hover={{ borderColor: "gray.300" }}
_focus={{ borderColor: "blue.500", outline: "none", bg: "white" }} _focus={{ borderColor: "blue.500", outline: "none", bg: "white" }}
onMouseEnter={() => setVariableInputHovered(true)}
onMouseLeave={() => setVariableInputHovered(false)}
/> />
</Flex> </Flex>
); );

View File

@@ -11,6 +11,7 @@ import AutoResizeTextArea from "../AutoResizeTextArea";
export default function VariantHeader(props: { variant: PromptVariant }) { export default function VariantHeader(props: { variant: PromptVariant }) {
const utils = api.useContext(); const utils = api.useContext();
const [isDragTarget, setIsDragTarget] = useState(false); const [isDragTarget, setIsDragTarget] = useState(false);
const [isInputHovered, setIsInputHovered] = useState(false);
const [label, setLabel] = useState(props.variant.label); const [label, setLabel] = useState(props.variant.label);
const updateMutation = api.promptVariants.update.useMutation(); const updateMutation = api.promptVariants.update.useMutation();
@@ -53,7 +54,7 @@ export default function VariantHeader(props: { variant: PromptVariant }) {
spacing={4} spacing={4}
alignItems="center" alignItems="center"
minH={headerMinHeight} minH={headerMinHeight}
draggable draggable={!isInputHovered}
onDragStart={(e) => { onDragStart={(e) => {
e.dataTransfer.setData("text/plain", props.variant.id); e.dataTransfer.setData("text/plain", props.variant.id);
e.currentTarget.style.opacity = "0.4"; e.currentTarget.style.opacity = "0.4";
@@ -91,6 +92,8 @@ export default function VariantHeader(props: { variant: PromptVariant }) {
_focus={{ borderColor: "blue.500", outline: "none" }} _focus={{ borderColor: "blue.500", outline: "none" }}
flex={1} flex={1}
px={cellPadding.x} px={cellPadding.x}
onMouseEnter={() => setIsInputHovered(true)}
onMouseLeave={() => setIsInputHovered(false)}
/> />
<Tooltip label="Hide Variant" hasArrow> <Tooltip label="Hide Variant" hasArrow>
<Button variant="ghost" colorScheme="gray" size="sm" onClick={onHide}> <Button variant="ghost" colorScheme="gray" size="sm" onClick={onHide}>