# Wi-Fi QR Code (Components)

URL: https://qrdx.dev/docs/components/wifi-qr-code
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/components/wifi-qr-code.mdx

A QR code for shadcn/ui projects that joins a Wi-Fi network when scanned, with a typed, escaped payload builder.

`WifiQrCode` renders a code that joins a Wi-Fi network when a phone camera scans it, with the network name under it. Use it for a guest network card at reception, a table tent in a cafe or a rental's welcome page.

## Installation [#installation]

```bash
npx shadcn@latest add @qrdx/wifi-qr-code
```

Or by URL, which works with older versions of the CLI too:

```bash
npx shadcn@latest add https://qrdx.dev/r/wifi-qr-code.json
```

## Usage [#usage]

```tsx title="components/example.tsx"
import { WifiQrCode } from "@/components/wifi-qr-code";
```

```tsx title="components/example.tsx"
<WifiQrCode ssid="Cafe Guest" password="espresso-2024" />
```

The iOS and Android cameras offer to join the network when they scan the code. No app is needed. Under the code the component prints the network name and "Scan with your camera to join".

## Examples [#examples]

### Variants [#variants]

`showPassword` prints the password for guests who type it in. Use `encryption="nopass"` for open networks and `hidden` for networks that do not broadcast their name.

### Payload builder [#payload-builder]

`buildWifiPayload` returns the `WIFI:` text the code encodes. It escapes `\`, `;`, `,`, `:` and `"` in names and passwords, which is where hand-written payloads usually break. Use it with any QR renderer, or to print the payload for debugging.

## Accessibility and rendering [#accessibility-and-rendering]

- The code has `aria-label="QR code to join the Wi-Fi network <ssid>"`. The payload, which holds the password, is never read out.
- The name and password under the code are the figure's `<figcaption>`. Set `showDetails={false}` to show the code alone.
- The component is a Client Component, and the code is rendered on the server.

## API reference [#api-reference]

### $Fumadocs

| Prop            | Type          | Description                                                                       |
| --------------- | ------------- | --------------------------------------------------------------------------------- |
| `ssid`          | `string`      | Network name (SSID).                                                              |
| `password?`     | `string`      | Network password. Ignored when `encryption` is "nopass".                          |
| `encryption?`   | `union`       | "WPA" covers WPA, WPA2 and WPA3. Use "nopass" for open networks. Default: `"WPA"` |
| `hidden?`       | `union`       | Set when the network does not broadcast its name. Default: `false`                |
| `size?`         | `number`      | Width and height of the code in pixels. Default: `180`                            |
| `qr?`           | `QrCodeStyle` | qrdx style options for the code.                                                  |
| `showDetails?`  | `union`       | Show the network name under the code. Default: `true`                             |
| `showPassword?` | `union`       | Also print the password, for guests who type it in. Default: `false`              |

Any other prop, such as `className`, is passed to the wrapping `<figure>`.

### buildWifiPayload [#buildwifipayload]

`buildWifiPayload(network: WifiNetwork): string` takes the same network fields as the component: `ssid`, `password`, `encryption` and `hidden`. `"WPA"` covers WPA, WPA2 and WPA3; `"WEP"` and `"nopass"` are the other values. With `"nopass"` the password is left out.

## Related [#related]

- [vCard QR Code](https://qrdx.dev/docs/components/vcard-qr-code): The same idea for a contact card.
- [QR Code](https://qrdx.dev/docs/components/qr-code): A code for any payload, with download buttons.
- [QR Code Download](https://qrdx.dev/docs/components/qr-code-download): Export the Wi-Fi code for printing.
