Display background colour

[MAILPOET-2600]
This commit is contained in:
Pavel Dohnal
2020-02-25 15:09:14 +01:00
committed by Jack Kitterhing
parent 317bed32b1
commit eef74fa2cc
3 changed files with 50 additions and 13 deletions

View File

@@ -17,6 +17,7 @@ import Notices from './notices.jsx';
import UnsavedChangesNotice from './unsaved_changes_notice.jsx'; import UnsavedChangesNotice from './unsaved_changes_notice.jsx';
import FormStyles from './form_styles.jsx'; import FormStyles from './form_styles.jsx';
import Preview from './preview.jsx'; import Preview from './preview.jsx';
import FormBackground from './form_background.jsx';
// Editor settings - see @wordpress/block-editor/src/store/defaults.js // Editor settings - see @wordpress/block-editor/src/store/defaults.js
const editorSettings = { const editorSettings = {
@@ -68,12 +69,14 @@ export default () => {
<BlockEditorKeyboardShortcuts /> <BlockEditorKeyboardShortcuts />
<BlockEditorKeyboardShortcuts.Register /> <BlockEditorKeyboardShortcuts.Register />
<div className="mailpoet_form"> <div className="mailpoet_form">
<FormBackground>
<WritingFlow> <WritingFlow>
<ObserveTyping> <ObserveTyping>
<FormTitle /> <FormTitle />
<BlockList /> <BlockList />
</ObserveTyping> </ObserveTyping>
</WritingFlow> </WritingFlow>
</FormBackground>
</div> </div>
</BlockSelectionClearer> </BlockSelectionClearer>
</div> </div>

View File

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

View File

@@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React from 'react';
import { import {
ColorIndicator, ColorIndicator,
ColorPalette, ColorPalette,
@@ -7,10 +7,20 @@ import {
} from '@wordpress/components'; } from '@wordpress/components';
import MailPoet from 'mailpoet'; import MailPoet from 'mailpoet';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useSelect } from '@wordpress/data'; import { useSelect, useDispatch } from '@wordpress/data';
const BasicSettingsPanel = ({ onToggle, isOpened }) => { const BasicSettingsPanel = ({ onToggle, isOpened }) => {
const [selectedColor, setSelectedColor] = useState(undefined); const { changeFormSettings } = useDispatch('mailpoet-form-editor');
const settings = useSelect(
(select) => select('mailpoet-form-editor').getFormSettings(),
[]
);
const setBackgroundColor = (color) => {
changeFormSettings({
...settings,
backgroundColor: color,
});
};
const settingsColors = useSelect( const settingsColors = useSelect(
(select) => { (select) => {
const { getSettings } = select('core/block-editor'); const { getSettings } = select('core/block-editor');
@@ -25,17 +35,17 @@ const BasicSettingsPanel = ({ onToggle, isOpened }) => {
<span className="components-base-control__label"> <span className="components-base-control__label">
{MailPoet.I18n.t('formSettingsStylesBackgroundColor')} {MailPoet.I18n.t('formSettingsStylesBackgroundColor')}
{ {
selectedColor !== undefined settings.backgroundColor !== undefined
&& ( && (
<ColorIndicator <ColorIndicator
colorValue={selectedColor} colorValue={settings.backgroundColor}
/> />
) )
} }
</span> </span>
<ColorPalette <ColorPalette
value={selectedColor} value={settings.backgroundColor}
onChange={setSelectedColor} onChange={setBackgroundColor}
colors={settingsColors} colors={settingsColors}
/> />
</div> </div>