Skip to content

Commit

Permalink
StoryBook: Add story for observe-typing
Browse files Browse the repository at this point in the history
  • Loading branch information
im3dabasia committed Jan 15, 2025
1 parent 041ca27 commit ecf6ecf
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 { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import ObserveTyping from '../index.js';

const meta = {
title: 'BlockEditor/ObserveTyping',
component: ObserveTyping,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'A component that observes typing events and manages the typing flag in the editor.',
},
},
},
argTypes: {
children: {
control: 'text',
description: 'Content wrapped by the ObserveTyping component.',
table: {
type: { summary: 'ReactNode' },
},
},
},
};

export default meta;

export const Default = {
render: function Template( { children, ...args } ) {
const [ isTyping, setIsTyping ] = useState( false );

const onTypingStart = () => setIsTyping( true );
const onTypingStop = () => setIsTyping( false );

return (
<ObserveTyping { ...args }>
<div>
<p>{ isTyping ? 'Typing...' : 'Not typing' }</p>
<input
type="text"
onFocus={ onTypingStart }
onBlur={ onTypingStop }
/>
</div>
</ObserveTyping>
);
},
args: {
children: 'This is the area where typing will be observed.',
},
};

0 comments on commit ecf6ecf

Please sign in to comment.