# Linear 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 Linear's. Measured from the running Linear app (linear.app). 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 logged-in Linear app, light and dark. The dark border on the dashed ghost variant is a guess.

## Variants

- `variant`: `primary`, `secondary`, `ghost`, `borderless`, `muted`, `dangerous-borderless`, `link`, `dangerous`, `circle`, `tab`
- `size`: `small`, `medium`, `normal`, `large`

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--text-primary` | `lch(9.794% 0 282)` | `lch(100% 0 272)` |
| `--text-secondary` | `lch(19.588% 1.25 282)` | `lch(90.451% 1.2 272)` |
| `--text-tertiary` | `lch(39.176% 1.25 282)` | `lch(61.803% 1.2 272)` |
| `--accent` | `lch(53% 52.26 286.91)` | `lch(47.918% 59.303 288.421)` |
| `--accent-hover` | `lch(47% 50.26 286.91)` | `lch(52.418% 61.103 288.421)` |
| `--accent-text` | `lch(100% 5 286.91)` | `lch(100% 5 288.421)` |
| `--bg-hover` | `lch(94.854% 0.5 282)` | `lch(14.006% 0.593 272)` |
| `--button-secondary-bg` | `lch(99.997% 0.5 282)` | `lch(10.149% 0.689 272)` |
| `--button-secondary-bg-hover` | `lch(95.883% 0.157 282)` | `lch(14.777% 1.075 272)` |
| `--button-ring` | `lch(0% 0 0 / 0.09)` | `lch(100% 0 0 / 0.137)` |
| `--button-ring-hover` | `lch(0% 0 0 / 0.15)` | `lch(100% 0 0 / 0.229)` |
| `--button-ghost-border` | `lch(78.5% 0 282)` | `lch(30% 1.5 272)` |
| `--button-tab-active` | `lch(93.483% 0.5 282)` | `lch(16.5% 1.3 272)` |
| `--button-circle-bg` | `lch(94.3% 0 282)` | `lch(45.4% 0 272)` |
| `--danger` | `lch(58% 73 29)` | `lch(58% 73 29)` |
| `--danger-hover` | `lch(53% 73 29)` | `lch(62.5% 73 29)` |
| `--danger-text` | `lch(50% 80 29)` | `lch(80% 80 29)` |
| `--danger-bg-hover` | `lch(92.134% 7.526 15.947)` | `lch(11.767% 15.869 22.59)` |
| `--shadow-low` | `lch(0% 0 0 / 0.02) 0 3px 6px -2px, lch(0% 0 0 / 0.04) 0 1px 1px 0` | `lch(0% 0 0 / 0.3) 0 0.5px 1px 1px` |
| `--focus-ring` | `#5e69d1` | `#5e69d1` |
| `--font-size-mini` | `0.75rem` | `0.75rem` |
| `--font-size-small` | `0.8125rem` | `0.8125rem` |
| `--font-weight-medium` | `500` | `500` |
| `--radius-rounded` | `9999px` | `9999px` |
| `--speed-highlight-fade-in` | `0s` | `0s` |
| `--speed-highlight-fade-out` | `0.15s` | `0.15s` |

## CSS

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

```css
[data-style="linear"] {
  .ui-button {
    --button-shadow: none;
    --button-overlay: none;

    position: relative;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 28px;
    margin: 0;
    padding: 0 10px;
    border: 0.5px solid transparent;
    border-radius: var(--radius-rounded);
    background-color: transparent;
    box-shadow: var(--button-shadow);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--font-size-mini);
    font-weight: var(--font-weight-medium);
    line-height: normal;
    white-space: nowrap;
    user-select: none;
    cursor: default;
    transition:
      border var(--speed-highlight-fade-out),
      background-color var(--speed-highlight-fade-out),
      color var(--speed-highlight-fade-out),
      opacity var(--speed-highlight-fade-out);

    &::after {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: inherit;
      box-shadow: var(--button-overlay);
      pointer-events: none;
      transition: box-shadow var(--speed-highlight-fade-out);
    }

    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        transition-duration: var(--speed-highlight-fade-in);
      }
    }

    &:active:not([data-disabled]) {
      transition-duration: var(--speed-highlight-fade-in);
    }

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

    &[data-disabled] {
      opacity: 0.6;
    }

    & svg {
      width: 14px;
      height: 14px;
      flex-shrink: 0;
    }
  }

  .ui-button[data-size="small"] {
    height: 24px;
    padding: 0 8px;
  }

  .ui-button[data-size="medium"] {
    height: 28px;
    padding: 0 10px;
  }

  .ui-button[data-size="normal"] {
    height: 32px;
    padding: 0 12px;
    font-size: var(--font-size-small);

    & svg {
      width: 16px;
      height: 16px;
    }
  }

  .ui-button[data-size="large"] {
    height: 44px;
    padding: 0 18px;
    font-size: var(--font-size-small);

    & svg {
      width: 16px;
      height: 16px;
    }
  }

  .ui-button:is([data-icon-only], [data-variant="circle"]) {
    aspect-ratio: 1;
    padding: 0;
  }

  .ui-button[data-variant="primary"] {
    --button-shadow: var(--shadow-low);

    background-color: var(--accent);
    color: var(--accent-text);

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

  .ui-button:is([data-variant="secondary"], [data-variant="tab"]) {
    --button-overlay: 0 0 0 0.5px var(--button-ring), var(--shadow-low);

    background-color: var(--button-secondary-bg);

    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        --button-overlay: 0 0 0 0.5px var(--button-ring-hover), var(--shadow-low);

        background-color: var(--button-secondary-bg-hover);
      }
    }
  }

  .ui-button[data-variant="tab"] {
    color: var(--text-tertiary);

    &:is([data-pressed], [aria-pressed="true"], [data-active]) {
      background-color: var(--button-tab-active);
      color: var(--text-primary);
    }

    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        color: var(--text-secondary);
      }
    }
  }

  .ui-button[data-variant="ghost"] {
    border: 1px dashed var(--button-ghost-border);
  }

  .ui-button:is([data-variant="ghost"], [data-variant="borderless"]) {
    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        background-color: var(--bg-hover);
        color: var(--text-primary);
      }
    }
  }

  .ui-button[data-variant="muted"] {
    color: var(--text-tertiary);

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

  .ui-button[data-variant="link"] {
    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        color: var(--text-primary);
      }
    }
  }

  .ui-button[data-variant="dangerous-borderless"] {
    color: var(--danger-text);

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

  .ui-button[data-variant="dangerous"] {
    background-color: var(--danger);
    color: var(--accent-text);

    &:focus-visible {
      outline-color: var(--danger);
    }

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

  .ui-button[data-variant="circle"] {
    background-color: var(--button-circle-bg);
  }

  .ui-button[data-loading] {
    opacity: 1;
    cursor: wait;
  }

  .ui-button-spinner {
    box-sizing: border-box;
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--radius-rounded);
    opacity: 0.8;
    animation: linear-spinner-spin 0.7s 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 Linear style, as a skill: https://replicas.raphaelsalaja.com/skills/linear/SKILL.md