Skip to content

Commit

Permalink
Footnotes: show in inserter and placehold (#52445)
Browse files Browse the repository at this point in the history
* Footnotes: show in inserter and placehold

* Fix placeholder block membrane; fix copy; add icon, label

---------

Co-authored-by: Miguel Fonseca <[email protected]>
  • Loading branch information
2 people authored and ockham committed Jul 13, 2023
1 parent 899a719 commit 90151eb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Add a link to a downloadable file. ([Source](https://github.com/WordPress/gutenb

- **Name:** core/footnotes
- **Category:** text
- **Supports:** ~~html~~, ~~inserter~~, ~~multiple~~, ~~reusable~~
- **Supports:** ~~html~~, ~~multiple~~, ~~reusable~~
- **Attributes:**

## Classic
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/footnotes/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"supports": {
"html": false,
"multiple": false,
"inserter": false,
"reusable": false
},
"style": "wp-block-footnotes"
Expand Down
23 changes: 21 additions & 2 deletions packages/block-library/src/footnotes/edit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { BlockIcon, RichText, useBlockProps } from '@wordpress/block-editor';
import { useEntityProp } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import { Placeholder } from '@wordpress/components';
import { formatListNumbered as icon } from '@wordpress/icons';

export default function FootnotesEdit( { context: { postType, postId } } ) {
const [ meta, updateMeta ] = useEntityProp(
Expand All @@ -12,8 +15,24 @@ export default function FootnotesEdit( { context: { postType, postId } } ) {
postId
);
const footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];
const blockProps = useBlockProps();

if ( ! footnotes.length ) {
return (
<div { ...blockProps }>
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Footnotes' ) }
instructions={ __(
'Footnotes found in blocks within this document will be displayed here.'
) }
/>
</div>
);
}

return (
<ol { ...useBlockProps() }>
<ol { ...blockProps }>
{ footnotes.map( ( { id, content } ) => (
<li key={ id }>
<RichText
Expand Down

1 comment on commit 90151eb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 90151eb.
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/5544623843
📝 Reported issues:

Please sign in to comment.