Add background color input style to styles settings
[MAILPOET-2599]
This commit is contained in:
committed by
Veljko V
parent
026a35fffb
commit
eadd6af544
@@ -1,10 +1,13 @@
|
||||
import React, { useState } from 'react';
|
||||
import MailPoet from 'mailpoet';
|
||||
import {
|
||||
ColorIndicator,
|
||||
ColorPalette,
|
||||
Panel,
|
||||
PanelBody,
|
||||
ToggleControl,
|
||||
} from '@wordpress/components';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { partial } from 'underscore';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
@@ -14,6 +17,16 @@ const InputStylesSettings = ({
|
||||
}) => {
|
||||
const [localStyles, setStyles] = useState(styles);
|
||||
|
||||
const { settingsColors } = useSelect(
|
||||
(select) => {
|
||||
const { getSettings } = select('core/block-editor');
|
||||
return {
|
||||
settingsColors: getSettings().colors,
|
||||
};
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const updateStyles = (property, value) => {
|
||||
const updated = { ...localStyles };
|
||||
updated[property] = value;
|
||||
@@ -35,6 +48,24 @@ const InputStylesSettings = ({
|
||||
/>
|
||||
{!localStyles.inheritFromTheme ? (
|
||||
<>
|
||||
<div>
|
||||
<h3 className="mailpoet-styles-settings-heading">
|
||||
{MailPoet.I18n.t('formSettingsStylesBackgroundColor')}
|
||||
{
|
||||
styles.backgroundColor !== undefined
|
||||
&& (
|
||||
<ColorIndicator
|
||||
colorValue={styles.backgroundColor}
|
||||
/>
|
||||
)
|
||||
}
|
||||
</h3>
|
||||
<ColorPalette
|
||||
value={styles.backgroundColor}
|
||||
onChange={partial(updateStyles, 'backgroundColor')}
|
||||
colors={settingsColors}
|
||||
/>
|
||||
</div>
|
||||
<ToggleControl
|
||||
label={MailPoet.I18n.t('formSettingsBold')}
|
||||
checked={localStyles.bold || false}
|
||||
|
@@ -8,6 +8,9 @@ const mapBlockStyles = (styles) => {
|
||||
return mappedStyles;
|
||||
}
|
||||
mappedStyles.bold = styles.bold ? '1' : '0';
|
||||
if (has(styles, 'backgroundColor') && styles.backgroundColor) {
|
||||
mappedStyles.background_color = styles.backgroundColor;
|
||||
}
|
||||
return mappedStyles;
|
||||
};
|
||||
|
||||
|
@@ -39,6 +39,9 @@ const mapBlockStyles = (styles) => {
|
||||
}
|
||||
mappedStyles.inheritFromTheme = false;
|
||||
mappedStyles.bold = styles.bold === '1';
|
||||
if (has(styles, 'background_color') && styles.background_color) {
|
||||
mappedStyles.backgroundColor = styles.background_color;
|
||||
}
|
||||
return mappedStyles;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user