Skip to content
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
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ Show minutes required to finish reading the post. Can also show a word count. ([

- **Name:** core/post-time-to-read
- **Category:** theme
- **Supports:** anchor, color (background, gradients, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** averageReadingSpeed, displayAsRange, displayMode, textAlign
- **Supports:** anchor, color (background, gradients, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign), ~~html~~
- **Attributes:** averageReadingSpeed, displayAsRange, displayMode

## Title

Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/post-time-to-read/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"textdomain": "default",
"usesContext": [ "postId", "postType" ],
"attributes": {
"textAlign": {
"type": "string"
},
"displayAsRange": {
"type": "boolean",
"default": true
Expand Down Expand Up @@ -45,6 +42,7 @@
"typography": {
"fontSize": true,
"lineHeight": true,
"textAlign": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
Expand Down
69 changes: 69 additions & 0 deletions packages/block-library/src/post-time-to-read/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Internal dependencies
*/
import migrateTextAlign from '../utils/migrate-text-align';

const v1 = {
attributes: {
textAlign: {
type: 'string',
},
displayAsRange: {
type: 'boolean',
default: true,
},
displayMode: {
type: 'string',
default: 'time',
},
averageReadingSpeed: {
type: 'number',
default: 189,
},
},
supports: {
anchor: true,
color: {
gradients: true,
__experimentalDefaultControls: {
background: true,
text: true,
},
},
html: false,
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontFamily: true,
__experimentalFontWeight: true,
__experimentalFontStyle: true,
__experimentalTextTransform: true,
__experimentalTextDecoration: true,
__experimentalLetterSpacing: true,
__experimentalDefaultControls: {
fontSize: true,
},
},
interactivity: {
clientNavigation: true,
},
__experimentalBorder: {
radius: true,
color: true,
width: true,
style: true,
},
},
migrate: migrateTextAlign,
isEligible( attributes ) {
return (
!! attributes.textAlign ||
!! attributes.className?.match(
/\bhas-text-align-(left|center|right)\b/
)
);
},
save: () => null,
};

export default [ v1 ];
30 changes: 3 additions & 27 deletions packages/block-library/src/post-time-to-read/edit.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import { __, _x, _n, sprintf } from '@wordpress/i18n';
import { useMemo } from '@wordpress/element';
import {
AlignmentControl,
BlockControls,
InspectorControls,
useBlockProps,
} from '@wordpress/block-editor';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import {
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
Expand All @@ -29,9 +19,7 @@ import { count as wordCount } from '@wordpress/wordcount';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

function PostTimeToReadEdit( { attributes, setAttributes, context } ) {
const { textAlign, displayAsRange, displayMode, averageReadingSpeed } =
attributes;

const { displayAsRange, displayMode, averageReadingSpeed } = attributes;
const { postId, postType } = context;
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

Expand Down Expand Up @@ -128,22 +116,10 @@ function PostTimeToReadEdit( { attributes, setAttributes, context } ) {
averageReadingSpeed,
] );

const blockProps = useBlockProps( {
className: clsx( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
} );
const blockProps = useBlockProps();

return (
<>
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
{ displayMode === 'time' && (
<InspectorControls>
<ToolsPanel
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/post-time-to-read/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import initBlock from '../utils/init-block';
import metadata from './block.json';
import edit from './edit';
import variations from './variations';
import deprecated from './deprecated';

const { name } = metadata;
export { metadata, name };
Expand All @@ -19,6 +20,7 @@ export const settings = {
edit,
variations,
example: {},
deprecated,
};

export const init = () => initBlock( { name, metadata, settings } );
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:post-time-to-read {"textAlign":"left"} /-->

<!-- wp:post-time-to-read {"textAlign":"center"} /-->

<!-- wp:post-time-to-read {"textAlign":"right"} /-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"name": "core/post-time-to-read",
"isValid": true,
"attributes": {
"averageReadingSpeed": 189,
"displayAsRange": true,
"displayMode": "time",
"style": {
"typography": {
"textAlign": "left"
}
}
},
"innerBlocks": []
},
{
"name": "core/post-time-to-read",
"isValid": true,
"attributes": {
"averageReadingSpeed": 189,
"displayAsRange": true,
"displayMode": "time",
"style": {
"typography": {
"textAlign": "center"
}
}
},
"innerBlocks": []
},
{
"name": "core/post-time-to-read",
"isValid": true,
"attributes": {
"averageReadingSpeed": 189,
"displayAsRange": true,
"displayMode": "time",
"style": {
"typography": {
"textAlign": "right"
}
}
},
"innerBlocks": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
{
"blockName": "core/post-time-to-read",
"attrs": {
"textAlign": "left"
},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n\n",
"innerContent": [ "\n\n" ]
},
{
"blockName": "core/post-time-to-read",
"attrs": {
"textAlign": "center"
},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n\n",
"innerContent": [ "\n\n" ]
},
{
"blockName": "core/post-time-to-read",
"attrs": {
"textAlign": "right"
},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:post-time-to-read {"style":{"typography":{"textAlign":"left"}}} /-->

<!-- wp:post-time-to-read {"style":{"typography":{"textAlign":"center"}}} /-->

<!-- wp:post-time-to-read {"style":{"typography":{"textAlign":"right"}}} /-->
Loading