Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Remove copy button when copying is not supported #786

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions web/src/components/DocumentControlButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default function DocumentControlButtons(props: Props): JSX.Element {
const [shareModalUseLatest, setShareModalUseLatest] = useState<boolean>(false)
const [shareModalHideUi, setShareModalHideUi] = useState<boolean>(false)

// Cannot copy when page is served over HTTP
const canCopy = navigator.clipboard !== undefined

const getShareUrl = (): string => {
// adapt the current URL so we can leave Docs.tsx's state as refs
// (which means if the page was passed down as a prop it wouldn't update correctly)
Expand Down Expand Up @@ -97,18 +100,20 @@ export default function DocumentControlButtons(props: Props): JSX.Element {
<div className={styles['share-modal']}>
<div className={styles['share-modal-link-container']}>
<p className={styles['share-modal-link']}>{getShareUrl()}</p>
<div className={styles['share-modal-copy-container']}>
<button
className={styles['share-modal-copy']}
onClick={() => {
void (async () => {
await navigator.clipboard.writeText(getShareUrl())
})()
}}
>
Copy
</button>
</div>
{canCopy && (
<div className={styles['share-modal-copy-container']}>
<button
className={styles['share-modal-copy']}
onClick={() => {
void (async () => {
await navigator.clipboard.writeText(getShareUrl())
})()
}}
>
Copy
</button>
</div>
)}
</div>

<FormGroup>
Expand Down
5 changes: 5 additions & 0 deletions web/src/style/components/DocumentControlButtons.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
-moz-user-select: all;
-webkit-user-select: all;
font-size: small;
width: 100%;
}

.share-modal-copy-container {
Expand Down Expand Up @@ -131,6 +132,10 @@
align-items: center;
}

.share-modal-link {
width: auto;
}

.share-modal-copy-container {
margin-left: 0;
margin-top: 1rem;
Expand Down