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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: DNS copy buttons don't trigger/show tooltips like "Copied" (#4160)
Ivan Starkovd7af39652a3a
diff --git a/apps/builder/app/builder/features/topbar/domains.tsx b/apps/builder/app/builder/features/topbar/domains.tsxindex 00264c68e1..f87f23abdd 100644--- a/apps/builder/app/builder/features/topbar/domains.tsx+++ b/apps/builder/app/builder/features/topbar/domains.tsx@@ -36,6 +36,7 @@ import { $publisherHost } from "~/shared/nano-states";import { extractCname } from "./cname";import { useEffectEvent } from "~/shared/hook-utils/effect-event";import DomainCheckbox from "./domain-checkbox";+import { CopyToClipboard } from "~/builder/shared/copy-to-clipboard";export type Domain = Project["domainsVirtual"][number];@@ -45,21 +46,6 @@ const InputEllipsis = styled(InputField, {},});-const CopyToClipboard = (props: { text: string }) => {- return (- <Tooltip content={"Copy to clipboard"}>- <NestedInputButton- type="button"- onClick={() => {- navigator.clipboard.writeText(props.text);- }}- >- <CopyIcon />- </NestedInputButton>- </Tooltip>- );-};-export const getStatus = (projectDomain: Domain) =>projectDomain.verified? (`VERIFIED_${projectDomain.status}` as const)@@ -456,24 +442,48 @@ const DomainItem = (props: {<InputEllipsisreadOnlyvalue={cnameRecord.host}- suffix={<CopyToClipboard text={cnameRecord.host} />}+ suffix={+ <CopyToClipboard text={cnameRecord.host}>+ <NestedInputButton type="button">+ <CopyIcon />+ </NestedInputButton>+ </CopyToClipboard>+ }/><InputEllipsisreadOnlyvalue={cnameRecord.value}- suffix={<CopyToClipboard text={cnameRecord.value} />}+ suffix={+ <CopyToClipboard text={cnameRecord.value}>+ <NestedInputButton type="button">+ <CopyIcon />+ </NestedInputButton>+ </CopyToClipboard>+ }/><InputEllipsis readOnly value="TXT" /><InputEllipsisreadOnlyvalue={txtRecord.host}- suffix={<CopyToClipboard text={txtRecord.host} />}+ suffix={+ <CopyToClipboard text={txtRecord.host}>+ <NestedInputButton type="button">+ <CopyIcon />+ </NestedInputButton>+ </CopyToClipboard>+ }/><InputEllipsisreadOnlyvalue={txtRecord.value}- suffix={<CopyToClipboard text={txtRecord.value} />}+ suffix={+ <CopyToClipboard text={txtRecord.value}>+ <NestedInputButton type="button">+ <CopyIcon />+ </NestedInputButton>+ </CopyToClipboard>+ }/></Grid>diff --git a/apps/builder/app/builder/features/topbar/publish.tsx b/apps/builder/app/builder/features/topbar/publish.tsxindex b355de9f7b..7b0b179831 100644--- a/apps/builder/app/builder/features/topbar/publish.tsx+++ b/apps/builder/app/builder/features/topbar/publish.tsx@@ -56,6 +56,7 @@ import { isFeatureEnabled } from "@webstudio-is/feature-flags";import type { Templates } from "@webstudio-is/sdk";import { formatDistance } from "date-fns/formatDistance";import DomainCheckbox, { domainToPublishName } from "./domain-checkbox";+import { CopyToClipboard } from "~/builder/shared/copy-to-clipboard";type ChangeProjectDomainProps = {project: Project;@@ -778,18 +779,11 @@ const ExportContent = (props: { projectId: Project["id"] }) => {value={npxCommand}/>- <Tooltip content={"Copy to clipboard"}>- <Button- type="button"- color="neutral"- onClick={() => {- navigator.clipboard.writeText(npxCommand);- }}- prefix={<CopyIcon />}- >+ <CopyToClipboard text={npxCommand}>+ <Button type="button" color="neutral" prefix={<CopyIcon />}>Copy</Button>- </Tooltip>+ </CopyToClipboard></Flex></Grid><Grid columns={1} gap={2}>@@ -820,21 +814,17 @@ const ExportContent = (props: { projectId: Project["id"] }) => {.trimStart().replace(/ +$/, "")}/>- <Tooltip content={"Copy to clipboard"}>++ <CopyToClipboard text={deployTargets[deployTarget].command}><Buttontype="button"css={{ flexShrink: 0 }}color="neutral"- onClick={() => {- navigator.clipboard.writeText(- deployTargets[deployTarget].command- );- }}prefix={<CopyIcon />}>Copy</Button>- </Tooltip>+ </CopyToClipboard></Flex></Grid><Grid columns={1} gap={1}>diff --git a/apps/builder/app/builder/shared/copy-to-clipboard.tsx b/apps/builder/app/builder/shared/copy-to-clipboard.tsxnew file mode 100644index 0000000000..1ea75a5b75--- /dev/null+++ b/apps/builder/app/builder/shared/copy-to-clipboard.tsx@@ -0,0 +1,42 @@+import { Tooltip } from "@webstudio-is/design-system";+import { useState } from "react";++export const CopyToClipboard = ({+ text,+ copyText = "Copy to clipboard",+ copiedText = "Copied",+ children,+}: {+ text: string;+ copyText?: string;+ copiedText?: string;+ children: React.ReactNode;+}) => {+ const [isCopied, setIsCopied] = useState(false);++ return (+ <div+ style={{ display: "contents" }}+ onClick={() => {+ navigator.clipboard.writeText(text);+ setIsCopied(true);+ }}+ >+ <Tooltip+ // Tooltip sometimes receives onOpenChange with isOpen=false immediately after a click.+ // Changing the key seems like a workaround to address this issue.+ key={isCopied ? "copied" : "copy"}+ disableHoverableContent+ content={isCopied ? copiedText : copyText}+ open={isCopied === true ? true : undefined}+ onOpenChange={(isOpen) => {+ if (isOpen === false) {+ setIsCopied(false);+ }+ }}+ >+ {children}+ </Tooltip>+ </div>+ );+};diff --git a/apps/builder/app/shared/share-project/share-project.tsx b/apps/builder/app/shared/share-project/share-project.tsxindex 6563a97740..7a64f8f87a 100644--- a/apps/builder/app/shared/share-project/share-project.tsx+++ b/apps/builder/app/shared/share-project/share-project.tsx@@ -31,6 +31,7 @@ import {} from "@webstudio-is/icons";import { Fragment, useState, type ComponentProps, type ReactNode } from "react";import { useIds } from "../form-utils";+import { CopyToClipboard } from "~/builder/shared/copy-to-clipboard";const Item = (props: ComponentProps<typeof Flex>) => (<Flex@@ -316,35 +317,21 @@ const SharedLinkItem = ({hasProPlan,}: SharedLinkItemType) => {const [currentName, setCurrentName] = useState(value.name);- const [isCopied, setIsCopied] = useState(false);return (<Box className={itemStyle()}><Label css={{ flexGrow: 1 }}>{currentName}</Label>- <Tooltip- content={isCopied ? "Copied" : "Copy link"}- open={isCopied === true ? true : undefined}- onOpenChange={(isOpen) => {- if (isOpen === false) {- setIsCopied(false);- }- }}+ <CopyToClipboard+ text={builderUrl({+ authToken: value.token,+ mode: value.relation === "viewers" ? "preview" : "edit",+ })}+ copyText="Copy link">- <IconButton- aria-label="Copy link"- onClick={() => {- navigator.clipboard.writeText(- builderUrl({- authToken: value.token,- mode: value.relation === "viewers" ? "preview" : "edit",- })- );- setIsCopied(true);- }}- >+ <IconButton aria-label="Copy link"><CopyIcon aria-hidden /></IconButton>- </Tooltip>+ </CopyToClipboard><Menuname={currentName}value={value}