Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

8.6 KB
Raw Blame
import type { Meta, StoryObj } from "@storybook/react-vite";
import { Link as RouterLink } from "@tanstack/react-router";
import {
  ArrowLeftIcon,
  BoxesIcon as SubOrgIcon,
  BoxIcon as ProjectIcon,
  Building2Icon as OrgIcon,
  CheckIcon,
  CircleXIcon,
  ExternalLinkIcon,
  InfoIcon,
  LogInIcon,
  TriangleAlertIcon
} from "lucide-react";

import { Button } from "./Button";
import { ButtonBadge } from "./ButtonBadge";

/**
 * Buttons trigger actions or events when clicked or pressed.
 * You can place text and icons inside a button.
 * Buttons are often used for submitting forms, navigating between pages, or triggering specific actions.
 */
const meta = {
  title: "Generic/Button",
  component: Button,
  parameters: {
    layout: "centered"
  },
  tags: ["autodocs"],
  argTypes: {
    variant: {
      control: "select",
      options: [
        "outline",
        "ghost",
        "link",
        "text",
        "neutral",
        "success",
        "info",
        "warning",
        "danger",
        "project",
        "org",
        "sub-org"
      ]
    },
    size: {
      control: "select",
      options: ["xs", "sm", "md", "lg"]
    },
    isPending: {
      control: "boolean"
    },
    isFullWidth: {
      control: "boolean"
    },
    isDisabled: {
      control: "boolean"
    },
    asChild: {
      table: {
        disable: true
      }
    },
    children: {
      table: {
        disable: true
      }
    }
  },
  args: { children: "Button", isPending: false, isDisabled: false, isFullWidth: false, size: "md" }
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Outline: Story = {
  name: "Variant: Outline",
  args: {
    variant: "outline",
    children: <>Outline</>
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for general page actions."
      }
    }
  }
};

export const Text: Story = {
  name: "Variant: Text",
  args: {
    variant: "text",
    children: "Copy value"
  },
  parameters: {
    docs: {
      description: {
        story:
          "Use for compact text actions without padding or an underline. Hover and pressed colors indicate interaction; keyboard focus remains visible."
      }
    }
  }
};

export const WithCornerBadge: Story = {
  name: "Composition: Corner Badge",
  render: () => (
    <div className="flex flex-col items-start gap-6">
      <Button variant="outline" size="lg">
        <LogInIcon />
        Continue with GitHub
        <ButtonBadge variant="project">Last used</ButtonBadge>
      </Button>
      <Button variant="outline" size="lg">
        Explore feature
        <ButtonBadge variant="info">New</ButtonBadge>
      </Button>
      <Button variant="outline" size="lg">
        Use recommended setup
        <ButtonBadge variant="success">Recommended</ButtonBadge>
      </Button>
    </div>
  ),
  parameters: {
    docs: {
      description: {
        story:
          "Place `ButtonBadge` inside a `Button` for short contextual flags such as Last used, New, or Recommended. It inherits Badge typography, sizing, radius, and casing while adding corner positioning and an opaque semantic tint. Choose an existing semantic variant or an intentionally branded project variant, and keep the label concise."
      }
    }
  }
};

export const Neutral: Story = {
  name: "Variant: Neutral",
  args: {
    variant: "neutral",
    children: (
      <>
        <ArrowLeftIcon />
        Back
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story:
          "Use this variant for neutral / general actions that don't warrant a semantic tone — a step up from `ghost` with a subtle filled background."
      }
    }
  }
};

export const Ghost: Story = {
  name: "Variant: Ghost",
  args: {
    variant: "ghost",
    children: <>Cancel</>
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for optional / non-primary actions."
      }
    }
  }
};

export const Link: Story = {
  name: "Variant: Link",
  args: {
    variant: "link",
    children: <>Link</>
  },
  parameters: {
    docs: {
      description: {
        story:
          "Use this zero-padding text variant for compact secondary actions embedded in labels or prose."
      }
    }
  }
};

export const Success: Story = {
  name: "Variant: Success",
  args: {
    variant: "success",
    children: (
      <>
        <CheckIcon />
        Success
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for generic positive / productive call-to-action functionality."
      }
    }
  }
};

export const Info: Story = {
  name: "Variant: Info",
  args: {
    variant: "info",
    children: (
      <>
        <InfoIcon />
        Info
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for generic informational call-to-action functionality."
      }
    }
  }
};

export const Warning: Story = {
  name: "Variant: Warning",
  args: {
    variant: "warning",
    children: (
      <>
        <TriangleAlertIcon />
        Warning
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for buttons with disruptive actions."
      }
    }
  }
};

export const Danger: Story = {
  name: "Variant: Danger",
  args: {
    variant: "danger",
    children: (
      <>
        <CircleXIcon />
        Danger
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for buttons with destructive action."
      }
    }
  }
};

export const Organization: Story = {
  name: "Variant: Organization",
  args: {
    variant: "org",
    children: (
      <>
        <OrgIcon />
        Organization
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for organization scope call-to-action buttons."
      }
    }
  }
};

export const SubOrganization: Story = {
  name: "Variant: Sub-Organization",
  args: {
    variant: "sub-org",
    children: (
      <>
        <SubOrgIcon />
        Sub-Organization
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for sub-organization scope call-to-action buttons."
      }
    }
  }
};

export const Project: Story = {
  name: "Variant: Project",
  args: {
    variant: "project",
    children: (
      <>
        <ProjectIcon />
        Project
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use this variant for project scope call-to-action buttons."
      }
    }
  }
};

export const AsExternalLink: Story = {
  name: "Example: As External Link",
  args: {
    variant: "info",
    asChild: true,
    children: (
      <a target="_blank" rel="noopener noreferrer" href="https://infisical.com/">
        Link <ExternalLinkIcon />
      </a>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use the `asChild` prop with an `a` tag to use a button as an external link."
      }
    }
  }
};

export const AsRouterLink: Story = {
  name: "Example: As Router Link",
  args: {
    variant: "project",
    asChild: true,
    children: (
      <RouterLink to=".">
        <ProjectIcon />
        View Project
      </RouterLink>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use the `asChild` prop with a `Link` component to use a button as an internal link."
      }
    }
  }
};

export const IsFullWidth: Story = {
  name: "Example: isFullWidth",
  args: {
    variant: "neutral",
    isFullWidth: true,
    children: (
      <>
        Login
        <LogInIcon />
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story: "Use the `isFullWidth` prop to expand button width to fill it's parent container."
      }
    }
  },
  decorators: (Story) => (
    <div className="w-64">
      <Story />
    </div>
  )
};

export const IsPending: Story = {
  name: "Example: isPending",
  args: {
    variant: "neutral",
    isPending: true,
    children: (
      <>
        Login
        <LogInIcon />
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story:
          "Use the `isPending` prop to indicate loading states and disable button functionality."
      }
    }
  }
};

export const IsDisabled: Story = {
  name: "Example: isDisabled",
  args: {
    variant: "neutral",
    isDisabled: true,
    children: (
      <>
        Login
        <LogInIcon />
      </>
    )
  },
  parameters: {
    docs: {
      description: {
        story:
          "Use the `isDisabled` prop to block interaction and mute the button (50% opacity). Applies to every variant identically."
      }
    }
  }
};