# Qr

Renders a value as a QR code.

[View source and API](https://github.com/tempoxyz/ds/blob/main/src/web/components/Qr.tsx)

## Overview

Qr renders a value as a QR code in the foreground color on a transparent ground.

## Examples

### Basic

```tsx
import { Qr } from '@tempoxyz/ds'

export function Demo() {
  return <Qr value="tempo:0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" />
}
```

[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Qr/Basic.tsx)

### Size

Set `size` to `small`, `medium` (default), or `large`.

```tsx
import { Qr, style } from '@tempoxyz/ds'

export function Demo() {
  return (
    <div {...styles.row()}>
      {(['small', 'medium', 'large'] as const).map((size) => (
        <Qr key={size} size={size} value="tempo:0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" />
      ))}
    </div>
  )
}

namespace styles {
  export const row = style({ alignItems: 'start', display: 'flex', flexWrap: 'wrap', gap: '16' })
}
```

[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Qr/Size.tsx)

### Arena

Pass an image URL to `arena` to draw a logo in the center.

```tsx
import { Qr } from '@tempoxyz/ds'
import pathUsd from '../../coins/PathUSD.svg'

export function Demo() {
  return <Qr arena={pathUsd} value="https://example.org" />
}
```

[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Qr/Arena.tsx)

## Anatomy

Import the component and assemble its parts.

```tsx
import { Qr } from '@tempoxyz/ds'

<Qr />
```

## Guidelines

### When to Use

* Show a deposit address in a receive flow, for a scan from another wallet.
* Move a link from a computer to a phone, such as a payment request.

### When Not to Use

* Use a link or `Button.Link` ([Button](/docs/components/button)) for a URL opened on the same device.
* Use [Hex](/docs/components/hex) with `copy` alone when the reader needs the value on the same device. A phone cannot scan its own screen.

### Show the Address as Text Too

Many people cannot scan: someone on the same phone, a screen reader user, or someone without a camera.

* **Copy:** Put the address beside the code with [Hex](/docs/components/hex) and `copy`.
* **Match:** The text must match what the code encodes. If the code holds a URI, such as `tempo:` and the address, show the same address. Never encode a different value, such as a tracking link.
* **Network:** A code does not show its network. State what the address accepts, such as Send USDC on Tempo to this address.

**Do:** Show the address with a copy button, and the network it accepts, beside the code.

```tsx
/**
 * Do example for "Show the Address as Text Too" on the Qr page.
 * Show the address with a copy button, and the network it accepts, beside the code.
 * @module
 */
import { Hex, Qr, style } from '@tempoxyz/ds'

const address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'

/** Renders the static preview, which the guideline card shows inert. */
export function Demo() {
  return (
    <div {...styles.stack()}>
      <Qr aria-label="Deposit address QR code" size="small" value={address} />
      <span {...styles.note()}>Send USDC on Tempo to this address</span>
      <Hex copy size="small" value={address} variant="filled" {...styles.hex()} />
    </div>
  )
}

namespace styles {
  export const hex = style({ width: '100% !custom' })

  export const note = style({
    color: 'content.secondary',
    textAlign: 'center',
    typography: 'body.b3',
  })

  export const stack = style({
    display: 'grid',
    gap: '12',
    justifyItems: 'center',
    width: '100% !custom',
  })
}
```

**Don't:** Show a code without the value it encodes.

```tsx
/**
 * Don't example for "Show the Address as Text Too" on the Qr page.
 * Don't show a code without the value it encodes.
 * @module
 */
import { Qr } from '@tempoxyz/ds'

/** Renders the static preview, which the guideline card shows inert. */
export function Demo() {
  return <Qr size="small" value="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" />
}
```

### Keep Contrast and Clear Space

* **Dark mode:** The modules turn light on a dark ground, and some scanners cannot read inverted codes. If older scanners matter, use a light panel and set `color` to a dark value with 3:1 contrast in both schemes.
* **Clear space:** Keep borders, text, and controls off the edges of the code.

**Do:** Place the code on a plain background with space around it.

```tsx
/**
 * Do example for "Keep Contrast and Clear Space" on the Qr page.
 * Place the code on a plain background with space around it.
 * @module
 */
import { Qr, style } from '@tempoxyz/ds'

/** Renders the static preview, which the guideline card shows inert. */
export function Demo() {
  return (
    <div {...styles.panel()}>
      <Qr
        aria-label="Deposit address QR code"
        size="small"
        value="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
      />
    </div>
  )
}

namespace styles {
  export const panel = style({
    backgroundColor: 'background.primary',
    borderRadius: 'sm',
    padding: '24',
  })
}
```

**Don't:** Place the code over an image or gradient.

```tsx
/**
 * Don't example for "Keep Contrast and Clear Space" on the Qr page.
 * Don't place the code over an image or gradient.
 * @module
 */
import { Qr, style } from '@tempoxyz/ds'

/** Renders the static preview, which the guideline card shows inert. */
export function Demo() {
  return (
    <div {...styles.panel()}>
      <Qr
        aria-label="Deposit address QR code"
        size="small"
        value="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
      />
    </div>
  )
}

namespace styles {
  export const panel = style({
    backgroundImage: 'linear-gradient(135deg, #3b82f6, #a855f7 50%, #f97316) !custom',
    borderRadius: 'sm',
    padding: '4',
  })
}
```

### Use a Logo Only at Larger Sizes

`arena` draws a logo in the center and raises error correction to medium, so scanners recover the covered modules. Use the token's logo or Tempo's.

**Do:** Add a logo only to a `medium` or `large` code.

```tsx
/**
 * Do example for "Use a Logo Only at Larger Sizes" on the Qr page.
 * Add a logo only to a `medium` or `large` code.
 * @module
 */
import { Qr } from '@tempoxyz/ds'
import pathUsd from '../../coins/PathUSD.svg'

/** Renders the static preview, which the guideline card shows inert. */
export function Demo() {
  return (
    <Qr
      arena={pathUsd}
      aria-label="Deposit address QR code"
      size="medium"
      value="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
    />
  )
}
```

**Don't:** Add a logo to a `small` code.

```tsx
/**
 * Don't example for "Use a Logo Only at Larger Sizes" on the Qr page.
 * Don't add a logo to a `small` code.
 * @module
 */
import { Qr } from '@tempoxyz/ds'
import pathUsd from '../../coins/PathUSD.svg'

/** Renders the static preview, which the guideline card shows inert. */
export function Demo() {
  return (
    <Qr
      arena={pathUsd}
      aria-label="Deposit address QR code"
      size="small"
      value="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
    />
  )
}
```

### Size for the Screen

* **Small (160px):** In a panel beside other content.
* **Medium (240px):** The default, for a receive dialog.
* **Large (320px):** The roomiest size, for a code with a logo.

## Accessibility

Qr renders an `<svg>` with the `img` role. It is not interactive and takes no focus.

### Semantics

* **Root (img):** An image that screen readers announce by its name.
* **Name (aria-label):** Defaults to "QR code for" and the full value.
* **Arena (Arena):** Set `arena` to an image URL to add a logo, announced as a nested image.
* **Modules (foreground):** On a transparent ground, so the code follows the light or dark scheme.

### Your Responsibilities

* **Name It by Purpose (aria-label):** Describe what it encodes, such as "Deposit address QR code".
* **Name the Logo (arena):** Pass a node with its own accessible name, or make sure the logo's name adds no noise.

## Related

[Hex](/docs/components/hex)

Use for showing and copying the address.

[CopyButton](/docs/components/copy-button)

Use for copying a value.

[Snippet](/docs/components/snippet)

Use for links and other values.

[Payments](/docs/patterns/payments)

Covers send and receive flows.

[Tempo Wallet](/docs/products/tempo-wallet)

Covers the receive screen.
