# Interfere 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 Interfere's. Measured from the running Interfere app (interfere.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 primary and secondary buttons, at rest and hovered, on Interfere's design site button page.

## Variants

- `variant`: `primary`, `secondary`, `tertiary`, `transparent`, `brand`, `danger`, `warning`, `danger-subtle`, `success-subtle`, `link`, `link-primary`, `link-danger`
- `size`: `xs`, `sm`, `md`, `lg`, `xl`

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--tomato-a11` | `#cd2200ea` | `#ff977d` |
| `--color-component` | `#0000000f` | `#ffffff12` |
| `--color-component-hover` | `#00000017` | `#ffffff1b` |
| `--color-component-on-container-strong` | `#fff` | `#ffffff12` |
| `--color-component-on-container-strong-hover` | `#f9f9f9` | `#ffffff1b` |
| `--color-transparent-hover` | `#0000000f` | `#ffffff1b` |
| `--color-brand-solid` | `#0090ff` | `#0090ff` |
| `--color-brand-solid-hover` | `#0588f0` | `#3b9eff` |
| `--color-positive-subtle` | `#00a43319` | `#22ff991e` |
| `--color-positive-subtle-hover` | `#00a83829` | `#11ff992d` |
| `--color-warning-solid` | `#f76b15` | `#f76b15` |
| `--color-warning-solid-hover` | `#ef5f00` | `#ff801f` |
| `--color-danger-solid` | `#e54d2e` | `#e54d2e` |
| `--color-danger-solid-hover` | `#dd4425` | `#ec6142` |
| `--color-danger-subtle` | `#ff200008` | `#ff55330f` |
| `--color-danger-subtle-hover` | `#f52b0018` | `#ff35232b` |
| `--color-inverted-solid` | `#000000f2` | `#fffffff2` |
| `--color-inverted-solid-hover` | `#000c` | `#fffc` |
| `--color-disabled` | `#0000000f` | `#ffffff09` |
| `--color-primary-foreground` | `#000000df` | `#ffffffed` |
| `--color-secondary-foreground` | `#0000009b` | `#ffffffaf` |
| `--color-disabled-foreground` | `#0004` | `#fff5` |
| `--color-brand-foreground` | `#0086f0fa` | `#3b9eff` |
| `--color-positive-foreground` | `#008647d4` | `#43fea4ab` |
| `--color-danger-foreground` | `#d72400da` | `#ff6847eb` |
| `--color-on-inverted-foreground` | `#fff` | `#000` |
| `--color-on-brand-solid-foreground` | `#fff` | `#fff` |
| `--color-on-warning-solid-foreground` | `#fefcfb` | `#fff` |
| `--color-on-danger-solid-foreground` | `#fffcfc` | `#fff` |
| `--s-default` | `0 0 0 .5px var(--shadow-inner-1) inset, 0 0 0 .5px var(--shadow-drop-1), 0 1px 1px -1px var(--shadow-drop-2), 0 1px 2px 0px var(--shadow-drop-3)` | `0 0 0 .5px #ffffff12 inset, 0 0 0 .5px #0000, 0 1px 1px -1px #0000, 0 1px 2px 0px #0000` |
| `--focus-ring` | `#0084e6a1` | `#0090ff` |
| `--font-regular` | `"InterVariable", "Inter Variable", "InterVariable Fallback", sans-serif` | `"InterVariable", "Inter Variable", "InterVariable Fallback", sans-serif` |
| `--font-features` | `"ss03"` | `"ss03"` |
| `--font-size-mini` | `12px` | `12px` |
| `--font-size-small` | `13px` | `13px` |
| `--font-weight-medium` | `500` | `500` |
| `--radius-sm` | `4px` | `4px` |
| `--radius-md` | `6px` | `6px` |
| `--radius-lg` | `8px` | `8px` |
| `--radius-xl` | `10px` | `10px` |
| `--ease-out` | `cubic-bezier(0, 0, 0.2, 1)` | `cubic-bezier(0, 0, 0.2, 1)` |
| `--default-transition-duration` | `150ms` | `150ms` |
| `--duration-popup` | `200ms` | `200ms` |
| `--duration-spinner` | `1.2s` | `1.2s` |
| `--ease-spring-button` | `linear(0, 0.0575, 0.1803, 0.3208, 0.4551, 0.5729, 0.6711, 0.7501, 0.8122, 0.8601, 0.8966, 0.924, 0.9445, 0.9596, 0.9708, 0.9789, 0.9848, 0.9891, 0.9922, 0.9944, 0.996, 0.9972, 0.998, 0.9986, 1)` | `linear(0, 0.0575, 0.1803, 0.3208, 0.4551, 0.5729, 0.6711, 0.7501, 0.8122, 0.8601, 0.8966, 0.924, 0.9445, 0.9596, 0.9708, 0.9789, 0.9848, 0.9891, 0.9922, 0.9944, 0.996, 0.9972, 0.998, 0.9986, 1)` |
| `--duration-spring-button` | `400ms` | `400ms` |

