Veil UI
Components

QR Code

A scannable QR code rendered as SVG with a caption.

Installation

$ npx veil-ui@latest add qrcode

Usage

import { QRCode } from "@/components/ui/qrcode";

<QRCode value="https://veil-ui.dev" />;

Examples

Basic

Labeled

Scan to open the QR code documentation.

API reference

The package exports qrcode along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.

Accessibility

  • Media players use native <video> and <audio> controls with accessible labels.
  • Images require meaningful alt text; clickable thumbnails are buttons named Play <title>.
  • Decorative play overlays, durations and icons are hidden from assistive technology.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add qrcode --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { computed } from "vue";

import qrcode from "qrcode-generator";

import { cn } from "@/lib/utils";

const props = withDefaults(
  defineProps<{
    value: string;
    size?: number;
    level?: "L" | "M" | "Q" | "H";
    label?: string;
    caption?: string;
    bgColor?: string;
    fgColor?: string;
    class?: string;
  }>(),
  { size: 160, level: "M", bgColor: "#ffffff", fgColor: "#000000" },
);

const matrix = computed(() => {
  const generator = qrcode(0, props.level);
  generator.addData(props.value);
  generator.make();
  const count = generator.getModuleCount();
  const cells: Array<[number, number]> = [];

  for (let row = 0; row < count; row += 1) {
    for (let column = 0; column < count; column += 1) {
      if (generator.isDark(row, column)) cells.push([column, row]);
    }
  }

  return { count, cells };
});
</script>

<template>
  <figure
    data-slot="qrcode"
    :class="cn('inline-flex flex-col items-center gap-2', props.class)"
  >
    <div class="rounded-lg p-2" :style="{ backgroundColor: bgColor }">
      <svg
        :width="size"
        :height="size"
        :viewBox="`0 0 ${matrix.count} ${matrix.count}`"
        shape-rendering="crispEdges"
        role="img"
        :aria-label="label ?? value"
      >
        <title>{{ label ?? value }}</title>
        <rect
          v-for="([x, y], index) in matrix.cells"
          :key="index"
          :x="x"
          :y="y"
          width="1"
          height="1"
          :fill="fgColor"
        />
      </svg>
    </div>
    <figcaption
      v-if="caption"
      class="max-w-[16rem] text-center text-xs text-muted-foreground"
    >
      {{ caption }}
    </figcaption>
  </figure>
</template>

On this page