diff --git a/packages/editor/src/bindings/utils.ts b/packages/editor/src/bindings/utils.ts index bacd668754217..f7dc6d6599519 100644 --- a/packages/editor/src/bindings/utils.ts +++ b/packages/editor/src/bindings/utils.ts @@ -1,3 +1,8 @@ +/** + * WordPress dependencies + */ +import { useViewportMatch } from '@wordpress/compose'; + type MetaData = { bindings?: Record< string, string >; }; @@ -54,3 +59,16 @@ export const removeConnection = ( Object.keys( newMetadata ).length === 0 ? undefined : newMetadata, } ); }; + +export function useToolsPanelDropdownMenuProps() { + const isMobile = useViewportMatch( 'medium', '<' ); + return ! isMobile + ? { + popoverProps: { + placement: 'left-start', + // For non-mobile, inner sidebar width (248px) - button width (24px) - border (1px) + padding (16px) + spacing (20px) + offset: 259, + }, + } + : {}; +} diff --git a/packages/editor/src/hooks/block-bindings.js b/packages/editor/src/hooks/block-bindings.js index cf47608b4bd35..85cdeb2efbf8e 100644 --- a/packages/editor/src/hooks/block-bindings.js +++ b/packages/editor/src/hooks/block-bindings.js @@ -7,7 +7,11 @@ import { } from './use-bindings-attributes'; import { unlock } from '../lock-unlock'; import { store as editorStore } from '../store'; -import { removeConnection, addConnection } from '../bindings/utils'; +import { + removeConnection, + addConnection, + useToolsPanelDropdownMenuProps, +} from '../bindings/utils'; /** * WordPress dependencies @@ -15,14 +19,24 @@ import { removeConnection, addConnection } from '../bindings/utils'; import { __ } from '@wordpress/i18n'; import { store as blocksStore } from '@wordpress/blocks'; import { - BaseControl, - PanelBody, MenuGroup, MenuItem, privateApis as componentsPrivateApis, + __experimentalToolsPanel as ToolsPanel, + __experimentalToolsPanelItem as ToolsPanelItem, + __experimentalHStack as Hstack, + __experimentalTruncate as Truncate, + FlexItem, + Icon, + Button, } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; -import { plus, reset } from '@wordpress/icons'; +import { + chevronRightSmall, + customPostType, + plus, + reset, +} from '@wordpress/icons'; import { InspectorControls, store as blockEditorStore, @@ -30,12 +44,7 @@ import { import { addFilter } from '@wordpress/hooks'; import { createHigherOrderComponent } from '@wordpress/compose'; -const { - DropdownMenuV2: DropdownMenu, - DropdownMenuItemV2: DropdownMenuItem, - DropdownMenuItemLabelV2: DropdownMenuItemLabel, - DropdownMenuItemHelpTextV2: DropDownMenuItemHelpText, -} = unlock( componentsPrivateApis ); +const { DropdownMenuV2: DropdownMenu } = unlock( componentsPrivateApis ); const BlockBindingsPanel = ( { name, attributes: { metadata } } ) => { const { bindings } = metadata || {}; @@ -49,6 +58,7 @@ const BlockBindingsPanel = ( { name, attributes: { metadata } } ) => { }, [] ); const bindableAttributes = getBindableAttributes( name ); + const dropdownMenuProps = useToolsPanelDropdownMenuProps(); // Don't show not allowed attributes. // Don't show the bindings connected to pattern overrides in the inspectors panel. @@ -83,99 +93,74 @@ const BlockBindingsPanel = ( { name, attributes: { metadata } } ) => { return ( - {} } + dropdownMenuProps={ dropdownMenuProps } > - - - { bindableAttributes.length > 0 && - ! allAttributesBinded && ( + { bindableAttributes.length > 0 && ! allAttributesBinded && ( + <> + { bindableAttributes.map( ( attribute ) => ( + false } + label={ attribute } + onDeselect={ () => {} } + > - { __( 'Add new connection' ) } - + + + { attribute } + + + + + } placement="left" gutter={ 20 } > - { bindableAttributes.map( ( attribute ) => ( - - - { attribute } - - - } - placement="left" - gutter={ 10 } - > - { Object.keys( postMeta ) - .filter( - ( value ) => - value !== 'footnotes' - ) - .map( ( key ) => ( - { - addConnection( - key, - attribute, - metadata, - _id, - updateBlockAttributes - ); - } } - > - + + { Object.keys( postMeta ).map( + ( key ) => ( + { + addConnection( + key, + attribute, + metadata, + _id, + updateBlockAttributes + ); + } } + icon={ + + } + iconPosition="left" + suffix={ + { postMeta[ key ] } - - - { key } - - - ) ) } - - ) ) } + + } + > + { key } + + ) + ) } + - ) } - { Object.keys( filteredBindings ).map( ( key ) => { - const source = sources[ - filteredBindings[ key ].source - ] - ? sources[ filteredBindings[ key ].source ] - .label - : filteredBindings[ key ].source; - return ( - - removeConnection( - key, - metadata, - _id, - updateBlockAttributes - ) - } - icon={ reset } - > - { key } - { source } - - ); - } ) } - - - + + ) ) } + + ) } + ); };