-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored URLPopover to use React Hook (#23918)
- Loading branch information
1 parent
0e2040f
commit d7af685
Showing
2 changed files
with
95 additions
and
61 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
packages/block-editor/src/components/url-popover/stories/index.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,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button, ToggleControl } from '@wordpress/components'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { keyboardReturn } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import URLPopover from '../'; | ||
|
||
export default { title: 'BlockEditor/URLPopover' }; | ||
|
||
const TestURLPopover = () => { | ||
const [ isVisible, setVisiblility ] = useState( false ); | ||
const [ url, setUrl ] = useState( '' ); | ||
|
||
const close = () => setVisiblility( false ); | ||
const setTarget = () => {}; | ||
|
||
return ( | ||
<> | ||
<Button onClick={ () => setVisiblility( true ) }>Edit URL</Button> | ||
{ isVisible && ( | ||
<URLPopover | ||
onClose={ close } | ||
renderSettings={ () => ( | ||
<ToggleControl | ||
label={ __( 'Open in new tab' ) } | ||
onChange={ setTarget } | ||
/> | ||
) } | ||
> | ||
<form onSubmit={ close }> | ||
<input type="url" value={ url } onChange={ setUrl } /> | ||
<Button | ||
icon={ keyboardReturn } | ||
label={ __( 'Apply' ) } | ||
type="submit" | ||
/> | ||
</form> | ||
</URLPopover> | ||
) } | ||
</> | ||
); | ||
}; | ||
|
||
export const _default = () => { | ||
return <TestURLPopover />; | ||
}; |