Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Split out @dub/blocks and add/use new PaginationControls component

Tim Wilsonfb0fd7b8f2bb
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsx
index 4acc2ed6c6..b67ce29cb4 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsx
@@ -7,9 +7,9 @@ import DomainCard from "@/ui/domains/domain-card";
import DomainCardPlaceholder from "@/ui/domains/domain-card-placeholder";
import { useAddEditDomainModal } from "@/ui/modals/add-edit-domain-modal";
import EmptyState from "@/ui/shared/empty-state";
-import Pagination from "@/ui/shared/pagination";
import { SearchBoxPersisted } from "@/ui/shared/search-box";
-import { Globe, useRouterStuff } from "@dub/ui";
+import { PaginationControls } from "@dub/blocks/src/pagination-controls";
+import { Globe, usePagination, useRouterStuff } from "@dub/ui";
import { ToggleGroup } from "@dub/ui/src/toggle-group";
import { InfoTooltip, TooltipContent } from "@dub/ui/src/tooltip";
import { DefaultDomains } from "./default-domains";
@@ -30,6 +30,8 @@ export default function WorkspaceDomainsClient() {
const { allWorkspaceDomains, loading } = useDomains({ includeParams: true });
const { data: domainsCount } = useDomainsCount();
+ const { pagination, setPagination } = usePagination(50);
+
return (
<>
<div className="grid gap-5">
@@ -113,11 +115,14 @@ export default function WorkspaceDomainsClient() {
</ul>
)}
</div>
- <Pagination
- pageSize={50}
- totalCount={domainsCount || 0}
- unit="domains"
- />
+ <div className="sticky bottom-0 rounded-b-[inherit] border-t border-gray-200 bg-white px-3.5 py-2">
+ <PaginationControls
+ pagination={pagination}
+ setPagination={setPagination}
+ totalCount={domainsCount || 0}
+ unit={(p) => `domain${p ? "s" : ""}`}
+ />
+ </div>
</div>
<DefaultDomains />
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
index 9fc231c199..8cadd789f5 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
@@ -4,7 +4,7 @@ import { EventType } from "@/lib/analytics/types";
import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";
import { leadEventEnrichedSchema } from "@/lib/zod/schemas/leads";
import { saleEventEnrichedSchema } from "@/lib/zod/schemas/sales";
-import { EventList } from "@/ui/blocks/event-list";
+import { EventList } from "@dub/blocks";
import { CursorRays, Globe, InvoiceDollar, UserCheck } from "@dub/ui/src/icons";
import { COUNTRIES, timeAgo } from "@dub/utils";
import { useSearchParams } from "next/navigation";
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
index d45fa5a26e..ea0d3cdd64 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
@@ -1,6 +1,6 @@
import { EventType } from "@/lib/analytics/types";
import { dub } from "@/lib/dub";
-import { EventListSkeleton } from "@/ui/blocks/event-list";
+import { EventListSkeleton } from "@dub/blocks";
import { CopyButton, Logo } from "@dub/ui";
import { Check } from "@dub/ui/src/icons";
import { getPrettyUrl } from "@dub/utils";
diff --git a/apps/web/package.json b/apps/web/package.json
index 7168a54e26..bbcb261478 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -19,6 +19,7 @@
"@dub/analytics": "^0.0.14",
"@dub/tailwind-config": "workspace:*",
"@dub/ui": "workspace:*",
+ "@dub/blocks": "workspace:*",
"@dub/utils": "workspace:*",
"@hookform/resolvers": "^3.9.0",
"@next-auth/prisma-adapter": "^1.0.5",
diff --git a/apps/web/tailwind.config.ts b/apps/web/tailwind.config.ts
index 2b570d3ad8..9020aa0f49 100644
--- a/apps/web/tailwind.config.ts
+++ b/apps/web/tailwind.config.ts
@@ -10,6 +10,7 @@ const config: Pick<Config, "presets"> = {
"./ui/**/*.{js,ts,jsx,tsx}",
// h/t to https://www.willliu.com/blog/Why-your-Tailwind-styles-aren-t-working-in-your-Turborepo
"../../packages/ui/src/**/*{.js,.ts,.jsx,.tsx}",
+ "../../packages/blocks/src/**/*{.js,.ts,.jsx,.tsx}",
],
theme: {
extend: {
diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json
index 654bd7eba5..eb47f6ac23 100644
--- a/apps/web/tsconfig.json
+++ b/apps/web/tsconfig.json
@@ -30,6 +30,13 @@
}
]
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ ".next/types/**/*.ts",
+ "../../packages/blocks/src/event-list.tsx",
+ "../../packages/ui/src/hooks/use-pagination.ts"
+ ],
"exclude": ["node_modules"]
}
diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsx
index 0f051bb25a..63214d8b98 100644
--- a/apps/web/ui/analytics/events/events-table.tsx
+++ b/apps/web/ui/analytics/events/events-table.tsx
@@ -6,7 +6,14 @@ import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";
import { leadEventEnrichedSchema } from "@/lib/zod/schemas/leads";
import { saleEventEnrichedSchema } from "@/lib/zod/schemas/sales";
import EmptyState from "@/ui/shared/empty-state";
-import { LinkLogo, Table, Tooltip, useRouterStuff, useTable } from "@dub/ui";
+import {
+ LinkLogo,
+ Table,
+ Tooltip,
+ usePagination,
+ useRouterStuff,
+ useTable,
+} from "@dub/ui";
import {
CursorRays,
FilterBars,
@@ -37,7 +44,6 @@ import { EventsContext } from "./events-provider";
import { exampleData } from "./example-data";
import { RowMenuButton } from "./row-menu-button";
import { eventColumns, useColumnVisibility } from "./use-column-visibility";
-import usePagination from "./use-pagination";
export type EventDatum =
| z.infer<typeof clickEventEnrichedSchema>
diff --git a/apps/web/ui/blocks/pagination-controls.tsx b/apps/web/ui/blocks/pagination-controls.tsx
new file mode 100644
index 0000000000..0578aaee78
--- /dev/null
+++ b/apps/web/ui/blocks/pagination-controls.tsx
@@ -0,0 +1,7 @@
+export type PaginationState = {
+ page: number;
+ pageSize: number;
+ total: number;
+};
+
+export function PaginationControls() {}
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 3d18d9d049..a917ddccc8 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -3,11 +3,12 @@
import useLinks from "@/lib/swr/use-links";
import useLinksCount from "@/lib/swr/use-links-count";
import { LinkWithTagsProps, UserProps } from "@/lib/types";
+import { PaginationControls } from "@dub/blocks/src/pagination-controls";
import {
CardList,
MaxWidthWrapper,
useInputFocused,
- useRouterStuff,
+ usePagination,
} from "@dub/ui";
import { LoadingSpinner } from "@dub/ui/src/icons";
import { useSearchParams } from "next/navigation";
@@ -75,11 +76,10 @@ function LinksList({
loading?: boolean;
compact: boolean;
}) {
- const { queryParams } = useRouterStuff();
const searchParams = useSearchParams();
const showHoverStates = !useInputFocused();
- const page = (parseInt(searchParams?.get("page") || "1") || 1) - 1;
+ const { pagination, setPagination } = usePagination();
const [openMenuLinkId, setOpenMenuLinkId] = useState<string | null>(null);
@@ -122,31 +122,27 @@ function LinksList({
{/* Pagination */}
{links && (
- <CardList.Pagination
- page={page}
- onPageChange={(p) => {
- const newPage = p(page);
- queryParams(
- newPage === 0
- ? { del: "page" }
- : {
- set: {
- page: (newPage + 1).toString(),
- },
- },
- );
- }}
- totalCount={count ?? links?.length ?? 0}
- resourceName={(plural) => `${plural ? "links" : "link"}`}
- >
- {loading ? (
- <LoadingSpinner className="size-3.5" />
- ) : (
- <div className="hidden sm:block">
- <ArchivedLinksHint />
+ <>
+ <div className="h-[90px]" />
+ <div className="fixed bottom-4 left-1/2 w-full max-w-[768px] -translate-x-1/2 px-2.5 max-[920px]:bottom-5 max-[920px]:pr-20">
+ <div className="rounded-xl border border-gray-200 bg-white px-4 py-3.5 [filter:drop-shadow(0_5px_8px_#222A351d)]">
+ <PaginationControls
+ pagination={pagination}
+ setPagination={setPagination}
+ totalCount={count ?? links?.length ?? 0}
+ unit={(plural) => `${plural ? "links" : "link"}`}
+ >
+ {loading ? (
+ <LoadingSpinner className="size-3.5" />
+ ) : (
+ <div className="hidden sm:block">
+ <ArchivedLinksHint />
+ </div>
+ )}
+ </PaginationControls>
</div>
- )}
- </CardList.Pagination>
+ </div>
+ </>
)}
</>
);
diff --git a/apps/web/ui/shared/pagination.tsx b/apps/web/ui/shared/pagination.tsx
deleted file mode 100644
index 369f7dd99b..0000000000
--- a/apps/web/ui/shared/pagination.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import { Button } from "@dub/ui";
-import usePagination from "../analytics/events/use-pagination";
-
-export default function Pagination({
- pageSize,
- totalCount,
- unit,
-}: {
- pageSize: number;
- totalCount: number;
- unit: string;
-}) {
- const { pagination, setPagination } = usePagination(pageSize);
-
- return (
- <div className="sticky bottom-0 flex items-center justify-between rounded-b-[inherit] border-t border-gray-200 bg-white px-4 py-3.5 text-sm leading-6 text-gray-600">
- <div>
- <span className="hidden sm:inline-block">Viewing</span>{" "}
- <span className="font-medium">
- {pagination.pageIndex * pagination.pageSize + 1}-
- {Math.min(
- pagination.pageIndex * pagination.pageSize + pagination.pageSize,
- totalCount,
- )}
- </span>{" "}
- of <span className="font-medium">{totalCount}</span> {unit}
- </div>
- <div className="flex items-center gap-2">
- <Button
- variant="secondary"
- text="Previous"
- className="h-7 px-2"
- onClick={() =>
- setPagination({
- pageIndex: pagination.pageIndex - 1,
- pageSize: pagination.pageSize,
- })
- }
- disabled={pagination.pageIndex === 0}
- />
- <Button
- variant="secondary"
- text="Next"
- className="h-7 px-2"
- onClick={() =>
- setPagination({
- pageIndex: pagination.pageIndex + 1,
- pageSize: pagination.pageSize,
- })
- }
- disabled={
- pagination.pageIndex * pagination.pageSize + pagination.pageSize >=
- totalCount
- }
- />
- </div>
- </div>
- );
-}
diff --git a/packages/blocks/README.md b/packages/blocks/README.md
new file mode 100644
index 0000000000..a22876d7b9
--- /dev/null
+++ b/packages/blocks/README.md
@@ -0,0 +1,11 @@
+# `@dub/blocks`
+
+`@dub/blocks` is a library of React components built by Dub.
+
+## Installation
+
+To install the package, run:
+
+```bash
+pnpm i @dub/blocks
+```
diff --git a/packages/blocks/package.json b/packages/blocks/package.json
new file mode 100644
index 0000000000..8f3f2f6654
--- /dev/null
+++ b/packages/blocks/package.json
@@ -0,0 +1,58 @@
+{
+ "name": "@dub/blocks",
+ "description": "UI components built by Dub",
+ "version": "0.0.1",
+ "sideEffects": false,
+ "main": "./dist/index.js",
+ "module": "./dist/index.mjs",
+ "types": "./dist/index.d.ts",
+ "files": [
+ "dist/**"
+ ],
+ "scripts": {
+ "build": "tsup",
+ "lint": "eslint src/",
+ "dev": "tsup --watch",
+ "check-types": "tsc --noEmit"
+ },
+ "peerDependencies": {
+ "next": "14.2.0-canary.47",
+ "react": "^18.2.0",
+ "react-dom": "^18.2.0",
+ "@dub/ui": "workspace:*",
+ "@dub/utils": "workspace:*"
+ },
+ "devDependencies": {
+ "@dub/tailwind-config": "workspace:*",
+ "@types/react": "^18.2.47",
+ "@types/react-dom": "^18.2.14",
+ "autoprefixer": "^10.4.16",
+ "next": "14.2.0-canary.67",
+ "postcss": "^8.4.31",
+ "react": "^18.2.0",
+ "tailwindcss": "^3.4.4",
+ "tsconfig": "workspace:*",
+ "tsup": "^6.1.3",
+ "typescript": "^5.1.6"
+ },
+ "dependencies": {
+ "class-variance-authority": "^0.7.0"
+ },
+ "author": "Steven Tey <[email protected]>",
+ "homepage": "https://dub.co",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/dubinc/dub.git"
+ },
+ "bugs": {
+ "url": "https://github.com/dubinc/dub/issues"
+ },
+ "keywords": [
+ "dub",
+ "dub.co",
+ "blocks"
+ ],
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/blocks/postcss.config.js b/packages/blocks/postcss.config.js
new file mode 100644
index 0000000000..07aa434b2b
--- /dev/null
+++ b/packages/blocks/postcss.config.js
@@ -0,0 +1,9 @@
+// If you want to use other PostCSS plugins, see the following:
+// https://tailwindcss.com/docs/using-with-preprocessors
+
+module.exports = {
+ plugins: {
+ tailwindcss: {},
+ autoprefixer: {},
+ },
+};
diff --git a/apps/web/ui/blocks/event-list.tsx b/packages/blocks/src/event-list.tsx
similarity index 51%
rename from apps/web/ui/blocks/event-list.tsx
rename to packages/blocks/src/event-list.tsx
index 8927301c03..7ae72f0c9f 100644
--- a/apps/web/ui/blocks/event-list.tsx
+++ b/packages/blocks/src/event-list.tsx
@@ -1,8 +1,8 @@
"use client";
-import { nFormatter, PAGINATION_LIMIT } from "@dub/utils";
+import { usePagination } from "@dub/ui";
import { PropsWithChildren, ReactNode } from "react";
-import usePagination from "../analytics/events/use-pagination";
+import { PaginationControls } from "./pagination-controls";
export type EventListProps = PropsWithChildren<{
events: { icon: ReactNode; content: ReactNode; right?: ReactNode }[];
@@ -16,7 +16,8 @@ const buttonClassName = [
].join(" ");
export function EventList({ events, totalEvents }: EventListProps) {
- const { pagination, setPagination } = usePagination(PAGINATION_LIMIT);
+ const { pagination, setPagination } = usePagination();
+
return (
<div className="rounded-xl border border-gray-200">
<div className="flex flex-col divide-y divide-gray-200">
@@ -35,54 +36,13 @@ export function EventList({ events, totalEvents }: EventListProps) {
</div>
))}
</div>
- <div className="sticky bottom-0 flex items-center justify-between gap-2 rounded-b-[inherit] border-t border-gray-200 bg-white px-3.5 py-2 text-sm leading-6 text-gray-600">
- <div>
- <span className="hidden sm:inline-block">Viewing</span>{" "}
- <span className="font-medium">
- {pagination.pageIndex * pagination.pageSize + 1}-
- {Math.min(
- pagination.pageIndex * pagination.pageSize + pagination.pageSize,
- totalEvents,
- )}
- </span>{" "}
- of{" "}
- <span className="font-medium">
- {nFormatter(totalEvents, { full: true })}
- </span>{" "}
- events
- </div>
- <div className="flex items-center gap-2">
- <button
- type="button"
- className={buttonClassName}
- onClick={() =>
- setPagination({
- pageIndex: pagination.pageIndex - 1,
- pageSize: pagination.pageSize,
- })
- }
- disabled={pagination.pageIndex === 0}
- >
- Previous
- </button>
- <button
- type="button"
- className={buttonClassName}
- onClick={() =>
- setPagination({
- pageIndex: pagination.pageIndex + 1,
- pageSize: pagination.pageSize,
- })
- }
- disabled={
- pagination.pageIndex * pagination.pageSize +
- pagination.pageSize >=
- totalEvents
- }
- >
- Next
- </button>
- </div>
+ <div className="sticky bottom-0 rounded-b-[inherit] border-t border-gray-200 bg-white px-3.5 py-2">
+ <PaginationControls
+ pagination={pagination}
+ setPagination={setPagination}
+ totalCount={totalEvents}
+ unit={(p) => `event${p ? "s" : ""}`}
+ />
</div>
</div>
);
diff --git a/packages/blocks/src/index.tsx b/packages/blocks/src/index.tsx
new file mode 100644
index 0000000000..456086cade
--- /dev/null
+++ b/packages/blocks/src/index.tsx
@@ -0,0 +1,5 @@
+// styles
+import "./styles.css";
+
+export * from "./event-list";
+export * from "./pagination-controls";
diff --git a/packages/blocks/src/pagination-controls.tsx b/packages/blocks/src/pagination-controls.tsx
new file mode 100644
index 0000000000..19b35b9148
--- /dev/null
+++ b/packages/blocks/src/pagination-controls.tsx
@@ -0,0 +1,88 @@
+import { PaginationState } from "@dub/ui";
+import { cn, nFormatter } from "@dub/utils";
+import { PropsWithChildren } from "react";
+
+const buttonClassName = cn(
+ "flex h-7 items-center justify-center gap-2 whitespace-nowrap rounded-md border border-gray-200 bg-white px-2 text-sm text-gray-600",
+ "outline-none hover:bg-gray-50 focus-visible:border-gray-500",
+ "disabled:cursor-not-allowed disabled:border-gray-200 disabled:text-gray-400 disabled:bg-gray-100",
+);
+
+export function PaginationControls({
+ pagination,
+ setPagination,
+ totalCount,
+ unit = (p) => `item${p ? "s" : ""}`,
+ className,
+ children,
+}: PropsWithChildren<{
+ pagination: PaginationState;
+ setPagination: (pagination: PaginationState) => void;
+ totalCount: number;
+ unit?: string | ((plural: boolean) => string);
+ className?: string;
+}>) {
+ return (
+ <div
+ className={cn(
+ "flex items-center justify-between gap-2 text-sm leading-6 text-gray-600",
+ className,
+ )}
+ >
+ <div className="flex items-center gap-2">
+ <div>
+ <span className="hidden sm:inline-block">Viewing</span>{" "}
+ {totalCount > 0 && (
+ <>
+ <span className="font-medium">
+ {pagination.pageIndex * pagination.pageSize + 1}-
+ {Math.min(
+ pagination.pageIndex * pagination.pageSize +
+ pagination.pageSize,
+ totalCount,
+ )}
+ </span>{" "}
+ of{" "}
+ </>
+ )}
+ <span className="font-medium">
+ {nFormatter(totalCount, { full: true })}
+ </span>{" "}
+ {typeof unit === "function" ? unit(totalCount !== 1) : unit}
+ </div>
+ {children}
+ </div>
+ <div className="flex items-center gap-2">
+ <button
+ type="button"
+ className={buttonClassName}
+ onClick={() =>
+ setPagination({
+ ...pagination,
+ pageIndex: pagination.pageIndex - 1,
+ })
+ }
+ disabled={pagination.pageIndex === 0}
+ >
+ Previous
+ </button>
+ <button
+ type="button"
+ className={buttonClassName}
+ onClick={() =>
+ setPagination({
+ ...pagination,
+ pageIndex: pagination.pageIndex + 1,
+ })
+ }
+ disabled={
+ pagination.pageIndex * pagination.pageSize + pagination.pageSize >=
+ totalCount
+ }
+ >
+ Next
+ </button>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/blocks/src/styles.css b/packages/blocks/src/styles.css
new file mode 100644
index 0000000000..b5c61c9567
--- /dev/null
+++ b/packages/blocks/src/styles.css
@@ -0,0 +1,3 @@
+@tailwind base;
+@tailwind components;
+@tailwind utilities;
diff --git a/packages/blocks/tailwind.config.ts b/packages/blocks/tailwind.config.ts
new file mode 100644
index 0000000000..5c39ec95b9
--- /dev/null
+++ b/packages/blocks/tailwind.config.ts
@@ -0,0 +1,9 @@
+// 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;
diff --git a/packages/blocks/tsconfig.json b/packages/blocks/tsconfig.json
new file mode 100644
index 0000000000..cd6c94d6e8
--- /dev/null
+++ b/packages/blocks/tsconfig.json
@@ -0,0 +1,5 @@
+{
+ "extends": "tsconfig/react-library.json",
+ "include": ["."],
+ "exclude": ["dist", "build", "node_modules"]
+}
diff --git a/packages/blocks/tsup.config.ts b/packages/blocks/tsup.config.ts
new file mode 100644
index 0000000000..6a8a1e5cb0
--- /dev/null
+++ b/packages/blocks/tsup.config.ts
@@ -0,0 +1,15 @@
+import { defineConfig, Options } from "tsup";
+
+export default defineConfig((options: Options) => ({
+ entry: ["src/**/*.tsx"],
+ format: ["esm"],
+ esbuildOptions(options) {
+ options.banner = {
+ js: '"use client"',
+ };
+ },
+ dts: true,
+ minify: true,
+ external: ["react"],
+ ...options,
+}));
diff --git a/packages/ui/src/card-list/card-list-pagination.tsx b/packages/ui/src/card-list/card-list-pagination.tsx
deleted file mode 100644
index 41fdc37bea..0000000000
--- a/packages/ui/src/card-list/card-list-pagination.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-import { PAGINATION_LIMIT } from "@dub/utils";
-import { PropsWithChildren } from "react";
-import { Button } from "../button";
-
-export function CardListPagination({
- page,
- onPageChange,
- pageSize = PAGINATION_LIMIT,
- totalCount,
- resourceName = (plural) => `item${plural ? "s" : ""}`,
- children,
-}: PropsWithChildren<{
- page: number;
- onPageChange: (fn: (prev: number) => number) => void;
- pageSize?: number;
- totalCount: number;
- resourceName?: (plural: boolean) => string;
-}>) {
- return (
- <>
- {/* Placeholder to make room for the floating pagination at the bottom of the list */}
- <div className="h-[90px]" />
- <div className="fixed bottom-4 left-1/2 w-full max-w-[768px] -translate-x-1/2 px-2.5 max-[920px]:bottom-5 max-[920px]:pr-20">
- <nav className="flex w-full items-center justify-between rounded-xl border border-gray-200 bg-white px-4 py-3.5 text-sm leading-6 text-gray-600 [filter:drop-shadow(0_5px_8px_#222A351d)]">
- <div className="flex items-center gap-2">
- <div>
- <span className="hidden sm:inline-block">Viewing</span>{" "}
- <span className="font-medium">
- {page * pageSize + (totalCount ? 1 : 0)}-
- {Math.min(page * pageSize + pageSize, totalCount)}
- </span>{" "}
- of{" "}
- <span className="font-medium">{totalCount.toLocaleString()}</span>{" "}
- {resourceName?.(totalCount !== 1) || "items"}
- </div>
- {children}
- </div>
- <div className="flex items-center gap-2">
- <Button
- variant="secondary"
- text="Previous"
- className="h-7 px-2"
- onClick={() => onPageChange((prev) => prev - 1)}
- disabled={page < 1}
- />
- <Button
- variant="secondary"
- text="Next"
- className="h-7 px-2"
- onClick={() => onPageChange((prev) => prev + 1)}
- disabled={(page + 1) * pageSize >= totalCount}
- />
- </div>
- </nav>
- </div>
- </>
- );
-}
diff --git a/packages/ui/src/card-list/index.ts b/packages/ui/src/card-list/index.ts
index 2ba4581e67..ebad8d9a59 100644
--- a/packages/ui/src/card-list/index.ts
+++ b/packages/ui/src/card-list/index.ts
@@ -1,13 +1,11 @@
import { CardList as CardListComponent, CardListContext } from "./card-list";
import { CardContext, CardListCard } from "./card-list-card";
-import { CardListPagination } from "./card-list-pagination";
const CardList = Object.assign(CardListComponent, {
Card: Object.assign(CardListCard, {
Context: CardContext,
}),
Context: CardListContext,
- Pagination: CardListPagination,
});
export { CardList };
diff --git a/packages/ui/src/hooks/index.ts b/packages/ui/src/hooks/index.ts
index e12102b71a..1d3693d235 100644
--- a/packages/ui/src/hooks/index.ts
+++ b/packages/ui/src/hooks/index.ts
@@ -8,6 +8,7 @@ export * from "./use-keyboard-shortcut";
export * from "./use-local-storage";
export * from "./use-media-query";
export * from "./use-optimistic-update";
+export * from "./use-pagination";
export * from "./use-resize-observer";
export * from "./use-router-stuff";
export * from "./use-scroll";
diff --git a/apps/web/ui/analytics/events/use-pagination.ts b/packages/ui/src/hooks/use-pagination.ts
similarity index 81%
rename from apps/web/ui/analytics/events/use-pagination.ts
rename to packages/ui/src/hooks/use-pagination.ts
index f47540d914..36e2ef930d 100644
--- a/apps/web/ui/analytics/events/use-pagination.ts
+++ b/packages/ui/src/hooks/use-pagination.ts
@@ -1,8 +1,14 @@
-import { useRouterStuff, useTablePagination } from "@dub/ui";
import { PAGINATION_LIMIT } from "@dub/utils";
import { useEffect, useMemo } from "react";
+import { useTablePagination } from "../table/use-table-pagination";
+import { useRouterStuff } from "./use-router-stuff";
-export default function usePagination(pageSize = PAGINATION_LIMIT) {
+export type PaginationState = {
+ pageIndex: number;
+ pageSize: number;
+};
+
+export function usePagination(pageSize = PAGINATION_LIMIT) {
const { searchParams, queryParams } = useRouterStuff();
const page = useMemo(
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 02a9545fc9..1df9068afb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -47,6 +47,9 @@ importers:
'@dub/analytics':
specifier: ^0.0.14
version: 0.0.14
+ '@dub/blocks':
+ specifier: workspace:*
+ version: link:../../packages/blocks
'@dub/tailwind-config':
specifier: workspace:*
version: link:../../packages/tailwind-config
@@ -412,6 +415,55 @@ importers:
specifier: 1.5.0
version: 1.5.0(@types/[email protected])
+ packages/blocks:
+ dependencies:
+ '@dub/ui':
+ specifier: workspace:*
+ version: link:../ui
+ '@dub/utils':
+ specifier: workspace:*
+ version: link:../utils
+ class-variance-authority:
+ specifier: ^0.7.0
+ version: 0.7.0
+ react-dom:
+ specifier: ^18.2.0
+ version: 18.2.0([email protected])
+ devDependencies:
+ '@dub/tailwind-config':
+ specifier: workspace:*
+ version: link:../tailwind-config
+ '@types/react':
+ specifier: ^18.2.47
+ version: 18.2.48
+ '@types/react-dom':
+ specifier: ^18.2.14
+ version: 18.2.14
+ autoprefixer:
+ specifier: ^10.4.16
+ version: 10.4.16([email protected])
+ next:
+ specifier: 14.2.0-canary.67
+ version: 14.2.0-canary.67([email protected])([email protected])
+ postcss:
+ specifier: ^8.4.31
+ version: 8.4.38
+ react:
+ specifier: ^18.2.0
+ version: 18.2.0
+ tailwindcss:
+ specifier: ^3.4.4
+ version: 3.4.4
+ tsconfig:
+ specifier: workspace:*
+ version: link:../tsconfig
+ tsup:
+ specifier: ^6.1.3
+ typescript:
+ specifier: ^5.1.6
+ version: 5.5.3
+
packages/stripe-app:
dependencies:
'@stripe/ui-extension-sdk':
@@ -1583,7 +1635,7 @@ packages:
engines: {node: '>=6.9.0'}
dependencies:
'@babel/highlight': 7.24.7
- picocolors: 1.0.0
+ picocolors: 1.0.1
resolution: {integrity: sha512-BQYjKbpXjoXwFW5jGqiizJQQT/aC7pFm9Ok1OWssonuguICi264lbgMzRp2ZMmRSlfkX6DsWDDcsrctK8Rwfiw==}
@@ -1644,7 +1696,7 @@ packages:
engines: {node: '>=6.9.0'}
dependencies:
'@babel/types': 7.23.0
- '@jridgewell/gen-mapping': 0.3.3
+ '@jridgewell/gen-mapping': 0.3.5
'@jridgewell/trace-mapping': 0.3.22
jsesc: 2.5.2
dev: true
@@ -1678,7 +1730,7 @@ packages:
dependencies:
'@babel/compat-data': 7.22.20
'@babel/helper-validator-option': 7.22.15
- browserslist: 4.22.1
+ browserslist: 4.23.3
lru-cache: 5.1.1
semver: 6.3.1
dev: true
@@ -1937,7 +1989,7 @@ packages:
'@babel/helper-validator-identifier': 7.24.7
chalk: 2.4.2
js-tokens: 4.0.0
- picocolors: 1.0.0
+ picocolors: 1.0.1
resolution: {integrity: sha512-zTvEBcghmeBma9QIGunWevvBAp4/Qu9Bdq+2k0Ot4fVMD6v3dsC9WOcRSKk7tRRyBM/53yKMJko9xOatGQAwSg==}
@@ -10415,7 +10467,7 @@ packages:
caniuse-lite: 1.0.30001583
fraction.js: 4.3.6
normalize-range: 0.1.2
- picocolors: 1.0.0
+ picocolors: 1.0.1
postcss: 8.4.38
postcss-value-parser: 4.2.0
dev: false
@@ -10436,6 +10488,22 @@ packages:
postcss-value-parser: 4.2.0
dev: true
+ resolution: {integrity: sha512-7vd3UC6xKp0HLfua5IjZlcXvGAGy7cBAXTg2lyQ/8WpNhd6SiZ8Be+xm3FyBSYJx5GKcpRCzBh7RH4/0dnY+uQ==}
+ engines: {node: ^10 || ^12 || >=14}
+ hasBin: true
+ peerDependencies:
+ postcss: ^8.1.0
+ dependencies:
+ browserslist: 4.23.3
+ caniuse-lite: 1.0.30001651
+ fraction.js: 4.3.6
+ normalize-range: 0.1.2
+ picocolors: 1.0.1
+ postcss: 8.4.38
+ postcss-value-parser: 4.2.0
+ dev: true
+
resolution: {integrity: sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==}
engines: {node: '>= 0.4'}
@@ -16682,7 +16750,7 @@ packages:
'@next/env': 14.2.0-canary.67
'@swc/helpers': 0.5.5
busboy: 1.6.0
- caniuse-lite: 1.0.30001583
+ caniuse-lite: 1.0.30001651
graceful-fs: 4.2.11
postcss: 8.4.31
react: 18.2.0
@@ -17408,6 +17476,23 @@ packages:
yaml: 1.10.2
dev: true
+ resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==}
+ engines: {node: '>= 10'}
+ peerDependencies:
+ postcss: '>=8.0.9'
+ ts-node: '>=9.0.0'
+ peerDependenciesMeta:
+ postcss:
+ optional: true
+ ts-node:
+ optional: true
+ dependencies:
+ lilconfig: 2.1.0
+ postcss: 8.4.38
+ yaml: 1.10.2
+ dev: true
+
resolution: {integrity: sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA==}
engines: {node: '>= 14'}
@@ -17464,7 +17549,7 @@ packages:
engines: {node: ^10 || ^12 || >=14}
dependencies:
nanoid: 3.3.7
- picocolors: 1.0.0
+ picocolors: 1.0.1
source-map-js: 1.2.0
@@ -19612,7 +19697,7 @@ packages:
micromatch: 4.0.5
normalize-path: 3.0.0
object-hash: 3.0.0
- picocolors: 1.0.0
+ picocolors: 1.0.1
postcss: 8.4.38
postcss-import: 15.1.0([email protected])
postcss-js: 4.0.1([email protected])
@@ -19959,6 +20044,43 @@ packages:
- ts-node
dev: true
+ resolution: {integrity: sha512-eRpBnbfpDFng+EJNTQ90N7QAf4HAGGC7O3buHIjroKWK7D1ibk9/YnR/3cS8HsMU5T+6Oi+cnF+yU5WmCnB//Q==}
+ engines: {node: '>=14'}
+ hasBin: true
+ peerDependencies:
+ '@swc/core': ^1
+ postcss: ^8.4.12
+ typescript: ^4.1.0
+ peerDependenciesMeta:
+ '@swc/core':
+ optional: true
+ postcss:
+ optional: true
+ typescript:
+ optional: true
+ dependencies:
+ bundle-require: 3.1.2([email protected])
+ cac: 6.7.14
+ chokidar: 3.5.3
+ debug: 4.3.4
+ esbuild: 0.14.54
+ execa: 5.1.1
+ globby: 11.1.0
+ joycon: 3.1.1
+ postcss: 8.4.38
+ postcss-load-config: 3.1.4([email protected])
+ resolve-from: 5.0.0
+ rollup: 2.79.1
+ source-map: 0.8.0-beta.0
+ sucrase: 3.34.0
+ tree-kill: 1.2.2
+ typescript: 5.5.3
+ transitivePeerDependencies:
+ - supports-color
+ - ts-node
+ dev: true
+
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}
@@ -20499,7 +20621,7 @@ packages:
dependencies:
browserslist: 4.22.1
escalade: 3.1.1
- picocolors: 1.0.0
+ picocolors: 1.0.1
resolution: {integrity: sha512-EdRAaAyk2cUE1wOf2DkEhzxqOQvFOoRJFNS6NeyJ01Gp2beMRpBAINjM2iDXE3KCuKhwnvHIQCJm6ThL2Z+HzQ==}