Skip to content

Commit

Permalink
Add color tools to time to read block (#49496)
Browse files Browse the repository at this point in the history
* Add color tools to time to read block

* Make the block element a `<div>`

* Update tests to expect a div instead of a paragraph
  • Loading branch information
talldan authored Mar 31, 2023
1 parent c2b4b1e commit eabaf5a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 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 @@ -590,7 +590,7 @@ Show minutes required to finish reading the post. ([Source](https://github.com/W

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

## Post Title
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/post-time-to-read/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
}
},
"supports": {
"color": {
"gradients": true,
"__experimentalDefaultControls": {
"background": true,
"text": true
}
},
"html": false,
"spacing": {
"margin": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/post-time-to-read/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function PostTimeToReadEdit( { attributes, setAttributes, context } ) {
} }
/>
</BlockControls>
<p { ...blockProps }>{ minutesToReadString }</p>
<div { ...blockProps }>{ minutesToReadString }</div>
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/post-time-to-read/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function render_block_core_post_time_to_read( $attributes, $content, $block ) {
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );

return sprintf(
'<p %1$s>%2$s</p>',
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$minutes_to_read_string
);
Expand Down
8 changes: 4 additions & 4 deletions phpunit/blocks/render-post-time-to-read-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function test_no_content_post() {
$block = new WP_Block( $parsed_block, $context );

$actual = gutenberg_render_block_core_post_time_to_read( $attributes, '', $block );
$expected = '<p class="wp-block-post-time-to-read">1 minute</p>';
$expected = '<div class="wp-block-post-time-to-read">1 minute</div>';

$this->assertSame( $expected, $actual );
}
Expand All @@ -136,7 +136,7 @@ public function test_less_than_one_minute_post() {
$block = new WP_Block( $parsed_block, $context );

$actual = gutenberg_render_block_core_post_time_to_read( $attributes, '', $block );
$expected = '<p class="wp-block-post-time-to-read">1 minute</p>';
$expected = '<div class="wp-block-post-time-to-read">1 minute</div>';

$this->assertSame( $expected, $actual );
}
Expand All @@ -158,7 +158,7 @@ public function test_one_minute_post() {
$block = new WP_Block( $parsed_block, $context );

$actual = gutenberg_render_block_core_post_time_to_read( $attributes, '', $block );
$expected = '<p class="wp-block-post-time-to-read">1 minute</p>';
$expected = '<div class="wp-block-post-time-to-read">1 minute</div>';

$this->assertSame( $expected, $actual );
}
Expand All @@ -180,7 +180,7 @@ public function test_two_minutes_post() {
$block = new WP_Block( $parsed_block, $context );

$actual = gutenberg_render_block_core_post_time_to_read( $attributes, '', $block );
$expected = '<p class="wp-block-post-time-to-read">2 minutes</p>';
$expected = '<div class="wp-block-post-time-to-read">2 minutes</div>';

$this->assertSame( $expected, $actual );
}
Expand Down

0 comments on commit eabaf5a

Please sign in to comment.