Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(ui): match pending loaders to button variants (#8619)
Andrew Huangc9a76fe2ffb1
diff --git a/frontend/src/components/v3/generic/Button/Button.tsx b/frontend/src/components/v3/generic/Button/Button.tsxindex e711946f3e..b0fe6ee9b6 100644--- a/frontend/src/components/v3/generic/Button/Button.tsx+++ b/frontend/src/components/v3/generic/Button/Button.tsx@@ -6,6 +6,7 @@ import { cva, type VariantProps } from "cva";import { cn } from "@app/components/v3/utils";import { Loader } from "../Loader";+import { getButtonLoaderVariant } from "./getButtonLoaderVariant";const buttonVariants = cva(cn(@@ -106,7 +107,14 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>() : (<>{_children}- {isPending && <Loader aria-hidden size="sm" className="absolute rounded-xl" />}+ {isPending && (+ <Loader+ aria-hidden+ variant={getButtonLoaderVariant(variant)}+ size="sm"+ className="absolute rounded-xl"+ />+ )}</>);diff --git a/frontend/src/components/v3/generic/Button/getButtonLoaderVariant.ts b/frontend/src/components/v3/generic/Button/getButtonLoaderVariant.tsnew file mode 100644index 0000000000..86bc4ed290--- /dev/null+++ b/frontend/src/components/v3/generic/Button/getButtonLoaderVariant.ts@@ -0,0 +1,27 @@+import type { IconButtonProps } from "../IconButton";+import type { LoaderVariant } from "../Loader";+import type { ButtonProps } from "./Button";++const buttonLoaderVariants = {+ default: "background",+ outline: "neutral",+ ghost: "neutral",+ "ghost-muted": "neutral",+ link: "neutral",+ text: "neutral",+ neutral: "neutral",+ danger: "neutral",+ project: "project",+ org: "org",+ "sub-org": "sub-org",+ success: "success",+ info: "info",+ warning: "warning",+ pam: "pam",+ av: "av",+ product: "product"+} satisfies Record<NonNullable<ButtonProps["variant"] | IconButtonProps["variant"]>, LoaderVariant>;++export const getButtonLoaderVariant = (+ variant: ButtonProps["variant"] | IconButtonProps["variant"]+) => (variant ? buttonLoaderVariants[variant] : "neutral");diff --git a/frontend/src/components/v3/generic/IconButton/IconButton.stories.tsx b/frontend/src/components/v3/generic/IconButton/IconButton.stories.tsxindex 9ad039fa4a..eb02c8f529 100644--- a/frontend/src/components/v3/generic/IconButton/IconButton.stories.tsx+++ b/frontend/src/components/v3/generic/IconButton/IconButton.stories.tsx@@ -337,7 +337,7 @@ export const IsPending: Story = {docs: {description: {story:- "Use `isPending` to show a loading animation inside the button and disable interaction. The `Loader` swaps to its `inverse` tint automatically for the filled `default` variant."+ "Use `isPending` to show a loading animation inside the button and disable interaction. The filled `default` variant uses the background token so its loader stays legible in both themes. Other variants follow their scope or semantic token, with neutral loaders for danger and uncolored controls."}}}diff --git a/frontend/src/components/v3/generic/IconButton/IconButton.tsx b/frontend/src/components/v3/generic/IconButton/IconButton.tsxindex 02e5c9c52c..ed98ade604 100644--- a/frontend/src/components/v3/generic/IconButton/IconButton.tsx+++ b/frontend/src/components/v3/generic/IconButton/IconButton.tsx@@ -6,6 +6,7 @@ import { twMerge } from "tailwind-merge";import { cn } from "@app/components/v3/utils";+import { getButtonLoaderVariant } from "../Button/getButtonLoaderVariant";import { Loader } from "../Loader";const iconButtonVariants = cva(@@ -105,7 +106,7 @@ const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>({isPending && (<Loaderaria-hidden- variant={variant === "default" ? "inverse" : "brand"}+ variant={getButtonLoaderVariant(variant)}size="xs"className={twMerge("absolute rounded-xl",diff --git a/frontend/src/components/v3/generic/Loader/Loader.stories.tsx b/frontend/src/components/v3/generic/Loader/Loader.stories.tsxindex f6e9614c4b..65fe9ef4ff 100644--- a/frontend/src/components/v3/generic/Loader/Loader.stories.tsx+++ b/frontend/src/components/v3/generic/Loader/Loader.stories.tsx@@ -1,3 +1,4 @@+import type { CSSProperties } from "react";import type { Meta, StoryObj } from "@storybook/react-vite";import { RefreshCwIcon, Trash2Icon } from "lucide-react";@@ -7,7 +8,7 @@ import { Loader } from "./Loader";/*** `Loader` is the branded Infisical loading animation — the stroke-draw of the- * logo mark. It is the single source for that animation: the mark, the two+ * logo mark. It is the single source for that animation: the mark, the* tints, and the size scale all live here, and every product call site composes* it rather than naming a Lottie asset itself, including the router's full-page* pending state in `main.tsx`.@@ -43,8 +44,24 @@ const meta = {tags: ["autodocs"],argTypes: {variant: {+ description:+ "Token variants recolor the existing animated mark without changing its motion. The product variant uses --product-color, just like Button.",control: "select",- options: ["brand", "inverse"]+ options: [+ "brand",+ "inverse",+ "neutral",+ "background",+ "org",+ "sub-org",+ "project",+ "success",+ "info",+ "warning",+ "pam",+ "av",+ "product"+ ]},size: {control: "select",@@ -72,7 +89,7 @@ export const Default: Story = {docs: {description: {story:- "The default: the brand-colored mark at `md`. It is the one tint for every loading state, from the router's pending page to a `Card` body waiting on a fetch, so consecutive loaders never switch color. Use it on standard product surfaces — a `Card` body waiting on a fetch, or a section that owns its own loading state. The animation loops for as long as the wait lasts, or remains on its fully drawn first frame when the operating system requests reduced motion. It carries no progress information, so pair it with copy when the wait is long enough to need explaining."+ "The default: the brand-colored mark at `md`. Standalone loaders and `PageLoader` keep this tint. Pending controls choose their tint from the button variant instead. The animation loops for as long as the wait lasts, or remains on its fully drawn first frame when the operating system requests reduced motion. It carries no progress information, so pair it with copy when the wait is long enough to need explaining."}}}@@ -94,7 +111,7 @@ export const VariantInverse: Story = {docs: {description: {story:- "Black mark, the only alternative to `brand`, for inverted surfaces where the foreground color is the background — the solid `default` `IconButton`, and anything else painted `bg-foreground`. Shown here on `bg-foreground`, since it is invisible against the page."+ "The explicit black mark for inverted surfaces. Shown here on `bg-foreground`, since it is invisible against the dark page. Automatic pending controls use theme-aware tokens instead."}}}@@ -109,7 +126,23 @@ export const VariantBrand: Story = {docs: {description: {story:- "The colored mark and the default tint. Use it everywhere except inverted surfaces, where `inverse` keeps the stroke legible."+ "The colored mark and the standalone default tint. Choose a token variant when the loader needs to follow the surface's scope or semantic intent."+ }+ }+ }+};++export const VariantProduct: Story = {+ name: "Variant: Product",+ args: {+ variant: "product",+ style: { "--product-color": "var(--color-product-kms)" } as CSSProperties+ },+ parameters: {+ docs: {+ description: {+ story:+ "Set --product-color to the product's existing token. This example uses the KMS token; the product-color utility resolves its light-theme tint just as it does for a product Button."}}}@@ -142,7 +175,7 @@ export const ExamplePendingButton: Story = {docs: {description: {story:- "`Button` composes `Loader` itself: set `isPending` and the label goes transparent while the `sm` mark draws over the control. Prefer `isPending` over rendering a `Loader` as a Button child — it also disables the control, which is what stops the double submit. `LDAPModal`'s Test Connection button is the one legacy exception: it swaps its label for an inline mark instead of overlaying one."+ "`Button` composes `Loader` itself: set `isPending` and the label goes transparent while the `sm` mark draws over the control. Scope and product variants choose their matching token; danger and uncolored variants choose neutral. Prefer `isPending` over rendering a `Loader` as a Button child — it also disables the control, which is what stops the double submit."}}},@@ -164,7 +197,7 @@ export const ExamplePendingIconButton: Story = {docs: {description: {story:- "`IconButton` composes `Loader` the same way, sizing the mark to the control and switching to the `inverse` tint on the solid `default` variant so the stroke stays legible against `bg-foreground`. Use it for row actions and toolbar triggers that fire a mutation."+ "`IconButton` uses the same variant mapping as `Button`, sizing the mark to the control. Its solid `default` variant uses the background token so the mark stays legible against `bg-foreground` in both themes. Use it for row actions and toolbar triggers that fire a mutation."}}},diff --git a/frontend/src/components/v3/generic/Loader/Loader.tsx b/frontend/src/components/v3/generic/Loader/Loader.tsxindex d8d773ef78..7b8fafa5dc 100644--- a/frontend/src/components/v3/generic/Loader/Loader.tsx+++ b/frontend/src/components/v3/generic/Loader/Loader.tsx@@ -1,9 +1,23 @@-import { type ComponentProps, useEffect, useRef, useSyncExternalStore } from "react";+import { type ComponentProps, useEffect, useId, useRef, useSyncExternalStore } from "react";import { type DotLottie, DotLottieReact } from "@lottiefiles/dotlottie-react";import { cn } from "../../utils";-type LoaderVariant = "brand" | "inverse";+const colorStyles = {+ neutral: "text-neutral",+ background: "text-background",+ project: "text-project",+ org: "text-org",+ "sub-org": "text-sub-org",+ success: "text-success",+ info: "text-info",+ warning: "text-warning",+ pam: "text-product-pam",+ av: "text-product-av",+ product: "product-color text-(--product-color-resolved)"+};++type LoaderVariant = "brand" | "inverse" | keyof typeof colorStyles;type LoaderSize = "xs" | "sm" | "md" | "lg";@@ -13,7 +27,7 @@ type LoaderProps = Omit<ComponentProps<"div">, "children"> & {variant?: LoaderVariant;};-const animationSources: Record<LoaderVariant, string> = {+const animationSources = {brand: "/lotties/infisical_loading.json",inverse: "/lotties/infisical_loading_bw.json"};@@ -38,8 +52,11 @@ function Loader({label = "Loading",size = "md",variant = "brand",+ style,...props}: LoaderProps) {+ const filterId = useId();+ const isTokenColor = variant !== "brand" && variant !== "inverse";const prefersReducedMotion = useSyncExternalStore(subscribeToReducedMotion,() => window.matchMedia("(prefers-reduced-motion: reduce)").matches,@@ -60,9 +77,20 @@ function Loader({role="status"aria-label={label}data-slot="loader"- className={cn(sizeStyles[size], className)}+ className={cn(sizeStyles[size], isTokenColor && colorStyles[variant], className)}+ style={isTokenColor ? { filter: `url("#${filterId}")`, ...style } : style}{...props}>+ {isTokenColor && (+ <svg aria-hidden="true" className="pointer-events-none absolute h-0 w-0">+ <defs>+ <filter id={filterId} colorInterpolationFilters="sRGB">+ <feFlood floodColor="currentColor" />+ <feComposite in2="SourceAlpha" operator="in" />+ </filter>+ </defs>+ </svg>+ )}{/* The reduced-motion state intentionally stops at the fully drawn first frame,preserving the loading indicator without continuous animation. */}<DotLottieReact@@ -72,7 +100,7 @@ function Loader({animation?.stop();}}}- src={animationSources[variant]}+ src={animationSources[isTokenColor ? "brand" : variant]}loopautoplay={!prefersReducedMotion}className="h-full w-full"