Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index.story.js for button block appender component #68598

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import ButtonBlockAppender from '../';

const meta = {
title: 'BlockEditor/ButtonBlockAppender',
component: ButtonBlockAppender,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component: __(
'A block appender button that allows users to add new blocks.'
),
},
},
},
argTypes: {
rootClientId: {
control: { type: 'text' },
description: __(
'The root client ID where new blocks will be inserted'
),
table: {
type: { summary: 'string' },
},
},
className: {
control: { type: 'text' },
description: __(
'Additional CSS class name to be added to the button'
),
table: {
type: { summary: 'string' },
},
},
onFocus: {
action: 'onFocus',
description: __( 'Callback function when button receives focus' ),
table: {
type: { summary: 'function' },
},
},
tabIndex: {
control: { type: 'number' },
description: __( 'Tab index for the button' ),
table: {
type: { summary: 'number' },
},
},
onSelect: {
action: 'onSelect',
description: __( 'Callback function when a block is selected' ),
table: {
type: { summary: 'function' },
},
},
},
args: {
rootClientId: '',
className: '',
tabIndex: 0,
},
};

export default meta;

export const Default = {
render: function Template( args ) {
return <ButtonBlockAppender { ...args } />;
},
};

export const WithCustomClassName = {
render: function Template( args ) {
return (
<ButtonBlockAppender
{ ...args }
className="custom-appender-class"
/>
);
},
};

export const WithRootClientId = {
render: function Template( args ) {
return (
<ButtonBlockAppender
{ ...args }
rootClientId="test-root-client-id"
/>
);
},
};

export const WithCustomTabIndex = {
render: function Template( args ) {
return <ButtonBlockAppender { ...args } tabIndex={ -1 } />;
},
};

export const WithCallbacks = {
render: function Template( args ) {
const handleFocus = () => {
// eslint-disable-next-line no-console
console.log( 'Button focused' );
};

const handleSelect = ( block ) => {
// eslint-disable-next-line no-console
console.log( 'Block selected:', block );
};

return (
<div>
<p>
{ __(
'Open browser console to see focus and select events.'
) }
</p>
<ButtonBlockAppender
{ ...args }
onFocus={ handleFocus }
onSelect={ handleSelect }
/>
</div>
);
},
};
Loading