The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix center placement and add accentColor option
Tim Wilson08a9a3c9f4ec
diff --git a/apps/web/app/app.dub.co/embed/widget/page-client.tsx b/apps/web/app/app.dub.co/embed/widget/page-client.tsxindex 687aca1833..e8d92ef6f5 100644--- a/apps/web/app/app.dub.co/embed/widget/page-client.tsx+++ b/apps/web/app/app.dub.co/embed/widget/page-client.tsx@@ -20,7 +20,7 @@ import {nFormatter,} from "@dub/utils";import { Link, Program } from "@prisma/client";-import { useState } from "react";+import { CSSProperties, useState } from "react";import useSWR from "swr";import { LinkToken } from "../token";@@ -30,10 +30,12 @@ export function EmbedWidgetPageClient({program,link,earnings,+ accentColor,}: {program: Program;link: Link;earnings: number;+ accentColor: string;}) {const [copied, copyToClipboard] = useCopyToClipboard();const [selectedTab, setSelectedTab] = useState<Tab>("invite");@@ -53,8 +55,11 @@ export function EmbedWidgetPageClient({);return (- <div className="flex min-h-screen flex-col">- <div className="flex flex-col gap-2 rounded-lg rounded-b-none bg-black p-5">+ <div+ className="flex min-h-screen flex-col"+ style={{ "--accent-color": accentColor } as CSSProperties}+ >+ <div className="flex flex-col gap-2 rounded-lg rounded-b-none bg-[var(--accent-color,black)] p-5"><div className="w-fit rounded-full bg-white/20 p-3"><GiftFill className="size-5 text-white" /></div>@@ -103,6 +108,7 @@ export function EmbedWidgetPageClient({}text={copied ? "Copied link" : "Copy link"}onClick={() => copyToClipboard(getPrettyUrl(link.shortLink))}+ className="enabled:border-[var(--accent-color)] enabled:bg-[var(--accent-color)] enabled:hover:bg-[var(--accent-color)]"/></div><div className="mt-4 grid grid-cols-3 gap-2">@@ -133,7 +139,7 @@ export function EmbedWidgetPageClient({className="flex h-7 items-center justify-center rounded-md border border-neutral-300 text-neutral-800 transition-colors duration-75 hover:bg-neutral-50 active:bg-neutral-100"><Icon- className="size-4 text-current"+ className="size-4 text-neutral-800"fill="currentColor"/></a>diff --git a/apps/web/app/app.dub.co/embed/widget/page.tsx b/apps/web/app/app.dub.co/embed/widget/page.tsxindex dae7b859d7..4294261c94 100644--- a/apps/web/app/app.dub.co/embed/widget/page.tsx+++ b/apps/web/app/app.dub.co/embed/widget/page.tsx@@ -4,13 +4,18 @@ import { EmbedWidgetPageClient } from "./page-client";export default async function EmbedWidgetPage({searchParams,}: {- searchParams: { token: string };+ searchParams: { token: string; accentColor?: string };}) {- const { token } = searchParams;+ const { token, accentColor } = searchParams;const { link, program, earnings } = await getLinkAndProgram(token);return (- <EmbedWidgetPageClient program={program} link={link} earnings={earnings} />+ <EmbedWidgetPageClient+ program={program}+ link={link}+ earnings={earnings}+ accentColor={accentColor ?? "#000"}+ />);}diff --git a/apps/web/ui/layout/sidebar/refer-button.tsx b/apps/web/ui/layout/sidebar/refer-button.tsxindex c7704eb8f3..df9a517945 100644--- a/apps/web/ui/layout/sidebar/refer-button.tsx+++ b/apps/web/ui/layout/sidebar/refer-button.tsx@@ -17,7 +17,6 @@ export function ReferButton() {token="dub_embed_zNettp9ZaXTmdq3VM0lODQjeIfADNqM1qj2w"trigger="manual"placement="top-left"- anchorId="dub-refer-button"><buttontype="button"diff --git a/packages/embeds/core/src/core.ts b/packages/embeds/core/src/core.tsindex 0a9d23f6ac..101b591a01 100644--- a/packages/embeds/core/src/core.ts+++ b/packages/embeds/core/src/core.ts@@ -93,10 +93,14 @@ const CLOSE_BUTTON_STYLE = {let isWidgetOpen = false;-const createIframe = (iframeUrl: string, token: string): HTMLIFrameElement => {+const createIframe = (+ iframeUrl: string,+ token: string,+ accentColor?: string,+): HTMLIFrameElement => {const iframe = document.createElement("iframe");- iframe.src = `${iframeUrl}?token=${token}`;+ iframe.src = `${iframeUrl}?token=${token}&accentColor=${encodeURIComponent(accentColor ?? "#000")}`;iframe.style.width = "100%";iframe.style.height = "100%";iframe.style.border = "none";@@ -176,6 +180,7 @@ const renderWidget = (options: DubOptions): RenderWidgetResult => {const {token,placement,+ accentColor,containerStyles,popupStyles,anchorId,@@ -220,7 +225,7 @@ const renderWidget = (options: DubOptions): RenderWidgetResult => {display: "none",});- const iframe = createIframe(WIDGET_URL, token);+ const iframe = createIframe(WIDGET_URL, token, accentColor);// Close buttonconst closeButton = document.createElement("button");diff --git a/packages/embeds/core/src/types.ts b/packages/embeds/core/src/types.tsindex 1707bcfa8c..96c85d18e6 100644--- a/packages/embeds/core/src/types.ts+++ b/packages/embeds/core/src/types.ts@@ -35,6 +35,9 @@ export type DubOptions = {// The ID of the anchor elementanchorId?: string;+ // Custom accent color+ accentColor?: string;+// The styles for the widget containercontainerStyles?: Partial<CSSStyleDeclaration>;popupStyles?: Partial<CSSStyleDeclaration>;diff --git a/packages/embeds/react/src/widget.tsx b/packages/embeds/react/src/widget.tsxindex ede213a65a..d0f9074d1c 100644--- a/packages/embeds/react/src/widget.tsx+++ b/packages/embeds/react/src/widget.tsx@@ -20,7 +20,7 @@ export const DubWidget = memo(const { destroy } = init({...options,type: "widget",- anchorId: children ? id : undefined,+ anchorId: children && options.placement !== "center" ? id : undefined,});return () => destroy();