Skip to content

Commit

Permalink
Storybook: Add stories for BlockTitle Component (#67234)
Browse files Browse the repository at this point in the history
* Doc: Add Storybook for BlockTitle

* Refactor: Simplify Storybook for BlockTitle and add type summaries to controls

* Refactor: Updated descriptions to match the JSDoc

* Refactor: Remove comment from BlockTitle story

* Storybook: Refactor BlockTitle story to use ExperimentalBlockEditorProvider

- Replaced BlockEditorProvider with ExperimentalBlockEditorProvider.
- Simplified blocks array to include a single paragraph block.
- Removed unnecessary client ID mappings and control options.
- Cleaned up redundant comments and controls.

* Storybook: Set clientId control to null for BlockTitle

Co-authored-by: SainathPoojary <sainathpoojary@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
  • Loading branch information
4 people authored Dec 19, 2024
1 parent 0c9da7c commit e29541d
Showing 1 changed file with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* WordPress dependencies
*/
import { registerCoreBlocks } from '@wordpress/block-library';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { ExperimentalBlockEditorProvider } from '../../provider';
import BlockTitle from '../';

// Register core blocks for the story environment
registerCoreBlocks();

// Sample blocks for testing
const blocks = [ createBlock( 'core/paragraph' ) ];

const meta = {
title: 'BlockEditor/BlockTitle',
component: BlockTitle,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
"Renders the block's configured title as a string, or empty if the title cannot be determined.",
},
},
},
decorators: [
( Story ) => (
<ExperimentalBlockEditorProvider value={ blocks }>
<Story />
</ExperimentalBlockEditorProvider>
),
],
argTypes: {
clientId: {
control: { type: null },
description: 'Client ID of block.',
table: {
type: {
summary: 'string',
},
},
},
maximumLength: {
control: { type: 'number' },
description:
'The maximum length that the block title string may be before truncated.',
table: {
type: {
summary: 'number',
},
},
},
context: {
control: { type: 'text' },
description: 'The context to pass to `getBlockLabel`.',
table: {
type: {
summary: 'string',
},
},
},
},
};

export default meta;

export const Default = {
args: {
clientId: blocks[ 0 ].clientId,
},
};

1 comment on commit e29541d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e29541d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12408292906
📝 Reported issues:

Please sign in to comment.