feat: add asset QR code
This commit is contained in:
parent
3abbb34352
commit
3442ed452e
32
app/components/assets/asset-qr.tsx
Normal file
32
app/components/assets/asset-qr.tsx
Normal file
@ -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 <div className={cn(frameVariants({ size }), className)} dangerouslySetInnerHTML={{ __html: markup }} />;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user