Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(frontend): add shadcn-style UI components with Base UI (#19758)

Danny Xu0ffacdcad48f
diff --git a/frontend/package.json b/frontend/package.json
index c671a6c6ad..a84a52cd88 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -37,6 +37,8 @@
"@markdoc/markdoc": "0.5.5",
"@vueuse/core": "14.2.1",
"bootstrap": "5.3.8",
+ "class-variance-authority": "^0.7.1",
+ "clsx": "^2.1.1",
"crypto-js": "^4.2.0",
"d3-shape": "^3.2.0",
"dayjs": "1.11.19",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 76cfbefd1a..8d63ae945b 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -60,6 +60,12 @@ importers:
bootstrap:
specifier: 5.3.8
version: 5.3.8(@popperjs/[email protected])
+ class-variance-authority:
+ specifier: ^0.7.1
+ version: 0.7.1
+ clsx:
+ specifier: ^2.1.1
+ version: 2.1.1
crypto-js:
specifier: ^4.2.0
version: 4.2.0
@@ -2733,6 +2739,9 @@ packages:
resolution: {integrity: sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==}
engines: {node: '>= 20.19.0'}
+ resolution: {integrity: sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg==}
+
resolution: {integrity: sha512-C+0bbOqkezLIsmWSvlsXS0Q0bmkugu7jcfMIACB+RDEntIzQIkdr148we28AfSloQLRdZlYL/QYyrq05j/3Faw==}
@@ -2740,6 +2749,10 @@ packages:
resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==}
engines: {node: '>=12'}
+ resolution: {integrity: sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==}
+ engines: {node: '>=6'}
+
resolution: {integrity: sha512-fdrSiP5jJ+FFLQmUyaF52xBB1yelJJtGdzr9wwFUJlbq5di4+rfyBHIzSrYgCTU5EAMrsRZ2eSnJb4zFa8Svvw==}
@@ -7612,6 +7625,10 @@ snapshots:
dependencies:
readdirp: 5.0.0
+ dependencies:
+ clsx: 2.1.1
+
dependencies:
good-listener: 1.2.2
@@ -7624,6 +7641,8 @@ snapshots:
strip-ansi: 6.0.1
wrap-ansi: 7.0.0
+
dependencies:
'@code-inspector/core': 1.4.4
diff --git a/frontend/src/react/components/ui/badge.tsx b/frontend/src/react/components/ui/badge.tsx
new file mode 100644
index 0000000000..1fbd963209
--- /dev/null
+++ b/frontend/src/react/components/ui/badge.tsx
@@ -0,0 +1,31 @@
+import { cva, type VariantProps } from "class-variance-authority";
+import type { ComponentProps } from "react";
+import { cn } from "@/react/lib/utils";
+
+const badgeVariants = cva(
+ "inline-flex items-center rounded-full px-3 py-0.5 text-sm font-medium",
+ {
+ variants: {
+ variant: {
+ default: "bg-control-bg text-control",
+ secondary: "bg-accent/10 text-accent",
+ destructive: "bg-error/10 text-error",
+ success: "bg-success/10 text-success",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+ }
+);
+
+type BadgeProps = ComponentProps<"span"> & VariantProps<typeof badgeVariants>;
+
+function Badge({ className, variant, ...props }: BadgeProps) {
+ return (
+ <span className={cn(badgeVariants({ variant, className }))} {...props} />
+ );
+}
+
+export { Badge, badgeVariants };
+export type { BadgeProps };
diff --git a/frontend/src/react/components/ui/button.tsx b/frontend/src/react/components/ui/button.tsx
new file mode 100644
index 0000000000..655e40f88c
--- /dev/null
+++ b/frontend/src/react/components/ui/button.tsx
@@ -0,0 +1,46 @@
+import { Button as BaseButton } from "@base-ui/react/button";
+import { cva, type VariantProps } from "class-variance-authority";
+import type { ComponentProps } from "react";
+import { cn } from "@/react/lib/utils";
+
+const buttonVariants = cva(
+ "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-colors focus:outline-hidden focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
+ {
+ variants: {
+ variant: {
+ default: "bg-accent text-accent-text hover:bg-accent-hover",
+ outline:
+ "border border-control-border bg-transparent hover:bg-control-bg text-control",
+ ghost: "hover:bg-control-bg text-control",
+ destructive: "bg-error text-white hover:bg-error-hover",
+ link: "text-accent underline-offset-4 hover:underline",
+ },
+ size: {
+ default: "h-9 px-4 py-2",
+ sm: "h-8 px-3 text-xs",
+ lg: "h-10 px-6",
+ icon: "h-9 w-9",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ size: "default",
+ },
+ }
+);
+
+type ButtonProps = ComponentProps<"button"> &
+ VariantProps<typeof buttonVariants>;
+
+function Button({ className, variant, size, ref, ...props }: ButtonProps) {
+ return (
+ <BaseButton
+ ref={ref}
+ className={cn(buttonVariants({ variant, size, className }))}
+ {...props}
+ />
+ );
+}
+
+export { Button, buttonVariants };
+export type { ButtonProps };
diff --git a/frontend/src/react/components/ui/input.tsx b/frontend/src/react/components/ui/input.tsx
new file mode 100644
index 0000000000..cfdd714520
--- /dev/null
+++ b/frontend/src/react/components/ui/input.tsx
@@ -0,0 +1,25 @@
+import { Input as BaseInput } from "@base-ui/react/input";
+import type { ComponentProps } from "react";
+import { cn } from "@/react/lib/utils";
+
+type InputProps = ComponentProps<"input">;
+
+function Input({ className, ref, ...props }: InputProps) {
+ return (
+ <BaseInput
+ ref={ref}
+ className={cn(
+ "flex h-9 w-full rounded-md border border-control-border bg-transparent px-3 py-1 text-sm text-main transition-colors",
+ "placeholder:text-control-placeholder",
+ "focus:outline-hidden focus:ring-2 focus:ring-accent focus:border-accent",
+ "disabled:cursor-not-allowed disabled:bg-control-bg disabled:opacity-50",
+ "read-only:cursor-default read-only:bg-control-bg read-only:focus:ring-0 read-only:focus:border-control-border",
+ className
+ )}
+ {...props}
+ />
+ );
+}
+
+export { Input };
+export type { InputProps };
diff --git a/frontend/src/react/components/ui/textarea.tsx b/frontend/src/react/components/ui/textarea.tsx
new file mode 100644
index 0000000000..d0cbc7fe53
--- /dev/null
+++ b/frontend/src/react/components/ui/textarea.tsx
@@ -0,0 +1,23 @@
+import type { ComponentProps } from "react";
+import { cn } from "@/react/lib/utils";
+
+type TextareaProps = ComponentProps<"textarea">;
+
+function Textarea({ className, ref, ...props }: TextareaProps) {
+ return (
+ <textarea
+ ref={ref}
+ className={cn(
+ "flex min-h-[100px] w-full rounded-md border border-control-border bg-transparent px-3 py-2 text-sm text-main transition-colors",
+ "placeholder:text-control-placeholder",
+ "focus:outline-hidden focus:ring-2 focus:ring-accent focus:border-accent",
+ "disabled:cursor-not-allowed disabled:bg-control-bg disabled:opacity-50",
+ className
+ )}
+ {...props}
+ />
+ );
+}
+
+export { Textarea };
+export type { TextareaProps };
diff --git a/frontend/src/react/lib/utils.ts b/frontend/src/react/lib/utils.ts
new file mode 100644
index 0000000000..365058cebd
--- /dev/null
+++ b/frontend/src/react/lib/utils.ts
@@ -0,0 +1,6 @@
+import { type ClassValue, clsx } from "clsx";
+import { twMerge } from "tailwind-merge";
+
+export function cn(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs));
+}
diff --git a/frontend/src/react/pages/settings/SubscriptionPage.tsx b/frontend/src/react/pages/settings/SubscriptionPage.tsx
index e884c80fcd..8ce4290283 100644
--- a/frontend/src/react/pages/settings/SubscriptionPage.tsx
+++ b/frontend/src/react/pages/settings/SubscriptionPage.tsx
@@ -1,6 +1,10 @@
import { Copy, Pencil } from "lucide-react";
-import { useState } from "react";
+import { type ChangeEvent, useState } from "react";
import { useTranslation } from "react-i18next";
+import { Badge } from "@/react/components/ui/badge";
+import { Button } from "@/react/components/ui/button";
+import { Input } from "@/react/components/ui/input";
+import { Textarea } from "@/react/components/ui/textarea";
import type { SubscriptionData } from "@/react/types";
interface SubscriptionPageProps {
@@ -69,17 +73,17 @@ export function SubscriptionPage({
<div className="flex items-center text-main">
{t("subscription.current")}
{data.isExpired && (
- <span className="ml-2 inline-flex items-center px-3 py-0.5 rounded-full text-base font-sm bg-red-100 text-red-800 h-6">
+ <Badge variant="destructive" className="ml-2 h-6">
{t("subscription.expired")}
- </span>
+ </Badge>
)}
{!data.isExpired && data.isTrialing && (
- <span className="ml-2 inline-flex items-center px-3 py-0.5 rounded-full text-base font-sm bg-indigo-100 text-indigo-800 h-6">
+ <Badge variant="secondary" className="ml-2 h-6">
{t("subscription.trialing")}
- </span>
+ </Badge>
)}
</div>
- <div className="text-indigo-600 mt-1 text-3xl lg:text-4xl">
+ <div className="text-accent mt-1 text-3xl lg:text-4xl">
{data.currentPlan}
</div>
</div>
@@ -99,14 +103,11 @@ export function SubscriptionPage({
<div className="flex flex-col text-left">
<div className="text-main">{t("subscription.try-for-free")}</div>
<div className="mt-1">
- <button
- className="rounded-md bg-indigo-600 px-4 py-2 text-white text-lg hover:bg-indigo-700"
- onClick={onRequireEnterprise}
- >
+ <Button className="text-lg" onClick={onRequireEnterprise}>
{t("subscription.enterprise-free-trial", {
days: data.trialingDays,
})}
- </button>
+ </Button>
</div>
</div>
)}
@@ -118,12 +119,9 @@ export function SubscriptionPage({
{t("subscription.inquire-enterprise-plan")}
</div>
<div className="mt-1 ml-auto">
- <button
- className="rounded-md bg-indigo-600 px-4 py-2 text-white text-lg hover:bg-indigo-700"
- onClick={onRequireEnterprise}
- >
+ <Button className="text-lg" onClick={onRequireEnterprise}>
{t("subscription.contact-us")}
- </button>
+ </Button>
</div>
</div>
)}
@@ -146,14 +144,14 @@ export function SubscriptionPage({
</div>
<div className="mt-1 text-4xl flex items-center gap-2">
{data.activeUserCount}
- <span className="font-mono text-gray-500">/</span>
+ <span className="font-mono text-control-light">/</span>
{userLimit}
</div>
</div>
</div>
{/* Divider */}
- <hr className="my-6 border-t border-gray-200" />
+ <hr className="my-6 border-t border-block-border" />
{/* Workspace ID */}
<div>
@@ -162,25 +160,25 @@ export function SubscriptionPage({
{t("settings.general.workspace.id")}
</span>
</label>
- <div className="mb-3 text-sm text-gray-400">
+ <div className="mb-3 text-sm text-control-placeholder">
{t("settings.general.workspace.id-description")}
</div>
<div className="mb-4 flex items-center gap-x-2">
- <input
- className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm bg-gray-50 cursor-default focus:outline-none"
+ <Input
readOnly
value={data.workspaceId}
onClick={(e) => (e.target as HTMLInputElement).select()}
/>
- <button
- className="inline-flex items-center justify-center rounded-md p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100"
+ <Button
+ variant="ghost"
+ size="icon"
onClick={handleCopy}
title={t("common.copy")}
>
<Copy className="h-4 w-4" />
- </button>
+ </Button>
{copied && (
- <span className="text-sm text-green-600">{t("common.copied")}</span>
+ <span className="text-sm text-success">{t("common.copied")}</span>
)}
</div>
</div>
@@ -193,40 +191,43 @@ export function SubscriptionPage({
{t("subscription.upload-license")}
</span>
</label>
- <div className="mb-3 text-sm text-gray-400">
+ <div className="mb-3 text-sm text-control-placeholder">
{t("subscription.description")} {t("subscription.plan-compare")}{" "}
<a
href="https://www.bytebase.com/pricing?source=console"
target="_blank"
rel="noopener noreferrer"
- className="text-indigo-600 hover:underline"
+ className="text-accent hover:underline"
>
{t("common.learn-more")} &gt;
</a>
{data.showTrial && allowEdit && (
- <button
- className="ml-1 text-indigo-600 hover:underline text-sm"
+ <Button
+ variant="link"
+ size="sm"
+ className="ml-1"
onClick={onRequireEnterprise}
>
{t("subscription.plan.try")}
- </button>
+ </Button>
)}
</div>
- <textarea
- className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm min-h-[100px] focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 disabled:bg-gray-100 disabled:cursor-not-allowed"
+ <Textarea
value={license}
- onChange={(e) => setLicense(e.target.value)}
+ onChange={(e: ChangeEvent<HTMLTextAreaElement>) =>
+ setLicense(e.target.value)
+ }
disabled={!allowEdit}
placeholder={t("common.sensitive-placeholder")}
/>
<div className="ml-auto mt-3">
- <button
- className="rounded-md bg-indigo-600 px-4 py-2 text-white capitalize hover:bg-indigo-700 disabled:opacity-50 disabled:cursor-not-allowed"
+ <Button
disabled={disabled || !allowEdit}
onClick={handleUpload}
+ className="capitalize"
>
{t("subscription.upload-license")}
- </button>
+ </Button>
</div>
</div>
)}
@@ -267,15 +268,16 @@ function InstanceLicenseStats({
<div className="mt-1 text-4xl flex items-center gap-2">
<span>
{activatedCount}
- <span className="font-mono text-gray-500"> / </span>
+ <span className="font-mono text-control-light"> / </span>
{totalLicenseCount}
</span>
- <button
- className="text-gray-500 hover:text-gray-700"
+ <Button
+ variant="ghost"
+ size="icon"
onClick={onManageInstanceLicenses}
>
- <Pencil className="h-8 w-8" />
- </button>
+ <Pencil className="h-5 w-5" />
+ </Button>
</div>
</div>
</>