Basic block structure and checkbox import

[MAILPOET-3920]
This commit is contained in:
Mike Jolley
2021-11-02 14:01:20 +00:00
committed by Veljko V
parent 78e0ac4d4a
commit 53d3fb9c1e
13 changed files with 196 additions and 12 deletions

View File

@@ -3,8 +3,29 @@
"name": "mailpoet/newsletter-block",
"version": "0.1.0",
"title": "MailPoet Subscribe to Newsletter block",
"category": "widgets",
"category": "woocommerce",
"textdomain": "mailpoet",
"supports": {
"align": false,
"html": false,
"multiple": false,
"reusable": false,
"inserter": false
},
"attributes": {
"text": {
"type": "string",
"required": false
},
"lock": {
"type": "object",
"default": {
"remove": true,
"move": false
}
}
},
"parent": ["woocommerce/checkout-contact-information-block"],
"editorScript": "file:../../../dist/js/newsletter_block/newsletter_block.js",
"editorStyle": "file:../../../dist/js/newsletter_block/style-newsletter-block.css"
"editorStyle": "file:../../../dist/js/newsletter_block/newsletter_block.css"
}

View File

@@ -0,0 +1,6 @@
/* eslint-disable react/react-in-jsx-scope */
const Block = ({ className }: { className: string }): JSX.Element => (
<div className={className}>Hello I am a block</div>
);
export default Block;

View File

@@ -1,2 +0,0 @@
import "./style.scss";
console.log("edit.js");

View File

@@ -0,0 +1,37 @@
/**
* External dependencies
*/
/* eslint-disable react/react-in-jsx-scope */
import { useBlockProps, RichText } from '@wordpress/block-editor';
/* eslint-disable import/no-unresolved */
import { CheckboxControl } from '@woocommerce/blocks-checkout';
/**
* Internal dependencies
*/
import './editor.scss';
export const Edit = ({
attributes: { text },
setAttributes,
}: {
attributes: { text: string; checkbox: boolean };
setAttributes: (attributes: Record<string, unknown>) => void;
}): JSX.Element => {
const blockProps = useBlockProps();
const defaultText = 'Hello I am default checkbox text';
const currentText = text || defaultText;
return (
<div {...blockProps}>
<div className="wc-block-checkout__newsletter">
<CheckboxControl id="subscribe-to-newsletter" checked={false} />
<RichText
value={currentText}
onChange={(value) => setAttributes({ text: value })}
/>
</div>
</div>
);
};
export const Save = (): JSX.Element => (<div {...useBlockProps.save()} />);

View File

@@ -0,0 +1,16 @@
.wc-block-checkout__newsletter {
align-items: flex-start;
display: flex;
margin: 20px 0;
padding-bottom: 4px;
padding-top: 4px;
.block-editor-rich-text__editable {
line-height: em(24px);
vertical-align: middle;
}
.wc-block-components-checkbox {
margin-top: 0;
}
}

View File

@@ -1 +0,0 @@
console.log("frontend.js");

View File

@@ -0,0 +1,17 @@
/**
* External dependencies
*/
/* eslint-disable react/react-in-jsx-scope */
/* eslint-disable import/no-unresolved */
import { registerCheckoutBlock } from '@woocommerce/blocks-checkout';
/**
* Internal dependencies
*/
import metadata from './block.json';
import FrontendBlock from './block';
registerCheckoutBlock({
metadata,
component: FrontendBlock,
});

View File

@@ -1,2 +0,0 @@
import "./edit";
console.log("index.js");

View File

@@ -0,0 +1,21 @@
/**
* External dependencies
*/
/* eslint-disable react/react-in-jsx-scope */
import { Icon, button } from '@wordpress/icons';
import { registerBlockType } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
registerBlockType(metadata, {
icon: {
src: <Icon icon={button} />,
foreground: '#7f54b3',
},
edit: Edit,
save: Save,
});