Skip to content

Commit 1b09096

Browse files
authored
Merge pull request #157 from infinum/blog/adding-fonts
[PRODUCTION] Blog/adding fonts
2 parents 30f2af5 + 6eb1e8c commit 1b09096

File tree

6 files changed

+227
-22
lines changed

6 files changed

+227
-22
lines changed

website/blog/2022-01-20-initial-setup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ As is often the case when trying out something new, you might encounter some hic
1111
<!--truncate-->
1212
If you haven't already, be sure to read our official [Eightshift Docs](https://infinum.github.io/eightshift-docs/docs/welcome).
1313

14-
### Setup
14+
## Setup
1515

1616
To create Eightshift theme, navigate to `wp-content/themes` in your project and type the following in the terminal:
1717

@@ -35,7 +35,7 @@ OK, you went through the process, filled out all required information, but the t
3535

3636
Congratulations, you've set up your Eightshift theme!
3737

38-
### Getting to know Eightshift dev tools
38+
## Getting to know Eightshift dev tools
3939

4040
After successfully setting up the theme and going through files, you'll notice this file structure is quite different from traditional WordPress themes and you may think to yourself: "Oh wow, what did I get myself into?"
4141

@@ -47,7 +47,7 @@ The final tip in this post is related to troubleshooting. Maybe you tried to add
4747

4848
> Have you tried `composer dump-autoload` and re-running `npm start`?
4949
50-
### What's next in store?
50+
## What's next in store?
5151

5252
That's all for this post. In future posts we'll go through some more how-to examples like:
5353
- the difference between components and blocks

website/blog/2022-01-21-components-and-blocks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this blog post, we'll give you a practical explanation about the difference b
1111
<!--truncate-->
1212
One of the things that is really confusing to newcomers is the difference between components and blocks. Let's break it all down.
1313

14-
### Component
14+
## Component
1515

1616
> A component is like a blank slate, a template without context.
1717
@@ -43,7 +43,7 @@ These attributes give you the option to modify the look of the component, so thi
4343

4444
You can even add conditional logic to your options, e.g. to have the option for `imageWidth` visible only when `imagePosition` is set to left or right. And when `imagePosition` is set to top or bottom, it defaults to 100% width.
4545

46-
### Block
46+
## Block
4747

4848
So, what about blocks? Blocks can consist of one or more components and, most importantly, allow you to use them in the editor. Technically, blocks can consist of zero components, but we encourage you to build blocks from components because that increases the reusability.
4949

@@ -57,6 +57,6 @@ To do that, we'll add a new attribute called `featuredPosts` which will define w
5757

5858
You may be wondering, can you have a block that allows you to use all options of the `card-simple` component? Of course! You can create a block that allows you to set all available options in the editor and manually add content to the image and heading. There are also block variations, which allow you to set up predefined attributes for a block. More about setting up block variations may be covered in one of the future posts.
5959

60-
### Conclusion
60+
## Conclusion
6161

6262
Hopefully, these examples helped you get a better understanding of the difference between components and blocks. It may take a bit more time or practical use to understand the difference and reasoning behind it. Our next post will walk you through downloading one of our components and blocks with WP CLI and modifying it.

website/blog/2022-03-03-adding-blocks-wpcli.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ Although there are a few basic blocks available after creating a project, there
1212
These can be used out-of-the-box, but also as a good starting point if you need similar blocks in your projects. It will also speed up your development time since you don't have to build everything from scratch.
1313

1414
<!--truncate-->
15-
### Storybook
15+
## Storybook
1616

1717
Storybook allows you to preview how the components and blocks look and which options they have available. Since Storybook is interactive, you can try out most of the options. Think of it as a catalog with all custom blocks we've built and made ready for public use.
1818

1919
Each entry in Storybook should have documentation that explains the block in more detail, along with implementation instructions. Before using any block, be sure to check `Dependencies` section. Although `Implementation` section lists all the necessary WP-CLI commands required to use a specific block or a component, it is recommended to check if you have the required dependencies ready in your theme.
2020

