diff --git a/app/components/assets/asset-qr.tsx b/app/components/assets/asset-qr.tsx new file mode 100644 index 0000000..cc08ea7 --- /dev/null +++ b/app/components/assets/asset-qr.tsx @@ -0,0 +1,32 @@ +import { useMemo } from 'react'; +import { cva } from 'class-variance-authority'; +import { getArUrl, qrLogoFill, qrSvgMarkup } from '~/lib/assets/qr'; +import { cn } from '~/lib/utils'; +import { isBrandedQr, toBrand } from '~/services/asset-media'; +import type { ArAsset } from '~/types/asset'; + +const frameVariants = cva('relative aspect-square w-full overflow-hidden bg-qr-surface [&>svg]:block', { + variants: { + size: { + card: 'rounded-item', + panel: 'max-w-[300px] rounded-card-sm', + }, + }, +}); + +// The asset's QR code; a branded code has the client logo inside it, in a cleared square at the centre +export function AssetQr({ asset, size, className }: { asset: ArAsset; size: 'card' | 'panel'; className?: string }) { + const project = asset.expand?.project; + const brand = isBrandedQr(asset) && project ? toBrand(project) : undefined; + const markup = useMemo( + () => + qrSvgMarkup(getArUrl(asset.id), { + logo: brand?.logoUrl ? { href: brand.logoUrl, fill: qrLogoFill(brand) } : undefined, + label: `QR code for ${asset.name}`, + }), + [asset.id, asset.name, brand?.logoUrl, brand?.logoBg, brand?.logoBgColor], + ); + + // Markup built by qrSvgMarkup from our own data, with attribute values escaped + return
; +}