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 <150562+mcsf@users.noreply.github.com>
  • Loading branch information
2 people authored and tellthemachines committed Jul 11, 2023
1 parent 93a06ed commit c98e64d
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

0 comments on commit c98e64d

Please sign in to comment.