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

Create comments title with simple styling #40419

Merged
merged 15 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Use ToggleGroupControl and internal state for editing mode
  • Loading branch information
ockham committed Apr 19, 2022
commit b649cbaf99962ad14172ee4979117b25bd5656ad
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Displays a title with the number of comments ([Source](https://github.com/WordPr
- **Name:** core/comments-title
- **Category:** theme
- **Supports:** align, color (background, gradients, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~anchor~~, ~~html~~
- **Attributes:** level, multipleCommentsLabel, showCommentsCount, showPostTitle, showSingleCommentLabel, singleCommentLabel, textAlign
- **Attributes:** level, multipleCommentsLabel, showCommentsCount, showPostTitle, singleCommentLabel, textAlign

## Cover

Expand Down
3 changes: 0 additions & 3 deletions packages/block-library/src/comments-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"type": "boolean",
"default": true
},
"showSingleCommentLabel": {
"type": "boolean"
},
"showCommentsCount": {
"type": "boolean",
"default": true
Expand Down
39 changes: 24 additions & 15 deletions packages/block-library/src/comments-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { useEntityProp } from '@wordpress/core-data';
import { PanelBody, ToggleControl } from '@wordpress/components';
import {
PanelBody,
ToggleControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from '@wordpress/components';
import { useState, useEffect } from '@wordpress/element';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
Expand All @@ -30,7 +35,6 @@ export default function Edit( {
textAlign,
singleCommentLabel,
multipleCommentsLabel,
showSingleCommentLabel,
showPostTitle,
showCommentsCount,
level,
Expand All @@ -40,6 +44,7 @@ export default function Edit( {
} ) {
const TagName = 'h' + level;
const [ commentsCount, setCommentsCount ] = useState();
const [ editingMode, setEditingMode ] = useState( 'plural' );
const [ rawTitle ] = useEntityProp( 'postType', postType, 'title', postId );
const isSiteEditor = typeof postId === 'undefined';
const blockProps = useBlockProps( {
Expand Down Expand Up @@ -95,6 +100,22 @@ export default function Edit( {
const inspectorControls = (
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
{ isSiteEditor && (
<ToggleGroupControl
label={ __( 'Editing mode' ) }
onChange={ setEditingMode }
value={ editingMode }
>
<ToggleGroupControlOption
label={ __( 'Singular' ) }
value="singular"
/>
<ToggleGroupControlOption
label={ __( 'Plural' ) }
value="plural"
/>
</ToggleGroupControl>
) }
<ToggleControl
label={ __( 'Show post title' ) }
checked={ showPostTitle }
Expand All @@ -109,18 +130,6 @@ export default function Edit( {
setAttributes( { showCommentsCount: value } )
}
/>
{ isSiteEditor && (
<ToggleControl
label={ __( 'Show single comment' ) }
help={ __(
'Toggles between single comments and multiple comments reply sentence'
) }
checked={ showSingleCommentLabel }
onChange={ ( value ) =>
setAttributes( { showSingleCommentLabel: value } )
}
/>
) }
</PanelBody>
</InspectorControls>
);
Expand All @@ -140,7 +149,7 @@ export default function Edit( {
{ blockControls }
{ inspectorControls }
<TagName { ...blockProps }>
{ showSingleCommentLabel || commentsCount === 1 ? (
{ editingMode === 'singular' || commentsCount === 1 ? (
<>
<PlainText
__experimentalVersion={ 2 }
Expand Down