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

add color support to separator block #16784

Merged
merged 7 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
70 changes: 67 additions & 3 deletions packages/block-library/src/separator/edit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { HorizontalRule } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

import {
Component,
} from '@wordpress/element';

export default function SeparatorEdit( { className } ) {
return <HorizontalRule className={ className } />;
import {
compose,
withInstanceId,
} from '@wordpress/compose';

import {
HorizontalRule,
} from '@wordpress/components';

import {
InspectorControls,
withColors,
PanelColorSettings,
} from '@wordpress/block-editor';

class SeparatorEdit extends Component {
senadir marked this conversation as resolved.
Show resolved Hide resolved
render() {
const {
backgroundColor,
setBackgroundColor,
className,
} = this.props;
return (
<div>
<HorizontalRule
className={ classnames(
className, {
'has-background': backgroundColor.color,
[ backgroundColor.class ]: backgroundColor.class,
}
) }
style={ {
borderColor: backgroundColor.color,
color: backgroundColor.color,
} }
/>
<InspectorControls>
<PanelColorSettings
title={ __( 'Color Settings' ) }
colorSettings={ [
{
value: backgroundColor.color,
onChange: setBackgroundColor,
label: __( 'Background Color' ),
},
] }
>
</PanelColorSettings>
</InspectorControls>
</div>
);
}
}

export default compose( [
withInstanceId,
senadir marked this conversation as resolved.
Show resolved Hide resolved
withColors( 'backgroundColor', { textColor: 'color' } ),
] )( SeparatorEdit );
37 changes: 35 additions & 2 deletions packages/block-library/src/separator/save.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
export default function save() {
return <hr />;
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import {
getColorClassName,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const {
backgroundColor,
customBackgroundColor,
} = attributes;

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

const separatorClasses = classnames( {
'has-text-color has-background': backgroundColor || customBackgroundColor,
[ backgroundClass ]: backgroundClass,
[ textClass ]: textClass,
senadir marked this conversation as resolved.
Show resolved Hide resolved
} );

const separatorStyle = {
backgroundColor: backgroundClass ? undefined : customBackgroundColor,
color: textClass ? undefined : customBackgroundColor,
};
return <hr
senadir marked this conversation as resolved.
Show resolved Hide resolved
className={ separatorClasses }
style={ separatorStyle }
/>;
}
5 changes: 3 additions & 2 deletions packages/block-library/src/separator/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

// Dots style
&.is-style-dots {
background: none; // Override any background themes often set on the hr tag for this style.
background: none !important; // Override any background themes often set on the hr tag for this style.
senadir marked this conversation as resolved.
Show resolved Hide resolved
// also override the color set on the editor
border: none;
text-align: center;
max-width: none;
Expand All @@ -17,7 +18,7 @@

&::before {
content: "\00b7 \00b7 \00b7";
color: $dark-gray-900;
color: currentColor;
font-size: 20px;
letter-spacing: 2em;
padding-left: 2em;
Expand Down