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

Feature/410 preformatted block #35

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Changes from all 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
27 changes: 8 additions & 19 deletions themes/wds_headless/js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,11 @@ addFilter(
/**
* Filter block registration to add custom color attributes to specified blocks.
*
* TODO: Extend this to apply to other blocks that use the color palette.
*
* @author WebDevStudios
* @param {object} settings Block settings config.
* @param {string} name Block name.
* @return {object} Block settings config.
*/
function wdsAddColorPaletteHexValues(settings, name) {
/**
* Filter the array of blocks to receive hex color values.
*
* @author WebDevStudios
* @param {array} allowedBlocks Array of blocks.
*/
const allowedBlocks = applyFilters(
"wds/colorPaletteHexValuesAllowedBlocks",
["core/button", "core/paragraph", "core/pullquote"]
);

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

function wdsAddColorPaletteHexValues(settings) {
// Add background color hex attribute.
if (settings.attributes.hasOwnProperty("backgroundColor")) {
settings.attributes.backgroundColorHex = {
Expand Down Expand Up @@ -96,6 +79,8 @@ function wdsAddColorPaletteHexValues(settings, name) {
// Retrieve color hex value.
props.attributes.backgroundColorHex =
backgroundColorObj?.[0]?.color || null;
} else {
delete props.attributes.backgroundColorHex;
}

// Check for presence of main color attr.
Expand All @@ -108,6 +93,8 @@ function wdsAddColorPaletteHexValues(settings, name) {
// Retrieve color hex value.
props.attributes.mainColorHex =
mainColorObj?.[0]?.color || null;
} else {
delete props.attributes.mainColorHex;
}

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

Expand Down