Button
A button component that can be rendered as another tag or focusable when disabled.
Measured from the Stripe Dashboard's products page buttons and Sail's Button styles. The primary and secondary buttons have rest and hover references. Destructive and the small and large sizes follow Sail.
import { Button } from "@replicas/ui";
export default function ButtonDemo() {
return (
<>
<Button variant="primary">Save changes</Button>
<Button>Share</Button>
<Button variant="ghost">Cancel</Button>
<Button size="small">Edit</Button>
<Button disabled>Disabled</Button>
</>
);
}Examples
Variants
<Button variant="primary">Primary</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="destructive">Destructive</Button>Sizes
<Button size="small">Small</Button>
<Button size="medium">Medium</Button>
<Button size="large">Large</Button>With Icon
function WithIcon() {
return (
<Button variant="primary">
{plus}
New file
</Button>
);
}Icon Only
function IconOnly() {
return (
<Tooltip content="New file">
<Button iconOnly aria-label="New file">
{plus}
</Button>
</Tooltip>
);
}Loading State
function LoadingState() {
return <Button loading>Saving</Button>;
}Disabled State
function DisabledState() {
return <Button disabled>Archive</Button>;
}Link As Button
function LinkAsButton() {
return <Button nativeButton={false} render={<a href="#" />}>Open docs</Button>;
}Prompt
Copy Prompt hands your agent everything it needs to build the Button in the Stripe style: the measured tokens, the CSS and the structure.
Show Prompt
# Stripe Button
A button component that can be rendered as another tag or focusable when disabled.
Build a Button in this project that looks and behaves like Stripe's. Measured from the running Stripe app (dashboard.stripe.com). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or [Base UI](https://base-ui.com/react/components/button) if it has none.
Fidelity: Measured from the Stripe Dashboard's products page buttons and Sail's Button styles. The primary and secondary buttons have rest and hover references. Destructive and the small and large sizes follow Sail.
## Variants
- `variant`: `primary`, `secondary`, `destructive`
- `size`: `small`, `medium`, `large`
## Tokens
| Token | Light | Dark |
| --- | --- | --- |
| `--color-text-action-secondary` | `#273951` | `#c9ced8` |
| `--color-text-on-action-primary` | `#ffffff` | `#eceef1` |
| `--color-text-on-action-primary-pressed` | `#e0d9fb` | `#eceef1` |
| `--color-background-surface` | `#ffffff` | `#14171d` |
| `--color-background-offset` | `#f4f7fa` | `#1b1e25` |
| `--color-background-container` | `#ecf1f6` | `#21252c` |
| `--color-background-action-primary` | `#533afd` | `#5f4cfe` |
| `--color-background-action-primary-pressed` | `#4e11e2` | `#581bf7` |
| `--color-background-action-secondary` | `#ffffff` | `#1a1d24` |
| `--color-background-action-secondary-pressed` | `#f4f7fa` | `#1f222a` |
| `--color-background-action-destructive` | `#e61947` | `#cc2748` |
| `--color-background-action-destructive-pressed` | `#c0123c` | `#f23154` |
| `--color-border-action-primary` | `#533afd` | `#5f4cfe` |
| `--color-border-action-primary-hovered` | `#44139f` | `#746cff` |
| `--color-border-action-secondary` | `#d4dee9` | `#272c34` |
| `--color-border-action-secondary-hovered` | `#95a4ba` | `#3e444f` |
| `--color-border-action-destructive` | `#e61947` | `#cc2748` |
| `--color-border-action-destructive-hovered` | `#9b0c36` | `#f23154` |
| `--shadow-action-primary` | `0 0 0 0 transparent` | `0 -1px 0 0 #746cff` |
| `--shadow-action-primary-pressed` | `0 -1px 1px 0 rgba(20, 19, 78, 0.32)` | `0 -1px 0 0 #746cff` |
| `--shadow-action-secondary` | `0 0 0 0 transparent` | `0 -1px 0 0 #3e444f` |
| `--shadow-action-secondary-pressed` | `0 -1px 1px 0 rgba(16, 17, 26, 0.16)` | `0 -1px 0 0 #3e444f` |
| `--shadow-action-destructive` | `0 0 0 0 transparent` | `0 -1px 0 0 #f46b7d` |
| `--shadow-action-destructive-pressed` | `0 -1px 1px 0 rgba(62, 2, 26, 0.32)` | `0 -1px 0 0 #f46b7d` |
| `--shadow-focus` | `0 0 0 4px rgba(1, 150, 237, 0.36)` | `0 0 0 4px rgba(43, 157, 246, 0.36)` |
| `--border-radius-small` | `6px` | `6px` |
| `--border-radius-rounded` | `9999px` | `9999px` |
| `--font-label-small` | `12px` | `12px` |
| `--font-label-medium` | `14px` | `14px` |
| `--font-label-large` | `16px` | `16px` |
| `--line-height-small` | `16px` | `16px` |
| `--line-height-medium` | `20px` | `20px` |
| `--line-height-large` | `24px` | `24px` |
| `--duration-medium` | `150ms` | `150ms` |
| `--duration-spinner-fade` | `250ms` | `250ms` |
| `--duration-spinner` | `700ms` | `700ms` |
| `--ease-default` | `cubic-bezier(0, 0.09, 0.4, 1)` | `cubic-bezier(0, 0.09, 0.4, 1)` |
| `--ease-action` | `ease-out` | `ease-out` |
| `--font-weight-semibold` | `600` | `600` |
| `--speed-highlight-fade-in` | `0s` | `0s` |
## CSS
Scoped under `[data-style="stripe"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.
```css
[data-style="stripe"] {
.ui-button {
--top-shadow: var(--shadow-action-secondary);
--keyline: var(--color-border-action-secondary);
--focus-shadow: 0 0 0 0 transparent;
position: relative;
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
min-height: 28px;
margin: 0;
padding: 4px 8px;
border: 0;
border-radius: var(--border-radius-small);
background-color: var(--color-background-action-secondary);
box-shadow:
var(--top-shadow),
0 0 0 1px var(--keyline),
var(--focus-shadow),
0 0 0 0 transparent;
color: var(--color-text-action-secondary);
font-family: inherit;
font-size: var(--font-label-medium);
font-weight: var(--font-weight-semibold);
line-height: var(--line-height-medium);
white-space: nowrap;
user-select: none;
cursor: pointer;
outline: none;
transition:
background-color var(--duration-medium) var(--ease-default),
box-shadow var(--duration-medium) var(--ease-default);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--keyline: var(--color-border-action-secondary-hovered);
transition-duration: var(--speed-highlight-fade-in);
}
}
&:active:not([data-disabled]) {
--top-shadow: var(--shadow-action-secondary-pressed);
background-color: var(--color-background-action-secondary-pressed);
transition-duration: var(--speed-highlight-fade-in);
}
&::before {
content: "\200b";
display: block;
height: var(--line-height-medium);
margin-right: -6px;
}
&:focus-visible {
--focus-shadow: var(--shadow-focus);
}
&[data-disabled] {
cursor: default;
&::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
background-color: var(--color-background-surface);
opacity: 0.5;
pointer-events: none;
}
}
& svg {
width: 12px;
height: 12px;
flex-shrink: 0;
fill: currentColor;
}
}
.ui-button[data-size="small"] {
gap: 4px;
min-height: 24px;
padding: 4px 8px;
font-size: var(--font-label-small);
line-height: var(--line-height-small);
&::before {
height: var(--line-height-small);
margin-right: -4px;
}
}
.ui-button[data-size="large"] {
gap: 8px;
min-height: 40px;
padding: 8px 16px;
font-size: var(--font-label-large);
line-height: var(--line-height-large);
&::before {
height: var(--line-height-large);
margin-right: -8px;
}
& svg {
width: 16px;
height: 16px;
}
}
.ui-button[data-icon-only] {
width: 28px;
height: 28px;
padding: 0;
&[data-size="small"] {
width: 24px;
height: 24px;
}
&[data-size="large"] {
width: 40px;
height: 40px;
}
}
.ui-button[data-variant="primary"] {
--top-shadow: var(--shadow-action-primary);
--keyline: var(--color-border-action-primary);
background-color: var(--color-background-action-primary);
color: var(--color-text-on-action-primary);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--keyline: var(--color-border-action-primary-hovered);
}
}
&:active:not([data-disabled]) {
--top-shadow: var(--shadow-action-primary-pressed);
--keyline: var(--color-border-action-primary-hovered);
background-color: var(--color-background-action-primary-pressed);
color: var(--color-text-on-action-primary-pressed);
}
}
.ui-button[data-variant="destructive"] {
--top-shadow: var(--shadow-action-destructive);
--keyline: var(--color-border-action-destructive);
background-color: var(--color-background-action-destructive);
color: var(--color-text-on-action-primary);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--keyline: var(--color-border-action-destructive-hovered);
}
}
&:active:not([data-disabled]) {
--top-shadow: var(--shadow-action-destructive-pressed);
--keyline: var(--color-border-action-destructive-hovered);
background-color: var(--color-background-action-destructive-pressed);
}
}
.ui-button[data-variant="ghost"] {
--top-shadow: 0 0 0 0 transparent;
--keyline: transparent;
background-color: transparent;
transition: background-color var(--duration-medium) var(--ease-action);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--keyline: transparent;
background-color: var(--color-background-offset);
}
}
&:active:not([data-disabled]) {
background-color: var(--color-background-container);
}
}
.ui-button[data-loading] {
cursor: default;
&::after {
content: none;
}
}
.ui-button-spinner {
box-sizing: border-box;
width: 12px;
height: 12px;
flex-shrink: 0;
border: 1.5px solid currentColor;
border-right-color: transparent;
border-radius: var(--border-radius-rounded);
animation:
stripe-spinner-fade var(--duration-spinner-fade) ease,
stripe-spinner-spin var(--duration-spinner) linear infinite;
}
@media (prefers-reduced-motion: reduce) {
.ui-button-spinner {
animation-duration: var(--duration-spinner-fade), 2s;
}
}
}
```
## Structure
How Replicas assembles it on Base UI.
```tsx
import { Button as BaseButton } from "@base-ui/react/button";
import { join } from "./utils";
export type ButtonProps = Omit<BaseButton.Props, "className"> & {
className?: string;
variant?: string;
size?: string;
iconOnly?: boolean;
loading?: boolean;
};
export function Button({
className,
variant = "secondary",
size = "medium",
iconOnly = false,
loading = false,
disabled,
children,
...props
}: ButtonProps) {
return (
<BaseButton
className={join("ui-button", className)}
data-variant={variant}
data-size={size}
data-icon-only={iconOnly || undefined}
data-loading={loading || undefined}
aria-busy={loading || undefined}
disabled={disabled || loading}
focusableWhenDisabled={loading}
{...props}
>
{loading ? <span className="ui-button-spinner" aria-hidden /> : null}
{children}
</BaseButton>
);
}
```
## Example
```tsx
import { Button } from "@replicas/ui";
export default function ButtonDemo() {
return (
<>
<Button variant="primary">Save changes</Button>
<Button>Share</Button>
<Button variant="ghost">Cancel</Button>
<Button size="small">Edit</Button>
<Button disabled>Disabled</Button>
</>
);
}
```
## Foundations
The rest of the Stripe style, as a skill: https://replicas.raphaelsalaja.com/skills/stripe/SKILL.md