Skip to content

Commit

Permalink
Add text color support to Columns block (#20016)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLedesma authored Feb 10, 2020
1 parent e00f7b4 commit 8428ead
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/block-library/src/columns/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
},
"customBackgroundColor": {
"type": "string"
},
"customTextColor" : {
"type": "string"
},
"textColor": {
"type": "string"
}
}
}
31 changes: 22 additions & 9 deletions packages/block-library/src/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { dropRight, get, map, times } from 'lodash';
*/
import { __ } from '@wordpress/i18n';
import { PanelBody, RangeControl } from '@wordpress/components';
import { useRef } from '@wordpress/element';

import {
InspectorControls,
InnerBlocks,
Expand Down Expand Up @@ -59,12 +61,21 @@ function ColumnsEditContainer( {
[ clientId ]
);

const ref = useRef();
const {
BackgroundColor,
InspectorControlsColorPanel,
} = __experimentalUseColors( [
{ name: 'backgroundColor', className: 'has-background' },
] );
TextColor,
} = __experimentalUseColors(
[
{ name: 'textColor', property: 'color' },
{ name: 'backgroundColor', className: 'has-background' },
],
{
contrastCheckers: { backgroundColor: true, textColor: true },
colorDetector: { targetRef: ref },
}
);

const classes = classnames( className, {
[ `are-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
Expand All @@ -91,12 +102,14 @@ function ColumnsEditContainer( {
</InspectorControls>
{ InspectorControlsColorPanel }
<BackgroundColor>
<div className={ classes }>
<InnerBlocks
templateLock="all"
allowedBlocks={ ALLOWED_BLOCKS }
/>
</div>
<TextColor>
<div className={ classes } ref={ ref }>
<InnerBlocks
templateLock="all"
allowedBlocks={ ALLOWED_BLOCKS }
/>
</div>
</TextColor>
</BackgroundColor>
</>
);
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/columns/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@ export default function save( { attributes } ) {
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 (
Expand Down

0 comments on commit 8428ead

Please sign in to comment.