Skip to content

Commit 51c14bc

Browse files
committed
cta progress
1 parent 98dc6b6 commit 51c14bc

File tree

6 files changed

+80
-31
lines changed

6 files changed

+80
-31
lines changed

blocks/cta/build/block.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,16 @@
1515
"editorScript": "file:./index.js",
1616
"editorStyle": "file:./index.css",
1717
"style": "file:./style-index.css",
18-
"viewScript": "file:./view.js"
18+
"viewScript": "file:./view.js",
19+
"attributes": {
20+
"title": {
21+
"type": "string",
22+
"selector": "h2"
23+
},
24+
"content": {
25+
"type": "string",
26+
"source": "html",
27+
"selector": "p"
28+
}
29+
}
1930
}

blocks/cta/build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'cf68f46bdd87bb727410');
1+
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => '55caffc50288a78d256d');

blocks/cta/build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/cta/src/block.json

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
{
2-
"$schema": "https://schemas.wp.org/trunk/block.json",
3-
"apiVersion": 3,
4-
"name": "air-light/cta",
5-
"version": "0.1.0",
6-
"title": "Cta",
7-
"category": "widgets",
8-
"icon": "smiley",
9-
"description": "Example block scaffolded with Create Block tool.",
10-
"example": {},
11-
"supports": {
12-
"html": false
13-
},
14-
"textdomain": "cta",
15-
"editorScript": "file:./index.js",
16-
"editorStyle": "file:./index.css",
17-
"style": "file:./style-index.css",
18-
"viewScript": "file:./view.js"
19-
}
2+
"$schema": "https://schemas.wp.org/trunk/block.json",
3+
"apiVersion": 3,
4+
"name": "air-light/cta",
5+
"version": "0.1.0",
6+
"title": "Cta",
7+
"category": "widgets",
8+
"icon": "smiley",
9+
"description": "Example block scaffolded with Create Block tool.",
10+
"example": {},
11+
"supports": {
12+
"html": false
13+
},
14+
"textdomain": "cta",
15+
"editorScript": "file:./index.js",
16+
"editorStyle": "file:./index.css",
17+
"style": "file:./style-index.css",
18+
"viewScript": "file:./view.js",
19+
"attributes": {
20+
"title": {
21+
"type": "string",
22+
"selector": "h2"
23+
},
24+
"content": {
25+
"type": "string",
26+
"source": "html",
27+
"selector": "p"
28+
}
29+
}
30+
}

blocks/cta/src/edit.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { __ } from '@wordpress/i18n';
1111
*
1212
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
1313
*/
14-
import { useBlockProps } from '@wordpress/block-editor';
14+
import { RichText, InnerBlocks, useBlockProps } from '@wordpress/block-editor';
1515

1616
/**
1717
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
@@ -29,10 +29,30 @@ import './editor.scss';
2929
*
3030
* @return {Element} Element to render.
3131
*/
32-
export default function Edit() {
32+
export default function Edit({ attributes, setAttributes }) {
3333
return (
34-
<p { ...useBlockProps() }>
35-
{ __( 'Cta – hello from the editor!', 'cta' ) }
36-
</p>
34+
<section {...useBlockProps()}>
35+
<div className='container'>
36+
<RichText
37+
tagName='h2'
38+
value={attributes.title}
39+
onChange={(title) => setAttributes({ title })}
40+
placeholder='Otsikko...'
41+
/>
42+
43+
<RichText
44+
tagName='p'
45+
value={attributes.content}
46+
onChange={(content) => setAttributes({ content })}
47+
/>
48+
</div>
49+
50+
<InnerBlocks
51+
template={[['core/button', {
52+
text: 'Nappi'
53+
}]]}
54+
allowedBlocks={['core/button']}
55+
/>
56+
</section>
3757
);
3858
}

blocks/cta/src/save.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*
55
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
66
*/
7-
import { useBlockProps } from '@wordpress/block-editor';
7+
import { __ } from '@wordpress/i18n';
8+
import { RichText, useBlockProps } from '@wordpress/block-editor';
89

910
/**
1011
* The save function defines the way in which the different attributes should
@@ -15,10 +16,16 @@ import { useBlockProps } from '@wordpress/block-editor';
1516
*
1617
* @return {Element} Element to render.
1718
*/
18-
export default function save() {
19+
export default function save({ attributes }) {
1920
return (
20-
<p { ...useBlockProps.save() }>
21-
{ 'Cta – hello from the saved content!' }
22-
</p>
21+
<section {...useBlockProps.save()}>
22+
<div className='container'>
23+
<h2>
24+
{attributes.title}
25+
</h2>
26+
27+
<RichText.Content tagName='p' value={attributes.content} />
28+
</div>
29+
</section>
2330
);
2431
}

0 commit comments

Comments
 (0)