-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add color support to separator block (#16784)
* add color support to separator block * add color to frontend render * add support for dots style in frontend * fix review problems, update block.json file * fix border issue with theme.scss * extend border remove in editor * fix problems with no color selected
- Loading branch information
Showing
5 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
{ | ||
"name": "core/separator", | ||
"category": "layout" | ||
"category": "layout", | ||
"attributes": { | ||
"color": { | ||
"type": "string" | ||
}, | ||
"customColor": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,49 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { HorizontalRule } from '@wordpress/components'; | ||
import { | ||
InspectorControls, | ||
withColors, | ||
PanelColorSettings, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function SeparatorEdit( { className } ) { | ||
return <HorizontalRule className={ className } />; | ||
function SeparatorEdit( { color, setColor, className } ) { | ||
return ( | ||
<> | ||
<HorizontalRule | ||
className={ classnames( | ||
className, { | ||
'has-background': color.color, | ||
[ color.class ]: color.class, | ||
} | ||
) } | ||
style={ { | ||
backgroundColor: color.color, | ||
color: color.color, | ||
} } | ||
/> | ||
<InspectorControls> | ||
<PanelColorSettings | ||
title={ __( 'Color Settings' ) } | ||
colorSettings={ [ | ||
{ | ||
value: color.color, | ||
onChange: setColor, | ||
label: __( 'Color' ), | ||
}, | ||
] } | ||
> | ||
</PanelColorSettings> | ||
</InspectorControls> | ||
</> | ||
); | ||
} | ||
|
||
export default withColors( 'color', { textColor: 'color' } )( SeparatorEdit ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,41 @@ | ||
export default function save() { | ||
return <hr />; | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
getColorClassName, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function separatorSave( { attributes } ) { | ||
const { | ||
color, | ||
customColor, | ||
} = attributes; | ||
|
||
// the hr support changing color using border-color, since border-color | ||
// is not yet supported in the color palette, we use background-color | ||
const backgroundClass = getColorClassName( 'background-color', color ); | ||
// the dots styles uses text for the dots, to change those dots color is | ||
// using color, not backgroundColor | ||
const colorClass = getColorClassName( 'color', color ); | ||
|
||
const separatorClasses = classnames( { | ||
'has-text-color has-background': color || customColor, | ||
[ backgroundClass ]: backgroundClass, | ||
[ colorClass ]: colorClass, | ||
} ); | ||
|
||
const separatorStyle = { | ||
backgroundColor: backgroundClass ? undefined : customColor, | ||
color: colorClass ? undefined : customColor, | ||
}; | ||
|
||
return ( <hr | ||
className={ separatorClasses } | ||
style={ separatorStyle } | ||
/> ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters