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

Blocks: Add direction attribute / LTR button to paragraph block #10663

Merged
merged 1 commit into from
Oct 18, 2018
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
31 changes: 30 additions & 1 deletion packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, _x } from '@wordpress/i18n';
import {
Component,
Fragment,
} from '@wordpress/element';
import {
PanelBody,
ToggleControl,
Toolbar,
withFallbackStyles,
} from '@wordpress/components';
import {
Expand All @@ -29,6 +30,7 @@ import {
} from '@wordpress/editor';
import { createBlock } from '@wordpress/blocks';
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';

const { getComputedStyle } = window;

Expand Down Expand Up @@ -137,13 +139,15 @@ class ParagraphBlock extends Component {
fallbackFontSize,
fontSize,
setFontSize,
isRTL,
} = this.props;

const {
align,
content,
dropCap,
placeholder,
direction,
} = attributes;

return (
Expand All @@ -155,6 +159,23 @@ class ParagraphBlock extends Component {
setAttributes( { align: nextAlign } );
} }
/>
{ isRTL && (
<Toolbar
controls={ [
{
icon: 'editor-ltr',
title: _x( 'Left to right', 'editor button' ),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case this raises eyebrows, the hope / intention is to inherit the existing string:

https://github.com/WordPress/WordPress/blob/da7a80d67fea29c2badfc538bfc01c8a585f0cbe/wp-includes/class-wp-editor.php#L1128

isActive: direction === 'ltr',
onClick() {
const nextDirection = direction === 'ltr' ? undefined : 'ltr';
setAttributes( {
direction: nextDirection,
} );
},
},
] }
/>
) }
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Text Settings' ) } className="blocks-font-size">
Expand Down Expand Up @@ -212,6 +233,7 @@ class ParagraphBlock extends Component {
color: textColor.color,
fontSize: fontSize.size ? fontSize.size + 'px' : undefined,
textAlign: align,
direction,
} }
value={ content }
onChange={ ( nextContent ) => {
Expand All @@ -234,6 +256,13 @@ const ParagraphEdit = compose( [
withColors( 'backgroundColor', { textColor: 'color' } ),
withFontSizes( 'fontSize' ),
applyFallbackStyles,
withSelect( ( select ) => {
const { getEditorSettings } = select( 'core/editor' );

return {
isRTL: getEditorSettings().isRTL,
};
} ),
] )( ParagraphBlock );

export default ParagraphEdit;
6 changes: 6 additions & 0 deletions packages/block-library/src/paragraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const schema = {
customFontSize: {
type: 'number',
},
direction: {
type: 'string',
enum: [ 'ltr', 'rtl' ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we support this enum property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to clarify, it's supported in the server-side validation, but isn't ported to the client. Idea with adding here now is it "just works" when ported.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably a lot of block attributes where this could be considered. align for instance

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
};

export const name = 'core/paragraph';
Expand Down Expand Up @@ -230,6 +234,7 @@ export const settings = {
customTextColor,
fontSize,
customFontSize,
direction,
} = attributes;

const textClass = getColorClassName( 'color', textColor );
Expand Down Expand Up @@ -258,6 +263,7 @@ export const settings = {
style={ styles }
className={ className ? className : undefined }
value={ content }
dir={ direction }
/>
);
},
Expand Down