diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 7e55cf53c2703a..9bde7d863522f2 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -582,7 +582,7 @@ Time to read the post. ([Source](https://github.com/WordPress/gutenberg/tree/tru - **Name:** core/post-time-to-read - **Category:** theme - **Supports:** ~~html~~, ~~multiple~~ -- **Attributes:** textAlign +- **Attributes:** prefix, suffix, textAlign ## Post Title diff --git a/packages/block-library/src/post-time-to-read/block.json b/packages/block-library/src/post-time-to-read/block.json index fb7449cd9ee5e6..d3c3b9b9320030 100644 --- a/packages/block-library/src/post-time-to-read/block.json +++ b/packages/block-library/src/post-time-to-read/block.json @@ -10,6 +10,14 @@ "attributes": { "textAlign": { "type": "string" + }, + "prefix": { + "type": "string", + "default": "" + }, + "suffix": { + "type": "string", + "default": "" } }, "supports": { diff --git a/packages/block-library/src/post-time-to-read/edit.js b/packages/block-library/src/post-time-to-read/edit.js index 4519cdfd2b4cf6..2475c0a0cb323a 100644 --- a/packages/block-library/src/post-time-to-read/edit.js +++ b/packages/block-library/src/post-time-to-read/edit.js @@ -11,8 +11,13 @@ import { AlignmentControl, BlockControls, useBlockProps, + RichText, } from '@wordpress/block-editor'; -import { __unstableSerializeAndClean } from '@wordpress/blocks'; +import { + createBlock, + getDefaultBlockName, + __unstableSerializeAndClean, +} from '@wordpress/blocks'; import { useEntityProp, useEntityBlockEditor } from '@wordpress/core-data'; import { count as wordCount } from '@wordpress/wordcount'; @@ -23,8 +28,24 @@ import { count as wordCount } from '@wordpress/wordcount'; */ const AVERAGE_READING_RATE = 189; -function PostTimeToReadEdit( { attributes, setAttributes, context } ) { - const { textAlign } = attributes; +// Allowed formats for the prefix and suffix fields. +const ALLOWED_FORMATS = [ + 'core/bold', + 'core/image', + 'core/italic', + 'core/link', + 'core/strikethrough', + 'core/text-color', +]; + +function PostTimeToReadEdit( { + attributes, + setAttributes, + insertBlocksAfter, + isSelected, + context, +} ) { + const { textAlign, prefix, suffix } = attributes; const { postId, postType } = context; const [ contentStructure ] = useEntityProp( @@ -69,14 +90,10 @@ function PostTimeToReadEdit( { attributes, setAttributes, context } ) { minutesToRead !== 0 ? sprintf( /* translators: %d is the number of minutes the post will take to read. */ - _n( - 'You can read this post in %d minute.', - 'You can read this post in %d minutes.', - minutesToRead - ), + _n( '%d minute', '%d minutes', minutesToRead ), minutesToRead ) - : __( 'You can read this post in less than a minute.' ); + : __( 'less than a minute' ); } const blockProps = useBlockProps( { @@ -95,7 +112,42 @@ function PostTimeToReadEdit( { attributes, setAttributes, context } ) { } } /> -
{ minutesToReadString }
+
+ { ( isSelected || prefix ) && (
+