21-
### WP-CLI commands
21+
## WP-CLI commands
2222

2323
If you've read our [Initial Setup](/blog/initial-setup) post, you're already familiar with our custom WP-CLI commands. For implementing additional components, we have `wp boilerplate use_component` command. For blocks, we have `wp_boilerplate use_block` command.
2424

25-
### Adding new component and block in our project
25+
## Adding new component and block in our project
2626

2727
Let's say we need a Quote block in our project. After going through the documentation of the Quote block, we see that we have one dependency, and that is the Quote component. So, to make Quote block available in our project, we need two WP-CLI commands:
2828

@@ -35,15 +35,15 @@ You should do the commands in this order because Quote component doesn't have an
3535

3636
The Quote block is now ready to use and available in your blocks list. You may use it as-is, or you may want to expand its functionalities with some additional attributes. More about that will be covered in the next blog post.
3737

38-
### Using Example block
38+
## Using Example block
3939

4040
If you want to build a block almost from scratch, you can use our Example block. This is a very simple block that generates all necessary files with some example options. To add an Example block to your project, use the following WP-CLI command:
4141
```bash
4242
wp boilerplate use_block --name=example
4343
```
4444
Since our blocks use a predefined structure to make everything register automatically, adding Example block with WP-CLI will generate all required files. After it's added, feel free to rename the folder, as well as files with the name of your block and start modifying all the files. Simply replace "example" with the name of your block.
4545

46-
### Further reading
46+
## Further reading
4747

4848
Our documentation has all this covered in a lot more detail, so if you would like to better understand the structure of our blocks and components, here are some chapters covering these topics:
4949

website/blog/2022-03-04-modifying-blocks.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ In our previous post, we covered how to use Storybook and WP-CLI to add addition
1313

1414
Since Eightshift Development kit is a starter theme, made for developers to jumpstart and speed up their development, you're welcome to modify files in it directly. There is no need to create a child theme to protect changes from updates.
1515

16-
### Modifying a block or a component?
16+
## Modifying a block or a component?
1717
Because we used the Quote block in our previous post, we will continue using it as an example as it's a fairly simple one. One of the first questions you may ask yourself could be: "Should I modify a component or a block?". And the answer is - it depends.
1818

1919
If you compare **_components/quote/quote.php_** (component) and **_custom/quote/quote.php_** (block), you'll notice that most of the HTML code is inside the component, while the block pretty much only renders the Quote component inside a wrapper. This example will walk you through the whole process of adding a new attribute and its options to a block.
2020

21-
### What will we do?
21+
## What will we do?
2222

2323
We want to style the block and add a new feature. An option to choose a color theme for the Quote block. These are the specs:
2424
- each Quote block has a background with rounded corners
@@ -29,7 +29,7 @@ We want to style the block and add a new feature. An option to choose a color th
2929
To better help you visualize, this is how the Quote block should look like after making these changes, showcasing all three color theme variations:
3030
![Color Theme Examples](/img/blog/color-theme-examples.png)
3131

32-
### Adding background
32+
## Adding background
3333

3434
Initial background styling is fairly straightforward. Navigate to **_src/Blocks/components/quote/quote-style.scss_** and paste the following code inside `.quote` class:
3535

@@ -45,7 +45,7 @@ For now, we will add a simple light grey background to see how it looks. We'll r
4545
4646
You'll notice that the changes are visible both in the editor and on the frontend. Since the Gutenberg editor adds some additional markup, sometimes you'll need to add additional styling only for the editor. In case we need to override something in the editor for our Quote component, we would simply create **_quote-editor.scss_**.
4747

48-
### Adding new colors to your project
48+
## Adding new colors to your project
4949

5050
Because the theme currently doesn't have all the required colors, we need to add additional colors which will be used for the color theme feature. We will use the colors already defined in the manifest for icon color, but we need to add lighter variations of those colors to use them for the background. Navigate to your global manifest, which is located inside **_src/Blocks/manifest.json_** and add the following values inside `colors`:
5151
```json
@@ -66,7 +66,7 @@ Because the theme currently doesn't have all the required colors, we need to add
6666
}
6767
```
6868

