Button
A button component that can be rendered as another tag or focusable when disabled.
Measured from The Today, Realtime, Performance and Start trial buttons on the public demo dashboard (visitors.now/s/godly.website), and the login page buttons. Surface, surface hover, primary, primary disabled, ghost, ghost xs, its hover and its disabled state are checked in light and dark. Solid, outline, transparent, destructive and the icon size come from the same variant map.
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="solid">Solid</Button>
<Button variant="primary">Primary</Button>
<Button variant="surface">Surface</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="transparent">Transparent</Button>
<Button variant="destructive">Destructive</Button>Sizes
<Button size="xs">Xs</Button>
<Button size="sm">Sm</Button>
<Button size="default">Default</Button>
<Button size="icon">Icon</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 Visitors style: the measured tokens, the CSS and the structure.
Show Prompt
# Visitors 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 Visitors's. Measured from the running Visitors app (visitors.now). 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 Today, Realtime, Performance and Start trial buttons on the public demo dashboard (visitors.now/s/godly.website), and the login page buttons. Surface, surface hover, primary, primary disabled, ghost, ghost xs, its hover and its disabled state are checked in light and dark. Solid, outline, transparent, destructive and the icon size come from the same variant map.
## Variants
- `variant`: `solid`, `primary`, `surface`, `outline`, `ghost`, `transparent`, `destructive`
- `size`: `xs`, `sm`, `default`, `icon`
## Tokens
| Token | Light | Dark |
| --- | --- | --- |
| `--background` | `#fff` | `#14141f` |
| `--bg-1` | `#fff` | `#181925` |
| `--bg-2` | `#f5f5f5` | `#212131` |
| `--bg-3` | `#f0f0f0` | `#2b2c3b` |
| `--bg-4` | `#e8e8e8` | `#333447` |
| `--fg-1` | `#b3b3b3` | `#73748c` |
| `--fg-3` | `#666` | `#bbbcc3` |
| `--fg-4` | `#181925` | `#eaeaeb` |
| `--bg-a2` | `#0000000d` | `#cccfff1a` |
| `--fg-a1` | `#0000004d` | `#ffffff4d` |
| `--red-2` | `#ffe2db` | `#4d0e00` |
| `--red-4` | `#ff2f00` | `#ff2f00` |
| `--purple-2` | `#dad9fc` | `#080547` |
| `--purple-4` | `#918df6` | `#9580ff` |
| `--shadow-1` | `0px 1px 1px #00000014, 0px 0px 0px 1px #0000000d` | `0px 1px 1px #00000014, 0px 0px 0px 1px #0000000d` |
| `--shadow-surface` | `0px 1px 1px rgba(0, 0, 0, 0.08), 0px 0px 0px 1px rgba(0, 0, 0, 0.05)` | `0px 1px 1px rgba(0, 0, 0, 0.08), inset 0px 0px 0px 1px rgba(255, 255, 255, 0.1)` |
| `--shadow-surface-hover` | `0px 1px 1px rgba(0, 0, 0, 0.12), 0px 0px 0px 1px rgba(0, 0, 0, 0.1)` | `0px 1px 1px rgba(0, 0, 0, 0.1), inset 0px 0px 0px 1px rgba(255, 255, 255, 0.2)` |
| `--surface-control` | `#fff` | `#2b2c3b` |
| `--ghost-fill` | `#00000008` | `#cccfff24` |
| `--ghost-fill-hover` | `#0000000d` | `#cccfff33` |
| `--button-ghost-border` | `color-mix(in srgb, var(--fg-4) 12%, transparent)` | `color-mix(in srgb, var(--fg-4) 12%, transparent)` |
| `--font-regular` | `"OpenRunde", "Open Runde", "Inter", sans-serif` | `"OpenRunde", "Open Runde", "Inter", sans-serif` |
| `--letter-spacing` | `-0.32px` | `-0.32px` |
| `--font-size-mini` | `0.75rem` | `0.75rem` |
| `--font-size-small` | `0.875rem` | `0.875rem` |
| `--font-size-regular` | `1rem` | `1rem` |
| `--font-weight-medium` | `500` | `500` |
| `--radius-rounded` | `9999px` | `9999px` |
| `--ease-in-out` | `cubic-bezier(0.4, 0, 0.2, 1)` | `cubic-bezier(0.4, 0, 0.2, 1)` |
| `--duration-fast` | `150ms` | `150ms` |
| `--duration-spin` | `1s` | `1s` |
## CSS
Scoped under `[data-style="visitors"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.
```css
[data-style="visitors"] {
.ui-button {
--button-text: var(--fg-4);
--button-shadow: var(--shadow-surface);
position: relative;
box-sizing: border-box;
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
gap: 8px;
height: 32px;
margin: 0;
padding: 0 10px;
border: 0 solid transparent;
border-radius: var(--radius-rounded);
corner-shape: superellipse(1.125);
background-color: var(--surface-control);
box-shadow: var(--button-shadow);
color: var(--button-text);
font-family: var(--font-regular);
font-size: var(--font-size-small);
font-weight: var(--font-weight-medium);
line-height: 20px;
letter-spacing: var(--letter-spacing);
white-space: nowrap;
cursor: pointer;
user-select: none;
transition: all var(--duration-fast) var(--ease-in-out);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--button-shadow: var(--shadow-surface-hover);
}
}
&:active:not([data-disabled]) {
background-color: var(--bg-1);
scale: 0.99;
}
&:focus-visible {
outline: none;
box-shadow:
0 0 0 4px var(--background),
0 0 0 6px var(--purple-2),
var(--button-shadow);
}
&[data-disabled] {
--button-text: var(--fg-1);
cursor: not-allowed;
& svg {
opacity: 0.3;
}
}
& svg {
width: 16px;
height: 16px;
flex-shrink: 0;
pointer-events: none;
}
}
&[data-theme="dark"] .ui-button:active:not([data-disabled]) {
background-color: var(--bg-4);
}
.ui-button:is([data-size="xs"], [data-size="small"]) {
gap: 4px;
height: 24px;
padding: 0 8px;
font-size: var(--font-size-mini);
line-height: 16px;
}
.ui-button:is([data-size="sm"], [data-size="medium"]) {
height: 32px;
padding: 0 10px;
}
.ui-button:is([data-size="default"], [data-size="large"]) {
height: 44px;
padding: 0 20px;
font-size: var(--font-size-regular);
line-height: 24px;
}
.ui-button[data-size="icon"] {
width: 30px;
height: 30px;
padding: 0;
}
.ui-button[data-icon-only] {
aspect-ratio: 1;
padding: 0;
}
.ui-button[data-variant="solid"] {
--button-text: var(--background);
--button-shadow: var(--shadow-1);
background-color: var(--fg-4);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--button-shadow: var(--shadow-1);
background-color: color-mix(in srgb, var(--fg-4) 80%, transparent);
}
}
&:active:not([data-disabled]) {
background-color: var(--fg-4);
}
}
.ui-button[data-variant="primary"] {
--button-text: #fff;
--button-shadow: 0 0 #0000;
background-color: var(--purple-4);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--button-shadow: 0 0 #0000;
opacity: 0.9;
}
}
&:active:not([data-disabled]) {
background-color: var(--purple-4);
}
&[data-disabled] {
--button-text: #fff;
background-color: var(--purple-2);
}
}
&[data-theme="dark"] .ui-button[data-variant="primary"][data-disabled] {
background-color: var(--bg-3);
}
.ui-button[data-variant="outline"] {
--button-shadow: 0 0 #0000;
border-width: 1px;
border-color: var(--button-ghost-border);
background-color: transparent;
backdrop-filter: blur(16px);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--button-shadow: 0 0 #0000;
border-color: color-mix(in srgb, var(--fg-4) 24%, transparent);
}
}
&:active:not([data-disabled]) {
background-color: var(--bg-2);
}
}
.ui-button[data-variant="ghost"] {
--button-text: var(--fg-3);
--button-shadow: 0 0 #0000;
background-color: var(--ghost-fill);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--button-shadow: 0 0 #0000;
background-color: var(--ghost-fill-hover);
}
}
&:active:not([data-disabled]) {
background-color: var(--ghost-fill-hover);
}
&[data-disabled] {
--button-text: color-mix(in srgb, var(--fg-a1) 50%, transparent);
background-color: var(--bg-2);
}
}
&[data-theme="dark"] .ui-button[data-variant="ghost"][data-disabled] {
background-color: var(--ghost-fill);
}
.ui-button[data-variant="transparent"] {
--button-shadow: 0 0 #0000;
background-color: transparent;
@media (hover: hover) {
&:hover:not([data-disabled]) {
--button-shadow: 0 0 #0000;
background-color: color-mix(in srgb, var(--bg-a2) 70%, transparent);
}
}
&:active:not([data-disabled]) {
background-color: var(--bg-a2);
}
}
.ui-button[data-variant="destructive"] {
--button-text: #fff;
--button-shadow: var(--shadow-1);
background-color: var(--red-4);
@media (hover: hover) {
&:hover:not([data-disabled]) {
--button-shadow: var(--shadow-1);
}
}
&:active:not([data-disabled]) {
background-color: var(--red-2);
}
}
.ui-button[data-loading] {
color: transparent;
cursor: wait;
}
.ui-button-spinner {
position: absolute;
inset: 0;
width: 16px;
height: 16px;
margin: auto;
color: var(--button-text);
&::before,
&::after {
content: "";
position: absolute;
inset: 0;
box-sizing: border-box;
border: 2px solid currentColor;
border-radius: var(--radius-rounded);
}
&::before {
opacity: 0.3;
}
&::after {
border-top-color: transparent;
animation: visitors-button-spin var(--duration-spin) linear infinite;
}
}
@media (prefers-reduced-motion: reduce) {
.ui-button {
transition-duration: 0s;
}
.ui-button:active:not([data-disabled]) {
scale: 1;
}
.ui-button-spinner::after {
animation-duration: 3s;
}
}
}
@keyframes visitors-button-spin {
to {
transform: rotate(360deg);
}
}
```
## 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 Visitors style, as a skill: https://replicas.raphaelsalaja.com/skills/visitors/SKILL.md