Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30 from WebDevStudios/feature/410-pullquote-block
Browse files Browse the repository at this point in the history
Feature/410 pullquote block
  • Loading branch information
Greg Rickaby authored Jun 4, 2021
2 parents c0cdf9e + 8eeb775 commit de02808
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions themes/wds_headless/js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,42 @@ function wdsAddColorPaletteHexValues(settings, name) {
*/
const allowedBlocks = applyFilters(
"wds/colorPaletteHexValuesAllowedBlocks",
["core/button", "core/paragraph"]
["core/button", "core/paragraph", "core/pullquote"]
);

if (!allowedBlocks.includes(name)) {
return settings;
}

// Add hex color attributes.
settings.attributes = {
...settings.attributes,
backgroundColorHex: {
// Add background color hex attribute.
if (settings.attributes.hasOwnProperty("backgroundColor")) {
settings.attributes.backgroundColorHex = {
type: "string",
default: "",
},
textColorHex: {
};
}

// Add main color hex attribute.
if (settings.attributes.hasOwnProperty("mainColor")) {
settings.attributes.mainColorHex = {
type: "string",
default: "",
},
};
};
}

// Add text color hex attribute.
if (settings.attributes.hasOwnProperty("textColor")) {
settings.attributes.textColorHex = {
type: "string",
default: "",
};
}

return {
...settings,
edit(props) {
const {
attributes: { backgroundColor, textColor },
attributes: { backgroundColor, mainColor, textColor },
} = props;

useEffect(() => {
Expand All @@ -85,8 +96,18 @@ function wdsAddColorPaletteHexValues(settings, name) {
// Retrieve color hex value.
props.attributes.backgroundColorHex =
backgroundColorObj?.[0]?.color || null;
} else {
props.attributes.backgroundColorHex = "";
}

// Check for presence of main color attr.
if (mainColor) {
// Get color object by slug.
const mainColorObj = defaultColors.filter(
(color) => color.slug === mainColor
);

// Retrieve color hex value.
props.attributes.mainColorHex =
mainColorObj?.[0]?.color || null;
}

// Check for presence of text color attr.
Expand All @@ -99,10 +120,8 @@ function wdsAddColorPaletteHexValues(settings, name) {
// Retrieve color hex value.
props.attributes.textColorHex =
textColorObj?.[0]?.color || null;
} else {
props.attributes.textColorHex = "";
}
}, [backgroundColor, textColor]);
}, [backgroundColor, mainColor, textColor]);

return settings.edit(props);
},
Expand Down

0 comments on commit de02808

Please sign in to comment.