Skip to content

Commit

Permalink
style: fix Copied button misalignment on mobile browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
hfdem committed Sep 25, 2024
1 parent ebfe081 commit 147d372
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 45 deletions.
80 changes: 47 additions & 33 deletions client/src/components/LinkDisplay/Style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
border-width: 1px;
font-family: inherit;
font-size: 18px;
width: 100px;
width: 50px;
height: 40px;
border-radius: 5px;
cursor: pointer;
Expand All @@ -64,6 +64,7 @@

.copyIcon {
font-size: '15px';
transform: translateY(2px);
}

.textAreaContainer {
Expand Down Expand Up @@ -121,47 +122,17 @@
color: #aeaeae;
}

@media screen and (min-width: 640px) {
.fullWidth {
display: flex;
flex-flow: wrap;
}
.fullWidth > div {
flex: 1 auto;
}
.pinDisplay {
margin: 0;
}
.pinDisplayMsg {
width: 100%;
font-size: 18px;
padding-bottom: 20px;
}

.openLink {
width: 100%;
flex: 1 auto;
}

.divider {
margin: 30px 0;
border-top: 1px solid #434343;
width: 100%;
}
}

.qrCodeContainer {
margin-top: 20px;
display: flex;
justify-content: center;
}


.qrButton {
border-width: 1px;
font-family: inherit;
font-size: 18px;
width: 110px;
width: 50px;
height: 40px;
border-radius: 5px;
cursor: pointer;
Expand All @@ -170,6 +141,7 @@
background: #4bb2f9;
color: white;
margin-left: 5px;
transform: translateY(2px);
}

.qrButton:hover {
Expand All @@ -185,5 +157,47 @@
.qrIcon {
display: inline-block;
margin-top: 0;
transform: translateY(2px);
transform: none;
}

@media screen and (min-width: 640px) {
.fullWidth {
display: flex;
flex-flow: wrap;
}
.fullWidth > div {
flex: 1 auto;
}
.pinDisplay {
margin: 0;
}
.pinDisplayMsg {
width: 100%;
font-size: 18px;
padding-bottom: 20px;
}

.openLink {
width: 100%;
flex: 1 auto;
}

.divider {
margin: 30px 0;
border-top: 1px solid #434343;
width: 100%;
}

.copyButton {
width: 100px;
}

.qrButton {
width: 100px;
transform: none;
}

.qrIcon {
transform: translateY(2px);
}
}
25 changes: 13 additions & 12 deletions client/src/components/LinkDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useRef, useState, useContext } from "react";
import { FiLink, FiCopy, FiExternalLink, FiArrowDown, FiArrowUp } from "react-icons/fi";
import React, { useRef, useState, useContext, useEffect } from "react";
import { FiLink, FiCopy, FiExternalLink } from "react-icons/fi";
import { MdOutlineQrCode } from "react-icons/md";
import styles from "./Style.module.css";
import { ThemeContext } from "../../ThemeContext";
import { LinkObjType } from "@chat-e2ee/service";
import QRCode from "qrcode.react";
import detectMobile from "../../utils/detectMobile";

const LinkDisplay: React.FC<{ content: LinkObjType }> = ({ content }) => {
const chatLink =
Expand All @@ -13,6 +15,11 @@ const LinkDisplay: React.FC<{ content: LinkObjType }> = ({ content }) => {
const [buttonText, setButtonText] = useState("Copy");
const [showQR, setShowQR] = useState(false);
const [darkMode] = useContext(ThemeContext);
const [isMobile, setIsMobile] = useState(false);

useEffect(() => {
setIsMobile(detectMobile());
}, []);

const copyCodeToClipboard = () => {
if (textAreaRef.current !== null) textAreaRef.current.select();
Expand Down Expand Up @@ -50,22 +57,16 @@ const LinkDisplay: React.FC<{ content: LinkObjType }> = ({ content }) => {
${!darkMode && styles.lightModeButton}`}
onClick={copyCodeToClipboard}
>
<FiCopy className={styles.copyIcon} /> {buttonText}
<FiCopy className={styles.copyIcon} /> {!isMobile && buttonText}
</button>
<button
type="button"
className={`${styles.qrButton} ${!darkMode && styles.lightModeButton}`}
onClick={() => setShowQR(!showQR)}
>
{showQR ? (
<div className={styles.QrCodeContent}>
QR Code <FiArrowUp className={styles.qrIcon} />
</div>
) : (
<div className={styles.QrCodeContent}>
QR Code <FiArrowDown className={styles.qrIcon} />
</div>
)}
<div className={styles.QrCodeContent}>
<MdOutlineQrCode className={styles.qrIcon} /> {!isMobile && "QR Code"}
</div>
</button>
</div>
</div>
Expand Down

0 comments on commit 147d372

Please sign in to comment.