Add "copy to clipboard" button to Variables pane (#2388)
This commit is contained in:
@ -3,6 +3,43 @@ import { useMemo } from 'react'
|
||||
import { ProgramMemory, Path, ExtrudeSurface } from 'lang/wasm'
|
||||
import { useKclContext } from 'lang/KclProvider'
|
||||
import { useResolvedTheme } from 'hooks/useResolvedTheme'
|
||||
import { ActionButton } from 'components/ActionButton'
|
||||
import toast from 'react-hot-toast'
|
||||
import Tooltip from 'components/Tooltip'
|
||||
|
||||
export const MemoryPaneMenu = () => {
|
||||
const { programMemory } = useKclContext()
|
||||
|
||||
function copyProgramMemoryToClipboard() {
|
||||
if (globalThis && 'navigator' in globalThis) {
|
||||
try {
|
||||
navigator.clipboard.writeText(JSON.stringify(programMemory))
|
||||
toast.success('Program memory copied to clipboard')
|
||||
} catch (e) {
|
||||
toast.error('Failed to copy program memory to clipboard')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ActionButton
|
||||
Element="button"
|
||||
iconStart={{
|
||||
icon: 'clipboardPlus',
|
||||
iconClassName: '!text-current',
|
||||
bgClassName: 'bg-transparent',
|
||||
}}
|
||||
className="!p-0 !bg-transparent hover:text-primary border-transparent hover:border-primary !outline-none"
|
||||
onClick={copyProgramMemoryToClipboard}
|
||||
>
|
||||
<Tooltip position="bottom-right" delay={750}>
|
||||
Copy to clipboard
|
||||
</Tooltip>
|
||||
</ActionButton>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export const MemoryPane = () => {
|
||||
const theme = useResolvedTheme()
|
||||
|
Reference in New Issue
Block a user