# vCard QR Code (Components)

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

A QR code for shadcn/ui projects that saves a contact card when scanned, with a typed vCard 3.0 builder.

`VCardQrCode` renders a code that saves a contact when a phone camera scans it, with the name and role under it. Use it on a business card, a staff directory, a conference badge or an email signature page.

## Installation [#installation]

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

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

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

## Usage [#usage]

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

```tsx title="components/example.tsx"
<VCardQrCode
  contact={{
    firstName: "Ada",
    lastName: "Lovelace",
    organization: "Analytical Engines",
    email: "ada@example.com",
  }}
/>
```

Phone cameras offer to save the contact when they scan the code. Empty fields are left out, which keeps the code small and quick to scan.

## Examples [#examples]

### vCard builder [#vcard-builder]

`buildVCard` returns the vCard 3.0 text the code encodes, with commas, semicolons, backslashes and line breaks escaped. Use it with any QR renderer, or to offer the same contact as a `.vcf` download.

Contact cards hold more text than a link, so the component uses error correction level `M` to keep the modules large. Add only the fields people need, and check how large to print it with the [print size calculator](https://qrdx.dev/tools/print-size).

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

- The code has `aria-label="QR code with the contact card for <name>"`. The card's fields are not read out.
- The name and the title and organization 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                                                    |
| -------------- | ------------- | -------------------------------------------------------------- |
| `contact`      | `object`      | The contact to encode.                                         |
| `size?`        | `number`      | Width and height of the code in pixels. Default: `200`         |
| `qr?`          | `QrCodeStyle` | qrdx style options for the code.                               |
| `showDetails?` | `union`       | Show the name and organization under the code. Default: `true` |

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

### VCardContact [#vcardcontact]

### VCardContact

| Prop            | Type     | Description                                                |
| --------------- | -------- | ---------------------------------------------------------- |
| `firstName`     | `string` |                                                            |
| `lastName?`     | `string` |                                                            |
| `organization?` | `string` |                                                            |
| `title?`        | `string` | Job title.                                                 |
| `phone?`        | `string` | Work phone, ideally in international format (+1 555 0100). |
| `mobile?`       | `string` |                                                            |
| `email?`        | `string` |                                                            |
| `url?`          | `string` | Website, including https://.                               |
| `address?`      | `object` |                                                            |
| `note?`         | `string` |                                                            |

`buildVCard(contact: VCardContact): string` writes `N`, `FN`, `ORG`, `TITLE`, `TEL` (work and mobile), `EMAIL`, `URL`, `ADR` and `NOTE` lines, each only when the field is set.

## Related [#related]

- [Wi-Fi QR Code](https://qrdx.dev/docs/components/wifi-qr-code): The same idea for a Wi-Fi network.
- [QR Code](https://qrdx.dev/docs/components/qr-code): A code for any payload, with download buttons.
- [NFC tags and business cards](https://qrdx.dev/docs/nfc): Put the same contact on an NFC tag.
