Button
A button component that can be rendered as another tag or focusable when disabled.
Measured from the Codex desktop app's sidebar and composer buttons. Only the ghost buttons in light mode have references.
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="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="accent">Accent</Button>
<Button variant="danger">Danger</Button>Sizes
<Button size="compact">Compact</Button>
<Button size="toolbar">Toolbar</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 Codex style: the measured tokens, the CSS and the structure.
Show Prompt
# Codex 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 Codex's. Measured from the running Codex app (openai.com/codex). 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 Codex desktop app's sidebar and composer buttons. Only the ghost buttons in light mode have references.
## Variants
- `variant`: `primary`, `secondary`, `outline`, `ghost`, `accent`, `danger`
- `size`: `compact`, `toolbar`, `medium`, `large`
## Tokens
| Token | Light | Dark |
| --- | --- | --- |
| `--border-secondary` | `rgb(13 13 13 / 0.087)` | `rgb(255 255 255 / 0.084)` |
| `--text-primary` | `rgb(26 28 31)` | `#ffffff` |
| `--text-secondary` | `rgb(21 28 42 / 0.8)` | `rgb(255 255 255 / 0.65)` |
| `--text-tertiary` | `rgb(21 28 42 / 0.494)` | `rgb(255 255 255 / 0.498)` |
| `--accent` | `#0d0d0d` | `#ffffff` |
| `--accent-hover` | `#303030` | `#ededed` |
| `--accent-text` | `#ffffff` | `#2d2d2d` |
| `--brand-bg` | `#339cff` | `#339cff` |
| `--brand-bg-hover` | `#0285ff` | `#0285ff` |
| `--brand-bg-active` | `#0169cc` | `#0169cc` |
| `--brand-text` | `#000000` | `#000000` |
| `--chip-bg` | `rgb(255 255 255 / 0.96)` | `rgb(255 255 255 / 0.032)` |
| `--chip-bg-hover` | `rgb(13 13 13 / 0.06)` | `rgb(255 255 255 / 0.078)` |
| `--ghost-bg-hover` | `rgb(26 28 31 / 0.055)` | `rgb(255 255 255 / 0.078)` |
| `--ghost-bg-active` | `rgb(13 13 13 / 0.12)` | `rgb(255 255 255 / 0.16)` |
| `--button-secondary-bg` | `rgb(13 13 13 / 0.05)` | `rgb(255 255 255 / 0.05)` |
| `--button-secondary-bg-hover` | `rgb(13 13 13 / 0.1)` | `rgb(255 255 255 / 0.1)` |
| `--danger-text` | `#ba2623` | `#fa423e` |
| `--danger-bg` | `rgb(250 66 62 / 0.16)` | `rgb(250 66 62 / 0.16)` |
| `--danger-bg-hover` | `rgb(250 66 62 / 0.3)` | `rgb(250 66 62 / 0.3)` |
| `--focus-ring` | `#339cff` | `rgb(131 195 255 / 0.76)` |
| `--font-size-mini` | `12px` | `12px` |
| `--font-size-small` | `13px` | `13px` |
| `--font-size-regular` | `14px` | `14px` |
| `--line-height-mini` | `16px` | `16px` |
| `--corner-shape` | `round` | `round` |
| `--radius-sm` | `calc(6px * var(--radius-scale))` | `calc(6px * var(--radius-scale))` |
| `--radius-md` | `calc(8px * var(--radius-scale))` | `calc(8px * var(--radius-scale))` |
| `--radius-rounded` | `9999px` | `9999px` |
| `--control-2xs` | `24px` | `24px` |
| `--control-sm` | `28px` | `28px` |
| `--control-md` | `32px` | `32px` |
| `--control-lg` | `36px` | `36px` |
| `--ease-basic` | `ease` | `ease` |
| `--transition-duration-basic` | `0.15s` | `0.15s` |
| `--indicator-rotate-duration` | `0.8s` | `0.8s` |
## CSS
Scoped under `[data-style="codex"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.
```css
[data-style="codex"] {
.ui-button {
--button-height: var(--control-md);
--button-gutter: 16px;
--button-fg: var(--text-primary);
--button-fg-hover: var(--button-fg);
--button-bg: var(--button-secondary-bg);
--button-bg-hover: var(--button-secondary-bg-hover);
--button-bg-active: var(--button-secondary-bg-hover);
--button-border: transparent;
--button-border-hover: var(--button-border);
position: relative;
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 4px;
height: var(--button-height);
margin: 0;
padding: 0 var(--button-gutter);
border: 1px solid var(--button-border);
border-radius: var(--radius-md);
corner-shape: var(--corner-shape);
background-color: var(--button-bg);
color: var(--button-fg);
font-family: inherit;
font-size: var(--font-size-regular);
font-weight: 400;
line-height: 1;
white-space: nowrap;
user-select: none;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
transition:
background-color var(--transition-duration-basic) var(--ease-basic),
border-color var(--transition-duration-basic) var(--ease-basic),
color var(--transition-duration-basic) var(--ease-basic),
opacity var(--transition-duration-basic) var(--ease-basic);
@media (hover: hover) {
&:hover:not([data-disabled], [data-loading]) {
border-color: var(--button-border-hover);
background-color: var(--button-bg-hover);
color: var(--button-fg-hover);
}
}
&:active:not([data-disabled], [data-loading]) {
background-color: var(--button-bg-active);
}
&:focus-visible {
outline: none;
box-shadow: 0 0 0 2px var(--focus-ring);
}
&[data-disabled]:not([data-loading]) {
opacity: 0.4;
cursor: default;
}
& svg {
width: 16px;
height: 16px;
flex-shrink: 0;
}
}
.ui-button[data-size="compact"] {
--button-height: var(--control-2xs);
--button-gutter: 8px;
font-size: var(--font-size-mini);
line-height: var(--line-height-mini);
}
.ui-button:is([data-size="toolbar"], [data-size="small"]) {
--button-height: var(--control-sm);
--button-gutter: 8px;
border-radius: var(--radius-sm);
font-size: var(--font-size-small);
}
.ui-button[data-size="medium"] {
--button-height: var(--control-md);
--button-gutter: 16px;
}
.ui-button[data-size="large"] {
--button-height: var(--control-lg);
--button-gutter: 20px;
border-radius: var(--radius-rounded);
corner-shape: round;
}
.ui-button[data-icon-only] {
width: var(--button-height);
padding: 0;
}
.ui-button[data-variant="primary"] {
--button-fg: var(--accent-text);
--button-bg: var(--accent);
--button-bg-hover: var(--accent-hover);
--button-bg-active: var(--accent-hover);
--button-border: var(--border-secondary);
}
.ui-button:is(:not([data-variant]), [data-variant="secondary"]) {
--button-bg: var(--button-secondary-bg);
--button-bg-hover: var(--button-secondary-bg-hover);
--button-bg-active: var(--button-secondary-bg-hover);
}
.ui-button[data-variant="outline"] {
--button-bg: var(--chip-bg);
--button-bg-hover: var(--chip-bg-hover);
--button-bg-active: var(--ghost-bg-active);
--button-border: var(--border-secondary);
}
.ui-button[data-variant="ghost"] {
--button-fg: var(--text-secondary);
--button-bg: transparent;
--button-bg-hover: var(--ghost-bg-hover);
--button-bg-active: var(--ghost-bg-active);
}
.ui-button[data-variant="ghost"][data-icon-only] {
--button-fg: var(--text-tertiary);
--button-fg-hover: var(--text-secondary);
}
.ui-button[data-variant="accent"] {
--button-fg: var(--brand-text);
--button-bg: var(--brand-bg);
--button-bg-hover: var(--brand-bg-hover);
--button-bg-active: var(--brand-bg-active);
}
.ui-button[data-variant="danger"] {
--button-fg: var(--danger-text);
--button-bg: var(--danger-bg);
--button-bg-hover: var(--danger-bg-hover);
--button-bg-active: var(--danger-bg-hover);
}
.ui-button[data-loading] {
color: transparent;
cursor: wait;
& > :not(.ui-button-spinner) {
opacity: 0;
}
}
.ui-button-spinner {
position: absolute;
top: 50%;
left: 50%;
box-sizing: border-box;
width: 14px;
height: 14px;
margin: -7px 0 0 -7px;
border: 1.5px solid var(--button-fg);
border-radius: var(--radius-rounded);
mask-image: conic-gradient(transparent 15%, #000);
animation: codex-spinner-spin var(--indicator-rotate-duration) linear infinite;
}
@media (prefers-reduced-motion: reduce) {
.ui-button-spinner {
animation-duration: 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 Codex style, as a skill: https://replicas.raphaelsalaja.com/skills/codex/SKILL.md