Skip to content

Commit

Permalink
Add: Added story for block-context.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvikpatel18 committed Jan 13, 2025
1 parent e5dca54 commit 4f3edf4
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<string,*>' },
defaultValue: { summary: '{}' },
},
},
},
};

export default meta;

const ContextConsumer = () => {
const context = useContext( Context );
return (
<div style={ { padding: '10px', border: '1px solid #ccc' } }>
<h3>Current Context Values:</h3>
<pre>{ JSON.stringify( context, null, 2 ) }</pre>
</div>
);
};

export const Default = {
args: {
value: {
postId: 1,
postType: 'post',
},
},
render: ( { value } ) => (
<BlockContextProvider value={ value }>
<ContextConsumer />
</BlockContextProvider>
),
};

0 comments on commit 4f3edf4

Please sign in to comment.