diff --git a/assets/js/src/form_editor/blocks/first_name/edit.jsx b/assets/js/src/form_editor/blocks/first_name/edit.jsx new file mode 100644 index 0000000000..0fc4956c85 --- /dev/null +++ b/assets/js/src/form_editor/blocks/first_name/edit.jsx @@ -0,0 +1,68 @@ +import React from 'react'; +import { + Panel, + PanelBody, + TextControl, + ToggleControl, +} from '@wordpress/components'; +import { InspectorControls } from '@wordpress/block-editor'; +import PropTypes from 'prop-types'; +import MailPoet from 'mailpoet'; + +const FirstNameEdit = ({ attributes, setAttributes }) => { + const inspectorControls = ( + + + + (setAttributes({ label }))} + /> + (setAttributes({ labelWithinInput }))} + /> + + + + + ); + + const getTextInput = (placeholder) => ( + + ); + + return ( + <> + {inspectorControls} + {attributes.labelWithinInput ? (getTextInput(attributes.label) + ) : ( + + )} + + ); +}; + +FirstNameEdit.propTypes = { + attributes: PropTypes.shape({ + label: PropTypes.string.isRequired, + labelWithinInput: PropTypes.bool.isRequired, + }).isRequired, + setAttributes: PropTypes.func.isRequired, +}; + +export default FirstNameEdit; diff --git a/assets/js/src/form_editor/blocks/first_name/first_name.jsx b/assets/js/src/form_editor/blocks/first_name/first_name.jsx new file mode 100644 index 0000000000..bece19aef8 --- /dev/null +++ b/assets/js/src/form_editor/blocks/first_name/first_name.jsx @@ -0,0 +1,35 @@ +import MailPoet from 'mailpoet'; +import icon from './icon.jsx'; +import edit from './edit.jsx'; + +export const name = 'mailpoet-form/first-name-input'; + +export const settings = { + title: MailPoet.I18n.t('blockFirstName'), + description: MailPoet.I18n.t('blockFirstNameDescription'), + icon, + category: 'fields', + attributes: { + label: { + type: 'string', + default: MailPoet.I18n.t('blockFirstName'), + }, + labelWithinInput: { + type: 'boolean', + default: true, + }, + mandatory: { + type: 'boolean', + default: true, + }, + }, + supports: { + html: false, + customClassName: false, + multiple: false, + }, + edit, + save() { + return null; + }, +}; diff --git a/assets/js/src/form_editor/blocks/first_name/icon.jsx b/assets/js/src/form_editor/blocks/first_name/icon.jsx new file mode 100644 index 0000000000..0382726f67 --- /dev/null +++ b/assets/js/src/form_editor/blocks/first_name/icon.jsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { G, Path, SVG } from '@wordpress/components'; + +export default ( + + + + + + +); diff --git a/views/form/editor.html b/views/form/editor.html index 5df7fc2772..1c65b92309 100644 --- a/views/form/editor.html +++ b/views/form/editor.html @@ -40,6 +40,8 @@ 'settingsShowMessage': __('Show message'), 'settingsGoToPage': __('Go to Page'), 'settingsPleaseSelectList': __('Please select a list'), + 'blockFirstName': __('First name'), + 'blockFirstNameDescription': __('Input field used to catch subscribers’ first names.'), 'blockEmail': __('Email'), 'blockEmailDescription': __('Input field used to catch subscribers’ email addresses.'), 'blockSubmit': __('Submit button'),