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.

Update export and column editing UI

Tim Wilson2ebe22dfcff7
diff --git a/apps/web/ui/analytics/analytics-options.tsx b/apps/web/ui/analytics/analytics-options.tsx
index f25aad077b..af0d07c08a 100644
--- a/apps/web/ui/analytics/analytics-options.tsx
+++ b/apps/web/ui/analytics/analytics-options.tsx
@@ -8,11 +8,7 @@ import { AnalyticsContext } from "./analytics-provider";
import ExportButton from "./export-button";
import ShareAnalytics from "./share-analytics";
-export default function AnalyticsOptions({
- page,
-}: {
- page: "analytics" | "events";
-}) {
+export default function AnalyticsOptions() {
const { isMobile } = useMediaQuery();
const { key } = useContext(AnalyticsContext);
const [openPopover, setOpenPopover] = useState(false);
@@ -33,8 +29,8 @@ export default function AnalyticsOptions({
{state === "default" && (
<div className="grid w-screen gap-px p-2 sm:w-48">
- <ExportButton page={page} setOpenPopover={setOpenPopover} />
- {page === "analytics" && key && (
+ <ExportButton setOpenPopover={setOpenPopover} />
+ {key && (
<Button
text="Share Analytics"
variant="outline"
diff --git a/apps/web/ui/analytics/events/edit-columns-button.tsx b/apps/web/ui/analytics/events/edit-columns-button.tsx
new file mode 100644
index 0000000000..67a898b411
--- /dev/null
+++ b/apps/web/ui/analytics/events/edit-columns-button.tsx
@@ -0,0 +1,52 @@
+import { Button, Gear, Popover } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { Table } from "@tanstack/react-table";
+import { Command } from "cmdk";
+import { useState } from "react";
+
+export default function EditColumnsButton({ table }: { table: Table<any> }) {
+ const [isOpen, setIsOpen] = useState(false);
+
+ return (
+ <Popover
+ openPopover={isOpen}
+ setOpenPopover={setIsOpen}
+ content={
+ <Command tabIndex={0} loop className="focus:outline-none">
+ <Command.List className="flex w-screen flex-col gap-1 p-1 text-sm sm:w-auto sm:min-w-[130px]">
+ {table
+ .getAllColumns()
+ .filter((c) => c.getCanHide())
+ .map((column) => (
+ <Command.Item
+ key={column.id}
+ className={cn(
+ "flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-md px-3 py-1.5",
+ "data-[selected=true]:bg-gray-100",
+ )}
+ onSelect={() => column.toggleVisibility()}
+ >
+ <input
+ checked={column.getIsVisible()}
+ type="checkbox"
+ className="h-3 w-3 rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"
+ disabled
+ />
+ {column.columnDef.header?.toString()}
+ </Command.Item>
+ ))}
+ </Command.List>
+ </Command>
+ }
+ align="end"
+ >
+ <Button
+ type="button"
+ className="h-8 whitespace-nowrap px-3"
+ variant="secondary"
+ icon={<Gear className="h-4 w-4 shrink-0" />}
+ text="Edit columns"
+ />
+ </Popover>
+ );
+}
diff --git a/apps/web/ui/analytics/events/events-table-menu.tsx b/apps/web/ui/analytics/events/events-table-menu.tsx
deleted file mode 100644
index 56e94d635f..0000000000
--- a/apps/web/ui/analytics/events/events-table-menu.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import { AnimatedSizeContainer, Popover, useMediaQuery } from "@dub/ui";
-import { cn } from "@dub/utils";
-import { Table } from "@tanstack/react-table";
-import { Command } from "cmdk";
-import { Ellipsis } from "lucide-react";
-import { RefObject, useState } from "react";
-
-export default function EventsTableMenu({
- table,
- scrollContainer,
-}: {
- table: Table<any>;
- scrollContainer: RefObject<Element>;
-}) {
- const { isMobile } = useMediaQuery();
-
- const [isOpen, setIsOpen] = useState(false);
-
- return (
- <Popover
- openPopover={isOpen}
- setOpenPopover={setIsOpen}
- collisionBoundary={scrollContainer.current ?? undefined}
- sticky="always"
- content={
- <AnimatedSizeContainer
- width={!isMobile}
- height
- className="rounded-[inherit]"
- style={{ transform: "translateZ(0)" }} // Fixes overflow on some browsers
- >
- <Command tabIndex={0} loop className="focus:outline-none">
- <Command.List className="flex w-screen flex-col gap-1 p-1 text-sm sm:w-auto sm:min-w-[130px]">
- {table
- .getAllColumns()
- .filter((c) => c.getCanHide())
- .map((column) => (
- <Command.Item
- key={column.id}
- className={cn(
- "flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-md px-3 py-1.5",
- "data-[selected=true]:bg-gray-100",
- )}
- onSelect={() => column.toggleVisibility()}
- >
- <input
- checked={column.getIsVisible()}
- type="checkbox"
- className="h-3 w-3 rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"
- disabled
- />
- {column.columnDef.header?.toString()}
- </Command.Item>
- ))}
- </Command.List>
- </Command>
- </AnimatedSizeContainer>
- }
- align="end"
- >
- <button
- type="button"
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-600 hover:bg-gray-100 active:text-gray-950"
- >
- <Ellipsis className="h-4 w-4" />
- </button>
- </Popover>
- );
-}
diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsx
index 07c5a98363..bb189ae151 100644
--- a/apps/web/ui/analytics/events/events-table.tsx
+++ b/apps/web/ui/analytics/events/events-table.tsx
@@ -35,11 +35,11 @@ import Link from "next/link";
import { useContext, useEffect, useMemo, useRef, useState } from "react";
import useSWR from "swr";
import z from "zod";
-import { EventsTableContext } from ".";
import { AnalyticsContext } from "../analytics-provider";
import DeviceIcon from "../device-icon";
+import EditColumnsButton from "./edit-columns-button";
import EventsLinkType from "./events-link-type";
-import EventsTableMenu from "./events-table-menu";
+import ExportButton from "./export-button";
import usePagination from "./use-pagination";
const PAGE_SIZE = 100;
@@ -450,20 +450,17 @@ export default function EventsTable() {
manualSorting: true,
});
- const { setExportQueryString } = useContext(EventsTableContext);
- useEffect(
+ const exportQueryString = useMemo(
() =>
- setExportQueryString(
- editQueryString(
- queryString,
- {
- columns: table
- .getVisibleFlatColumns()
- .map((c) => c.id)
- .join(","),
- },
- ["offset", "limit"], // Remove offset and limit
- ),
+ editQueryString(
+ queryString,
+ {
+ columns: table
+ .getVisibleFlatColumns()
+ .map((c) => c.id)
+ .join(","),
+ },
+ ["offset", "limit"], // Remove offset and limit
),
[queryString, table.getVisibleFlatColumns()],
);
@@ -486,195 +483,207 @@ export default function EventsTable() {
]);
return (
- <div className="border border-gray-200 bg-white sm:rounded-xl">
- <div className="relative rounded-[inherit]">
- {(!error && !!data?.length) || isLoading ? (
- <div
- ref={scrollContainer}
- className="min-h-[400px] overflow-x-auto rounded-[inherit]"
- >
- <table
- className={cn(
- "w-full table-fixed border-separate border-spacing-0",
-
- // Remove side borders from table to avoid interfering with outer border
- "[&_thead_tr:first-child>*]:border-t-0", // Top row
- "[&_tr>*:first-child]:border-l-0", // Left column
- "[&_tr>*:last-child]:border-r-0", // Right column
- )}
- style={columnSizeVars}
+ <div>
+ <div className="flex justify-end">
+ <div className="flex gap-1">
+ <ExportButton
+ queryString={exportQueryString}
+ disabled={error || !data?.length}
+ />
+ <EditColumnsButton table={table} />
+ </div>
+ </div>
+ <div className="mt-2 border border-gray-200 bg-white sm:rounded-xl">
+ <div className="relative rounded-[inherit]">
+ {(!error && !!data?.length) || isLoading ? (
+ <div
+ ref={scrollContainer}
+ className="min-h-[400px] overflow-x-auto rounded-[inherit]"
>
- <thead>
- {table.getHeaderGroups().map((headerGroup) => (
- <tr key={headerGroup.id}>
- {headerGroup.headers.map((header, columnIdx) => {
- const isSortableColumn = ["timestamp", "amount"].includes(
- header.column.id,
- );
- return (
- <th
- key={`${tab}-${header.id}`}
- className={cn(
- tableCellClassName,
- "relative select-none font-medium",
- )}
- style={{
- width: `calc(var(--header-${header?.id}-size) * 1px)`,
- }}
- >
- <div className="flex items-center justify-between gap-6 !pr-0">
- <button
- type="button"
- className="flex items-center gap-2"
- disabled={!isSortableColumn}
- onClick={() =>
- queryParams({
- set: {
- sort: header.column.id,
- order:
- sortBy !== header.column.id
- ? "desc"
- : order === "asc"
+ <table
+ className={cn(
+ "w-full table-fixed border-separate border-spacing-0",
+
+ // Remove side borders from table to avoid interfering with outer border
+ "[&_thead_tr:first-child>*]:border-t-0", // Top row
+ "[&_tr>*:first-child]:border-l-0", // Left column
+ "[&_tr>*:last-child]:border-r-0", // Right column
+ )}
+ style={columnSizeVars}
+ >
+ <thead>
+ {table.getHeaderGroups().map((headerGroup) => (
+ <tr key={headerGroup.id}>
+ {headerGroup.headers.map((header, columnIdx) => {
+ const isSortableColumn = [
+ "timestamp",
+ "amount",
+ ].includes(header.column.id);
+ return (
+ <th
+ key={`${tab}-${header.id}`}
+ className={cn(
+ tableCellClassName,
+ "relative select-none font-medium",
+ )}
+ style={{
+ width: `calc(var(--header-${header?.id}-size) * 1px)`,
+ }}
+ >
+ <div className="flex items-center justify-between gap-6 !pr-0">
+ <button
+ type="button"
+ className="flex items-center gap-2"
+ disabled={!isSortableColumn}
+ onClick={() =>
+ queryParams({
+ set: {
+ sort: header.column.id,
+ order:
+ sortBy !== header.column.id
? "desc"
- : "asc",
- },
- })
- }
- aria-label="Sort by column"
- >
- <span>
- {header.isPlaceholder
- ? null
- : flexRender(
- header.column.columnDef.header,
- header.getContext(),
- )}
- </span>
- {isSortableColumn && (
- <SortOrder
- order={
- sortBy === header.column.id ? order : null
- }
+ : order === "asc"
+ ? "desc"
+ : "asc",
+ },
+ })
+ }
+ aria-label="Sort by column"
+ >
+ <span>
+ {header.isPlaceholder
+ ? null
+ : flexRender(
+ header.column.columnDef.header,
+ header.getContext(),
+ )}
+ </span>
+ {isSortableColumn && (
+ <SortOrder
+ order={
+ sortBy === header.column.id ? order : null
+ }
+ />
+ )}
+ </button>
+ {header.id === "link" && (
+ <EventsLinkType
+ scrollContainer={scrollContainer}
/>
)}
- </button>
- {header.id === "link" && (
- <EventsLinkType
- scrollContainer={scrollContainer}
- />
- )}
- {columnIdx === headerGroup.headers.length - 1 && (
+ {/* {columnIdx === headerGroup.headers.length - 1 && (
// Last column
<EventsTableMenu
table={table}
scrollContainer={scrollContainer}
/>
+ )} */}
+ </div>
+ <div
+ className="absolute -right-[4px] top-0 z-[1] h-full w-[7px] cursor-col-resize"
+ {...{
+ onDoubleClick: () => header.column.resetSize(),
+ onMouseDown: header.getResizeHandler(),
+ onTouchStart: header.getResizeHandler(),
+ }}
+ />
+ </th>
+ );
+ })}
+ </tr>
+ ))}
+ </thead>
+ <tbody>
+ {table.getRowModel().rows.map((row) => (
+ <tr key={row.id}>
+ {row.getVisibleCells().map((cell) => {
+ const meta = cell.column.columnDef.meta as
+ | ColumnMeta
+ | undefined;
+
+ return (
+ <td
+ key={`${tab}-${cell.id}`}
+ className={cn(
+ tableCellClassName,
+ "group relative text-gray-600",
)}
- </div>
- <div
- className="absolute -right-[4px] top-0 z-[1] h-full w-[7px] cursor-col-resize"
- {...{
- onDoubleClick: () => header.column.resetSize(),
- onMouseDown: header.getResizeHandler(),
- onTouchStart: header.getResizeHandler(),
+ style={{
+ width: `calc(var(--col-${cell.column.id}-size) * 1px)`,
}}
- />
- </th>
- );
- })}
- </tr>
- ))}
- </thead>
- <tbody>
- {table.getRowModel().rows.map((row) => (
- <tr key={row.id}>
- {row.getVisibleCells().map((cell) => {
- const meta = cell.column.columnDef.meta as
- | ColumnMeta
- | undefined;
-
- return (
- <td
- key={`${tab}-${cell.id}`}
- className={cn(
- tableCellClassName,
- "group relative text-gray-600",
- )}
- style={{
- width: `calc(var(--col-${cell.column.id}-size) * 1px)`,
- }}
- >
- <div className="flex w-full items-center justify-between overflow-hidden truncate">
- <div className="min-w-0 shrink">
- {flexRender(
- cell.column.columnDef.cell,
- cell.getContext(),
+ >
+ <div className="flex w-full items-center justify-between overflow-hidden truncate">
+ <div className="min-w-0 shrink">
+ {flexRender(
+ cell.column.columnDef.cell,
+ cell.getContext(),
+ )}
+ </div>
+ {meta?.filterParams && (
+ <FilterButton set={meta.filterParams(cell)} />
)}
</div>
- {meta?.filterParams && (
- <FilterButton set={meta.filterParams(cell)} />
- )}
- </div>
- </td>
- );
- })}
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- ) : (
- <div className="flex h-64 w-full items-center justify-center text-sm text-gray-500">
- {error ? "Failed to fetch data" : "No data available"}
- </div>
- )}
- <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,
- table.getRowCount(),
- )}
- </span>{" "}
- of{" "}
- <span className="font-medium">
- {table.getRowCount().toLocaleString()}
- </span>{" "}
- events
- </div>
- <div className="flex items-center gap-2">
- <Button
- variant="secondary"
- text="Previous"
- className="h-7 px-2"
- onClick={() => table.previousPage()}
- disabled={!table.getCanPreviousPage()}
- />
- <Button
- variant="secondary"
- text="Next"
- className="h-7 px-2"
- onClick={() => table.nextPage()}
- disabled={!table.getCanNextPage()}
- />
+ </td>
+ );
+ })}
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ ) : (
+ <div className="flex h-64 w-full items-center justify-center text-sm text-gray-500">
+ {error ? "Failed to fetch data" : "No data available"}
+ </div>
+ )}
+ <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,
+ table.getRowCount(),
+ )}
+ </span>{" "}
+ of{" "}
+ <span className="font-medium">
+ {table.getRowCount().toLocaleString()}
+ </span>{" "}
+ events
+ </div>
+ <div className="flex items-center gap-2">
+ <Button
+ variant="secondary"
+ text="Previous"
+ className="h-7 px-2"
+ onClick={() => table.previousPage()}
+ disabled={!table.getCanPreviousPage()}
+ />
+ <Button
+ variant="secondary"
+ text="Next"
+ className="h-7 px-2"
+ onClick={() => table.nextPage()}
+ disabled={!table.getCanNextPage()}
+ />
+ </div>
</div>
- </div>
- {/* Loading/error overlay */}
- <AnimatePresence>
- {isLoading && (
- <motion.div
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- className="absolute inset-0 flex items-center justify-center bg-white/50"
- >
- <LoadingSpinner />
- </motion.div>
- )}
- </AnimatePresence>
+ {/* Loading/error overlay */}
+ <AnimatePresence>
+ {isLoading && (
+ <motion.div
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ className="absolute inset-0 flex items-center justify-center bg-white/50"
+ >
+ <LoadingSpinner />
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </div>
</div>
</div>
);
diff --git a/apps/web/ui/analytics/events/export-button.tsx b/apps/web/ui/analytics/events/export-button.tsx
new file mode 100644
index 0000000000..7bcb045029
--- /dev/null
+++ b/apps/web/ui/analytics/events/export-button.tsx
@@ -0,0 +1,61 @@
+import { Button, Download } from "@dub/ui";
+import { useState } from "react";
+import { toast } from "sonner";
+
+export default function ExportButton({
+ queryString,
+ disabled = false,
+}: {
+ queryString: string;
+ disabled?: boolean;
+}) {
+ const [loading, setLoading] = useState(false);
+
+ async function exportData() {
+ setLoading(true);
+ try {
+ const response = await fetch(
+ `/api/analytics/events/export?${queryString}`,
+ {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ },
+ );
+
+ if (!response.ok) {
+ setLoading(false);
+ throw new Error(response.statusText);
+ }
+
+ const blob = await response.blob();
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = `Dub Events Export - ${new Date().toISOString()}.csv`;
+ a.click();
+ } catch (error) {
+ throw new Error(error);
+ }
+ setLoading(false);
+ }
+
+ return (
+ <Button
+ className="h-8 whitespace-nowrap px-3"
+ variant="secondary"
+ icon={<Download className="h-4 w-4 shrink-0" />}
+ text="Export"
+ onClick={() => {
+ toast.promise(exportData(), {
+ loading: "Exporting file...",
+ success: "Exported successfully",
+ error: (error) => error,
+ });
+ }}
+ disabled={disabled}
+ loading={loading}
+ />
+ );
+}
diff --git a/apps/web/ui/analytics/events/index.tsx b/apps/web/ui/analytics/events/index.tsx
index c006debe20..bbdeb7709b 100644
--- a/apps/web/ui/analytics/events/index.tsx
+++ b/apps/web/ui/analytics/events/index.tsx
@@ -3,20 +3,11 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { useRouterStuff } from "@dub/ui";
import { redirect } from "next/navigation";
-import { Dispatch, SetStateAction, createContext, useState } from "react";
import AnalyticsProvider from "../analytics-provider";
import Toggle from "../toggle";
import EventsTable from "./events-table";
import EventsTabs from "./events-tabs";
-export const EventsTableContext = createContext<{
- exportQueryString: string;
- setExportQueryString: Dispatch<SetStateAction<string>>;
-}>({
- exportQueryString: "",
- setExportQueryString: () => {},
-});
-
export default function AnalyticsEvents({
staticDomain,
staticUrl,
@@ -32,8 +23,6 @@ export default function AnalyticsEvents({
const { searchParams } = useRouterStuff();
const tab = searchParams.get("tab");
- const [exportQueryString, setExportQueryString] = useState<string>("");
-
if (!betaTester) {
redirect(`/${slug}/analytics`);
}
@@ -43,17 +32,13 @@ export default function AnalyticsEvents({
{...{ staticDomain, staticUrl, adminPage, demoPage }}
eventsPage
>
- <EventsTableContext.Provider
- value={{ exportQueryString, setExportQueryString }}
- >
- <div className="py-10">
- <Toggle page="events" />
- <div className="mx-auto flex max-w-screen-xl flex-col gap-5 px-2.5 lg:px-20">
- <EventsTabs />
- <EventsTable key={tab} />
- </div>
+ <div className="py-10">
+ <Toggle page="events" />
+ <div className="mx-auto flex max-w-screen-xl flex-col gap-8 px-2.5 lg:px-20">
+ <EventsTabs />
+ <EventsTable key={tab} />
</div>
- </EventsTableContext.Provider>
+ </div>
</AnalyticsProvider>
);
}
diff --git a/apps/web/ui/analytics/export-button.tsx b/apps/web/ui/analytics/export-button.tsx
index 91b3b531ca..c511310c5f 100644
--- a/apps/web/ui/analytics/export-button.tsx
+++ b/apps/web/ui/analytics/export-button.tsx
@@ -1,38 +1,26 @@
import { Button } from "@dub/ui/src/button";
import { Download } from "@dub/ui/src/icons";
-import { capitalize } from "@dub/utils";
import { Dispatch, SetStateAction, useContext, useState } from "react";
import { toast } from "sonner";
import { AnalyticsContext } from "./analytics-provider";
-import { EventsTableContext } from "./events";
export default function ExportButton({
- page,
setOpenPopover,
}: {
- page: "analytics" | "events";
setOpenPopover: Dispatch<SetStateAction<boolean>>;
}) {
const [loading, setLoading] = useState(false);
const { queryString } = useContext(AnalyticsContext);
- const { exportQueryString } = useContext(EventsTableContext);
-
- console.log(exportQueryString);
async function exportData() {
setLoading(true);
try {
- const response = await fetch(
- page === "analytics"
- ? `/api/analytics/export?${queryString}`
- : `/api/analytics/events/export?${exportQueryString}`,
- {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- },
+ const response = await fetch(`/api/analytics/export?${queryString}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
},
- );
+ });
if (!response.ok) {
setLoading(false);
@@ -43,7 +31,7 @@ export default function ExportButton({
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
- a.download = `Dub ${capitalize(page)} Export - ${new Date().toISOString()}.${page === "analytics" ? "zip" : "csv"}`;
+ a.download = `Dub Analytics Export - ${new Date().toISOString()}.zip`;
a.click();
} catch (error) {
throw new Error(error);
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index 101ea4423e..5d875c1ddb 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -617,7 +617,9 @@ export default function Toggle({
};
})}
/>
- {!isPublicStatsPage && <AnalyticsOptions page={page} />}
+ {!isPublicStatsPage && page === "analytics" && (
+ <AnalyticsOptions />
+ )}
</div>
</div>
</div>
diff --git a/packages/ui/src/button.tsx b/packages/ui/src/button.tsx
index 1741912e4d..d5bb357610 100644
--- a/packages/ui/src/button.tsx
+++ b/packages/ui/src/button.tsx
@@ -1,5 +1,5 @@
import { cn } from "@dub/utils";
-import { ReactNode } from "react";
+import { ReactNode, forwardRef } from "react";
import { LoadingSpinner } from "./icons";
import { Tooltip } from "./tooltip";
@@ -19,94 +19,105 @@ export interface ButtonProps
disabledTooltip?: string | ReactNode;
}
-export function Button({
- text,
- variant = "primary",
- className,
- loading,
- icon,
- shortcut,
- disabledTooltip,
- ...props
-}: ButtonProps) {
- if (disabledTooltip) {
+const Button = forwardRef<HTMLButtonElement, ButtonProps>(
+ (
+ {
+ text,
+ variant = "primary",
+ className,
+ loading,
+ icon,
+ shortcut,
+ disabledTooltip,
+ ...props
+ }: ButtonProps,
+ forwardedRef,
+ ) => {
+ if (disabledTooltip) {
+ return (
+ <Tooltip content={disabledTooltip}>
+ <div
+ className={cn(
+ "flex h-10 w-full cursor-not-allowed items-center justify-center space-x-2 rounded-md border border-gray-200 bg-gray-100 px-4 text-sm text-gray-400 transition-all focus:outline-none",
+ {
+ "border-transparent bg-transparent":
+ variant.endsWith("outline"),
+ },
+ className,
+ )}
+ >
+ {icon}
+ <p className={cn(shortcut && "flex-1 text-left")}>{text}</p>
+ {shortcut && (
+ <kbd
+ className={cn(
+ "hidden rounded bg-gray-200 px-2 py-0.5 text-xs font-light text-gray-400 md:inline-block",
+ {
+ "bg-gray-100": variant.endsWith("outline"),
+ },
+ )}
+ >
+ {shortcut}
+ </kbd>
+ )}
+ </div>
+ </Tooltip>
+ );
+ }
return (
- <Tooltip content={disabledTooltip}>
- <div
- className={cn(
- "flex h-10 w-full cursor-not-allowed items-center justify-center space-x-2 rounded-md border border-gray-200 bg-gray-100 px-4 text-sm text-gray-400 transition-all focus:outline-none",
- {
- "border-transparent bg-transparent": variant.endsWith("outline"),
- },
- className,
- )}
- >
- {icon}
- <p className={cn(shortcut && "flex-1 text-left")}>{text}</p>
- {shortcut && (
- <kbd
- className={cn(
- "hidden rounded bg-gray-200 px-2 py-0.5 text-xs font-light text-gray-400 md:inline-block",
- {
- "bg-gray-100": variant.endsWith("outline"),
- },
- )}
- >
- {shortcut}
- </kbd>
- )}
- </div>
- </Tooltip>
+ <button
+ ref={forwardedRef}
+ // if onClick is passed, it's a "button" type, otherwise it's being used in a form, hence "submit"
+ type={props.onClick ? "button" : "submit"}
+ className={cn(
+ "group flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all",
+ props.disabled || loading
+ ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"
+ : {
+ "border-black bg-black text-white hover:bg-gray-800 hover:ring-4 hover:ring-gray-200":
+ variant === "primary",
+ "border-gray-200 bg-white text-gray-600 hover:bg-gray-100":
+ variant === "secondary",
+ "border-transparent text-gray-500 duration-75 hover:bg-gray-100":
+ variant === "outline",
+ "border-blue-500 bg-blue-500 text-white hover:bg-blue-600 hover:ring-4 hover:ring-blue-100":
+ variant === "success",
+ "border-red-500 bg-red-500 text-white hover:bg-red-600 hover:ring-4 hover:ring-red-100":
+ variant === "danger",
+ "border-transparent bg-white text-red-500 hover:bg-red-600 hover:text-white":
+ variant === "danger-outline",
+ },
+ className,
+ )}
+ disabled={props.disabled || loading}
+ {...props}
+ >
+ {loading ? <LoadingSpinner /> : icon ? icon : null}
+ {text && <p className={cn(shortcut && "flex-1 text-left")}>{text}</p>}
+ {shortcut && (
+ <kbd
+ className={cn(
+ "hidden rounded px-2 py-0.5 text-xs font-light transition-all duration-75 md:inline-block",
+ {
+ "bg-gray-700 text-gray-400 group-hover:bg-gray-600 group-hover:text-gray-300":
+ variant === "primary",
+ "bg-gray-200 text-gray-400 group-hover:bg-gray-100 group-hover:text-gray-500":
+ variant === "secondary",
+ "bg-gray-100 text-gray-500 group-hover:bg-gray-200":
+ variant === "outline",
+ "bg-red-100 text-red-600 group-hover:bg-red-500 group-hover:text-white":
+ variant === "danger-outline",
+ },
+ )}
+ >
+ {shortcut}
+ </kbd>
+ )}
+ </button>
);
- }
- return (
- <button
- // if onClick is passed, it's a "button" type, otherwise it's being used in a form, hence "submit"
- type={props.onClick ? "button" : "submit"}
- className={cn(
- "group flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all",
- props.disabled || loading
- ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"
- : {
- "border-black bg-black text-white hover:bg-gray-800 hover:ring-4 hover:ring-gray-200":
- variant === "primary",
- "border-gray-200 bg-white text-gray-600 hover:bg-gray-100":
- variant === "secondary",
- "border-transparent text-gray-500 duration-75 hover:bg-gray-100":
- variant === "outline",
- "border-blue-500 bg-blue-500 text-white hover:bg-blue-600 hover:ring-4 hover:ring-blue-100":
- variant === "success",
- "border-red-500 bg-red-500 text-white hover:bg-red-600 hover:ring-4 hover:ring-red-100":
- variant === "danger",
- "border-transparent bg-white text-red-500 hover:bg-red-600 hover:text-white":
- variant === "danger-outline",
- },
- className,
- )}
- disabled={props.disabled || loading}
- {...props}
- >
- {loading ? <LoadingSpinner /> : icon ? icon : null}
- {text && <p className={cn(shortcut && "flex-1 text-left")}>{text}</p>}
- {shortcut && (
- <kbd
- className={cn(
- "hidden rounded px-2 py-0.5 text-xs font-light transition-all duration-75 md:inline-block",
- {
- "bg-gray-700 text-gray-400 group-hover:bg-gray-600 group-hover:text-gray-300":
- variant === "primary",
- "bg-gray-200 text-gray-400 group-hover:bg-gray-100 group-hover:text-gray-500":
- variant === "secondary",
- "bg-gray-100 text-gray-500 group-hover:bg-gray-200":
- variant === "outline",
- "bg-red-100 text-red-600 group-hover:bg-red-500 group-hover:text-white":
- variant === "danger-outline",
- },
- )}
- >
- {shortcut}
- </kbd>
- )}
- </button>
- );
-}
+ },
+);
+
+Button.displayName = "Button";
+
+export { Button };
diff --git a/packages/ui/src/icons/nucleo/gear.tsx b/packages/ui/src/icons/nucleo/gear.tsx
index 973acb514c..f61c735e04 100644
--- a/packages/ui/src/icons/nucleo/gear.tsx
+++ b/packages/ui/src/icons/nucleo/gear.tsx
@@ -9,13 +9,13 @@ export function Gear(props: SVGProps<SVGSVGElement>) {
xmlns="http://www.w3.org/2000/svg"
{...props}
>
- <g fill="#212121">
+ <g fill="currentColor">
<circle
cx="9"
cy="9"
fill="none"
r="2.25"
- stroke="#212121"
+ stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
@@ -23,7 +23,7 @@ export function Gear(props: SVGProps<SVGSVGElement>) {
<path
d="M16.25,9.355v-.71c0-.51-.383-.938-.89-.994l-1.094-.122-.503-1.214,.688-.859c.318-.398,.287-.971-.074-1.332l-.502-.502c-.36-.36-.934-.392-1.332-.074l-.859,.688-1.214-.503-.122-1.094c-.056-.506-.484-.89-.994-.89h-.71c-.51,0-.938,.383-.994,.89l-.122,1.094-1.214,.503-.859-.687c-.398-.318-.971-.287-1.332,.074l-.502,.502c-.36,.36-.392,.934-.074,1.332l.688,.859-.503,1.214-1.094,.122c-.506,.056-.89,.484-.89,.994v.71c0,.51,.383,.938,.89,.994l1.094,.122,.503,1.214-.687,.859c-.318,.398-.287,.972,.074,1.332l.502,.502c.36,.36,.934,.392,1.332,.074l.859-.688,1.214,.503,.122,1.094c.056,.506,.484,.89,.994,.89h.71c.51,0,.938-.383,.994-.89l.122-1.094,1.214-.503,.859,.688c.398,.318,.971,.287,1.332-.074l.502-.502c.36-.36,.392-.934,.074-1.332l-.687-.859,.503-1.214,1.094-.122c.506-.056,.89-.484,.89-.994Z"
fill="none"
- stroke="#212121"
+ stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"