-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copy button to code block actions (#62)
* Wrap long classNames to the next line * Add CopyCodeButton * Override primary button styles * Remove redundant ternary
- Loading branch information
1 parent
cef8151
commit 99472e7
Showing
5 changed files
with
56 additions
and
16 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
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
26 changes: 26 additions & 0 deletions
26
apps/front-end/src/plugins/CodeActionPlugin/CopyCodeButton.tsx
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,26 @@ | ||
import CopyButton from "@/components/CopyButton"; | ||
import { $getNodeByKey } from "lexical"; | ||
import { WithCodeNode } from "./ActionBar"; | ||
|
||
type CopyCodeButtonProps = WithCodeNode; | ||
|
||
function CopyCodeButton(props: CopyCodeButtonProps) { | ||
const handleClick = () => { | ||
props.editor.getEditorState().read(() => { | ||
const codeNode = $getNodeByKey(props.codeNodeKey); | ||
if (codeNode) { | ||
const text = codeNode.getTextContent(); | ||
navigator.clipboard.writeText(text); | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<CopyButton | ||
className="!bg-transparent !p-2.5 !text-inherit shadow-sm hover:!bg-slate-700" | ||
onClick={handleClick} | ||
/> | ||
); | ||
} | ||
|
||
export default CopyCodeButton; |
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