Skip to content

Commit

Permalink
Merge pull request #2989 from vodkaslime/add-toggle-codeblock-hook
Browse files Browse the repository at this point in the history
feat: add useToggleCodeBlockButton hook to code-block package
  • Loading branch information
zbeyens authored Feb 23, 2024
2 parents 75327e9 + f6a54ff commit 100f5cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-onions-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-code-block": minor
---

feat: `useToggleCodeBlockButton`
1 change: 1 addition & 0 deletions packages/code-block/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
export * from './useCodeBlockCombobox';
export * from './useCodeBlockElement';
export * from './useCodeSyntaxLeaf';
export * from './useToggleCodeBlockButton';
18 changes: 18 additions & 0 deletions packages/code-block/src/hooks/useToggleCodeBlockButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { useEditorRef } from '@udecode/plate-common';
import { toggleCodeBlock } from '../transforms';

export const useToggleCodeBlockButton = () => {
const editor = useEditorRef();

return {
props: {
onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
},
onClick: () => {
toggleCodeBlock(editor);
},
},
};
};

0 comments on commit 100f5cd

Please sign in to comment.