Improved QR code modal, to allow selecting size, format and copy URL

This commit is contained in:
Alejandro Celaya
2021-01-24 17:37:31 +01:00
parent 556495ea7e
commit 3546a17575
10 changed files with 106 additions and 47 deletions

View File

@@ -0,0 +1,19 @@
export interface QrCodeCapabilities {
useSizeInPath: boolean;
svgIsSupported: boolean;
}
export type QrCodeFormat = 'svg' | 'png';
export const buildQrCodeUrl = (
shortUrl: string,
size: number,
format: QrCodeFormat,
{ useSizeInPath, svgIsSupported }: QrCodeCapabilities,
): string => {
const sizeFragment = useSizeInPath ? `/${size}` : `?size=${size}`;
const formatFragment = !svgIsSupported ? '' : `format=${format}`;
const joinSymbol = useSizeInPath && svgIsSupported ? '?' : !useSizeInPath && svgIsSupported ? '&' : '';
return `${shortUrl}/qr-code${sizeFragment}${joinSymbol}${formatFragment}`;
};