From 4f3edf44770e339c618992278dc115bd16d6bbc6 Mon Sep 17 00:00:00 2001 From: dhruvikpatel18 Date: Mon, 13 Jan 2025 16:26:13 +0530 Subject: [PATCH] Add: Added story for block-context. --- .../block-context/stories/index.story.js | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 packages/block-editor/src/components/block-context/stories/index.story.js diff --git a/packages/block-editor/src/components/block-context/stories/index.story.js b/packages/block-editor/src/components/block-context/stories/index.story.js new file mode 100644 index 00000000000000..723b3ebefeb710 --- /dev/null +++ b/packages/block-editor/src/components/block-context/stories/index.story.js @@ -0,0 +1,59 @@ +/** + * WordPress dependencies + */ +import { useContext } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import { BlockContextProvider, default as Context } from '../'; + +const meta = { + title: 'BlockEditor/BlockContext', + component: BlockContextProvider, + parameters: { + docs: { + description: { + component: + 'The `BlockContextProvider` component allows passing and inheriting values deeply through a hierarchy of blocks, similar to React Context.', + }, + canvas: { sourceState: 'shown' }, + }, + }, + argTypes: { + value: { + control: 'object', + description: 'Context value to merge with current value.', + table: { + type: { summary: 'Record' }, + defaultValue: { summary: '{}' }, + }, + }, + }, +}; + +export default meta; + +const ContextConsumer = () => { + const context = useContext( Context ); + return ( +
+

Current Context Values:

+
{ JSON.stringify( context, null, 2 ) }
+
+ ); +}; + +export const Default = { + args: { + value: { + postId: 1, + postType: 'post', + }, + }, + render: ( { value } ) => ( + + + + ), +};