forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StoryBook: Add story for observe-typing
- Loading branch information
1 parent
041ca27
commit ecf6ecf
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/block-editor/src/components/observe-typing/stories/index.story.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
}, | ||
}; |