Skip to content

Commit

Permalink
Add character count to info panel (WordPress#24823)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 authored Aug 28, 2020
1 parent 7a80393 commit 2300f3c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/editor/src/components/character-count/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { count as characterCount } from '@wordpress/wordcount';

export default function CharacterCount() {
const content = useSelect( ( select ) =>
select( 'core/editor' ).getEditedPostAttribute( 'content' )
);

return characterCount( content, 'characters_including_spaces' );
}
7 changes: 7 additions & 0 deletions packages/editor/src/components/table-of-contents/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSelect } from '@wordpress/data';
*/
import WordCount from '../word-count';
import DocumentOutline from '../document-outline';
import CharacterCount from '../character-count';

function TableOfContentsPanel( { hasOutlineItemsDisabled, onRequestClose } ) {
const { headingCount, paragraphCount, numberOfBlocks } = useSelect(
Expand Down Expand Up @@ -36,6 +37,12 @@ function TableOfContentsPanel( { hasOutlineItemsDisabled, onRequestClose } ) {
tabIndex="0"
>
<ul role="list" className="table-of-contents__counts">
<li className="table-of-contents__count">
{ __( 'Characters' ) }
<span className="table-of-contents__number">
<CharacterCount />
</span>
</li>
<li className="table-of-contents__count">
{ __( 'Words' ) }
<WordCount />
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/components/table-of-contents/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
display: flex;
flex-wrap: wrap;
margin: 0;
margin-top: -$grid-unit-10;
}

.table-of-contents__count {
Expand All @@ -48,8 +49,9 @@
color: $dark-gray-300;
padding-right: $grid-unit-10;
margin-bottom: 0;
margin-top: $grid-unit-10;

&:last-child {
&:nth-child(4n) {
padding-right: 0;
}
}
Expand Down

0 comments on commit 2300f3c

Please sign in to comment.