# Shopify Spinner

An indeterminate loading indicator.

Build a Spinner 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 primitives if it has none.

Fidelity: Partly measured from Polaris s-spinner (2.0 runtime). The admin shows no spinner at rest. Size, opacity transition and rotation match the runtime. Polaris draws the ring as an SVG child. The replica's spinner has no children, so the ring is a ::before, and the check reports that pseudo-element.

## Variants

- `size`: `base`, `large`

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--p-color-bg-accent` | `#101010` | `#fcfcfc` |
| `--p-color-bg-accent-disabled` | `#00000021` | `#ffffff38` |
| `--p-height-500` | `1.25rem` | `1.25rem` |
| `--p-height-1000` | `2.5rem` | `2.5rem` |
| `--p-space-100` | `.25rem` | `.25rem` |
| `--duration-150` | `150ms` | `150ms` |
| `--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
@keyframes shopify-spinner-spin {
  to {
    transform: rotate(1turn);
  }
}

[data-style="shopify"] {
  .ui-spinner {
    --spinner-size: var(--p-height-500);

    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: var(--spinner-size);
    height: var(--spinner-size);
    vertical-align: middle;
    transition: opacity var(--duration-150) ease allow-discrete;

    &::before {
      content: "";
      position: absolute;
      inset: calc(var(--spinner-size) * 6.5 / 44);
      border-radius: 50%;
      background: conic-gradient(var(--p-color-bg-accent) 0 40%, var(--p-color-bg-accent-disabled) 0);
      mask: radial-gradient(
        farthest-side,
        transparent calc(100% - var(--spinner-size) * 3 / 44),
        #000 calc(100% - var(--spinner-size) * 3 / 44 + 0.5px)
      );
      animation: shopify-spinner-spin var(--duration-spinner) linear infinite;
    }
  }

  .ui-spinner:is([data-size="base"], [data-size="medium"]) {
    --spinner-size: var(--p-height-500);
  }

  .ui-spinner[data-size="large"] {
    --spinner-size: calc(var(--p-height-1000) + var(--p-space-100));
  }

  @media (prefers-reduced-motion: reduce) {
    .ui-spinner::before {
      animation: none;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import type { ComponentProps } from "react";
import { join } from "./utils";

export type SpinnerProps = ComponentProps<"span"> & {
  size?: string;
  label?: string;
};

export function Spinner({ className, size = "medium", label = "Loading", ...props }: SpinnerProps) {
  return <span role="status" aria-label={label} className={join("ui-spinner", className)} data-size={size} {...props} />;
}
```

## Example

```tsx
import { Spinner } from "@replicas/ui";

export default function SpinnerDemo() {
  return <Spinner />;
}
```

## Foundations

The rest of the Shopify style, as a skill: https://replicas.raphaelsalaja.com/skills/shopify/SKILL.md