Skip to content

Commit

Permalink
feat: block-y
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahcssiqueira committed Dec 1, 2023
1 parent 59f4ec3 commit 0dd1355
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 51 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ Structure to work with multiple Gutenberg blocks in a single plugin. Contains fo

### Block X

[To do]
Receives an attribute and displays it in frontend.

### Block Y

[To do]
Retrieve and display data from an API.

### Block W

[To do]
Show latest custom posts.

### Block Z

[To do]
Slider image.

## Custom block category

Expand Down
Empty file removed blocks/block-y/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions blocks/block-y/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"title": "Block Y",
"name": "xywz-blocks/block-y",
"description": "Block Y",
"version": "1.0.0-beta",
"category": "xywz-blocks",
"icon": "rest-api",
"supports": {
"html": true
},
"attributes": {
"exampleAttribute": {
"type": "string"
}
},
"keywords": ["basic", "model"],
"editorScript": "file:./build/index.js",
"editorStyle": "file:./src/style.css"
}
1 change: 1 addition & 0 deletions blocks/block-y/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => '00b087886b1e7ea641f9');
226 changes: 226 additions & 0 deletions blocks/block-y/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions blocks/block-y/build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions blocks/block-y/src/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import { __ } from "@wordpress/i18n";
import { useBlockProps } from "@wordpress/block-editor";

function Edit(props) {
function setExampleAttribute(e) {
props.setAttributes({ exampleAttribute: e.target.value });
}

return (
<div {...useBlockProps()}>
<div>
<h4>Block Y</h4>
<p>Insert the attribute value below</p>
<input
type="text"
value={props.attributes.exampleAttribute}
onChange={setExampleAttribute}
placeholder="Attribute value that will be displayed in the frontend"
/>
</div>
</div>
);
}

export default Edit;
10 changes: 10 additions & 0 deletions blocks/block-y/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { registerBlockType } from "@wordpress/blocks";

import Edit from "./edit";
import Save from "./save";
import metadata from "../block.json";

registerBlockType(metadata, {
edit: Edit,
save: Save,
});
12 changes: 12 additions & 0 deletions blocks/block-y/src/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { __ } from "@wordpress/i18n";
import { useBlockProps } from "@wordpress/block-editor";

function Save(props) {
return (
<p {...useBlockProps.save()}>
{__(<div>{props.attributes.exampleAttribute}</div>)}
</p>
);
}

export default Save;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"start": "wp-scripts start",
"build": "wp-scripts build",
"start:block-x": "wp-scripts start ./blocks/block-x/src/index.js --output-path=./blocks/block-x/build",
"build:block-x": "wp-scripts build ./blocks/block-x/src/index.js --output-path=./blocks/block-x/build"
"build:block-x": "wp-scripts build ./blocks/block-x/src/index.js --output-path=./blocks/block-x/build",
"start:block-y": "wp-scripts start ./blocks/block-y/src/index.js --output-path=./blocks/block-y/build",
"build:block-y": "wp-scripts build ./blocks/block-y/src/index.js --output-path=./blocks/block-y/build"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 0dd1355

Please sign in to comment.