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

@@ -15,3 +15,24 @@
vertical-align: text-bottom;
}
}
.mailpoet-styles-settings-image-url {
overflow: auto;
.mailpoet-styles-settings-image-url-body {
align-items: center;
display: flex;
flex-direction: row;
input {
flex-grow: 1;
flex-shrink: 1;
margin-right: 4px;
min-width: 100px;
}
button {
flex-shrink: 0;
}
}
}

View File

@@ -101,7 +101,6 @@
}
}
.mailpoet-toggle-list {
display: grid;
grid-row-gap: 20px;

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;

View File

@@ -44,6 +44,8 @@
'formSettings': _x('Settings', 'A settings section heading'),
'formSettingsStyles': __('Styles'),
'formSettingsStylesBackgroundColor': __('Background Color'),
'formSettingsStylesBackgroundImage': __('Background Image'),
'formSettingsStylesSelectImage': __('Select Image…'),
'formSettingsStylesFontSize': __('Font Size'),
'formSettingsStylesFontColor': __('Font Color'),
'formSettingsStylesFontColorInherit': __('Inherit from theme'),