REFACTOR FIX Handling fallback colors with text ang bg colors
This commit is contained in:
parent
d73c7d259b
commit
845b7b56f6
|
|
@ -21,12 +21,17 @@ import {
|
|||
|
||||
export default function Edit({ attributes, setAttributes, ...props }) {
|
||||
const colors = useSetting("color.palette.theme");
|
||||
const { hasBackgroundColor, backgroundColor, textColor } = attributes;
|
||||
|
||||
const isLightBackgroundColor = isColorLight(backgroundColor);
|
||||
console.log(isLightBackgroundColor);
|
||||
const { hasBackgroundColor, backgroundColor, textColor, hasLightBackground } =
|
||||
attributes;
|
||||
|
||||
function onBackgroundColorChange(value) {
|
||||
if (value === undefined) {
|
||||
setAttributes({ hasBackgroundColor: false });
|
||||
setAttributes({ backgroundColor: "transparent" });
|
||||
}
|
||||
const isLightBackgroundColor = isColorLight(backgroundColor);
|
||||
setAttributes({ hasLightBackground: isLightBackgroundColor });
|
||||
|
||||
setAttributes({ backgroundColor: value });
|
||||
}
|
||||
function onHasBackgroundColorChange(value) {
|
||||
|
|
@ -78,13 +83,15 @@ export default function Edit({ attributes, setAttributes, ...props }) {
|
|||
<section
|
||||
{...useBlockProps({
|
||||
className: `content-box ${
|
||||
isLightBackgroundColor
|
||||
hasLightBackground
|
||||
? "content-box--bg-light"
|
||||
: "content-box--bg-dark"
|
||||
}`,
|
||||
style: {
|
||||
"--content-box-background-color": backgroundColor,
|
||||
"--content-box-text-color": textColor,
|
||||
"--content-box-text-color": textColor ?? "inherit",
|
||||
"--content-box-background-color": hasBackgroundColor
|
||||
? backgroundColor
|
||||
: "transparent",
|
||||
},
|
||||
})}
|
||||
>
|
||||
|
|
@ -96,6 +103,7 @@ export default function Edit({ attributes, setAttributes, ...props }) {
|
|||
allowedBlocks={[
|
||||
"core/heading",
|
||||
"core/paragraph",
|
||||
"core/group",
|
||||
"core/list",
|
||||
"core/button",
|
||||
"core/buttons",
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ import { useBlockProps, InnerBlocks } from "@wordpress/block-editor";
|
|||
import { isColorLight } from "../../_utilities/utilities";
|
||||
|
||||
export default function save({ attributes }) {
|
||||
const { hasBackgroundColor, backgroundColor, textColor } = attributes;
|
||||
const isLightBackgroundColor = isColorLight(backgroundColor);
|
||||
const { backgroundColor, textColor, hasLightBackground, hasBackgroundColor } =
|
||||
attributes;
|
||||
return (
|
||||
<section
|
||||
{...useBlockProps.save({
|
||||
className: `content-box ${
|
||||
isLightBackgroundColor
|
||||
? "content-box--bg-light"
|
||||
: "content-box--bg-dark"
|
||||
hasLightBackground ? "content-box--bg-light" : "content-box--bg-dark"
|
||||
}`,
|
||||
style: {
|
||||
"--content-box-background-color": backgroundColor,
|
||||
"--content-box-text-color": textColor,
|
||||
"--content-box-text-color": textColor ?? "inherit",
|
||||
"--content-box-background-color": hasBackgroundColor
|
||||
? backgroundColor
|
||||
: "transparent",
|
||||
},
|
||||
})}
|
||||
>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user