Skip to content

Commit 947f6c6

Browse files
committed
List View: Try adding partial content for the paragraph block
1 parent c15cd49 commit 947f6c6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/block-editor/src/components/list-view/block-select-button.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
__experimentalHStack as HStack,
1212
__experimentalTruncate as Truncate,
1313
} from '@wordpress/components';
14+
import { getDefaultBlockName } from '@wordpress/blocks';
15+
import { useSelect } from '@wordpress/data';
16+
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
1417
import { forwardRef } from '@wordpress/element';
1518
import { Icon, lock } from '@wordpress/icons';
1619
import { SPACE, ENTER } from '@wordpress/keycodes';
@@ -23,6 +26,7 @@ import useBlockDisplayInformation from '../use-block-display-information';
2326
import useBlockDisplayTitle from '../block-title/use-block-display-title';
2427
import ListViewExpander from './expander';
2528
import { useBlockLock } from '../block-lock';
29+
import { store as blockEditorStore } from '../../store';
2630

2731
function ListViewBlockSelectButton(
2832
{
@@ -38,6 +42,20 @@ function ListViewBlockSelectButton(
3842
},
3943
ref
4044
) {
45+
const { partialContent } = useSelect(
46+
( select ) => {
47+
const block = select( blockEditorStore ).getBlock( clientId );
48+
const isDefaultBlock = block?.name === getDefaultBlockName();
49+
50+
return {
51+
partialContent: isDefaultBlock
52+
? stripHTML( block?.attributes?.content )
53+
: undefined,
54+
};
55+
},
56+
[ clientId ]
57+
);
58+
4159
const blockInformation = useBlockDisplayInformation( clientId );
4260
const blockTitle = useBlockDisplayTitle( {
4361
clientId,
@@ -89,6 +107,13 @@ function ListViewBlockSelectButton(
89107
<span className="block-editor-list-view-block-select-button__title">
90108
<Truncate ellipsizeMode="auto">{ blockTitle }</Truncate>
91109
</span>
110+
{ !! partialContent && (
111+
<span className="block-editor-list-view-block-select-button__partial-content">
112+
<Truncate ellipsizeMode="auto">
113+
{ partialContent }
114+
</Truncate>
115+
</span>
116+
) }
92117
{ blockInformation?.anchor && (
93118
<span className="block-editor-list-view-block-select-button__anchor">
94119
{ blockInformation.anchor }

packages/block-editor/src/components/list-view/style.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@
301301
min-width: 120px;
302302
}
303303

304-
.block-editor-list-view-block-select-button__title {
304+
.block-editor-list-view-block-select-button__title,
305+
.block-editor-list-view-block-select-button__partial-content {
305306
flex: 1;
306307
position: relative;
307308

@@ -312,6 +313,10 @@
312313
}
313314
}
314315

316+
.block-editor-list-view-block-select-button__partial-content {
317+
opacity: 0.5;
318+
}
319+
315320
.block-editor-list-view-block-select-button__anchor {
316321
background: rgba($black, 0.1);
317322
border-radius: $radius-block-ui;

0 commit comments

Comments
 (0)