69-
### Adding a new attribute and options to manifest
69+
## Adding a new attribute and options to manifest
7070

7171
For editors to be able to choose which color theme to use for the Quote block, we need to define an attribute for it in the manifest. Navigate to **_src/Blocks/components/quote/manifest.json_** and add the following value inside `attributes`:
7272

@@ -90,7 +90,7 @@ After that, since we want to have a fixed number of options, we need to define a
9090
}
9191
```
9292

93-
### CSS variables
93+
## CSS variables
9494

9595
Our next step is to add CSS variables to the Quote component's manifest. Inside **_manifest.json_**, on the same level as `attributes`, add the following code:
9696
```json
@@ -139,7 +139,7 @@ As you can see, the variable name is the same one we used when defining backgrou
139139
}
140140
```
141141

142-
### Outputting CSS variables in editor
142+
## Outputting CSS variables in editor
143143
To make our color theme visible in editor, we have to add few lines of code to **_src/Blocks/components/quote/components/quote-editor.js_** file. First, we need to import a few functions. We need `useMemo` from **_react_**, `outputCssVariables` and `getUnique` from **_@eightshift/frontend-libs/scripts_** and finally, we need data from the global manifest.
144144

145145
After importing these and defining a unique constant, your code should look like this:
@@ -171,7 +171,7 @@ return (
171171
172172
If you try adding a Quote block in the editor, you should notice that it now has a light blue background with a quote icon in a darker shade of blue. This is the default value for the `quoteColorTheme` attribute we added in the component's manifest.
173173
174-
### Outputting CSS variables in the PHP template
174+
## Outputting CSS variables in the PHP template
175175
The PHP template for the Quote component is located in **_src/Blocks/components/quote/quote.php_**. This process is similar to the one described above, it's just written in PHP. All helper methods we need for this are contained inside the `Components` class, which is already included in this file.
176176
177177
Similar to the JS template, we need a unique value, assign it to `data-id`, and output CSS variables. After adding these, the code should look like this:
@@ -195,7 +195,7 @@ $unique = Components::getUnique();
195195
196196
> Both PHP and JS have the same helpers to make writing code for editor and front view as similar as possible.
197197
198-
### Adding options
198+
## Adding options
199199
After adding these snippets, you should already see that your block is using the blue color theme, which we defined as the default value for `quoteColorTheme` in the manifest. We want to have an easy way to change the color theme in the editor. Now we'll add a new option which will do just that.
200200
201201
We will add these options in **_src/Blocks/components/quote/components/quote-options.js_**. Again, we will start with the imports we will need. First one is `__` from **_@wordpress/i18n_** package. Additional imports we need are from **_@eightshift/frontend-libs/scripts_**, so we will just add those to the list.
@@ -251,7 +251,7 @@ The Color Theme option should now be visible and fully functional inside the Quo
251251
252252
![Color Theme Options](/img/blog/color-theme-options.png)
253253
254-
### Adding transitions in the editor
254+
## Adding transitions in the editor
255255
256256
The options work, but you may notice there is no transition in the editor. It is not necessary but will improve the user experience. Since we do not need transition effects on the frontend, we can add these CSS rules only to the editor. To do that, we start by creating **_quote-editor.scss_** file inside **_src/Blocks/components/quote_** folder.
257257
@@ -270,7 +270,7 @@ Because we've added a new file, we have to run `npm start` again. Now the transi
270270
271271
![Color Theme Change](/img/blog/color-theme-change.gif)
272272
273-
### Closing thoughts
273+
## Closing thoughts
274274
275275
In this post, we've covered the whole process of adding a new attribute. It involves a lot of steps and things to keep in mind, but once you get used to it, you'll be able to add quite powerful features to your blocks.
276276

0 commit comments

Comments
 (0)