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

fix: Remove block alignment from paragraph block (fix #6476) #6511

Merged
merged 4 commits into from
May 3, 2018
Merged
Changes from 2 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
85 changes: 63 additions & 22 deletions core-blocks/paragraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
getColorClass,
withColors,
AlignmentToolbar,
BlockAlignmentToolbar,
BlockControls,
ColorPalette,
ContrastChecker,
Expand Down Expand Up @@ -142,7 +141,6 @@ class ParagraphBlock extends Component {
content,
dropCap,
placeholder,
width,
} = attributes;

const fontSize = this.getFontSize();
Expand Down Expand Up @@ -234,12 +232,6 @@ class ParagraphBlock extends Component {
} }
isLargeText={ fontSize >= 18 }
/>
<PanelBody title={ __( 'Block Alignment' ) }>
<BlockAlignmentToolbar
value={ width }
onChange={ ( nextWidth ) => setAttributes( { width: nextWidth } ) }
/>
</PanelBody>
</InspectorControls>
<div>
<RichText
Expand Down Expand Up @@ -287,7 +279,23 @@ const supports = {
className: false,
};

const deprecatedSchema = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand why these were extracted, from my point of view the custom* attributes should remain in the schema because they are still being used. The width attribute should not though and should only be added to the deprecated version's attributes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Arg, I thought these were deprecated attributes that are used only in deprecated versions of save… did I mix them up? I guess so.

When I removed width from the schema I got errors. I think deprecation is unclear to me.

customTextColor: {
type: 'string',
},
customBackgroundColor: {
type: 'string',
},
customFontSize: {
type: 'number',
},
width: {
type: 'string',
},
};

const schema = {
...deprecatedSchema,
content: {
type: 'array',
source: 'children',
Expand All @@ -304,27 +312,15 @@ const schema = {
placeholder: {
type: 'string',
},
width: {
type: 'string',
},
textColor: {
type: 'string',
},
customTextColor: {
type: 'string',
},
backgroundColor: {
type: 'string',
},
customBackgroundColor: {
type: 'string',
},
fontSize: {
type: 'string',
},
customFontSize: {
type: 'number',
},
};

export const name = 'core/paragraph';
Expand Down Expand Up @@ -359,6 +355,53 @@ export const settings = {
},

deprecated: [
{
supports,
attributes: schema,
save( { attributes } ) {
const {
width,
align,
content,
dropCap,
backgroundColor,
textColor,
customBackgroundColor,
customTextColor,
fontSize,
customFontSize,
} = attributes;

const textClass = getColorClass( 'color', textColor );
const backgroundClass = getColorClass( 'background-color', backgroundColor );
const fontSizeClass = fontSize && FONT_SIZES[ fontSize ] && `is-${ fontSize }-text`;

const className = classnames( {
[ `align${ width }` ]: width,
'has-background': backgroundColor || customBackgroundColor,
'has-drop-cap': dropCap,
[ fontSizeClass ]: fontSizeClass,
[ textClass ]: textClass,
[ backgroundClass ]: backgroundClass,
} );

const styles = {
backgroundColor: backgroundClass ? undefined : customBackgroundColor,
color: textClass ? undefined : customTextColor,
fontSize: fontSizeClass ? undefined : customFontSize,
textAlign: align,
};

return (
<RichText.Content
tagName="p"
style={ styles }
className={ className ? className : undefined }
value={ content }
/>
);
},
},
{
supports,
attributes: omit( {
Expand Down Expand Up @@ -435,7 +478,6 @@ export const settings = {

save( { attributes } ) {
const {
width,
align,
content,
dropCap,
Expand All @@ -452,7 +494,6 @@ export const settings = {
const fontSizeClass = fontSize && FONT_SIZES[ fontSize ] && `is-${ fontSize }-text`;

const className = classnames( {
[ `align${ width }` ]: width,
'has-background': backgroundColor || customBackgroundColor,
'has-drop-cap': dropCap,
[ fontSizeClass ]: fontSizeClass,
Expand Down