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

Footnotes: show in inserter and placeholder #52445

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading