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

List View: Display lock status #40088

Merged
merged 3 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
28 changes: 26 additions & 2 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
__experimentalTreeGridItem as TreeGridItem,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { moreVertical } from '@wordpress/icons';
import { lock, moreVertical, Icon } from '@wordpress/icons';
import {
useState,
useRef,
useEffect,
useCallback,
memo,
} from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { sprintf, __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -68,6 +68,15 @@ function ListViewBlock( {
level
);

const isLocked = useSelect(
( select ) => {
const { canMoveBlock, canRemoveBlock } = select( blockEditorStore );

return ! canMoveBlock( clientId ) || ! canRemoveBlock( clientId );
},
[ clientId ]
);
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved

const blockAriaLabel = blockInformation
? sprintf(
// translators: %s: The title of the block. This string indicates a link to select the block.
Expand Down Expand Up @@ -274,6 +283,21 @@ function ListViewBlock( {
</>
) }

{ isLocked && (
<TreeGridCell
className="block-editor-list-view-block__lock-cell"
aria-selected={ !! isSelected }
>
{ ( { tabIndex, onFocus } ) => (
<Icon
icon={ lock }
tabIndex={ tabIndex }
onFocus={ onFocus }
/>
) }
</TreeGridCell>
) }

{ showBlockActions && (
<TreeGridCell
className={ listViewBlockSettingsClassName }
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 @@ -196,6 +196,14 @@
}
}

.block-editor-list-view-block__lock-cell {
line-height: 0;
width: 24px;
min-width: 24px;
padding: 0;
vertical-align: middle;
}

.block-editor-list-view-block__mover-cell-alignment-wrapper {
display: flex;
height: 100%;
Expand Down