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

Feature/410 pullquote block #30

Merged
merged 3 commits into from
Jun 4, 2021
Merged
Changes from 2 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
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