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 React, { useState } from 'react';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import {
|
import {
|
||||||
|
ColorIndicator,
|
||||||
|
ColorPalette,
|
||||||
Panel,
|
Panel,
|
||||||
PanelBody,
|
PanelBody,
|
||||||
ToggleControl,
|
ToggleControl,
|
||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
|
import { useSelect } from '@wordpress/data';
|
||||||
import { partial } from 'underscore';
|
import { partial } from 'underscore';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
@ -14,6 +17,16 @@ const InputStylesSettings = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [localStyles, setStyles] = useState(styles);
|
const [localStyles, setStyles] = useState(styles);
|
||||||
|
|
||||||
|
const { settingsColors } = useSelect(
|
||||||
|
(select) => {
|
||||||
|
const { getSettings } = select('core/block-editor');
|
||||||
|
return {
|
||||||
|
settingsColors: getSettings().colors,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const updateStyles = (property, value) => {
|
const updateStyles = (property, value) => {
|
||||||
const updated = { ...localStyles };
|
const updated = { ...localStyles };
|
||||||
updated[property] = value;
|
updated[property] = value;
|
||||||
@ -35,6 +48,24 @@ const InputStylesSettings = ({
|
|||||||
/>
|
/>
|
||||||
{!localStyles.inheritFromTheme ? (
|
{!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
|
<ToggleControl
|
||||||
label={MailPoet.I18n.t('formSettingsBold')}
|
label={MailPoet.I18n.t('formSettingsBold')}
|
||||||
checked={localStyles.bold || false}
|
checked={localStyles.bold || false}
|
||||||
|
@ -8,6 +8,9 @@ const mapBlockStyles = (styles) => {
|
|||||||
return mappedStyles;
|
return mappedStyles;
|
||||||
}
|
}
|
||||||
mappedStyles.bold = styles.bold ? '1' : '0';
|
mappedStyles.bold = styles.bold ? '1' : '0';
|
||||||
|
if (has(styles, 'backgroundColor') && styles.backgroundColor) {
|
||||||
|
mappedStyles.background_color = styles.backgroundColor;
|
||||||
|
}
|
||||||
return mappedStyles;
|
return mappedStyles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ const mapBlockStyles = (styles) => {
|
|||||||
}
|
}
|
||||||
mappedStyles.inheritFromTheme = false;
|
mappedStyles.inheritFromTheme = false;
|
||||||
mappedStyles.bold = styles.bold === '1';
|
mappedStyles.bold = styles.bold === '1';
|
||||||
|
if (has(styles, 'background_color') && styles.background_color) {
|
||||||
|
mappedStyles.backgroundColor = styles.background_color;
|
||||||
|
}
|
||||||
return mappedStyles;
|
return mappedStyles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ describe('Blocks to Form Body', () => {
|
|||||||
fullWidth: false,
|
fullWidth: false,
|
||||||
inheritFromTheme: false,
|
inheritFromTheme: false,
|
||||||
bold: true,
|
bold: true,
|
||||||
|
backgroundColor: '#aaaaaa',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -96,6 +97,7 @@ describe('Blocks to Form Body', () => {
|
|||||||
expect(inputWithCustomStyles.styles).to.eql({
|
expect(inputWithCustomStyles.styles).to.eql({
|
||||||
full_width: '0',
|
full_width: '0',
|
||||||
bold: '1',
|
bold: '1',
|
||||||
|
background_color: '#aaaaaa',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -132,6 +132,7 @@ describe('Form Body To Blocks', () => {
|
|||||||
const customTextStyles = {
|
const customTextStyles = {
|
||||||
full_width: '0',
|
full_width: '0',
|
||||||
bold: '1',
|
bold: '1',
|
||||||
|
background_color: '#ffffff',
|
||||||
};
|
};
|
||||||
|
|
||||||
const map = formBodyToBlocksFactory(colorDefinitions, [customFieldText]);
|
const map = formBodyToBlocksFactory(colorDefinitions, [customFieldText]);
|
||||||
@ -147,6 +148,7 @@ describe('Form Body To Blocks', () => {
|
|||||||
fullWidth: false,
|
fullWidth: false,
|
||||||
inheritFromTheme: false,
|
inheritFromTheme: false,
|
||||||
bold: true,
|
bold: true,
|
||||||
|
backgroundColor: '#ffffff',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user