qr-code
diceui-radix/qr-codeFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/qr-code.jsonSource
1"use client";23import { Slot as SlotPrimitive } from "radix-ui";4import * as React from "react";5import { useComposedRefs } from "@/lib/compose-refs";6import { cn } from "@/lib/utils";7import { useLazyRef } from "@/registry/bases/radix/hooks/use-lazy-ref";89const ROOT_NAME = "QRCode";10const CANVAS_NAME = "QRCodeCanvas";11const SVG_NAME = "QRCodeSvg";12const IMAGE_NAME = "QRCodeImage";13const SKELETON_NAME = "QRCodeSkeleton";1415type QRCodeLevel = "L" | "M" | "Q" | "H";1617interface QRCodeCanvasOpts {18 errorCorrectionLevel: QRCodeLevel;19 type?: "image/png" | "image/jpeg" | "image/webp";20 quality?: number;21 margin?: number;22 color?: {23 dark: string;24 light: string;25 };26 width?: number;27 rendererOpts?: {28 quality?: number;29 };30}3132interface StoreState {33 dataUrl: string | null;34 svgString: string | null;35 isGenerating: boolean;36 error: Error | null;37 generationKey: string;38}3940interface Store {41 subscribe: (callback: () => void) => () => void;42 getState: () => StoreState;43 setState: <K extends keyof StoreState>(key: K, value: StoreState[K]) => void;44 setStates: (updates: Partial<StoreState>) => void;45 notify: () => void;46}4748interface QRCodeContextValue {49 value: string;50 size: number;51 margin: number;52 level: QRCodeLevel;53 backgroundColor: string;54 foregroundColor: string;55 canvasRef: React.RefObject<HTMLCanvasElement | null>;56}5758const StoreContext = React.createContext<Store | null>(null);5960function useStore<T>(selector: (state: StoreState) => T): T {61 const store = React.useContext(StoreContext);62 if (!store) {63 throw new Error(`\`useQRCode\` must be used within \`${ROOT_NAME}\``);64 }6566 const getSnapshot = React.useCallback(67 () => selector(store.getState()),68 [store, selector],69 );7071 return React.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);72}7374const QRCodeContext = React.createContext<QRCodeContextValue | null>(null);7576function useQRCodeContext(consumerName: string) {77 const context = React.useContext(QRCodeContext);78 if (!context) {79 throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);80 }81 return context;82}8384interface QRCodeProps extends Omit<React.ComponentProps<"div">, "onError"> {85 value: string;86 size?: number;87 level?: QRCodeLevel;88 margin?: number;89 quality?: number;90 backgroundColor?: string;91 foregroundColor?: string;92 onError?: (error: Error) => void;93 onGenerated?: () => void;94 asChild?: boolean;95}9697function QRCode(props: QRCodeProps) {98// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
