Display texts using selected colour

[MAILPOET-2600]
This commit is contained in:
Pavel Dohnal
2020-02-25 16:11:41 +01:00
committed by Jack Kitterhing
parent fbc650e331
commit 713908b6c3
3 changed files with 39 additions and 3 deletions

View File

@@ -10,10 +10,18 @@ import { InspectorControls } from '@wordpress/block-editor';
import PropTypes from 'prop-types';
import MailPoet from 'mailpoet';
import { debounce } from 'lodash';
import { useSelect } from '@wordpress/data';
import ParagraphEdit from '../paragraph_edit.jsx';
const CustomHtmlEdit = ({ attributes, setAttributes }) => {
const fontColor = useSelect(
(select) => {
const settings = select('mailpoet-form-editor').getFormSettings();
return settings.fontColor;
},
[]
);
const [renderedContent, setRenderedContent] = useState(attributes.content);
const setRenderedContentDebounced = useCallback(debounce((content) => {
setRenderedContent(content);
@@ -46,6 +54,7 @@ const CustomHtmlEdit = ({ attributes, setAttributes }) => {
</InspectorControls>
);
const styles = attributes.nl2br ? ['body { white-space: pre-line; }'] : [];
styles.push(` body {color: ${fontColor} `);
const key = `${renderedContent}_${styles}`;
return (
<ParagraphEdit>

View File

@@ -3,15 +3,18 @@ import PropTypes from 'prop-types';
import { useSelect } from '@wordpress/data';
const FormBackground = ({ children }) => {
const backgroundColor = useSelect(
const { fontColor, backgroundColor } = useSelect(
(select) => {
const settings = select('mailpoet-form-editor').getFormSettings();
return settings.backgroundColor;
return {
backgroundColor: settings.backgroundColor,
fontColor: settings.fontColor,
};
},
[]
);
return (
<div style={{ backgroundColor }}>
<div style={{ backgroundColor, color: fontColor }}>
{children}
</div>
);

View File

@@ -0,0 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useSelect } from '@wordpress/data';
const FormTextColor = ({ children }) => {
const fontColor = useSelect(
(select) => {
const settings = select('mailpoet-form-editor').getFormSettings();
return settings.fontColor;
},
[]
);
return (
<div style={{ color: fontColor }}>
{children}
</div>
);
};
FormTextColor.propTypes = {
children: PropTypes.node.isRequired,
};
export default FormTextColor;