-
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.
Cover: Add border support using ResizableBox via BlockPopover (#41153)
- Loading branch information
1 parent
eabaf5a
commit f2eb422
Showing
10 changed files
with
191 additions
and
114 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
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
27 changes: 27 additions & 0 deletions
27
packages/block-editor/src/components/resizable-box-popover/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,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ResizableBox } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockPopover from '../block-popover'; | ||
|
||
export default function ResizableBoxPopover( { | ||
clientId, | ||
resizableBoxProps, | ||
...props | ||
} ) { | ||
return ( | ||
<BlockPopover | ||
clientId={ clientId } | ||
__unstableCoverTarget | ||
__unstablePopoverSlot="block-toolbar" | ||
shift={ false } | ||
{ ...props } | ||
> | ||
<ResizableBox { ...resizableBoxProps } /> | ||
</BlockPopover> | ||
); | ||
} |
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
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
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
82 changes: 82 additions & 0 deletions
82
packages/block-library/src/cover/edit/resizable-cover-popover.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,82 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo, useState } from '@wordpress/element'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../private-apis'; | ||
|
||
const RESIZABLE_BOX_ENABLE_OPTION = { | ||
top: false, | ||
right: false, | ||
bottom: true, | ||
left: false, | ||
topRight: false, | ||
bottomRight: false, | ||
bottomLeft: false, | ||
topLeft: false, | ||
}; | ||
|
||
export default function ResizableCoverPopover( { | ||
className, | ||
height, | ||
minHeight, | ||
onResize, | ||
onResizeStart, | ||
onResizeStop, | ||
showHandle, | ||
size, | ||
width, | ||
...props | ||
} ) { | ||
const { ResizableBoxPopover } = unlock( blockEditorPrivateApis ); | ||
const [ isResizing, setIsResizing ] = useState( false ); | ||
const dimensions = useMemo( | ||
() => ( { height, minHeight, width } ), | ||
[ minHeight, height, width ] | ||
); | ||
|
||
const resizableBoxProps = { | ||
className: classnames( className, { 'is-resizing': isResizing } ), | ||
enable: RESIZABLE_BOX_ENABLE_OPTION, | ||
onResizeStart: ( _event, _direction, elt ) => { | ||
onResizeStart( elt.clientHeight ); | ||
onResize( elt.clientHeight ); | ||
}, | ||
onResize: ( _event, _direction, elt ) => { | ||
onResize( elt.clientHeight ); | ||
if ( ! isResizing ) { | ||
setIsResizing( true ); | ||
} | ||
}, | ||
onResizeStop: ( _event, _direction, elt ) => { | ||
onResizeStop( elt.clientHeight ); | ||
setIsResizing( false ); | ||
}, | ||
showHandle, | ||
size, | ||
__experimentalShowTooltip: true, | ||
__experimentalTooltipProps: { | ||
axis: 'y', | ||
position: 'bottom', | ||
isVisible: isResizing, | ||
}, | ||
}; | ||
|
||
return ( | ||
<ResizableBoxPopover | ||
className="block-library-cover__resizable-box-popover" | ||
__unstableRefreshSize={ dimensions } | ||
resizableBoxProps={ resizableBoxProps } | ||
{ ...props } | ||
/> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
f2eb422
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in f2eb422.
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/4571513210
📝 Reported issues:
/test/e2e/specs/site-editor/writing-flow.spec.js
/test/e2e/specs/site-editor/template-part.spec.js
/test/e2e/specs/site-editor/template-part.spec.js