prefix
stringlengths 23
4.36k
| suffix
stringlengths 0
3.29k
| middle
stringlengths 80
3.62k
| formatted_text
stringlengths 300
4.54k
| file_path
stringclasses 10
values |
---|---|---|---|---|
// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type {
|
Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
export default config;
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { <|fim_suffix|><|fim_middle|>Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
export default config;
|
packages/ui/tailwind.config.ts
|
|
// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailw
|
ts"> = {
presets: [sharedConfig],
};
export default config;
|
ind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "prese
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailw<|fim_suffix|>ts"> = {
presets: [sharedConfig],
};
export default config;
<|fim_middle|>ind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "prese
|
packages/ui/tailwind.config.ts
|
// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindcss";
const confi
|
fig;
|
g: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
export default con
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindcss";
const confi<|fim_suffix|>fig;
<|fim_middle|>g: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
export default con
|
packages/ui/tailwind.config.ts
|
// tailwind config is r
|
],
};
export default config;
|
equired for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig
|
<|fim_prefix|>// tailwind config is r<|fim_suffix|>],
};
export default config;
<|fim_middle|>equired for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig
|
packages/ui/tailwind.config.ts
|
// tailwind config is required for editor support
import sharedCon
|
ss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
export default config;
|
fig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindc
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedCon<|fim_suffix|>ss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
export default config;
<|fim_middle|>fig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindc
|
packages/ui/tailwind.config.ts
|
// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.con
|
= {
presets: [sharedConfig],
};
export default config;
|
fig.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets">
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.con<|fim_suffix|>= {
presets: [sharedConfig],
};
export default config;
<|fim_middle|>fig.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets">
|
packages/ui/tailwind.config.ts
|
// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Con
|
port default config;
|
fig } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
ex
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Con<|fim_suffix|>port default config;
<|fim_middle|>fig } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig],
};
ex
|
packages/ui/tailwind.config.ts
|
// tailwind config is required for
|
[sharedConfig],
};
export default config;
|
editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets:
|
<|fim_prefix|>// tailwind config is required for <|fim_suffix|>[sharedConfig],
};
export default config;
<|fim_middle|>editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets:
|
packages/ui/tailwind.config.ts
|
// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { C
|
],
};
export default config;
|
onfig } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-config/tailwind.config.ts";
import type { C<|fim_suffix|>],
};
export default config;
<|fim_middle|>onfig } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets: [sharedConfig
|
packages/ui/tailwind.config.ts
|
// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-c
|
[sharedConfig],
};
export default config;
|
onfig/tailwind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets:
|
<|fim_prefix|>// tailwind config is required for editor support
import sharedConfig from "@dub/tailwind-c<|fim_suffix|>[sharedConfig],
};
export default config;
<|fim_middle|>onfig/tailwind.config.ts";
import type { Config } from "tailwindcss";
const config: Pick<Config, "presets"> = {
presets:
|
packages/ui/tailwind.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
|
inify: true,
external: ["react"],
...options,
}));
|
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
m
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
<|fim_suffix|>inify: true,
external: ["react"],
...options,
}));
<|fim_middle|> format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
m
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig
|
dex.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
|
((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/in
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig<|fim_suffix|>dex.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
<|fim_middle|>((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/in
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js:
|
tions,
}));
|
'"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...op
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: <|fim_suffix|>tions,
}));
<|fim_middle|>'"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...op
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineCon
|
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
|
fig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineCon<|fim_suffix|>
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
<|fim_middle|>fig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineC
|
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
|
onfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineC<|fim_suffix|>},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
<|fim_middle|>onfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig((optio
|
external: ["react"],
...options,
}));
|
ns: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig((optio<|fim_suffix|> external: ["react"],
...options,
}));
<|fim_middle|>ns: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.ts
|
react"],
...options,
}));
|
x",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.ts<|fim_suffix|>react"],
...options,
}));
<|fim_middle|>x",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/in
|
banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
|
dex": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/in<|fim_suffix|>banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
<|fim_middle|>dex": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use cli
|
ns,
}));
|
ent"',
};
},
dts: true,
minify: true,
external: ["react"],
...optio
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/icons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use cli<|fim_suffix|>ns,
}));
<|fim_middle|>ent"',
};
},
dts: true,
minify: true,
external: ["react"],
...optio
|
packages/ui/tsup.config.ts
|
import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/i
|
cons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
|
<|fim_prefix|>import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: {
index: "src/index.tsx",
"icons/index": "src/i<|fim_suffix|><|fim_middle|>cons/index.tsx",
"charts/index": "src/charts/index.ts",
},
format: ["esm"],
esbuildOptions(options) {
options.banner = {
js: '"use client"',
};
},
dts: true,
minify: true,
external: ["react"],
...options,
}));
|
packages/ui/tsup.config.ts
|
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
|
lue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultVa
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
<|fim_suffix|>lue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|></div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultVa
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
|
outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (<|fim_suffix|>outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|>
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-
|
50">
|
neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-<|fim_suffix|>50">
<|fim_middle|>neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/d
|
ed-md border border-neutral-300 bg-neutral-50">
|
ubinc/dub"}
/>
</div>
<div className="relative overflow-hidden round
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/d<|fim_suffix|>ed-md border border-neutral-300 bg-neutral-50">
<|fim_middle|>ubinc/dub"}
/>
</div>
<div className="relative overflow-hidden round
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
|
.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
<|fim_suffix|>.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|> const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debo
|
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
unce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debo<|fim_suffix|>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|>unce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaul
|
p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
tUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaul<|fim_suffix|>p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|>tUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="re
|
dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
lative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="re<|fim_suffix|>dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|>lative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
|
n LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export functio
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.current.select();
}
}, [defaultUrl]);
<|fim_suffix|>n LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|> const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export functio
|
packages/ui/src/link-preview.tsx
|
"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.curr
|
er-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
|
ent.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:bord
|
<|fim_prefix|>"use client";
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
const hostname = useMemo(() => {
return getDomainWithoutWWW(debouncedUrl || "");
}, [debouncedUrl]);
const { data, isValidating } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
}>(
debouncedUrl &&
`/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
},
);
const { title, description, image } = data || {};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!defaultUrl && inputRef.current) {
inputRef.curr<|fim_suffix|>er-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
aria-invalid="true"
/>
</div>
)}
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
{isValidating && (
<div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
{image ? (
<img
src={image}
alt="Preview"
className="h-[250px] w-full border-b border-neutral-300 object-cover"
/>
) : (
<div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300">
<Photo className="h-8 w-8 text-neutral-400" />
<p className="text-sm text-neutral-400">
Enter a link to generate a preview.
</p>
</div>
)}
<div className="grid gap-1 bg-white p-3 text-left">
{hostname ? (
<p className="text-sm text-[#536471]">{hostname}</p>
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-neutral-100" />
)}
{title ? (
<h3 className="truncate text-sm font-medium text-[#0f1419]">
{title}
</h3>
) : (
<div className="mb-1 h-4 w-full rounded-md bg-neutral-100" />
)}
{description ? (
<p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-neutral-100" />
<div className="h-4 w-48 rounded-md bg-neutral-100" />
</div>
)}
</div>
</div>
</>
);
}
export function LinkPreviewPlaceholder({
defaultUrl,
}: {
defaultUrl?: string;
}) {
return (
<>
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
name="url"
id="url"
type="url"
disabled
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={defaultUrl || "https://github.com/dubinc/dub"}
/>
</div>
<div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
<|fim_middle|>ent.select();
}
}, [defaultUrl]);
const { isMobile } = useMediaQuery();
return (
<>
{!defaultUrl && (
<div className="relative flex items-center">
<Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-neutral-400" />
<input
ref={inputRef}
name="url"
id="url"
type="url"
autoFocus={!isMobile}
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:bord
|
packages/ui/src/link-preview.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="ht
|
ral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
tps://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neut
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="ht<|fim_suffix|>ral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>tps://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neut
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex
|
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex<|fim_suffix|> <p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|> max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [stat
|
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
us, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [stat<|fim_suffix|> href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>us, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
|
|
fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
"degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| <|fim_suffix|>fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>"degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus
|
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus<|fim_suffix|> const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5
|
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 <|fim_suffix|> status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [co
|
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
lor, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [co<|fim_suffix|> </div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>lor, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto siz
|
xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
e-2 rounded-full",
color,
)}
/>
</div>
<p className="text-
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto siz<|fim_suffix|>xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>e-2 rounded-full",
color,
)}
/>
</div>
<p className="text-
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-whit
|
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
e py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
className={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-whit<|fim_suffix|> className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>e py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-2">
<div
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
classN
|
2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
|
ame={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { fetcher } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
import useSWR from "swr";
export function DubStatusBadge({ className }: { className?: string }) {
const { data } = useSWR<{
ongoing_incidents: {
name: string;
current_worst_impact:
| "degraded_performance"
| "partial_outage"
| "full_outage";
}[];
}>("https://status.dub.co/api/v1/summary", fetcher);
const [color, setColor] = useState("bg-neutral-200");
const [status, setStatus] = useState("Loading status...");
useEffect(() => {
if (!data) return;
const { ongoing_incidents } = data;
if (ongoing_incidents.length > 0) {
const { current_worst_impact, name } = ongoing_incidents[0];
const color =
current_worst_impact === "degraded_performance"
? "bg-yellow-500"
: "bg-red-500";
setStatus(name);
setColor(color);
} else {
setStatus("All systems operational");
setColor("bg-green-500");
}
}, [data]);
return (
<Link
href="https://status.dub.co"
target="_blank"
classN<|fim_suffix|>2">
<div
className={cn(
"absolute inset-0 m-auto size-2 animate-ping items-center justify-center rounded-full group-hover:animate-none",
color,
status === "Loading status..." && "animate-none",
)}
/>
<div
className={cn(
"absolute inset-0 z-10 m-auto size-2 rounded-full",
color,
)}
/>
</div>
<p className="text-xs font-medium leading-none text-neutral-600">
{status}
</p>
</Link>
);
}
<|fim_middle|>ame={cn(
"group flex max-w-fit items-center gap-2 rounded-lg border border-neutral-200 bg-white py-2 pl-2 pr-2.5 transition-colors hover:bg-neutral-50 active:bg-neutral-100",
className,
)}
>
<div className="relative size-
|
packages/ui/src/dub-status-badge.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
|
tedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selec
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
<|fim_suffix|>tedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|> padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selec
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of
|
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of <|fim_suffix|> floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|>filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null)
|
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
;
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null)<|fim_suffix|> (a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|>;
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enable
|
width={16}
height={16}
|
d: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enable<|fim_suffix|> width={16}
height={16}
<|fim_middle|>d: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noIte
|
Dismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
msElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// use
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noIte<|fim_suffix|>Dismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|>msElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// use
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from
|
ist is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
"lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command l
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from <|fim_suffix|>ist is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|>"lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command l
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
|
.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
<|fim_suffix|>.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|> (a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filtered
|
e)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
Items = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.imag
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filtered<|fim_suffix|>e)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|>Items = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.imag
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/reac
|
ged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
t";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChan
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/reac<|fim_suffix|>ged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|>t";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = useState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChan
|
packages/ui/src/input-select.tsx
|
import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,
|
eState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
|
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = us
|
<|fim_prefix|>import { cn } from "@dub/utils";
import {
flip,
offset,
size,
useDismiss,
useFloating,
useInteractions,
} from "@floating-ui/react";
import { Command, useCommandState } from "cmdk";
import { Check, ChevronDown, Search, X } from "lucide-react";
import {
Dispatch,
HTMLAttributes,
InputHTMLAttributes,
ReactNode,
SetStateAction,
createContext,
forwardRef,
useContext,<|fim_suffix|>eState("");
// Whether the input has changed since opening
const [inputChanged, setInputChanged] = useState(false);
useEffect(() => {
// Reset inputChanged when the command list is opened
if (openCommandList) setInputChanged(false);
}, [openCommandList]);
useEffect(() => setInputChanged(true), [inputValue]);
useEffect(() => {
if (selectedItem) setInputValue(selectedItem.value);
}, [selectedItem]);
const filteredItems = useMemo(() => {
const search = inputValue.toLowerCase();
return inputChanged
? // Filter the items
items.filter((item: InputSelectItemProps) =>
item.value.toLowerCase().includes(search),
)
: inputValue
? // Just sort the items instead of filtering
items.sort(
(a: InputSelectItemProps, b: InputSelectItemProps) =>
(b.value.toLowerCase().includes(search) ? 1 : 0) -
(a.value.toLowerCase().includes(search) ? 1 : 0),
)
: items;
}, [inputChanged, inputValue, items]);
const {
refs: floatingRefs,
floatingStyles,
context,
} = useFloating({
open: openCommandList,
onOpenChange: setOpenCommandList,
middleware: [
offset(8),
size({
apply({ elements: { floating }, availableHeight }) {
Object.assign(floating.style, {
// Minimum height before 'flip' takes over is 112px
maxHeight: `${Math.max(75, Math.min(availableHeight, 290))}px`,
});
},
padding: 8,
}),
flip({
fallbackStrategy: "initialPlacement",
padding: 8,
}),
],
});
const dismiss = useDismiss(context, {
// useDismiss seems to break the mobile drawer for some reason
enabled: !isMobile || !adjustForMobile,
});
const { getReferenceProps, getFloatingProps } = useInteractions([dismiss]);
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const iconElement = useMemo(() => {
if (selectedItem && selectedItem.icon) return selectedItem.icon;
if (selectedItem && selectedItem.image)
return (
<BlurImage
src={selectedItem.image}
alt={selectedItem.value}
className="size-4 rounded-full"
width={16}
height={16}
<|fim_middle|>
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Drawer } from "vaul";
import { Badge } from "./badge";
import { BlurImage } from "./blur-image";
import { useMediaQuery } from "./hooks";
import { useScrollProgress } from "./hooks/use-scroll-progress";
const InputSelectContext = createContext<{
inputAttrs: InputHTMLAttributes<HTMLInputElement>;
openCommandList: boolean;
setOpenCommandList: Dispatch<SetStateAction<boolean>>;
inputValue: string;
setInputValue: Dispatch<SetStateAction<string>>;
disabled: boolean;
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
}>({
inputAttrs: {},
openCommandList: false,
setOpenCommandList: () => {},
inputValue: "",
setInputValue: () => {},
disabled: false,
selectedItem: null,
setSelectedItem: () => {},
});
export interface InputSelectItemProps {
id: string;
value: string;
color?: string;
icon?: ReactNode;
image?: string;
disabled?: boolean;
label?: string;
}
export function InputSelect({
items,
selectedItem,
setSelectedItem,
className,
disabled,
adjustForMobile,
icon,
inputAttrs,
noItemsElement,
}: {
items: InputSelectItemProps[] | [];
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
noItemsElement?: ReactNode;
}) {
const { isMobile } = useMediaQuery();
const commandRef = useRef<HTMLDivElement | null>(null);
const [openCommandList, setOpenCommandList] = useState(false);
const [inputValue, setInputValue] = us
|
packages/ui/src/input-select.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
|
}
|
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
<|fim_suffix|>
}
<|fim_middle|> toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copi
|
/>
)}
</button>
);
}
|
ed ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5"
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copi<|fim_suffix|>/>
)}
</button>
);
}
<|fim_middle|>ed ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5"
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants(
|
</button>
);
}
|
{ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants(<|fim_suffix|> </button>
);
}
<|fim_middle|>{ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMess
|
/>
)}
</button>
);
}
|
age || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5"
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMess<|fim_suffix|>/>
)}
</button>
);
}
<|fim_middle|>age || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5"
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
ret
|
n>
);
}
|
urn (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</butto
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
ret<|fim_suffix|>n>
);
}
<|fim_middle|>urn (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</butto
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative
|
e:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
|
group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 activ
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative <|fim_suffix|>e:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
<|fim_middle|>group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 activ
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
impo
|
{
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
|
rt { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants:
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
impo<|fim_suffix|>{
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
<|fim_middle|>rt { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants:
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "
|
w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
|
sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "<|fim_suffix|>w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
<|fim_middle|>sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">C
|
>
);
}
|
opy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={cn(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">C<|fim_suffix|>>
);
}
<|fim_middle|>opy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button
|
packages/ui/src/copy-button.tsx
|
"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const
|
n(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
|
copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={c
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
import { LucideIcon } from "lucide-react";
import { toast } from "sonner";
import { useCopyToClipboard } from "./hooks";
import { Copy, Tick } from "./icons";
const <|fim_suffix|>n(copyButtonVariants({ variant }), className)}
type="button"
>
<span className="sr-only">Copy</span>
{copied ? (
<Tick className="h-3.5 w-3.5" />
) : (
<Comp className="h-3.5 w-3.5" />
)}
</button>
);
}
<|fim_middle|>copyButtonVariants = cva(
"relative group rounded-full p-1.5 transition-all duration-75",
{
variants: {
variant: {
default: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
neutral: "bg-transparent hover:bg-neutral-100 active:bg-neutral-200",
},
},
defaultVariants: {
variant: "default",
},
},
);
export function CopyButton({
variant = "default",
value,
className,
icon,
successMessage,
}: {
value: string;
className?: string;
icon?: LucideIcon;
successMessage?: string;
} & VariantProps<typeof copyButtonVariants>) {
const [copied, copyToClipboard] = useCopyToClipboard();
const Comp = icon || Copy;
return (
<button
onClick={(e) => {
e.stopPropagation();
toast.promise(copyToClipboard(value), {
success: successMessage || "Copied to clipboard!",
});
}}
className={c
|
packages/ui/src/copy-button.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solution
|
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
s: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solution<|fim_suffix|> href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|>s: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
|
t-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 tex
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";<|fim_suffix|>t-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|>
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 tex
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
|
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;<|fim_suffix|> {socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|>
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
|
and" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/br
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
<|fim_suffix|>and" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|> {
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/br
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand"
|
vWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
, href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<Na
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand"<|fim_suffix|>vWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|>, href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<Na
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name:
|
key={item.name}>
|
"Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name:<|fim_suffix|>key={item.name}>
<|fim_middle|> "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
|
name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
<|fim_suffix|> name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|> { name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
}))
|
.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
,
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
}))<|fim_suffix|>.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|>,
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{
|
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ <|fim_suffix|>
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|>name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
|
packages/ui/src/footer.tsx
|
"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex
|
<div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
|
items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
|
<|fim_prefix|>"use client";
import { ALL_TOOLS, cn, createHref } from "@dub/utils";
import Image from "next/image";
import Link from "next/link";
import { useParams } from "next/navigation";
import { COMPARE_PAGES, FEATURES_LIST, LEGAL_PAGES } from "./content";
import { DubStatusBadge } from "./dub-status-badge";
import { Github, LinkedIn, ReferredVia, Twitter, YouTube } from "./icons";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavWordmark } from "./nav-wordmark";
const socials = [
{
name: "Twitter",
icon: Twitter,
href: "https://twitter.com/dubdotco",
},
{
name: "LinkedIn",
icon: LinkedIn,
href: "https://www.linkedin.com/company/dubinc",
},
{
name: "GitHub",
icon: Github,
href: "https://github.com/dubinc/dub",
},
{
name: "YouTube",
icon: YouTube,
href: "https://www.youtube.com/@dubdotco",
},
];
const navigation = {
product: [
...FEATURES_LIST.map(({ title, href }) => ({
name: title,
href,
})),
{ name: "Dub Enterprise", href: "/enterprise" },
{ name: "Pricing", href: "/pricing" },
],
solutions: [
{ name: "Marketing attribution", href: "/analytics" },
{ name: "Content creators", href: "/solutions/creators" },
{ name: "Affiliate management", href: "/partners" },
],
resources: [
{ name: "Docs", href: "/docs/introduction" },
{ name: "Help Center", href: "/help" },
{ name: "Changelog", href: "/changelog" },
{ name: "Blog", href: "/blog" },
{ name: "Customers", href: "/customers" },
{
name: "Affiliates",
href: "https://partners.dub.co/dub",
target: "_blank",
},
{ name: "About", href: "/about" },
{ name: "Brand", href: "/brand" },
{ name: "Contact", href: "/contact" },
],
compare: COMPARE_PAGES.map(({ name, slug }) => ({
name,
href: `/compare/${slug}`,
})),
legal: LEGAL_PAGES.map(({ name, slug }) => ({
name,
href: `/legal/${slug}`,
})),
tools: ALL_TOOLS.map(({ name, slug }) => ({
name,
href: `/tools/${slug}`,
})),
};
const linkListHeaderClassName = "text-sm font-medium text-neutral-900";
const linkListClassName = "flex flex-col mt-2.5 gap-3.5";
const linkListItemClassName =
"flex items-center gap-1 text-sm text-neutral-500 hover:text-neutral-700 transition-colors duration-75";
export function Footer({
staticDomain,
className,
}: {
staticDomain?: string;
className?: string;
}) {
let { domain = "dub.co" } = useParams() as { domain: string };
if (staticDomain) {
domain = staticDomain;
}
return (
<MaxWidthWrapper
className={cn(
"relative z-10 overflow-hidden border border-b-0 border-neutral-200 bg-white/50 py-16 backdrop-blur-lg md:rounded-t-2xl",
className,
)}
>
<footer>
<div className="xl:grid xl:grid-cols-3 xl:gap-8">
<div className="flex flex-col gap-6">
<div className="grow">
<Link
href={createHref("/", domain, {
utm_source: "Custom Domain",
utm_medium: "Footer",
utm_campaign: domain,
utm_content: "Logo",
})}
className="block max-w-fit"
>
<span className="sr-only">
{process.env.NEXT_PUBLIC_APP_NAME} Logo
</span>
<NavWordmark className="h-8 text-neutral-800" />
</Link>
</div>
<div className="flex <|fim_suffix|> <div className="grid gap-8">
<div>
<h3 className={linkListHeaderClassName}>Product</h3>
<ul role="list" className={linkListClassName}>
{navigation.product.map((item) => (
<li key={item.name}>
<|fim_middle|>items-center gap-3">
{socials.map(({ name, icon: Icon, href }) => (
<a
key={name}
href={href}
target="_blank"
rel="noreferrer"
className="group rounded-full p-1"
>
<span className="sr-only">{name}</span>
<Icon className="size-4 text-neutral-900 transition-colors duration-75 group-hover:text-neutral-600" />
</a>
))}
</div>
</div>
<div className="mt-16 grid grid-cols-2 gap-4 xl:col-span-2 xl:mt-0">
<div className="md:grid md:grid-cols-2">
|
packages/ui/src/footer.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis r
|
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
elative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis r<|fim_suffix|> className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|>elative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={opt
|
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
ion.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={opt<|fim_suffix|> )}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|>ion.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
|
(
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ?
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
<|fim_suffix|> (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|> return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ?
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
|
>
);
}
|
)}
</button>
))}
</motion.div>
</LayoutGroup
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
<|fim_suffix|>>
);
}
<|fim_middle|> )}
</button>
))}
</motion.div>
</LayoutGroup
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !==
|
(
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) :
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !==<|fim_suffix|> (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|> selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) :
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
|
}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
<|fim_suffix|>}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|> onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
|
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
<|fim_suffix|> indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|> )}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
|
)}
</motion.div>
</LayoutGroup>
);
}
|
transition={{ duration: 0.25 }}
/>
)}
</button>
)
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
<|fim_suffix|>)}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|> transition={{ duration: 0.25 }}
/>
)}
</button>
)
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
|
der-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-bor
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
<|fim_suffix|>der-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|> className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick={() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-bor
|
packages/ui/src/toggle-group.tsx
|
"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}
|
{() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
|
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick=
|
<|fim_prefix|>"use client";
import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "framer-motion";
import { useId } from "react";
interface ToggleOption {
value: string;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
export function ToggleGroup({
options,
selected,
selectAction,
className,
optionClassName,
indicatorClassName,
style,
}: {
options: ToggleOption[];
selected: string | null;
selectAction: (option: string) => void;
className?: string;
optionClassName?: string;
indicatorClassName?: string;
style?: React.CSSProperties;
}) {
const layoutGroupId = useId();
return (
<LayoutGroup id={layoutGroupId}>
<motion.div
layout
className={cn(
"border-border-subtle bg-bg-default relative z-0 inline-flex items-center gap-1 rounded-xl border p-1",
className,
)}
style={style}<|fim_suffix|>{() => selectAction(option.value)}
>
{typeof option.label === "string" ? (
<p>{option.label}</p>
) : (
option.label
)}
{option.badge}
{option.value === selected && (
<motion.div
layoutId={layoutGroupId}
className={cn(
"border-border-subtle bg-bg-muted absolute left-0 top-0 -z-[1] h-full w-full rounded-lg border",
indicatorClassName,
)}
transition={{ duration: 0.25 }}
/>
)}
</button>
))}
</motion.div>
</LayoutGroup>
);
}
<|fim_middle|>
>
{options.map((option) => (
<button
key={option.value}
type="button"
data-selected={option.value === selected}
className={cn(
"text-content-emphasis relative z-10 flex items-center gap-2 px-3 py-1 text-sm font-medium capitalize",
{
"hover:text-content-subtle z-[11] transition-colors":
option.value !== selected,
},
optionClassName,
)}
onClick=
|
packages/ui/src/toggle-group.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithout
|
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
Ref<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithout<|fim_suffix|> {...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>Ref<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<ty
|
imitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
peof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPr
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<ty<|fim_suffix|>imitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>peof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPr
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.
|
Name;
export { Checkbox };
|
Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.display
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.<|fim_suffix|>Name;
export { Checkbox };
<|fim_middle|>Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.display
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-cen
|
ayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
ter">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displ
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-cen<|fim_suffix|>ayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>ter">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displ
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrim
|
w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
itive.Indicator className="flex items-center justify-center">
<Check className="h-3
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrim<|fim_suffix|> w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>itive.Indicator className="flex items-center justify-center">
<Check className="h-3
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...pro
|
CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
ps}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...pro<|fim_suffix|>CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>ps}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disa
|
boxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
bled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</Check
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disa<|fim_suffix|>boxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>bled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</Check
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@
|
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@<|fim_suffix|> )}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPri
|
Checkbox };
|
mitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export {
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPri<|fim_suffix|>Checkbox };
<|fim_middle|>mitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export {
|
packages/ui/src/checkbox.tsx
|
"use client";
import * as CheckboxPrimitiv
|
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
|
e from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
|
<|fim_prefix|>"use client";
import * as CheckboxPrimitiv<|fim_suffix|></CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
export { Checkbox };
<|fim_middle|>e from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";
import { cn } from "@dub/utils";
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-5 w-5 shrink-0 rounded-md border border-neutral-200 bg-white outline-none focus-visible:border-black disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<Check className="h-3 w-3 text-white" />
</CheckboxPrimitive.Indicator>
|
packages/ui/src/checkbox.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl
|
}
animationFrameId = requestAnimationFrame(rend
|
&& canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl <|fim_suffix|> }
animationFrameId = requestAnimationFrame(rend<|fim_middle|>&& canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio ||
|
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || <|fim_suffix|> powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|>1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BU
|
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
FFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BU<|fim_suffix|> animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|>FFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Arr
|
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
ay(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Arr<|fim_suffix|> function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|>ay(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
fl
|
& canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
oat id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl &
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
fl<|fim_suffix|>& canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|>oat id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl &
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
retur
|
t position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
n;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
cons
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
retur<|fim_suffix|>t position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|>n;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
cons
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
|
lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
<|fim_suffix|> lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|> const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
|
stamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTime
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
<|fim_suffix|>stamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|> if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTime
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(sh
|
TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
aderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = canvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(sh<|fim_suffix|>TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|>aderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.
|
packages/ui/src/shimmer-dots.tsx
|
import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = c
|
if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend
|
anvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
|
<|fim_prefix|>import { cn } from "@dub/utils";
import { useEffect, useRef, useState } from "react";
const vertexShader = `
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
`;
const fragmentShader = `
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform float dotSize;
uniform float cellSize;
uniform float speed;
// Gold noise: https://stackoverflow.com/a/28095165
float PHI = 1.61803398874989484820459;
float random(in vec2 xy){
return fract(tan(distance(xy*PHI, xy))*xy.x);
}
void main(void) {
vec2 uv = gl_FragCoord.xy;
vec2 cellUv = vec2(int(uv.x / cellSize), int(uv.y / cellSize));
float id = random(cellUv + 1.0);
float fadeEffect = (sin(time * speed + id * 20.0) + 1.0) * 0.5;
vec2 dotUv = fract(uv / cellSize);
float dot = step(max(dotUv.x, dotUv.y), dotSize / cellSize);
float opacity = dot * fadeEffect;
vec4 fragColor = vec4(vec3(0.0), opacity);
fragColor.rgb *= fragColor.a;
gl_FragColor = fragColor;
}
`;
const TARGET_FPS = 60;
const FRAME_INTERVAL = 1000 / TARGET_FPS;
export function ShimmerDots({
dotSize = 1,
cellSize = 3,
speed = 5,
className,
}: {
dotSize?: number;
cellSize?: number;
speed?: number;
className?: string;
}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
// Whether the WebGL context has been lost
const [contextLost, setContextLost] = useState(false);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas || !canvas.parentElement) return;
const parent = c<|fim_suffix|> if (timestamp - lastTimestamp < FRAME_INTERVAL) {
animationFrameId = requestAnimationFrame(render);
return;
}
lastTimestamp = timestamp;
if (gl && canvas && shaderProgram) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniform1f(time, timestamp / 1000.0);
gl.uniform2f(resolution, canvas.width, canvas.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
animationFrameId = requestAnimationFrame(render);
}
animationFrameId = requestAnimationFrame(rend<|fim_middle|>anvas.parentElement;
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = parent.clientWidth * devicePixelRatio;
canvas.height = parent.clientHeight * devicePixelRatio;
const gl = canvas.getContext("webgl", {
powerPreference: "low-power",
depth: false,
stencil: false,
});
if (gl === null) {
alert("Failed to initialize WebGL");
return;
}
const shaderProgram = gl.createProgram();
if (!shaderProgram) {
console.error("Failed to create shader program");
return;
}
for (let i = 0; i < 2; ++i) {
const source = i === 0 ? vertexShader : fragmentShader;
const shaderObj = gl.createShader(
i === 0 ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
);
if (!shaderObj) {
console.error("Failed to create shader");
return;
}
gl.shaderSource(shaderObj, source);
gl.compileShader(shaderObj);
if (!gl.getShaderParameter(shaderObj, gl.COMPILE_STATUS))
console.error(gl.getShaderInfoLog(shaderObj));
gl.attachShader(shaderProgram, shaderObj);
gl.linkProgram(shaderProgram);
}
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
console.error(gl.getProgramInfoLog(shaderProgram));
const position = gl.getAttribLocation(shaderProgram, "position");
const time = gl.getUniformLocation(shaderProgram, "time");
const resolution = gl.getUniformLocation(shaderProgram, "resolution");
const dotSizeUniform = gl.getUniformLocation(shaderProgram, "dotSize");
const cellSizeUniform = gl.getUniformLocation(shaderProgram, "cellSize");
const speedUniform = gl.getUniformLocation(shaderProgram, "speed");
gl.useProgram(shaderProgram);
const pos = [1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0];
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pos), gl.STATIC_DRAW);
gl.enableVertexAttribArray(position);
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
gl.uniform1f(dotSizeUniform, dotSize * window.devicePixelRatio);
gl.uniform1f(cellSizeUniform, cellSize * window.devicePixelRatio);
gl.uniform1f(speedUniform, speed);
let animationFrameId: number;
let lastTimestamp = 0;
function render(timestamp: number) {
// Skip unncessary frames
|
packages/ui/src/shimmer-dots.tsx
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.