-
Notifications
You must be signed in to change notification settings - Fork 367
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
Reinstate clipboard functionality #339
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useState } from 'react' | ||
|
||
export const ClipboardCopy = ({ | ||
children | ||
}: { | ||
children: string | undefined | number | null | ||
}): JSX.Element => { | ||
const [copied, setCopied] = useState(false) | ||
|
||
function copyToClipboard() { | ||
if (typeof children === 'undefined' || children === null) { | ||
return | ||
} | ||
navigator.clipboard.writeText(children.toString()) | ||
|
||
setCopied(true) | ||
setTimeout(() => { | ||
setCopied(false) | ||
}, 200) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to clear it on component unmount, WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for an animation, so it needs to zoom out after quickly. Otherwise they would just stay scaled up until the component unmounts |
||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
cursor: 'pointer', | ||
scale: copied ? `1.15` : `1`, | ||
transition: 'scale 0.2s ease-in-out' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest defining styles in scss file, to keep it consistent with other components |
||
}} | ||
onClick={copyToClipboard} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ export const getKeyCodeEvent = ( | |
): KeyCodeEvent | undefined => { | ||
return keyCodeEventValues.find( | ||
keyCodeEvent => | ||
keyCodeEvent.code === keyCode.code && keyCodeEvent.key === keyCode.key | ||
keyCodeEvent.code === keyCode.code || keyCodeEvent.key === keyCode.key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you consider removing that change here, and keep it in #338? That would make tracking it easier |
||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider waiting for permission returned from
writeText
resolves or rejects, and handle potential rejection.