Display texts using selected colour
[MAILPOET-2600]
This commit is contained in:
committed by
Jack Kitterhing
parent
fbc650e331
commit
713908b6c3
@@ -10,10 +10,18 @@ import { InspectorControls } from '@wordpress/block-editor';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
import { useSelect } from '@wordpress/data';
|
||||||
|
|
||||||
import ParagraphEdit from '../paragraph_edit.jsx';
|
import ParagraphEdit from '../paragraph_edit.jsx';
|
||||||
|
|
||||||
const CustomHtmlEdit = ({ attributes, setAttributes }) => {
|
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 [renderedContent, setRenderedContent] = useState(attributes.content);
|
||||||
const setRenderedContentDebounced = useCallback(debounce((content) => {
|
const setRenderedContentDebounced = useCallback(debounce((content) => {
|
||||||
setRenderedContent(content);
|
setRenderedContent(content);
|
||||||
@@ -46,6 +54,7 @@ const CustomHtmlEdit = ({ attributes, setAttributes }) => {
|
|||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
);
|
);
|
||||||
const styles = attributes.nl2br ? ['body { white-space: pre-line; }'] : [];
|
const styles = attributes.nl2br ? ['body { white-space: pre-line; }'] : [];
|
||||||
|
styles.push(` body {color: ${fontColor} `);
|
||||||
const key = `${renderedContent}_${styles}`;
|
const key = `${renderedContent}_${styles}`;
|
||||||
return (
|
return (
|
||||||
<ParagraphEdit>
|
<ParagraphEdit>
|
||||||
|
@@ -3,15 +3,18 @@ import PropTypes from 'prop-types';
|
|||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect } from '@wordpress/data';
|
||||||
|
|
||||||
const FormBackground = ({ children }) => {
|
const FormBackground = ({ children }) => {
|
||||||
const backgroundColor = useSelect(
|
const { fontColor, backgroundColor } = useSelect(
|
||||||
(select) => {
|
(select) => {
|
||||||
const settings = select('mailpoet-form-editor').getFormSettings();
|
const settings = select('mailpoet-form-editor').getFormSettings();
|
||||||
return settings.backgroundColor;
|
return {
|
||||||
|
backgroundColor: settings.backgroundColor,
|
||||||
|
fontColor: settings.fontColor,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div style={{ backgroundColor }}>
|
<div style={{ backgroundColor, color: fontColor }}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
24
assets/js/src/form_editor/components/form_text_color.jsx
Normal file
24
assets/js/src/form_editor/components/form_text_color.jsx
Normal 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;
|
Reference in New Issue
Block a user