WordPress - React - Gutenberg Block

Gutenberg Block

This is a Gutenberg Block - Custom plugin which you can create dynamic sections similar to sections created by the Divi theme. You can add images, add content, and interact with the forms of these sections.

GitHub Link:

https://github.com/franciscojavierguardado101/Gutenberg-React

Screenshot 2024-02-25 at 8.21.01 PM.png

 

 

Screenshot 2024-02-25 at 8.22.11 PM.png

 

 

 

Screenshot 2024-02-25 at 8.26.08 PM.png

 

 

Screenshot 2024-02-25 at 8.26.54 PM.png

 

Screenshot 2024-02-25 at 8.30.49 PM.png

 

 

Then do on Terminal:

 

Control + C then run the command: NPM START

This will update our site changes

 

 

 

 

 

 

Screenshot 2024-02-25 at 8.52.09 PM.png

 

 

Screenshot 2024-02-25 at 9.31.00 PM.png

 

 

 

Screenshot 2024-02-25 at 9.35.32 PM.png

 

 

Using and referencing the correct class name is important

 

Check on

style.scss

Editor.scss

 

 

 

 

Screenshot 2024-02-26 at 7.11.25 PM.png

 

Go to SRC/BLOCKS /CURVY/ EDIT.JS

 

There we are working with React components. Edit is a react component

 

We always have to return mockups with a common single parent element

 

It’s best to use a ‘React fragment’ as a placeholder and there will not be html associated with it. = A container

 

 

 

Note: Following images and content will be for building up the settings for my block

Building:

 

 

 

 

Screenshot 2024-02-26 at 7.19.23 PM.png

 

Screenshot 2024-02-26 at 7.23.19 PM.png

 

 

 

Screenshot 2024-02-26 at 7.22.46 PM.png

 

 

===================================================

 

 

Note:
WordPress provides us with the React components to style our blocks and look design that would help to have everything matching with the branding using components such as PanelBody

 

 

 

 

We can also use the toggle component

We need to use React in order to interact with the toggle component in order to make the function work

 

 

 

Screenshot 2024-02-26 at 10.18.01 PM.png

 

Note:

 

The less hard code the better

 

 

 

 

 

 

Go to WP interface

Above our curvy block create a new one with some text such as ‘Some example text in here’

 

Then align it to the center

 

Then upper right side corner click on ‘Code Editor’

 

WordPress will give us a snippet of code and we are going to use those attributes within our block

 

 

Screenshot 2024-02-26 at 10.30.42 PM.png

 

 

 

Screenshot 2024-02-26 at 10.31.57 PM.png

 

 

Screenshot 2024-02-26 at 10.32.47 PM.png

 

 

Screenshot 2024-02-26 at 10.36.21 PM.png

 

 

 

Screenshot 2024-02-26 at 10.39.51 PM.png

 

 

Screenshot 2024-02-26 at 10.43.04 PM.png

 

 

Screenshot 2024-02-26 at 10.46.27 PM.png

 

 

 

Screenshot 2024-02-26 at 10.49.04 PM.png

 

 

 

 

 

 

 

 

Screenshot 2024-02-26 at 10.55.17 PM.png

 

It’s important to use ‘Console Logs’ with INSPECT because as I make changes in the code, the props I enable will show on INSPECT the attributes I need to use in my code

 

 

 

===============================================================

 

 

 

 

 

 

SRC/BLOCKS/CURVY. > THEN MAKE A NEW FOLDER CALLED ‘COMPONENTS’

 

Components directory is responsible to for rendering our current sag

 

Components > CURVE.JS will export a react component

Components: They are functions that return some html mock-up

 

Components need to be with first character as Capital: example C

 

Then make the import to the Edit file

 

 

 

Note:

 

Edit:

import { Curve } from "./components/curve";

 

It is imported that way because it’s a name component

 

 

 

 

Screenshot 2024-02-27 at 2.27.33 PM.png

 

 

 

 

 

 

 

 

 

 

 

Screenshot 2024-02-27 at 2.29.55 PM.png

 

 

 

Remember, the less hard code the better. The point of the process is to render the SVG

 

So, next  you change the div by SVG tag, to make a path with a “d” attribute

 

To create an SVG

 

 

 

Screenshot 2024-02-27 at 3.30.20 PM.png

 

 

 

 

 

Screenshot 2024-02-27 at 3.33.39 PM.png

 

Screenshot 2024-02-27 at 4.04.26 PM.png

 

 

 

 

Screenshot 2024-02-27 at 4.14.31 PM.png

 

 

 

 

 

Screenshot 2024-02-27 at 4.20.24 PM.png

 

 

 

Screenshot 2024-02-27 at 4.21.52 PM.png

 

 

 

 

 

Screenshot 2024-02-27 at 4.53.40 PM.png

 

 

 

Screenshot 2024-02-27 at 5.47.04 PM.png

 

 

 

Screenshot 2024-02-27 at 6.07.10 PM.png

 

 

 

Screenshot 2024-02-27 at 6.08.28 PM.png

 

 

 

Screenshot 2024-02-27 at 6.15.44 PM.png

 

 

Screenshot 2024-02-27 at 6.18.22 PM.png

 

Screenshot 2024-02-27 at 6.20.29 PM.png

 

 

 

 

Screenshot 2024-02-27 at 6.25.22 PM.png

 

 

 

Screenshot 2024-02-27 at 6.30.34 PM.png

 

 

 

Screenshot 2024-02-27 at 6.39.23 PM.png

 

 

 

Screenshot 2024-02-27 at 6.41.39 PM.png

 

 

Screenshot 2024-02-27 at 6.52.18 PM.png

 

 

Screenshot 2024-02-27 at 7.28.08 PM.png

 

 

 

 

Screenshot 2024-02-27 at 7.34.27 PM.png

 

 

Important to work with props. For example the interaction of the toggle function we need to write code for the props on the components/CURVE.JS

 

 

 

Screenshot 2024-02-27 at 10.08.58 PM.png

 

Screenshot 2024-02-27 at 10.21.49 PM.png

Screenshot 2024-02-27 at 10.32.37 PM.png