Skip to content

Commit e9b8d45

Browse files
committed
progress on cta block
1 parent 51c14bc commit e9b8d45

File tree

12 files changed

+94
-43
lines changed

12 files changed

+94
-43
lines changed

blocks/cta/build/block.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
"type": "string",
2222
"selector": "h2"
2323
},
24-
"content": {
24+
"style": {
2525
"type": "string",
26-
"source": "html",
27-
"selector": "p"
26+
"default": "light"
2827
}
2928
}
3029
}

blocks/cta/build/index-rtl.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.wp-block-air-light-cta{border:1px dotted red}
1+

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' => '55caffc50288a78d256d');
1+
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => 'b544945a995c582d9dca');

blocks/cta/build/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.wp-block-air-light-cta{border:1px dotted red}
1+

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/build/style-index-rtl.css

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/build/style-index.css

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
"type": "string",
2222
"selector": "h2"
2323
},
24-
"content": {
24+
"style": {
2525
"type": "string",
26-
"source": "html",
27-
"selector": "p"
26+
"default": "light"
2827
}
2928
}
3029
}

blocks/cta/src/edit.js

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
*/
66
import { __ } from '@wordpress/i18n';
77

8+
import {
9+
__experimentalToggleGroupControl as ToggleGroupControl,
10+
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
11+
PanelBody,
12+
} from '@wordpress/components';
13+
814
/**
915
* React hook that is used to mark the block wrapper element.
1016
* It provides all the necessary props like the class name.
1117
*
1218
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
1319
*/
14-
import { RichText, InnerBlocks, useBlockProps } from '@wordpress/block-editor';
20+
import { RichText, useBlockProps, useInnerBlocksProps, InspectorControls } from '@wordpress/block-editor';
1521

1622
/**
1723
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
@@ -30,29 +36,50 @@ import './editor.scss';
3036
* @return {Element} Element to render.
3137
*/
3238
export default function Edit({ attributes, setAttributes }) {
33-
return (
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-
/>
39+
const innerBlocksProps = useInnerBlocksProps(
40+
{},
41+
{
42+
allowedBlocks: ['core/paragraph', 'core/buttons'],
43+
template: [
44+
['core/paragraph'],
45+
[
46+
'core/buttons',
47+
{
48+
layout: { type: 'flex', justifyContent: 'left' },
49+
className: 'button-wrapper',
50+
},
51+
],
52+
],
53+
}
54+
);
4255

43-
<RichText
44-
tagName='p'
45-
value={attributes.content}
46-
onChange={(content) => setAttributes({ content })}
47-
/>
48-
</div>
56+
return (
57+
<>
58+
<InspectorControls>
59+
<PanelBody>
60+
<ToggleGroupControl
61+
label="Tyyli"
62+
isBlock
63+
onChange={(style) => setAttributes({ style: style })}
64+
value={attributes.style}
65+
>
66+
<ToggleGroupControlOption value="light" label="Vaalea" />
67+
<ToggleGroupControlOption value="dark" label="Tumma" />
68+
</ToggleGroupControl>
69+
</PanelBody>
70+
</InspectorControls>
71+
<section {...useBlockProps()}>
72+
<div className={`container has-color-${attributes.style}`}>
73+
<RichText
74+
tagName="h2"
75+
value={attributes.title}
76+
onChange={(title) => setAttributes({ title })}
77+
placeholder="Otsikko..."
78+
/>
4979

50-
<InnerBlocks
51-
template={[['core/button', {
52-
text: 'Nappi'
53-
}]]}
54-
allowedBlocks={['core/button']}
55-
/>
56-
</section>
80+
<div {...innerBlocksProps} />
81+
</div>
82+
</section>
83+
</>
5784
);
5885
}

blocks/cta/src/editor.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
*/
66

77
.wp-block-air-light-cta {
8-
border: 1px dotted #f00;
98
}

0 commit comments

Comments
 (0)