Skip to content

Commit

Permalink
Add columns deprecated version
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Mar 25, 2020
1 parent 2bc871c commit 1e07c2d
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion packages/block-library/src/columns/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, getColorClassName } from '@wordpress/block-editor';

/**
* Given an HTML string for a deprecated columns inner block, returns the
Expand Down Expand Up @@ -38,7 +38,84 @@ function getDeprecatedLayoutColumn( originalContent ) {
}
}

const migrateCustomColors = ( attributes ) => {
if ( ! attributes.customTextColor && ! attributes.customBackgroundColor ) {
return attributes;
}
const style = { color: {} };
if ( attributes.customTextColor ) {
style.color.text = attributes.customTextColor;
}
if ( attributes.customBackgroundColor ) {
style.color.background = attributes.customBackgroundColor;
}
return {
...attributes,
style,
};
};

export default [
{
attributes: {
verticalAlignment: {
type: 'string',
},
backgroundColor: {
type: 'string',
},
customBackgroundColor: {
type: 'string',
},
customTextColor: {
type: 'string',
},
textColor: {
type: 'string',
},
},
migrate: migrateCustomColors,
save( { attributes } ) {
const {
verticalAlignment,
backgroundColor,
customBackgroundColor,
textColor,
customTextColor,
} = attributes;

const backgroundClass = getColorClassName(
'background-color',
backgroundColor
);

const textClass = getColorClassName( 'color', textColor );

const className = classnames( {
'has-background': backgroundColor || customBackgroundColor,
'has-text-color': textColor || customTextColor,
[ backgroundClass ]: backgroundClass,
[ textClass ]: textClass,
[ `are-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
} );

const style = {
backgroundColor: backgroundClass
? undefined
: customBackgroundColor,
color: textClass ? undefined : customTextColor,
};

return (
<div
className={ className ? className : undefined }
style={ style }
>
<InnerBlocks.Content />
</div>
);
},
},
{
attributes: {
columns: {
Expand Down

0 comments on commit 1e07c2d

Please sign in to comment.