From c09c0a5f17b6779d9168c4104d00e31dd82fcbd8 Mon Sep 17 00:00:00 2001
From: Rishit Gupta <74411873+Rishit30G@users.noreply.github.com>
Date: Thu, 16 Jan 2025 16:41:55 +0530
Subject: [PATCH 1/2] Storybook: Add Story for RichTextShortcut
---
.../stories/rich-text-shortcut.story.js | 69 +++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js
diff --git a/packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js b/packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js
new file mode 100644
index 00000000000000..98844747eae3f6
--- /dev/null
+++ b/packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js
@@ -0,0 +1,69 @@
+/**
+ * Internal dependencies
+ */
+import { RichTextShortcut } from '../shortcut.js';
+
+/**
+ * WordPress dependencies
+ */
+const meta = {
+ title: 'BlockEditor/RichTextShortcut',
+ component: RichTextShortcut,
+ parameters: {
+ docs: {
+ canvas: {
+ sourceState: 'shown',
+ },
+ description: {
+ component:
+ 'The `RichTextShortcut` component is used to define a keyboard shortcut for a specific action.',
+ },
+ },
+ },
+ argTypes: {
+ character: {
+ control: {
+ type: 'text',
+ },
+ description: 'The character that triggers the shortcut.',
+ table: {
+ type: {
+ summary: 'string',
+ },
+ },
+ },
+ type: {
+ control: {
+ type: 'select',
+ options: [ 'primary', 'access' ],
+ },
+ description: 'The type of shortcut.',
+ table: {
+ type: {
+ summary: 'string',
+ },
+ },
+ },
+ onUse: {
+ description: 'Function to be called when the shortcut is used.',
+ table: {
+ type: {
+ summary: 'function',
+ },
+ },
+ },
+ },
+};
+
+export default meta;
+
+export const Default = {
+ args: {
+ character: 'b',
+ type: 'primary',
+ onUse: () => {},
+ },
+ render: function Template( args ) {
+ return ;
+ },
+};
From 8d375ffcad17fae522dd605ce50233ccb757cab6 Mon Sep 17 00:00:00 2001
From: Rishit Gupta <74411873+Rishit30G@users.noreply.github.com>
Date: Thu, 23 Jan 2025 12:16:48 +0530
Subject: [PATCH 2/2] Refactor rich-text-shortcut.story.js
---
.../stories/rich-text-shortcut.story.js | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js b/packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js
index 98844747eae3f6..98a8a3d615ae0e 100644
--- a/packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js
+++ b/packages/block-editor/src/components/rich-text/stories/rich-text-shortcut.story.js
@@ -1,11 +1,9 @@
/**
* Internal dependencies
*/
+import { keyboardShortcutContext } from '../index.js';
import { RichTextShortcut } from '../shortcut.js';
-/**
- * WordPress dependencies
- */
const meta = {
title: 'BlockEditor/RichTextShortcut',
component: RichTextShortcut,
@@ -53,6 +51,19 @@ const meta = {
},
},
},
+ decorators: [
+ ( Story ) => {
+ const keyboardShortcuts = {
+ current: new Set(),
+ };
+
+ return (
+
+ { Story() }
+
+ );
+ },
+ ],
};
export default meta;