Skip to content

Commit 6eb1e8c

Browse files
committed
Add image. Content updates
1 parent e6e2768 commit 6eb1e8c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

website/blog/2022-04-08-adding-fonts.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Every project is unique. Logo, colors, fonts, etc. are what define the visual id
1818
- [Everything Fonts](https://everythingfonts.com/ttf-to-woff)
1919
- [Transfonter](https://transfonter.org/)
2020

21+
> Just make sure you have the proper license for the fonts you are converting.
22+
2123
Fonts should go inside your theme's **_/assets/fonts_** folder. Copy the fonts you want to use there. You will also notice that this folder contains an **_index.js_** file, used to import fonts into your project. Here's an example of how I imported my fonts:
2224
```js
2325
// SourceSansPro WOFF
@@ -49,6 +51,8 @@ import './NotoSerif-Italic.woff2';
4951
import './NotoSerif-Regular.woff2';
5052
```
5153

54+
> If you don't need to support IE11, don't include `.woff` files. This will save you some bandwidth.
55+
5256
To add these fonts as your base font and secondary font, go to the global manifest located in **_/src/Blocks_** and add the following inside `globalVariables`:
5357
```json
5458
"globalVariables": {
@@ -89,7 +93,7 @@ Run `npm start` to rebuild your **_public_** folder and assets. If you did every
8993

9094
There are multiple ways of using fonts in a block. The simplest use case is if you have only one font you want to use for that specific block. In this case, we want the Heading block to only use _Noto Serif_.
9195

92-
To make our secondary font available for use, we need to first define it as a CSS variable. We can do that in **_/assets/styles/parts/utils/\_shared-variables.scss_**. The base font is already defined, so all we need to do is add our secondary font definition below.
96+
To make our secondary font available for use, we need to first define it as a CSS variable. We can do that in **_/assets/styles/parts/utils/\_shared-variables.scss_**. The base font is already defined there, so all we need to do is add our secondary font definition below it.
9397

9498
To make things a bit more consistent, we may also want to rename `--global-font-family` CSS variable to `--base-font-family`. Just don't forget to search/replace this new variable name across your project! Please note that the fallbacks for the fonts can be anything, this is just an example. Once we're done, it should look like this:
9599
```scss
@@ -136,7 +140,7 @@ First step is to add a new attribute, options and CSS variable values in **_/src
136140
}
137141
```
138142

139-
After defining the new attribute and options for the font family, we now have to add a variable to **_manifest.json_**. We can add it to the `variables` object. This approach is slightly different from the one explained in the [Modifying blocks](/blog/modifying-blocks) blog post. Here we can use `%value%` wildcard to dynamically add the selected value to our CSS variable.
143+
After defining the new attribute and options for the font family, we now have to add a variable to **_manifest.json_**. We can add it to the `variables` object. This approach is slightly different from the one explained in the [Modifying blocks](/blog/modifying-blocks-color-theme) blog post. Here we can use `%value%` wildcard to dynamically add the selected value to our CSS variable.
140144
```json
141145
"paragraphFontFamily": [
142146
{
@@ -180,7 +184,11 @@ Now we have to add an actual control to the options panel which will allow us to
180184
);
181185
```
182186

183-
The control for selecting a font should now be available under Paragraph options. Saving the choice now works, but the font stays the same both in the editor and on the frontend. The final step we need to make this work is to add a CSS rule that consumes our variable to **_/src/Blocks/components/paragraph/paragraph-style.scss_**:
187+
The control for selecting a font should now be available under Paragraph options. Saving the choice now works, but the font stays the same both in the editor and on the frontend.
188+
189+
![Font Picker](/img/blog/font-picker.png)
190+
191+
The final step we need to make this work is to add a CSS rule that consumes our variable to **_/src/Blocks/components/paragraph/paragraph-style.scss_**:
184192
```scss
185193
.paragraph {
186194
// ...
27.4 KB
Loading

0 commit comments

Comments
 (0)