-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widget): Metadata fields can be copied to clipboard (#217)
* Also fixed the bug where tooltips wouldn't appear after looking at detail view * Note that this new code is untested because playwright doesn't support testing the contents of the clipboard.
- Loading branch information
1 parent
9d11389
commit a7a6cb1
Showing
9 changed files
with
195 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { svg } from 'lit'; | ||
|
||
export const copyToClipboardButton = ( | ||
textToCopy: string, | ||
onCopy: (newText: string, x: number, y: number) => void, | ||
) => svg` | ||
<svg @click='${(event: PointerEvent) => copyToClipboard(event, textToCopy, onCopy)}' | ||
class='copy-to-clipboard-button clickable' width='12' height='14' viewBox='0 0 12 14' fill='none' xmlns='http://www.w3.org/2000/svg'> | ||
<path class='copy-to-clipboard-button-path' fill='#989898' fill-rule='evenodd' clip-rule='evenodd' d='M7 3H2C1.44772 3 1 3.44772 1 4V12C1 12.5523 1.44772 13 2 13H7C7.55228 13 8 12.5523 8 12V4C8 3.44772 7.55228 3 7 3ZM2 2C0.895431 2 0 2.89543 0 4V12C0 13.1046 0.89543 14 2 14H7C8.10457 14 9 13.1046 9 12V4C9 2.89543 8.10457 2 7 2H2ZM10 1H5C4.44772 1 4 1.44772 4 2V10C4 10.5523 4.44772 11 5 11H10C10.5523 11 11 10.5523 11 10V2C11 1.44772 10.5523 1 10 1ZM5 0C3.89543 0 3 0.895431 3 2V10C3 11.1046 3.89543 12 5 12H10C11.1046 12 12 11.1046 12 10V2C12 0.895431 11.1046 0 10 0H5Z'/> | ||
</svg> | ||
`; | ||
|
||
// Be aware: the copy-to-clipboard functionality is not tested. Sadly, it is basically impossible to test clipboard | ||
// functionality in Playwright. | ||
const copyToClipboard = ( | ||
event: PointerEvent, | ||
textToCopy: string, | ||
onCopy: (newText: string, x: number, y: number) => void, | ||
) => { | ||
navigator.clipboard | ||
.writeText(textToCopy) | ||
.then(() => { | ||
const x: number = event.pageX; | ||
const y: number = event.pageY; | ||
onCopy('Copied!', x, y); | ||
}) | ||
.catch((err) => { | ||
console.log('Failed to copy to clipboard\n\n', err); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// All files which will be accessible when the widget is installed via npm are declared here | ||
export * from './copy-to-clipboard'; | ||
export * from './close-details-button'; | ||
export * from './logo-small'; | ||
export * from './logo-large'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.