Files
open-safetylog-ehs/src/components/QrCode.tsx
T
jayjennings 3e964d1176
CI / Lint, typecheck, test, build (push) Canceled after 0s
CI / End-to-end tests (push) Canceled after 0s
feat(i18n): add internationalization support with English and Spanish translations
feat(kiosk): implement kiosk report submission functionality with offline support

test(outbox): add tests for outbox functionality including report submission and error handling

feat(outbox): create outbox management for queued reports with IndexedDB persistence

feat(uuid): add UUID generation utility for client IDs

feat(qr): implement QR code generation for reporting links by site and area

feat(kiosk): create Kiosk page for reporting incidents without an account
2026-10-06 11:38:40 -07:00

20 lines
915 B
TypeScript

import QRCode from 'qrcode'
import { useMemo } from 'react'
/** QR code as crisp SVG squares (prints sharply at any size). */
export function QrCode({ value, size = 160, label }: { value: string; size?: number; label: string }) {
const { path, count } = useMemo(() => {
const { modules } = QRCode.create(value, { errorCorrectionLevel: 'M' })
let d = ''
for (let y = 0; y < modules.size; y++) for (let x = 0; x < modules.size; x++) if (modules.get(x, y)) d += `M${x} ${y}h1v1h-1z`
return { path: d, count: modules.size }
}, [value])
const margin = 2
return (
<svg width={size} height={size} viewBox={`${-margin} ${-margin} ${count + margin * 2} ${count + margin * 2}`} role="img" aria-label={label} shapeRendering="crispEdges">
<rect x={-margin} y={-margin} width={count + margin * 2} height={count + margin * 2} fill="#fff" />
<path d={path} fill="#000" />
</svg>
)
}