Sign-in provider button
Sign-in button for a provider or method, such as Continue with Google or Sign in with a passkey, with an icon slot and a last-used tag.
pnpm dlx shadcn@latest add @haze/oauth-button---
import { Building2, KeyRound, Mail, Smartphone } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
/** Name of the provider, used in the default label: "Continue with Google". */
provider?: string;
/** "provider" shows no icon unless you pass one in the icon slot. The others draw a generic icon. */
method?: "provider" | "email" | "passkey" | "sso" | "phone";
/** Replaces the default label. Keep the provider name in it. */
label?: string;
variant?: "outline" | "solid";
size?: "sm" | "md" | "lg";
fullWidth?: boolean;
/** Replaces the label with a spinner and disables the button. The button keeps its width. */
loading?: boolean;
/** Shows a small "Last used" tag after the label. */
lastUsed?: boolean;
/** Renders a link instead of a button. */
href?: string;
type?: "button" | "submit" | "reset";
class?: string;
[key: string]: unknown;
}
const {
provider = "Google",
method = "provider",
label,
variant = "outline",
size = "md",
fullWidth = false,
loading = false,
lastUsed = false,
href,
type = "button",
class: className,
...rest
} = Astro.props;
const defaultLabels = {
provider: `Continue with ${provider}`,
email: "Continue with email",
passkey: "Sign in with a passkey",
sso: "Continue with SSO",
phone: "Continue with your phone",
};
const text = label ?? defaultLabels[method];
const icons = { email: Mail, passkey: KeyRound, sso: Building2, phone: Smartphone };
const Icon = method === "provider" ? undefined : icons[method];
const hasIcon = Astro.slots.has("icon");
const variants = {
outline: "border border-frame bg-field text-foreground shadow-key hover:border-frame-strong hover:bg-accent active:bg-accent",
solid: "border border-primary bg-primary text-primary-foreground hover:opacity-91 hover:shadow-key active:opacity-84",
};
const sizes = {
sm: "h-8 gap-1.5 px-3",
md: "h-10 gap-2 px-4",
lg: "h-11 gap-2 px-4.5",
};
const classes = cn(
"relative inline-flex shrink-0 cursor-pointer items-center justify-center rounded-lg text-[0.8125rem]/5 font-medium whitespace-nowrap select-none",
"transition-[background-color,border-color,color,box-shadow,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-100",
"focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",
"disabled:pointer-events-none disabled:opacity-52 aria-disabled:pointer-events-none aria-disabled:opacity-52 [&_svg]:size-4 [&_svg]:shrink-0",
sizes[size],
variants[variant],
fullWidth ? "w-full" : "max-w-full",
lastUsed && "px-3",
loading && "disabled:opacity-100",
className,
);
const spinner = "size-4 animate-spin rounded-full border-2 border-current border-r-transparent";
---
{
href ? (
<a href={href} class={classes} {...rest}>
{hasIcon ? <span aria-hidden="true" class="inline-flex shrink-0 items-center"><slot name="icon" /></span> : Icon && <Icon aria-hidden="true" />}
<span class="min-w-0 truncate">{text}</span>
{lastUsed && <span class="shrink-0 rounded-sm border border-border px-1 text-muted-foreground text-[0.6875rem]/4 font-medium">Last used</span>}
</a>
) : (
<button type={type} class={classes} disabled={loading || undefined} aria-busy={loading ? "true" : undefined} {...rest}>
<span class={cn("inline-flex min-w-0 items-center justify-center gap-[inherit]", loading && "opacity-0")}>
{hasIcon ? <span aria-hidden="true" class="inline-flex shrink-0 items-center"><slot name="icon" /></span> : Icon && <Icon aria-hidden="true" />}
<span class="min-w-0 truncate">{text}</span>
{lastUsed && <span class="shrink-0 rounded-sm border border-border px-1 text-muted-foreground text-[0.6875rem]/4 font-medium">Last used</span>}
</span>
{loading && <span class="absolute inset-0 grid place-items-center"><span aria-hidden="true" class={spinner} /></span>}
</button>
)
}When to use
- Listing the ways to sign in or sign up on a login screen, one button per provider or method
- Marking the method the person used last so they can pick it again quickly
- A generic icon for email, passkey, SSO or phone sign-in without drawing any brand mark
When not to use
- A general action such as Save or Delete; use button
- Several related actions grouped in one bar; use button-group
Installation
Add the Haze registry to components.json once, then install Sign-in provider button with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/oauth-buttonnpx shadcn@latest add @haze/oauth-buttonyarn dlx shadcn@latest add @haze/oauth-buttonbunx --bun shadcn@latest add @haze/oauth-buttonFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| provider | string | "Google" | Provider name used in the default label "Continue with {provider}" when method is "provider". |
| method | "provider" | "email" | "passkey" | "sso" | "phone" | "provider" | Picks the default label and a generic icon (mail, key, building, phone). "provider" draws no icon unless you fill the icon slot. |
| label | string | – | Replaces the default label. Keep the provider or method in it so the accessible name stays clear. |
| variant | "outline" | "solid" | "outline" | outline is a raised key (border, card fill, resting shadow); solid is the primary fill. |
| size | "sm" | "md" | "lg" | "md" | Height 32, 40 or 44 px. |
| fullWidth | boolean | false | Stretches to the width of its container; a stack of these lines up at one width. |
| loading | boolean | false | Shows a spinner, disables the button and sets aria-busy. The label stays in the DOM and the width does not change. Buttons only, not links. |
| lastUsed | boolean | false | Adds a small bordered "Last used" tag after the label. It is text, so it does not rely on color. |
| href | string | – | Renders an <a> to your provider's authorize URL instead of a <button>. |
| type | "button" | "submit" | "reset" | "button" | Button type when no href is set. |
| icon (slot) | named slot | – | Where you place the provider's official mark, taken from the provider's own brand guidelines. The wrapper is aria-hidden and sizes the svg to 16 px. |
| class | string | – | Extra classes, merged with tailwind-merge. |
| ...attributes | HTML button or anchor attributes | – | Passed to the <button> or <a>: name, value, form, formaction, aria-describedby, data attributes. |
Keyboard interactions
- EnterSpace
- Activate (Space only for <button>)
Accessibility
- The visible label is the accessible name and always includes the provider or method ("Continue with GitHub"), so a screen reader list of buttons is distinguishable. If you override label, keep the provider in it.
- Icons, generic or slotted, are aria-hidden and never the only content. This component draws no brand marks; put the provider's official mark in the icon slot and follow that provider's brand guidelines for size, color and spacing.
- "Last used" is visible text inside the button, so it is read as part of the name and does not depend on color.
- A loading button is disabled and aria-busy. Its label stays in the DOM, hidden from sight, so the name does not change while it works.
- Keyboard focus shows a 2 px outline with a 2 px offset; the smallest size is 32 px tall and the label truncates with an ellipsis rather than overflowing at narrow widths.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Sign-in provider button" with `npx shadcn@latest add @haze/oauth-button`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import OauthButton from "@/components/haze/ui/oauth-button.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/oauth-button.md
Customize with real content
Adapt the Haze oauth-button ui for our product. Replace the demo values of these props with our real content: provider, method, label, variant, size, fullWidth, loading, lastUsed, href, type, icon (slot), class, ...attributes. Keep the layout, the heading level rules and these accessibility details: The visible label is the accessible name and always includes the provider or method ("Continue with GitHub"), so a screen reader list of buttons is distinguishable. If you override label, keep the provider in it. Icons, generic or slotted, are aria-hidden and never the only content. This component draws no brand marks; put the provider's official mark in the icon slot and follow that provider's brand guidelines for size, color and spacing. "Last used" is visible text inside the button, so it is read as part of the name and does not depend on color. A loading button is disabled and aria-busy. Its label stays in the DOM, hidden from sight, so the name does not change while it works. Keyboard focus shows a 2 px outline with a 2 px offset; the smallest size is 32 px tall and the label truncates with an ellipsis rather than overflowing at narrow widths. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using oauth-button, check it fits: use it when listing the ways to sign in or sign up on a login screen, one button per provider or method; marking the method the person used last so they can pick it again quickly; a generic icon for email, passkey, sso or phone sign-in without drawing any brand mark. Avoid it when a general action such as save or delete; use button; several related actions grouped in one bar; use button-group. Alternatives: @haze/button, @haze/button-group.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.