AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(frontend): `<Button variant="link" />` (#11320)
Ubbe0b680d499042
diff --git a/autogpt_platform/frontend/src/components/atoms/Button/Button.stories.tsx b/autogpt_platform/frontend/src/components/atoms/Button/Button.stories.tsxindex 85f6318405..35ef38bacb 100644--- a/autogpt_platform/frontend/src/components/atoms/Button/Button.stories.tsx+++ b/autogpt_platform/frontend/src/components/atoms/Button/Button.stories.tsx@@ -24,6 +24,7 @@ const meta: Meta<typeof Button> = {"destructive","outline","ghost",+ "link","loading",],description: "Button style variant",@@ -94,9 +95,17 @@ export const Ghost: Story = {},};+export const LinkVariant: Story = {+ args: {+ variant: "link",+ children: "Go to documentation",+ },+};+// Loading statesexport const Loading: Story = {args: {+ variant: "primary",loading: true,children: "Saving...",},@@ -110,6 +119,22 @@ export const Loading: Story = {},};+export const LoadingLink: Story = {+ args: {+ variant: "link",+ loading: true,+ children: "Loading link",+ },+ parameters: {+ docs: {+ description: {+ story:+ "Link buttons inherit the secondary link styling while respecting the loading state.",+ },+ },+ },+};+export const LoadingGhost: Story = {args: {variant: "ghost",@@ -601,6 +626,20 @@ function renderAllVariants() {</Button></div></div>+ <div className="flex flex-col gap-5">+ <div className="font-['Geist'] text-base font-medium text-zinc-800">+ Link+ </div>+ <div className="flex flex-col gap-8">+ <Button variant="link">Read documentation</Button>+ <Button variant="link" loading>+ Loading link+ </Button>+ <Button variant="link" disabled>+ Disabled link+ </Button>+ </div>+ </div></div></div></div>diff --git a/autogpt_platform/frontend/src/components/atoms/Button/Button.tsx b/autogpt_platform/frontend/src/components/atoms/Button/Button.tsxindex c39f561783..192e53fc00 100644--- a/autogpt_platform/frontend/src/components/atoms/Button/Button.tsx+++ b/autogpt_platform/frontend/src/components/atoms/Button/Button.tsx@@ -1,6 +1,6 @@import { cn } from "@/lib/utils";import { CircleNotchIcon } from "@phosphor-icons/react/dist/ssr";-import Link, { type LinkProps } from "next/link";+import NextLink, { type LinkProps } from "next/link";import React from "react";import { ButtonProps, extendedButtonVariants } from "./helpers";@@ -31,6 +31,28 @@ export function Button(props: ButtonProps) {</>);+ if (variant === "link") {+ const buttonRest = { ...(restProps as Record<string, unknown>) };++ if ("href" in buttonRest) {+ delete buttonRest.href;+ }++ return (+ <button+ className={cn(+ extendedButtonVariants({ variant: "link", className }),+ loading && "pointer-events-none opacity-60",+ isDisabled && "pointer-events-none opacity-50",+ )}+ disabled={isDisabled || loading}+ {...(buttonRest as React.ButtonHTMLAttributes<HTMLButtonElement>)}+ >+ {buttonContent}+ </button>+ );+ }+if (loading) {const loadingClassName =variant === "ghost"@@ -44,14 +66,14 @@ export function Button(props: ButtonProps) {);return as === "NextLink" ? (- <Link+ <NextLink{...(restProps as LinkProps)}className={loadingClassName}aria-disabled="true"><CircleNotchIcon className="h-4 w-4 animate-spin" weight="bold" />{children}- </Link>+ </NextLink>) : (<button className={loadingClassName} disabled><CircleNotchIcon className="h-4 w-4 animate-spin" weight="bold" />@@ -62,7 +84,7 @@ export function Button(props: ButtonProps) {if (as === "NextLink") {return (- <Link+ <NextLink{...(restProps as LinkProps)}className={cn(extendedButtonVariants({ variant, size, className }),@@ -72,7 +94,7 @@ export function Button(props: ButtonProps) {aria-disabled={isDisabled}>{buttonContent}- </Link>+ </NextLink>);}diff --git a/autogpt_platform/frontend/src/components/atoms/Button/helpers.ts b/autogpt_platform/frontend/src/components/atoms/Button/helpers.tsindex 6840afaae5..885f0012d7 100644--- a/autogpt_platform/frontend/src/components/atoms/Button/helpers.ts+++ b/autogpt_platform/frontend/src/components/atoms/Button/helpers.ts@@ -1,3 +1,9 @@+import {+ linkBaseClasses,+ linkFocusClasses,+ linkVariantClasses,+} from "@/components/atoms/Link/Link";+import { cn } from "@/lib/utils";import { cva, VariantProps } from "class-variance-authority";import { LinkProps } from "next/link";@@ -18,6 +24,12 @@ export const extendedButtonVariants = cva(ghost:"bg-transparent border-transparent text-black hover:bg-zinc-50 hover:border-zinc-50 rounded-full disabled:text-zinc-200 disabled:opacity-1",icon: "bg-white text-black border border-zinc-600 hover:bg-zinc-100 rounded-[96px] disabled:opacity-1 !min-w-0",+ link: cn(+ linkBaseClasses,+ linkVariantClasses.secondary,+ linkFocusClasses,+ "inline-flex items-center gap-2 border-none bg-transparent px-0 py-0 text-left",+ ),},size: {small: "px-3 py-2 text-sm gap-1.5 h-[2.25rem]",diff --git a/autogpt_platform/frontend/src/components/atoms/Link/Link.tsx b/autogpt_platform/frontend/src/components/atoms/Link/Link.tsxindex 6256a944bb..a5989067ff 100644--- a/autogpt_platform/frontend/src/components/atoms/Link/Link.tsx+++ b/autogpt_platform/frontend/src/components/atoms/Link/Link.tsx@@ -10,6 +10,20 @@ interface LinkProps {variant?: "primary" | "secondary";}+export const linkBaseClasses =+ "font-sans text-sm font-medium leading-[22px] text-[var(--AutoGPT-Text-text-black,#141414)]";++export const linkVariantClasses: Record<+ Required<LinkProps>["variant"],+ string+> = {+ primary: "hover:underline",+ secondary: "underline",+};++export const linkFocusClasses =+ "focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 rounded-sm";+const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link({href,@@ -22,13 +36,9 @@ const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(ref,) {const linkClasses = cn(- // Base styles from Figma- "font-sans text-sm font-medium leading-[22px] text-[var(--AutoGPT-Text-text-black,#141414)]",- // Variant-specific underline styles- variant === "primary" && "hover:underline",- variant === "secondary" && "underline",- // Focus state for accessibility- "focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 rounded-sm",+ linkBaseClasses,+ linkVariantClasses[variant],+ linkFocusClasses,className,);