# QR code

A code people scan with their phone camera.

```tsx
import { QRCode } from '@halo-ds/react';
```

## When to use it
QR code turns a link or short text into a code people scan with a phone camera. Use it to move someone from a computer or a printed page to their phone: to sign in, open an app, pay or check in with a ticket. In code it is drawn from its value, so it always scans.

## Do
- Say what scanning does, like Scan to sign in on your phone.
- Show the link or a short code as text too, for people who cannot scan.
- Keep the light border around the code; scanners need it.
- Keep printed codes at least 2cm across.

## Don't
- Show a QR code to people who are already on their phone; give them a link.
- Invert the colours or place the code on a busy picture.
- Cover more than a fifth of the code with a logo.
- Encode long text; long links make dense codes that are harder to scan.

## Props
### QRCode props
| Prop | Type | What it does |
| --- | --- | --- |
| `value` (required) | `string` | The text or link to encode. Up to about 2,900 characters at level L. |
| `size` | `number \| undefined` | Width and height in px, including the light border. Figma: Size. |
| `level` | `QRErrorLevel \| undefined` | How much of the code can be covered or damaged and still scan: L 7%, M 15%, Q 25%, H 30%. Higher levels make denser codes. Defaults to M, or H when there is a logo. |
| `margin` | `number \| undefined` | The light border around the code, in modules. Scanners need 4; go lower only on a plain light background. |
| `logo` | `ReactNode` | A small logo or icon in the middle, like an app icon. Keep it under a fifth of the width. Figma: Logo. |
| `status` | `"active" \| "loading" \| "expired" \| "scanned" \| undefined` | Covers the code while it is being made, when it has run out (for sign-in codes that expire), or once a phone has scanned it and people need to finish on their phone. Figma: State. |
| `onRefresh` | `(() => void) \| undefined` | Shows a Refresh button on an expired code. |
| `color` | `string \| undefined` | Colour of the dark squares. Any CSS colour. Keep it dark and the background light, with strong contrast between them, or some phones will not read the code. |
| `bgColor` | `string \| undefined` | Colour behind the code, including the light border. Any CSS colour. |
| `labels` | `Partial<QRCodeLabels> \| undefined` | Text on the expired and scanned covers, for other languages. |
| `label` (required) | `string` | What the code is for, read by screen readers, like "Scan to sign in on your phone". |
| `classNames` | `Partial<Record<QRCodePart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<QRCodePart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { QRCode } from '@halo-ds/react';

export default function Example() {
  return <QRCode value="https://example.com/invite/7Q2K9" label="Scan to open the invite link" />;
}
```

### States
Loading while a code is made, and Scanned once a phone has read it.
```tsx
import { QRCode } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-row" style={{ gap: 24 }}>
      <QRCode value="https://example.com/invite/7Q2K9" label="Scan to open the invite" status="loading" size={140} />
      <QRCode value="https://example.com/invite/7Q2K9" label="Scan to open the invite" status="scanned" size={140} />
    </div>
  );
}
```

### Sign in on a phone
The code, what it does, and a fallback for people who can not scan.
```tsx
import { QRCode, Text } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-panel" style={{ display: 'flex', gap: 24, alignItems: 'center', maxWidth: 520 }}>
      <QRCode value="https://example.com/login/device?code=WDJB-MJHT" label="Scan to sign in on your phone" size={144} />
      <div style={{ display: 'grid', gap: 8 }}>
        <Text size="lg" weight="semibold">Sign in on your phone</Text>
        <Text color="secondary">Point your camera at the code. Or go to example.com/device and enter WDJB-MJHT.</Text>
      </div>
    </div>
  );
}
```

More: https://halodesignsystem.dev/components/qr-code
