Skip to content

Commit

Permalink
Merge pull request #786 from docat-org/fix/hide-copy-button-http
Browse files Browse the repository at this point in the history
Fix: Remove copy button when copying is not supported
  • Loading branch information
reglim authored Feb 1, 2024
2 parents 1b759dc + d023b93 commit 31f5e24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
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

0 comments on commit 31f5e24

Please sign in to comment.