## CSS

Scoped under `[data-style="interfere"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="interfere"] {
  .ui-button {
    --button-bg: var(--color-component-on-container-strong);
    --button-hover-bg: var(--color-component-on-container-strong-hover);
    --button-fg: var(--color-primary-foreground);
    --button-hover-fg: var(--button-fg);
    --button-height: 28px;
    --button-padding: 10px;
    --button-gap: 6px;
    --icon-size: 16px;
    --icon-offset: 4px;
    --button-spinner-size: 16px;
    --button-spinner-color: var(--color-disabled-foreground);

    box-sizing: border-box;
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: var(--button-gap);
    min-width: 0;
    height: var(--button-height);
    margin: 0;
    padding: 0 var(--button-padding);
    border: 0;
    border-radius: var(--radius-md);
    background-color: var(--button-bg);
    color: var(--button-fg);
    font-family: var(--font-regular);
    font-feature-settings: var(--font-features);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-medium);
    line-height: 20px;
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
    touch-action: manipulation;
    cursor: default;
    transition-property: color, background-color, border-color, transform;
    transition-duration: var(--default-transition-duration), var(--default-transition-duration), var(--default-transition-duration), var(--duration-popup);
    transition-timing-function: var(--ease-out);

    & svg {
      flex-shrink: 0;
      width: var(--icon-size);
      height: var(--icon-size);
      pointer-events: none;
    }

    &:has(> svg:first-child) {
      padding-inline-start: calc(var(--button-padding) - var(--icon-offset));
    }

    &:has(> svg:last-child) {
      padding-inline-end: calc(var(--button-padding) - var(--icon-offset));
    }

    @media (hover: hover) {
      &:not([data-disabled]):hover {
        background-color: var(--button-hover-bg);
        color: var(--button-hover-fg);
      }
    }

    &[data-popup-open] {
      background-color: var(--button-hover-bg);
      color: var(--button-hover-fg);
    }

    &:focus-visible {
      outline: 1px solid var(--focus-ring);
      outline-offset: 0;
    }

    &[data-disabled] {
      cursor: not-allowed;
    }
  }

  .ui-button:is(:not([data-variant]), [data-variant="secondary"]):not([data-disabled]) {
    box-shadow: var(--s-default);
  }

  .ui-button[data-variant="primary"] {
    --button-bg: var(--color-inverted-solid);
    --button-hover-bg: var(--color-inverted-solid-hover);
    --button-fg: var(--color-on-inverted-foreground);
  }

  .ui-button[data-variant="tertiary"] {
    --button-bg: var(--color-component);
    --button-hover-bg: var(--color-component-hover);
    --button-fg: var(--color-secondary-foreground);
  }

  .ui-button[data-variant="brand"] {
    --button-bg: var(--color-brand-solid);
    --button-hover-bg: var(--color-brand-solid-hover);
    --button-fg: var(--color-on-brand-solid-foreground);
  }

  .ui-button[data-variant="danger"] {
    --button-bg: var(--color-danger-solid);
    --button-hover-bg: var(--color-danger-solid-hover);
    --button-fg: var(--color-on-danger-solid-foreground);
  }

  .ui-button[data-variant="warning"] {
    --button-bg: var(--color-warning-solid);
    --button-hover-bg: var(--color-warning-solid-hover);
    --button-fg: var(--color-on-warning-solid-foreground);
  }

  .ui-button[data-variant="danger-subtle"] {
    --button-bg: var(--color-danger-subtle);
    --button-hover-bg: var(--color-danger-subtle-hover);
    --button-fg: var(--color-danger-foreground);
  }

  .ui-button[data-variant="success-subtle"] {
    --button-bg: var(--color-positive-subtle);
    --button-hover-bg: var(--color-positive-subtle-hover);
    --button-fg: var(--color-positive-foreground);
  }

  .ui-button:is([data-variant="transparent"], [data-variant="ghost"]) {
    --button-bg: transparent;
    --button-hover-bg: var(--color-transparent-hover);
    --button-fg: var(--color-secondary-foreground);
    --button-hover-fg: var(--color-primary-foreground);
  }

  .ui-button:is([data-variant="link"], [data-variant="link-primary"], [data-variant="link-danger"]) {
    --button-bg: transparent;
    --button-hover-bg: transparent;
    --button-spinner-color: var(--button-fg);

    height: auto;
    padding: 0;
    font-weight: var(--font-weight-medium);
  }

  .ui-button[data-variant="link"] {
    --button-fg: var(--color-secondary-foreground);
    --button-hover-fg: var(--color-primary-foreground);
  }

  .ui-button[data-variant="link-primary"] {
    --button-fg: var(--color-brand-foreground);
  }

  .ui-button[data-variant="link-danger"] {
    --button-fg: var(--color-danger-foreground);
    --button-hover-fg: var(--tomato-a11);
  }

  .ui-button[data-disabled]:not([data-variant="link"], [data-variant="link-primary"], [data-variant="link-danger"]) {
    background-color: var(--color-disabled);
    color: var(--color-disabled-foreground);
  }

  .ui-button[data-disabled]:is([data-variant="transparent"], [data-variant="ghost"]) {
    background-color: transparent;
  }

  .ui-button[data-size="xs"] {
    --button-height: 20px;
    --button-padding: 6px;
    --button-gap: 4px;
    --icon-size: 12px;
    --icon-offset: 2px;
    --button-spinner-size: 10px;

    border-radius: var(--radius-sm);
    font-size: var(--font-size-mini);
    line-height: 16px;
  }

  .ui-button:is([data-size="sm"], [data-size="small"]) {
    --button-height: 24px;
    --button-padding: 8px;
    --button-gap: 4px;
    --icon-size: 14px;
    --icon-offset: 2px;
    --button-spinner-size: 12px;
  }

  .ui-button:is([data-size="lg"], [data-size="large"]) {
    --button-height: 32px;
    --button-padding: 12px;
    --icon-offset: 2px;

    border-radius: var(--radius-lg);
  }

  .ui-button[data-size="xl"] {
    --button-height: 40px;
    --button-padding: 14px;
    --button-gap: 8px;
    --icon-size: 20px;
    --button-spinner-size: 20px;

    border-radius: var(--radius-lg);
  }

  .ui-button[data-icon-only] {
    --button-padding: 0;
    --icon-offset: 0;

    width: var(--button-height);

    &:is([data-size="sm"], [data-size="small"]) {
      --icon-size: 16px;
    }

    &[data-size="xl"] {
      border-radius: var(--radius-xl);
    }
  }

  .ui-button[data-loading] {
    transition-property: color;
    transition-duration: var(--duration-spring-button);
    transition-timing-function: var(--ease-spring-button);
  }

  .ui-button[data-loading]:is([data-disabled], :hover) {
    color: transparent;
  }

  .ui-button-spinner {
    position: absolute;
    inset: 0;
    width: var(--button-spinner-size);
    height: var(--button-spinner-size);
    margin: auto;
    color: var(--button-spinner-color);
  }

  .ui-button > .ui-button-spinner {
    animation:
      interfere-button-spinner-in var(--duration-spring-button) var(--ease-spring-button),
      interfere-spinner-spin var(--duration-spinner) steps(12) infinite;

    @media (prefers-reduced-motion: reduce) {
      animation: none;
    }
  }
}

@keyframes interfere-button-spinner-in {
  from {
    opacity: 0;
    translate: 0 -24px;
  }
}
```

## 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 Interfere style, as a skill: https://replicas.raphaelsalaja.com/skills/interfere/SKILL.md