Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visual indicator if a block is connected to block binding source #59185

Merged
merged 19 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6bcef66
Add BlockControlsFirst slot to block controls groups
michalczaplinski Feb 19, 2024
3d6fe72
Add connection icon to BlockControls toolbar button
michalczaplinski Feb 19, 2024
385b13c
Add block binding toolbar button if block is connected to a source
michalczaplinski Feb 19, 2024
44b1c72
Add i18n support for block toolbar button label
michalczaplinski Feb 21, 2024
91c78a4
Add BlockBindingsButton component and remove BlockControlsFirst group
michalczaplinski Feb 21, 2024
be8afcd
Refactor BlockBindingsButton to check for block connections
michalczaplinski Feb 22, 2024
1c51cc2
Change the ToolbarButton label
michalczaplinski Feb 22, 2024
752dcc3
Update block-bindings-button import to block-bindings-indicator
michalczaplinski Feb 22, 2024
bbdd7bf
Block Bindings: Add connection icon to list view (#59331)
artemiomorales Feb 26, 2024
3bc3062
Move bindings style to useBlockProps
artemiomorales Feb 27, 2024
9d6f97c
Remove extraneous comment
artemiomorales Feb 27, 2024
ec3885d
Move bindings selector logic to toolbar
artemiomorales Feb 28, 2024
d9a4b88
Rename indicator file
artemiomorales Feb 28, 2024
d571f82
Move purple stroke style from SVG markup to CSS
artemiomorales Feb 28, 2024
6cd25eb
Merge branch 'trunk' into fix/update-block-bindings-ui-indicator
artemiomorales Feb 28, 2024
ac72c0a
Check if block can be bound before adding styles
artemiomorales Feb 28, 2024
f63e4ef
Simplify the SVG icon:
michalczaplinski Feb 29, 2024
3f9fa3b
Update the CSS namespacing to include the `__`
michalczaplinski Feb 29, 2024
4dc1103
Fix issues with block binding indicator color
michalczaplinski Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/base-styles/_default-custom-properties.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

// It is important to include these styles in all built stylesheets.
// This allows to CSS variables post CSS plugin to generate fallbacks.
// It also provides default CSS variables for npm package consumers.
:root {
@include admin-scheme(#007cba);
--wp-block-synced-color: #7a00df;
--wp-block-synced-color--rgb: #{hex-to-rgb(#7a00df)};
--wp-bound-block-color: #9747ff;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { ToolbarItem, ToolbarGroup, Icon } from '@wordpress/components';
import { connection } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';

export default function BlockBindingsToolbarIndicator() {
return (
<ToolbarGroup>
<ToolbarItem
as={ 'div' }
aria-label={ _x( 'Connected', 'block toolbar button label' ) }
className="block-editor-block-bindings-toolbar-indicator"
>
<Icon icon={ connection } size={ 24 } />
</ToolbarItem>
</ToolbarGroup>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.block-editor-block-bindings-toolbar-indicator {
display: inline-flex;
align-items: center;
height: 48px;
padding: 6px;

svg g {
stroke: var(--wp-bound-block-color);
fill: transparent;
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ import useMovingAnimation from '../../use-moving-animation';
import { PrivateBlockContext } from '../private-block-context';
import { useFocusFirstElement } from './use-focus-first-element';
import { useIsHovered } from './use-is-hovered';
import { useBlockEditContext } from '../../block-edit/context';
import {
blockBindingsKey,
useBlockEditContext,
} from '../../block-edit/context';
import { useFocusHandler } from './use-focus-handler';
import { useEventHandlers } from './use-selected-block-event-handlers';
import { useNavModeExit } from './use-nav-mode-exit';
import { useBlockRefProvider } from './use-block-refs';
import { useIntersectionObserver } from './use-intersection-observer';
import { useFlashEditableBlocks } from '../../use-flash-editable-blocks';
import { canBindBlock } from '../../../hooks/use-bindings-attributes';

/**
* This hook is used to lightly mark an element as a block element. The element
Expand Down Expand Up @@ -123,6 +127,12 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
] );

const blockEditContext = useBlockEditContext();
const hasBlockBindings = !! blockEditContext[ blockBindingsKey ];
const bindingsStyle =
hasBlockBindings && canBindBlock( name )
? { '--wp-admin-theme-color': 'var(--wp-bound-block-color)' }
: {};

// Ensures it warns only inside the `edit` implementation for the block.
if ( blockApiVersion < 2 && clientId === blockEditContext.clientId ) {
warning(
Expand Down Expand Up @@ -168,7 +178,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
wrapperProps.className,
defaultClassName
),
style: { ...wrapperProps.style, ...props.style },
style: { ...wrapperProps.style, ...props.style, ...bindingsStyle },
};
}

Expand Down
18 changes: 14 additions & 4 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import { store as blockEditorStore } from '../../store';
import __unstableBlockNameContext from './block-name-context';
import NavigableToolbar from '../navigable-toolbar';
import Shuffle from './shuffle';
import BlockBindingsIndicator from '../block-bindings-toolbar-indicator';
import { useHasBlockToolbar } from './use-has-block-toolbar';
import { canBindBlock } from '../../hooks/use-bindings-attributes';
/**
* Renders the block toolbar.
*
Expand All @@ -60,8 +62,10 @@ export function PrivateBlockToolbar( {
blockClientIds,
isDefaultEditingMode,
blockType,
blockName,
shouldShowVisualToolbar,
showParentSelector,
isUsingBindings,
} = useSelect( ( select ) => {
const {
getBlockName,
Expand All @@ -71,6 +75,7 @@ export function PrivateBlockToolbar( {
isBlockValid,
getBlockRootClientId,
getBlockEditingMode,
getBlockAttributes,
} = select( blockEditorStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand All @@ -81,20 +86,21 @@ export function PrivateBlockToolbar( {
const parentBlockType = getBlockType( parentBlockName );
const _isDefaultEditingMode =
getBlockEditingMode( selectedBlockClientId ) === 'default';
const _blockName = getBlockName( selectedBlockClientId );
const isValid = selectedBlockClientIds.every( ( id ) =>
isBlockValid( id )
);
const isVisual = selectedBlockClientIds.every(
( id ) => getBlockMode( id ) === 'visual'
);
const _isUsingBindings = !! getBlockAttributes( selectedBlockClientId )
?.metadata?.bindings;
return {
blockClientId: selectedBlockClientId,
blockClientIds: selectedBlockClientIds,
isDefaultEditingMode: _isDefaultEditingMode,
blockType:
selectedBlockClientId &&
getBlockType( getBlockName( selectedBlockClientId ) ),

blockName: _blockName,
blockType: selectedBlockClientId && getBlockType( _blockName ),
shouldShowVisualToolbar: isValid && isVisual,
rootClientId: blockRootClientId,
showParentSelector:
Expand All @@ -107,6 +113,7 @@ export function PrivateBlockToolbar( {
) &&
selectedBlockClientIds.length === 1 &&
_isDefaultEditingMode,
isUsingBindings: _isUsingBindings,
};
}, [] );

Expand Down Expand Up @@ -158,6 +165,9 @@ export function PrivateBlockToolbar( {
{ ! isMultiToolbar &&
isLargeViewport &&
isDefaultEditingMode && <BlockParentSelector /> }
{ isUsingBindings && canBindBlock( blockName ) && (
<BlockBindingsIndicator />
) }
{ ( shouldShowVisualToolbar || isMultiToolbar ) &&
isDefaultEditingMode && (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
Tooltip,
} from '@wordpress/components';
import { forwardRef } from '@wordpress/element';
import { Icon, lockSmall as lock, pinSmall } from '@wordpress/icons';
import {
Icon,
connection,
lockSmall as lock,
pinSmall,
} from '@wordpress/icons';
import { SPACE, ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';
import { useSelect, useDispatch } from '@wordpress/data';
import { __unstableUseShortcutEventMatch as useShortcutEventMatch } from '@wordpress/keyboard-shortcuts';
Expand All @@ -32,11 +37,12 @@ import { useBlockLock } from '../block-lock';
import { store as blockEditorStore } from '../../store';
import useListViewImages from './use-list-view-images';
import { useListViewContext } from './context';
import { canBindBlock } from '../../hooks/use-bindings-attributes';

function ListViewBlockSelectButton(
{
className,
block: { clientId },
block: { clientId, name: blockName },
onClick,
onContextMenu,
onMouseDown,
Expand Down Expand Up @@ -66,6 +72,7 @@ function ListViewBlockSelectButton(
getBlockRootClientId,
getBlockOrder,
getBlocksByClientId,
getBlockAttributes,
canRemoveBlocks,
} = useSelect( blockEditorStore );
const { duplicateBlocks, multiSelect, removeBlocks } =
Expand All @@ -75,6 +82,8 @@ function ListViewBlockSelectButton(
const images = useListViewImages( { clientId, isExpanded } );
const { rootClientId } = useListViewContext();

const isConnected = getBlockAttributes( clientId )?.metadata?.bindings;
gziolo marked this conversation as resolved.
Show resolved Hide resolved

const positionLabel = blockInformation?.positionLabel
? sprintf(
// translators: 1: Position of selected block, e.g. "Sticky" or "Fixed".
Expand Down Expand Up @@ -278,6 +287,11 @@ function ListViewBlockSelectButton(
</Truncate>
</span>
) }
{ isConnected && canBindBlock( blockName ) && (
<span className="block-editor-list-view-block-select-button__bindings">
<Icon icon={ connection } />
</span>
) }
{ positionLabel && isSticky && (
<Tooltip text={ positionLabel }>
<Icon icon={ pinSmall } />
Expand Down
8 changes: 8 additions & 0 deletions packages/block-editor/src/components/list-view/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,11 @@ $block-navigation-max-indent: 8;
.list-view-appender__description {
display: none;
}

.block-editor-list-view-block-select-button__bindings svg g {
stroke: var(--wp-bound-block-color);
fill: transparent;
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
}
1 change: 1 addition & 0 deletions packages/block-editor/src/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "./autocompleters/style.scss";
@import "./components/block-alignment-control/style.scss";
@import "./components/block-bindings-toolbar-indicator/style.scss";
@import "./components/block-canvas/style.scss";
@import "./components/block-icon/style.scss";
@import "./components/block-inspector/style.scss";
Expand Down
1 change: 1 addition & 0 deletions packages/icons/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export { default as commentAuthorName } from './library/comment-author-name';
export { default as commentContent } from './library/comment-content';
export { default as commentReplyLink } from './library/comment-reply-link';
export { default as commentEditLink } from './library/comment-edit-link';
export { default as connection } from './library/connection';
export { default as cover } from './library/cover';
export { default as create } from './library/create';
export { default as crop } from './library/crop';
Expand Down
25 changes: 25 additions & 0 deletions packages/icons/src/library/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* WordPress dependencies
*/
import { SVG, Path, G } from '@wordpress/primitives';

const connection = (
michalczaplinski marked this conversation as resolved.
Show resolved Hide resolved
<SVG
width="24"
height="24"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
fill-rule="evenodd"
>
<Path d="M5 19L8 16L5 19Z" />
<Path d="M16 8L19 5L16 8Z" />
<G>
<Path d="M5 19L8 16" />
<Path d="M9.30003 17.3C9.523 17.5237 9.78794 17.7013 10.0797 17.8224C10.3714 17.9435 10.6842 18.0059 11 18.0059C11.3159 18.0059 11.6287 17.9435 11.9204 17.8224C12.2121 17.7013 12.4771 17.5237 12.7 17.3L15 15L9.00003 9L6.70003 11.3C6.47629 11.523 6.29876 11.7879 6.17763 12.0796C6.05649 12.3714 5.99414 12.6841 5.99414 13C5.99414 13.3159 6.05649 13.6286 6.17763 13.9204C6.29876 14.2121 6.47629 14.477 6.70003 14.7L9.30003 17.3Z" />
<Path d="M16 8L19 5" />
<Path d="M9 9.00003L15 15L17.3 12.7C17.5237 12.4771 17.7013 12.2121 17.8224 11.9204C17.9435 11.6287 18.0059 11.3159 18.0059 11C18.0059 10.6842 17.9435 10.3714 17.8224 10.0797C17.7013 9.78794 17.5237 9.523 17.3 9.30003L14.7 6.70003C14.477 6.47629 14.2121 6.29876 13.9204 6.17763C13.6286 6.05649 13.3159 5.99414 13 5.99414C12.6841 5.99414 12.3714 6.05649 12.0796 6.17763C11.7879 6.29876 11.523 6.47629 11.3 6.70003L9 9.00003Z" />
</G>
</SVG>
);

export default connection;
Loading