Skip to content

Commit

Permalink
add styled kits qrCode
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Jan 3, 2024
1 parent 24990ee commit fa9efcc
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 54 deletions.
26 changes: 26 additions & 0 deletions excalidraw-app/collab/RoomDialog.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
@import "../../packages/excalidraw/css/variables.module";

.excalidraw {
.RoomDialog__qrContainer {
display: flex;
margin: 1.5em 0;
display: flex;
align-items: center;
justify-content: center;
@include isMobile {
flex-direction: column;
}
}

.RoomDialog__qrDownloadContainer {
display: flex;
margin: 1.5em 0;
display: flex;
align-items: center;
justify-content: center;
@include isMobile {
flex-direction: column;
}

button {
margin:5px;
}
}

.RoomDialog {
display: flex;
flex-direction: column;
Expand Down
49 changes: 47 additions & 2 deletions excalidraw-app/collab/RoomDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from "react";
import { useRef, useState, useCallback } from "react";
import * as Popover from "@radix-ui/react-popover";

import { copyTextToSystemClipboard } from "../../packages/excalidraw/clipboard";
Expand All @@ -20,8 +20,9 @@ import {
import { TextField } from "../../packages/excalidraw/components/TextField";
import { FilledButton } from "../../packages/excalidraw/components/FilledButton";

import { ReactComponent as CollabImage } from "../../packages/excalidraw/assets/lock.svg";
import { ReactComponent as CollabImage } from "../../packages/excalidraw/assets/lock-kits.svg";
import "./RoomDialog.scss";
import QRCodeStyling, { FileExtension } from "qr-code-styling";

const getShareIcon = () => {
const navigator = window.navigator as any;
Expand All @@ -47,6 +48,30 @@ export type RoomModalProps = {
setErrorMessage: (message: string) => void;
};

const qrCode = new QRCodeStyling({
width: 200,
height: 200,
type: 'svg',
image: "",
dotsOptions: {
color: '#000000',
type: "dots",
},
cornersSquareOptions: {
type: 'square'
},
cornersDotOptions: {
type: 'dot'
},
backgroundOptions: {
color: "#fff",
},
imageOptions: {
crossOrigin: "anonymous",
margin: 20,
}
});

export const RoomModal = ({
activeRoomLink,
onRoomCreate,
Expand All @@ -62,6 +87,19 @@ export const RoomModal = ({
const ref = useRef<HTMLInputElement>(null);
const isShareSupported = "share" in navigator;

const qrRef = useCallback((node: HTMLDivElement) => {
if (node !== null) {
qrCode.append(node);
qrCode.update({ data: ref?.current?.value });
}
}, []);

const onQRDownloadClick = (extension: FileExtension) => {
qrCode.download({
extension
});
};

const copyRoomLink = async () => {
try {
await copyTextToSystemClipboard(activeRoomLink);
Expand Down Expand Up @@ -146,6 +184,13 @@ export const RoomModal = ({
</Popover.Content>
</Popover.Root>
</div>
<div>
<div className="RoomDialog__qrContainer" ref={qrRef} />
<div className="RoomDialog__qrDownloadContainer">
<FilledButton variant="outlined" size="large" onClick={() => onQRDownloadClick('png')} label={t("roomDialog.button_downloadPNG")}/>
<FilledButton variant="outlined" size="large" onClick={() => onQRDownloadClick('svg')} label={t("roomDialog.button_downloadSVG")}/>
</div>
</div>
<div className="RoomDialog__active__description">
<p>
<span
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-router-dom": "6.21.1",
"socket.io-client": "4.7.2"
"socket.io-client": "4.7.2",
"qr-code-styling": "1.6.0-rc.1"
},
"devDependencies": {
"@excalidraw/eslint-config": "1.0.3",
Expand Down
52 changes: 52 additions & 0 deletions packages/excalidraw/assets/lock-kits.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fa9efcc

Please sign in to comment.