# Magnetic Button

> A button that leans toward the mouse and springs back when it leaves.

```tsx
import { MagneticButton } from '@brand-studio/ui';
import { ArrowRight } from 'lucide-react';

export default function MagneticButtonDemo() {
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'space-between', gap: 24, width: '100%', maxWidth: 560, padding: '28px 32px', borderRadius: 20, background: 'var(--bs-elevated)', border: '1px solid var(--bs-line-soft)' }}>
      <div>
        <p style={{ margin: '0 0 4px', fontSize: 13, color: 'var(--bs-muted)' }}>Halden R · ships 14 October</p>
        <p style={{ margin: 0, fontSize: 22, fontWeight: 600 }}>From £1,890</p>
      </div>
      <MagneticButton shape="pill">Pre-order <ArrowRight size={16} aria-hidden="true" /></MagneticButton>
    </div>
  );
}
```

## Installation

```sh
npm install @brand-studio/ui
```

React 18 or 19 is a peer dependency. Import the stylesheet once and wrap the app in a brand theme:

```tsx
import '@brand-studio/ui/styles.css';
import { BrandTheme, MagneticButton } from '@brand-studio/ui';
import brand from './brand.json';

<BrandTheme palette={brand.tokens} mode="system">
  {/* your app */}
</BrandTheme>
```

## Usage

```tsx
import { MagneticButton } from '@brand-studio/ui';
```

```tsx
<MagneticButton shape="pill">Pre-order</MagneticButton>
```

It takes every `Button` prop. `strength` scales how far it leans; `1` moves the button up to 10 px.

## Accessibility

- It is an ordinary `button`, so keyboard and screen reader use is unchanged.
- Only a mouse moves it. Touch, pen and reduced motion get a still button.

## API Reference

| Prop | Type | Default |
|---|---|---|
| `tone?` | `"inverse" \| "primary" \| "secondary"` | – |
| `shape?` | `"default" \| "pill"` | – |
| `loading?` | `boolean` | – |
| `strength?` | `number` | `1` |

Source: https://brandstudio.js.org/docs/components/magnetic-button/
