Sign-in buttons
FreeThe sign-in stack: a full-width glass button per provider with its mark, then the email primary, each showing its own loading while its sign-in starts.
npx shadcn@latest add @pixilui/sign-in-buttonsPreview
The provider you pick waits on its promise; the others step back.
Show
import type { ReactNode, SVGProps } from "react";
import { IconPasskey } from "@/components/pixilui/icons/passkey";
import { SignInButtons, type SignInButtonsProvider } from "@/components/pixilui/sign-in-buttons";
// The item page's one row, Show: Styles, More styles, Icons and sizes, States (the button pages' layout).
export const knobs = {
show: ["styles", "more", "sizes", "states"],
} as const;
const wait = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
/** The Google G, one color. It passes its props to the svg, so the button can size and color it. */
function GoogleMark(props: SVGProps<SVGSVGElement>) {
return (
<svg viewBox="0 0 24 24" fill="currentColor" stroke="none" aria-hidden="true" {...props}>
<path d="M21.6 12.23c0-.68-.06-1.36-.18-2.02H12v3.83h5.38a4.6 4.6 0 0 1-2 3.02v2.5h3.24c1.9-1.75 2.98-4.32 2.98-7.33Z" />
<path d="M12 22c2.7 0 4.97-.9 6.62-2.43l-3.24-2.51c-.9.6-2.04.96-3.38.96-2.6 0-4.8-1.76-5.59-4.12H3.07v2.59A10 10 0 0 0 12 22Z" />
<path d="M6.41 13.9a6 6 0 0 1 0-3.8V7.51H3.07a10 10 0 0 0 0 8.98l3.34-2.59Z" />
<path d="M12 5.98c1.47 0 2.79.5 3.83 1.5l2.87-2.87A9.6 9.6 0 0 0 12 2a10 10 0 0 0-8.93 5.51l3.34 2.59C7.2 7.74 9.4 5.98 12 5.98Z" />
</svg>
);
}
/** The GitHub mark, one color. It passes its props to the svg, so the button can size and color it. */
function GitHubMark(props: SVGProps<SVGSVGElement>) {
return (
<svg viewBox="0 0 24 24" fill="currentColor" stroke="none" aria-hidden="true" {...props}>
<path d="M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.7c-2.78.6-3.37-1.34-3.37-1.34-.45-1.16-1.11-1.47-1.11-1.47-.9-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.9 1.52 2.34 1.08 2.91.83.09-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02a9.5 9.5 0 0 1 5 0c1.91-1.3 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.74c0 .27.18.58.69.48A10 10 0 0 0 12 2Z" />
</svg>
);
}
const google: SignInButtonsProvider = { id: "google", label: "Continue with Google", icon: <GoogleMark />, onClick: () => wait(1200) };
const github: SignInButtonsProvider = { id: "github", label: "Continue with GitHub", icon: <GitHubMark />, onClick: () => wait(1200) };
const Cap = ({ children }: { children: ReactNode }) => <p className="-mt-2 text-center text-caption text-muted">{children}</p>;
function Shown({ show }: { show: string }) {
if (show === "more")
return (
<>
<SignInButtons providers={[google, github]} />
<Cap>Providers only, for an app with no email sign-in</Cap>
</>
);
if (show === "sizes")
return (
<>
<SignInButtons providers={[{ id: "passkey", label: "Continue with a passkey", icon: <IconPasskey />, onClick: () => wait(900) }, google]} emailLabel="Email me a link" onEmail={() => wait(900)} />
<Cap>Any mark: a passkey, then Google, then email</Cap>
</>
);
if (show === "states")
return (
<>
<SignInButtons providers={[google, github]} onEmail={() => wait(900)} />
<Cap>Press a provider: it waits on its promise and the others step back until it settles</Cap>
</>
);
return (
<>
<SignInButtons providers={[google, github]} onEmail={() => wait(900)} />
<Cap>The providers in the glass with their marks, email as the primary</Cap>
</>
);
}
export default function SignInButtonsDemo({ show = "styles" }: KnobValues<typeof knobs>) {
return (
<div key={show} className="grid w-full max-w-80 justify-items-center gap-4.5" aria-live="polite">
<Shown show={show} />
</div>
);
}When to use
Use it when
- A sign-in or sign-up page or dialog with one or more identity providers and email.
- Connecting an account inside settings, with the providers your app supports.
Use something else when
- Connecting a tool to an agent (Linear, Slack): use a connection row or the dialog with scopes.
- One provider and nothing else: a single Button is enough.
Installation
Terminal
npx shadcn@latest add @pixilui/sign-in-buttonsAdds sign-in-buttons.tsx with button.tsx, and installs clsx and tailwind-merge. First PixilUI item in this app? Add the registry once, as in Installation.
components/pixilui/sign-in-buttons.tsx
"use client";
import { forwardRef, useState, type ComponentPropsWithoutRef, type ReactNode } from "react";
import { cn } from "./lib/utils";
import { Button } from "./button";
/*
The sign-in stack: one full-width glass secondary per provider with its mark, then the primary
for email. Each button shows its own pending state while its handler's promise runs, and the
others wait, so a second provider cannot start mid-redirect.
*/
export type SignInButtonsProvider = {
/** A stable id ("google", "github"); also the button's data-provider. */
id: string;
/** The label, a verb first: "Continue with Google". */
label: string;
/** The provider's mark, in currentColor or its own colors: an svg, or an icon component that passes `className` to its svg so the button can size it. */
icon?: ReactNode;
/** Starts the sign-in. Return a promise to show the button as loading until it settles. */
onClick?: () => void | Promise<void>;
};
export type SignInButtonsProps = Omit<ComponentPropsWithoutRef<"div">, "children"> & {
/** The providers, in order, each a full-width secondary. */
providers: SignInButtonsProvider[];
/** The primary's label. */
emailLabel?: string;
/** Continues with email. Leave it out to show providers only. Return a promise to show loading. */
onEmail?: () => void | Promise<void>;
};
/** Full-width provider buttons with their marks, then the email primary; each shows its own loading while its sign-in starts. */
export const SignInButtons = forwardRef<HTMLDivElement, SignInButtonsProps>(function SignInButtons(
{ providers, emailLabel = "Continue with email", onEmail, className, ...rest },
ref,
) {
const [pending, setPending] = useState<string | null>(null);
const run = async (id: string, action?: () => void | Promise<void>) => {
if (!action || pending) return;
const result = action();
if (!(result instanceof Promise)) return;
setPending(id);
try {
await result;
} finally {
setPending(null);
}
};
return (
<div ref={ref} className={cn("grid w-full max-w-80 gap-2 font-body", className)} data-pending={pending ?? undefined} {...rest}>
{providers.map((provider) => (
<Button
key={provider.id}
size="lg"
block
icon={provider.icon}
data-provider={provider.id}
loading={pending === provider.id}
aria-disabled={pending !== null && pending !== provider.id ? true : undefined}
onClick={() => void run(provider.id, provider.onClick)}
>
{provider.label}
</Button>
))}
{onEmail !== undefined || providers.length === 0 ? (
<Button
variant="primary"
size="lg"
block
data-provider="email"
loading={pending === "email"}
aria-disabled={pending !== null && pending !== "email" ? true : undefined}
onClick={() => void run("email", onEmail)}
>
{emailLabel}
</Button>
) : null}
</div>
);
});
It uses Button: add it the same way. Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
example.tsx
import { SignInButtons } from "@/components/pixilui/sign-in-buttons";
<SignInButtons providers={providers} onEmail={onEmail} />Fills its container up to 320px (max-w-80); set a className to change the measure.
API reference
PropTypeDefault
providersRequiredSignInButtonsProvider[]–The providers, in order, each a full-width secondary.emailLabelstring"Continue with email"The primary's label.onEmail() => void | Promise<void>–Continues with email. Leave it out to show providers only. Return a promise to show loading.Also takes every native <div> attribute, and a ref.
Keyboard
TabMoves through the providers, then the email button.
EnterStarts the focused sign-in; focus stays on it while it loads.
SpaceStarts the focused sign-in on release.
Accessibility
- Native buttons; each label says what happens ("Continue with GitHub"), and the marks are aria-hidden.
- While one sign-in runs, it is aria-busy and the others are aria-disabled, never disabled, so focus stays where it was.
- data-provider names each button and data-pending the running one, for styling and tests.
Motion
- The pressed button swaps its mark for the ring spinner, cross-fading in 200ms; the width holds, since it fills the stack.
- Each press scales to .96 in 150ms ease-out.
- Reduced motion: no press scale; the spinner slows to a still-readable turn.