Button
A button component that can be rendered as another tag or focusable when disabled.
Measured from Shopify admin Customers header (primary), Add product form (secondary) and Settings > General (tertiary). Primary, secondary and tertiary have rest and hover references in the admin. Critical and critical secondary have no admin instance and are checked against the Polaris 2.0 runtime. Secondary buttons paint on an inner fill span, compared as its own part; the check also reads the empty full-size ::before over the button and reports a transparent fill, which is expected. Page-header secondary buttons use the white page-button tokens; the replica follows the in-card button. Small and large sizes follow the Polaris height scale.
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="secondary">Secondary</Button>
<Button variant="primary">Primary</Button>
<Button variant="tertiary">Tertiary</Button>
<Button variant="critical">Critical</Button>
<Button variant="critical-secondary">Critical secondary</Button>Sizes
<Button size="small">Small</Button>
<Button size="base">Base</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 Shopify style: the measured tokens, the CSS and the structure.
Show Prompt
# Shopify 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 Shopify's. Measured from the running Shopify app (admin.shopify.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 Shopify admin Customers header (primary), Add product form (secondary) and Settings > General (tertiary). Primary, secondary and tertiary have rest and hover references in the admin. Critical and critical secondary have no admin instance and are checked against the Polaris 2.0 runtime. Secondary buttons paint on an inner fill span, compared as its own part; the check also reads the empty full-size ::before over the button and reports a transparent fill, which is expected. Page-header secondary buttons use the white page-button tokens; the replica follows the in-card button. Small and large sizes follow the Polaris height scale.
## Variants
- `variant`: `secondary`, `primary`, `tertiary`, `critical`, `critical-secondary`
- `size`: `small`, `base`, `large`
## Tokens
| Token | Light | Dark |
| --- | --- | --- |
| `--p-border-radius-action` | `624.9375rem` | `624.9375rem` |
| `--p-border-width-050` | `.125rem` | `.125rem` |
| `--p-color-bg-accent-disabled` | `#00000021` | `#ffffff38` |
| `--p-color-bg-fill-disabled` | `#00000008` | `#ffffff0f` |
| `--p-color-bg-fill-transparent-active` | `#00000021` | `#ffffff26` |
| `--p-color-bg-fill-transparent-hover` | `#00000014` | `#ffffff17` |
| `--p-color-border-critical` | `#e2221a` | `#c70a24` |
| `--p-color-border-focus` | `rgba(80,131,240,1)` | `#97adff` |
| `--p-color-button-bg-fill` | `#ebebeb` | `#2f2f2f` |
| `--p-color-button-bg-fill-active` | `#d0d0d0` | `#414141` |
| `--p-color-button-bg-fill-critical` | `#ffe7e6` | `#2f2f2f` |
| `--p-color-button-bg-fill-critical-active` | `#fcb5b1` | `#414141` |
| `--p-color-button-bg-fill-critical-hover` | `#ffd0cc` | `#373737` |
| `--p-color-button-bg-fill-hover` | `#ddd` | `#373737` |
| `--p-color-button-gradient-bg-fill` | `radial-gradient(50% 50% at 50% 0%, #ffffff33 0%, #ffffff00 100%), radial-gradient(49.59% 37.11% at 50.41% 101.56%, #ffffff26 0%, #ffffff00 66.46%)` | `linear-gradient(#ffffff00, #ffffff00)` |
| `--p-color-button-gradient-bg-fill-critical` | `radial-gradient(50% 50% at 50% 0%,rgba(255,255,255,.2) 0%, #ffffff00 100%), radial-gradient(49.59% 37.11% at 50.41% 101.56%, #ffffff26 0%, #ffffff00 66.46%)` | `none` |
| `--p-color-button-primary-bg` | `#101010` | `#fcfcfc` |
| `--p-color-button-primary-bg-active` | `#0a0a0a` | `#c6c6c6` |
| `--p-color-button-primary-bg-critical` | `rgba(216,32,25,1)` | `#c70a24` |
| `--p-color-button-primary-bg-critical-active` | `rgba(179,26,20,1)` | `#8e0b21` |
| `--p-color-button-primary-bg-critical-disabled` | `#00000021` | `#ffffff38` |
| `--p-color-button-primary-bg-critical-hover` | `rgba(206,31,24,1)` | `#a30a24` |
| `--p-color-button-primary-bg-disabled` | `#00000021` | `#ffffff38` |
| `--p-color-button-primary-bg-hover` | `#0a0a0a` | `#eee` |
| `--p-color-button-primary-text` | `#fff` | `#121212` |
| `--p-color-button-primary-text-active` | `#ddd` | `#121212` |
| `--p-color-button-primary-text-critical` | `#fff` | `#fff6f8` |
| `--p-color-button-primary-text-disabled` | `#fff` | `#121212` |
| `--p-color-button-primary-text-hover` | `#ddd` | `#121212` |
| `--p-color-icon-secondary` | `#606060` | `#aaa` |
| `--p-color-icon-secondary-hover` | `#4a4a4a` | `#c6c6c6` |
| `--p-color-text` | `#101010` | `#eee` |
| `--p-color-text-critical-accent` | `rgba(206,31,24,1)` | `#f78086` |
| `--p-color-text-critical-secondary` | `rgba(126,16,12,1)` | `#f78086` |
| `--p-color-text-disabled` | `#a6a6a6` | `#585858` |
| `--p-font-family-sans` | `"ShopifyInter", "Noto Sans Arabic", "Noto Sans Hebrew", ui-sans-serif, system-ui, sans-serif` | `"ShopifyInter", "Noto Sans Arabic", "Noto Sans Hebrew", ui-sans-serif, system-ui, sans-serif` |
| `--p-font-letter-spacing-denser` | `-.01em` | `-.01em` |
| `--p-font-line-height-button-label` | `1rem` | `1rem` |
| `--p-font-size-button-label` | `.75rem` | `.75rem` |
| `--p-font-weight-button-label` | `500` | `500` |
| `--p-height-600` | `1.5rem` | `1.5rem` |
| `--p-height-700` | `1.75rem` | `1.75rem` |
| `--p-height-900` | `2.25rem` | `2.25rem` |
| `--p-shadow-button` | `none` | `0rem 0rem 0rem .03125rem #0000003d, 0rem .0625rem .125rem -.03125rem #0000001f, 0rem .125rem .1875rem -.09375rem #0000001f, 0rem .25rem .25rem -.125rem #0000001f, inset 0rem .0625rem 0rem #ffffff0a, inset 0rem 0rem 0rem .0625rem #ffffff12, inset 0rem .25rem .25rem -.125rem #ffffff0a` |
| `--p-shadow-button-primary` | `0rem .0625rem .03125rem -.03125rem #00000021, 0rem .0625rem .125rem -.03125rem #00000021, 0rem .25rem .375rem -.125rem #00000021, 0rem .125rem .1875rem -.09375rem #00000021, inset 0rem 0rem .25rem .0625rem #101010, inset 0rem 0rem .25rem .125rem #ffffff1a, inset 0rem 0rem .75rem -.375rem #ffffffbf` | `0rem -.0625rem 0rem 0rem #aaa inset, 0rem 0rem 0rem .0625rem #0000001a inset, 0rem .03125rem 0rem .09375rem #fcfcfc inset` |
| `--p-shadow-button-primary-critical` | `0rem .0625rem .03125rem -.03125rem rgba(229,0,0,.16), 0rem .0625rem .125rem -.03125rem #e5000029, 0rem .25rem .375rem -.125rem #e5000029, 0rem .125rem .1875rem -.09375rem #ff00001a, inset 0rem 0rem .25rem .0625rem #F50000, inset 0rem 0rem .25rem .125rem #ffffff1a, inset 0rem 0rem .75rem -.375rem #ffffffbf` | `0rem -.0625rem 0rem .0625rem #8e0b21cc inset, 0rem 0rem 0rem .0625rem #a30a24cc inset, 0rem .03125rem 0rem .09375rem #f78086a3 inset` |
| `--p-shadow-button-primary-critical-hover` | `0rem .0625rem .03125rem -.03125rem rgba(229,0,0,.12), 0rem .0625rem .125rem -.03125rem #e500001f, 0rem .25rem .375rem -.125rem #e500001f, 0rem .125rem .1875rem -.09375rem #ff00001f, inset 0rem 0rem .25rem .0625rem #F50000, inset 0rem 0rem .25rem .125rem #ffffff1a, inset 0rem 0rem .75rem -.375rem #ffffffbf` | `0rem -.0625rem 0rem .0625rem #8e0b21cc inset, 0rem 0rem 0rem .0625rem #a30a24cc inset, 0rem .03125rem 0rem .09375rem #f7808670 inset` |
| `--p-shadow-button-primary-critical-inset` | `0rem .0625rem .03125rem -.03125rem rgba(0,0,0,.13), inset 0rem 0rem .75rem -.375rem #ffffffbf, inset 0rem 0rem .25rem .125rem #ffffff1a, inset 0rem 0rem .25rem .0625rem #e0000b` | `-.0625rem 0rem .0625rem 0rem #00000033 inset, .0625rem 0rem .0625rem 0rem #00000033 inset, 0rem .125rem 0rem 0rem #00000099 inset` |
| `--p-shadow-button-primary-hover` | `0rem .0625rem .03125rem -.03125rem #00000021, 0rem .0625rem .125rem -.03125rem #00000021, 0rem .25rem .375rem -.125rem #00000021, 0rem .125rem .1875rem -.09375rem #00000021, inset 0rem 0rem .25rem .0625rem #101010, inset 0rem 0rem .25rem .125rem #ffffff1a, inset 0rem 0rem .75rem -.375rem #ffffffbf` | `0rem -.0625rem 0rem 0rem #aaa inset, 0rem 0rem 0rem .0625rem #0000001a inset, 0rem .03125rem 0rem .09375rem #fcfcfc inset` |
| `--p-shadow-button-primary-inset` | `0rem .0625rem .03125rem -.03125rem #00000021, inset 0rem 0rem .75rem -.375rem #ffffffbf, inset 0rem 0rem .25rem .125rem #ffffff1a, inset 0rem 0rem .25rem .0625rem #101010` | `-.0625rem 0rem .0625rem 0rem #1a1a1a1f inset, .0625rem 0rem .0625rem 0rem #1a1a1a1f inset, 0rem .125rem .0625rem 0rem #1a1a1a33 inset` |
| `--p-space-025` | `.0625rem` | `.0625rem` |
| `--p-space-050` | `.125rem` | `.125rem` |
| `--p-space-100` | `.25rem` | `.25rem` |
| `--p-space-150` | `.375rem` | `.375rem` |
| `--p-space-200` | `.5rem` | `.5rem` |
| `--p-space-300` | `.75rem` | `.75rem` |
| `--p-space-400` | `1rem` | `1rem` |
| `--ease-out-emphasized` | `cubic-bezier(.2, .8, 0, 1)` | `cubic-bezier(.2, .8, 0, 1)` |
| `--duration-button` | `400ms` | `400ms` |
| `--duration-spinner` | `500ms` | `500ms` |
## CSS
Scoped under `[data-style="shopify"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.
```css
[data-style="shopify"] {
.ui-button {
position: relative;
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
gap: var(--p-space-050);
min-height: var(--p-height-700);
margin: 0;
padding: var(--p-space-150) var(--p-space-300);
border: 0;
border-radius: var(--p-border-radius-action);
background-color: var(--p-color-button-bg-fill);
box-shadow: var(--p-shadow-button);
color: var(--p-color-text);
font-family: var(--p-font-family-sans);
font-size: var(--p-font-size-button-label);
font-weight: var(--p-font-weight-button-label);
line-height: var(--p-font-line-height-button-label);
letter-spacing: var(--p-font-letter-spacing-denser);
white-space: nowrap;
user-select: none;
cursor: pointer;
transition:
background-color var(--duration-button) var(--ease-out-emphasized),
box-shadow var(--duration-button) var(--ease-out-emphasized),
transform var(--duration-button) var(--ease-out-emphasized);
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: var(--p-color-button-bg-fill-hover);
}
}
&:active:not([data-disabled]) {
background-color: var(--p-color-button-bg-fill-active);
transform: scale(0.97);
}
&:focus-visible {
outline: var(--p-border-width-050) solid var(--p-color-border-focus);
outline-offset: var(--p-space-025);
}
&[data-disabled] {
background-color: var(--p-color-bg-fill-disabled);
box-shadow: none;
color: var(--p-color-text-disabled);
cursor: default;
}
& svg {
width: 16px;
height: 16px;
margin: var(--p-space-050);
flex-shrink: 0;
}
&:has(> svg:first-child):not([data-icon-only]) {
padding-block: var(--p-space-100);
padding-inline-start: var(--p-space-150);
}
}
.ui-button[data-size="small"] {
min-height: var(--p-height-600);
padding: var(--p-space-100) 10px;
}
.ui-button[data-size="large"] {
min-height: calc(var(--p-height-900) + var(--p-space-050));
padding: 0 var(--p-space-400);
}
.ui-button[data-icon-only] {
min-width: var(--p-height-700);
padding: var(--p-space-100);
&[data-size="small"] {
min-width: var(--p-height-600);
padding: var(--p-space-050);
}
&[data-size="large"] {
min-width: calc(var(--p-height-900) + var(--p-space-050));
padding: var(--p-space-200);
}
}
.ui-button[data-variant="primary"] {
background-color: var(--p-color-button-primary-bg);
background-image: var(--p-color-button-gradient-bg-fill), none;
box-shadow: var(--p-shadow-button-primary);
color: var(--p-color-button-primary-text);
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: var(--p-color-button-primary-bg-hover);
box-shadow: var(--p-shadow-button-primary-hover);
color: var(--p-color-button-primary-text-hover);
}
}
&:active:not([data-disabled]) {
background-color: var(--p-color-button-primary-bg-active);
box-shadow: var(--p-shadow-button-primary-inset);
color: var(--p-color-button-primary-text-active);
}
&[data-disabled] {
background-color: var(--p-color-button-primary-bg-disabled);
background-image: none;
box-shadow: none;
color: var(--p-color-button-primary-text-disabled);
}
}
.ui-button:is([data-variant="tertiary"], [data-variant="ghost"]) {
background-color: transparent;
box-shadow: none;
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: var(--p-color-bg-fill-transparent-hover);
}
}
&:active:not([data-disabled]) {
background-color: var(--p-color-bg-fill-transparent-active);
}
&[data-disabled] {
background-color: transparent;
}
&[data-icon-only] {
color: var(--p-color-icon-secondary);
@media (hover: hover) {
&:hover:not([data-disabled]) {
color: var(--p-color-icon-secondary-hover);
}
}
}
}
.ui-button:is([data-variant="critical"], [data-variant="danger"], [data-variant="destructive"]) {
background-color: var(--p-color-button-primary-bg-critical);
background-image: var(--p-color-button-gradient-bg-fill-critical), none;
box-shadow: var(--p-shadow-button-primary-critical);
color: var(--p-color-button-primary-text-critical);
&:focus-visible {
outline-color: var(--p-color-border-critical);
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: var(--p-color-button-primary-bg-critical-hover);
box-shadow: var(--p-shadow-button-primary-critical-hover);
}
}
&:active:not([data-disabled]) {
background-color: var(--p-color-button-primary-bg-critical-active);
box-shadow: var(--p-shadow-button-primary-critical-inset);
}
&[data-disabled] {
background-color: var(--p-color-button-primary-bg-critical-disabled);
background-image: none;
box-shadow: none;
color: var(--p-color-button-primary-text-disabled);
}
}
.ui-button[data-variant="critical-secondary"] {
background-color: var(--p-color-button-bg-fill-critical);
color: var(--p-color-text-critical-secondary);
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: var(--p-color-button-bg-fill-critical-hover);
}
}
&:active:not([data-disabled]) {
background-color: var(--p-color-button-bg-fill-critical-active);
}
}
&[data-theme="dark"] .ui-button[data-variant="critical-secondary"] {
color: var(--p-color-text-critical-accent);
}
.ui-button[data-loading] {
cursor: wait;
}
.ui-button[data-loading][data-variant="primary"] {
background-color: var(--p-color-button-primary-bg-disabled);
background-image: none;
box-shadow: none;
}
.ui-button-spinner {
flex-shrink: 0;
width: 11px;
height: 11px;
margin: 2.5px;
border-radius: 50%;
background: conic-gradient(currentColor 0 40%, var(--p-color-bg-accent-disabled) 0);
mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1px));
animation: shopify-spinner-spin var(--duration-spinner) linear infinite;
}
@media (prefers-reduced-motion: reduce) {
.ui-button-spinner {
animation: none;
}
}
@media (prefers-reduced-motion: reduce) {
.ui-button:active:not([data-disabled]) {
transform: none;
}
}
}
```
## 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 Shopify style, as a skill: https://replicas.raphaelsalaja.com/skills/shopify/SKILL.md