Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix delete button

Sara Vieira62f994a37e49
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx b/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx
index 0c83c2b9d9..e826a4a86c 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx
@@ -39,12 +39,14 @@ export const AssetManagerThumbnail = ({
const isUploading = status === "uploading";
const src = useImageWithFallback({ path });
const [isToolTipOpen, setTolltipOpen] = useState(false);
+ const [isDeleting, setIsDeleting] = useState(false);
const [progressBarPercentage, setProgressBarPercentage] = useState(0);
+
+ const closeTooltip = () => setTolltipOpen(false);
+
const tooltipRef = useRef(null);
- useClickAway(tooltipRef, () => {
- setTolltipOpen(false);
- });
- useHotkeys(shortcuts["escape"], () => setTolltipOpen(false));
+ useClickAway(tooltipRef, closeTooltip);
+ useHotkeys(shortcuts["escape"], closeTooltip);
// @todo rewrite this fake indication to show real progress
useInterval(
@@ -53,16 +55,18 @@ export const AssetManagerThumbnail = ({
percentage < 60 ? percentage + 1 : percentage
);
},
- isUploading ? 100 : null
+ isUploading || isDeleting ? 100 : null
);
const deleteAsset = () => {
const formData = new FormData();
formData.append("assetId", id);
formData.append("assetName", name);
- setTolltipOpen(false);
+ closeTooltip();
+ setIsDeleting(true);
submit(formData, { method: "delete" });
};
+
return (
<Box
title={alt || ""}
@@ -90,37 +94,36 @@ export const AssetManagerThumbnail = ({
}}
></Box>
{!isUploading && (
- <Box ref={tooltipRef}>
- <Tooltip
- open={isToolTipOpen}
- multiline
- content={
- <Flex direction="column" gap={1} align="center" justify="center">
- Are you sure you want to delete this asset?
- <Button variant="red" onClick={deleteAsset}>
- Delete
- </Button>
- </Flex>
- }
+ <Tooltip
+ ref={tooltipRef}
+ open={isToolTipOpen}
+ multiline
+ content={
+ <Flex direction="column" gap={1} align="center" justify="center">
+ Are you sure you want to delete this asset?
+ <Button variant="red" onClick={deleteAsset}>
+ Delete
+ </Button>
+ </Flex>
+ }
+ >
+ <Button
+ variant="raw"
+ title="Delete asset"
+ onClick={() => setTolltipOpen(true)}
+ css={{
+ position: "absolute",
+ top: "$1",
+ right: "$1",
+ cursor: "pointer",
+ color: "$highContrast",
+ }}
>
- <Button
- variant="raw"
- title="Delete asset"
- onClick={() => setTolltipOpen(true)}
- css={{
- position: "absolute",
- top: "$1",
- right: "$1",
- cursor: "pointer",
- color: "$highContrast",
- }}
- >
- <Cross2Icon />
- </Button>
- </Tooltip>
- </Box>
+ <Cross2Icon />
+ </Button>
+ </Tooltip>
)}
- {isUploading && (
+ {(isUploading || isDeleting) && (
<ProgressBar
value={progressBarPercentage}
max={60}
diff --git a/apps/designer/app/shared/design-system/components/tooltip.tsx b/apps/designer/app/shared/design-system/components/tooltip.tsx
index be1a66fe1e..84214d4ae7 100644
--- a/apps/designer/app/shared/design-system/components/tooltip.tsx
+++ b/apps/designer/app/shared/design-system/components/tooltip.tsx
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { Ref } from "react";
import { styled } from "../stitches.config";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import { Box } from "./box";
@@ -39,16 +39,19 @@ const Arrow = styled(TooltipPrimitive.Arrow, {
marginTop: -0.5,
});
-export const Tooltip = ({
- children,
- content,
- open,
- defaultOpen,
- onOpenChange,
- multiline,
- delayDuration,
- ...props
-}: TooltipProps) => {
+export const Tooltip = React.forwardRef(function TooltipWrapper(
+ {
+ children,
+ content,
+ open,
+ defaultOpen,
+ onOpenChange,
+ multiline,
+ delayDuration,
+ ...props
+ }: TooltipProps,
+ ref: Ref<HTMLDivElement>
+) {
return (
<TooltipPrimitive.Root
open={open}
@@ -59,6 +62,7 @@ export const Tooltip = ({
<TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>
<Content
+ ref={ref}
side="top"
align="center"
sideOffset={5}
@@ -81,4 +85,4 @@ export const Tooltip = ({
</Content>
</TooltipPrimitive.Root>
);
-};
+});