Add component for image upload

[MAILPOET-2880]
This commit is contained in:
Pavel Dohnal
2020-05-12 11:42:57 +02:00
committed by Veljko V
parent f00fcc98a7
commit f5ba818cf2
5 changed files with 70 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ import HorizontalAlignment from 'common/styles';
import ColorSettings from 'form_editor/components/color_settings';
import FontSizeSettings from 'form_editor/components/font_size_settings';
import ImageSettings from 'form_editor/components/image_settings';
const BasicSettingsPanel = ({ onToggle, isOpened }) => {
const { changeFormSettings } = useDispatch('mailpoet-form-editor');
@@ -41,6 +42,11 @@ const BasicSettingsPanel = ({ onToggle, isOpened }) => {
value={settings.backgroundColor}
onChange={partial(updateStyles, 'backgroundColor')}
/>
<ImageSettings
name={MailPoet.I18n.t('formSettingsStylesBackgroundImage')}
value={settings.backgroundImageUrl}
onChange={partial(updateStyles, 'backgroundImageUrl')}
/>
<ColorSettings
name={MailPoet.I18n.t('formSettingsStylesFontColor')}
value={settings.fontColor}

View File

@@ -0,0 +1,41 @@
import React from 'react';
import { MediaUpload } from '@wordpress/block-editor';
import MailPoet from 'mailpoet';
import { Button } from '@wordpress/components';
type Props = {
name: string,
value?: string,
onChange: (value: string) => any,
}
const ImageSettings = ({
name,
value,
onChange,
}: Props) => (
<div className="mailpoet-styles-settings-image-url">
<h3 className="mailpoet-styles-settings-heading">
{name}
</h3>
<div className="mailpoet-styles-settings-image-url-body">
<input type="text" value={value ?? ''} onChange={(event) => onChange(event.target.value)} />
<MediaUpload
value={value}
onSelect={(image) => onChange(image.url)}
allowedTypes={['image']}
render={({ open }) => (
<Button
isSecondary
isSmall
onClick={open}
>
{MailPoet.I18n.t('formSettingsStylesSelectImage')}
</Button>
)}
/>
</div>
</div>
);
export default ImageSettings;