qrcode
delta-components/qrcodeFreeComponent
delta-components publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by delta-components on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://deltacomponents.dev/r/qrcode.jsonSource
1"use client"23import React, { useEffect, useRef } from "react"4import QRCodeStyling from "qr-code-styling"56import { cn } from "@/lib/utils"78interface QRCodeProps {9 value: string10 size?: number11 bgColor?: string // Can be a CSS variable (e.g. --color-background) or a color value12 fgColor?: string // Can be a CSS variable (e.g. --color-foreground) or a color value13 level?: "L" | "M" | "Q" | "H"14 marginSize?: number15 className?: string16 enableNavigation?: boolean // Enable click navigation to the QR code URL17 dotStyle?:18 | "rounded"19 | "dots"20 | "classy"21 | "classy-rounded"22 | "square"23 | "extra-rounded"24 cornerSquareStyle?:25 | "dot"26 | "square"27 | "extra-rounded"28 | "rounded"29 | "dots"30 | "classy"31 | "classy-rounded"32 cornerDotStyle?:33 | "dot"34 | "square"35 | "rounded"36 | "dots"37 | "classy"38 | "classy-rounded"39 | "extra-rounded"40 logoImage?: string // URL or data URI for the logo image41 logoSize?: number // Size of the logo as a percentage of the QR code size (0-1)42 logoMargin?: number // Margin around the logo in pixels43}4445// Helper to resolve CSS variable or direct color46function resolveColor(color?: string, fallback?: string) {47 if (!color) return fallback48 if (color.startsWith("--")) {49 if (typeof window !== "undefined") {50 const value = getComputedStyle(document.documentElement).getPropertyValue(51 color52 )53 if (value) return value.trim()54 }55 return fallback56 }57 return color58}5960export default function QRCode({61 value,62 size = 200,63 // Use shadcn theme variables for best contrast by default64 bgColor = "--color-background", // background65 fgColor = "--color-foreground", // foreground (text/qr dots)66 level = "M",67 marginSize = 0,68 className,69 enableNavigation = false,70 dotStyle = "square",71 cornerSquareStyle = "square",72 cornerDotStyle = "square",73 logoImage,74 logoSize = 0.2,75 logoMargin = 0,76}: QRCodeProps) {77 const ref = useRef<HTMLDivElement>(null)78 const qrCodeRef = useRef<QRCodeStyling | null>(null)7980 useEffect(() => {81 if (!value || !ref.current) return8283 // Always resolve to actual color values84 const resolvedBgColor = resolveColor(bgColor, "hsl(0, 0%, 100%)") // fallback: white85 const resolvedFgColor = resolveColor(fgColor, "hsl(222.2, 84%, 4.9%)") // fallback: dark8687 const qrCode = new QRCodeStyling({88 width: size,89 height: size,90 type: "svg",91 data: value,92 margin: marginSize,93// … truncated
What it pulls in
npm packages
Files it writes
More from delta-components
All 93 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| admonitionadmonition | delta-components | Components | Free | 1 dep | |
| cambio-imagecambio-image | delta-components | Components | Free | 2 deps | |
| card-deckcard-deck | delta-components | Components | Free | 3 deps | |
| chatchat | delta-components | Components | Free | 3 deps | |
| code-blockcode-block | delta-components | Components | Free | 3 deps | |
| code-block-iconscode-block-icons | delta-components | Components | Free | no deps | |
| copy-buttoncopy-button | delta-components | Components | Free | 1 dep | |
| input-otpinput-otp | delta-components | Components | Free | 1 dep |
