Product gallery 411
Product gallery 412
Product gallery 413
Product gallery 414

Custom Fonts

Custom Fonts plugin for grapesjs

This code is part of a bigger project: about Silex v3

About this plugin

Links

 

The plugin currently has these features

  • API to add / remove fonts from the site (from goole font name)
  • Updates the DOM and the "font family" dropdown
  • Save the fonts with the site data
  • Load the fonts when site data is loaded (add to the DOM on load)
  • UI to manage fonts
  • Integration with google API
  • Store google fonts list in local storage for performance and API quotas

Limitations:

For now this plugin supports only Goolge fonts and use the V2 API. It should be upgraded to V3 and take advantage of variable fonts.

See the "Development" section bellow to contribute

Motivations

I saw discussions and issues like "How can i add custom fonts in grapesjs editor? #4563"

What seems to work for me is

  1. update the "font family" dropdown
    const styleManager = editor.StyleManager
    const fontProperty = styleManager.getProperty('typography', 'font-family')
    fontProperty.setOptions(fonts)
    styleManager.render()
    
     
  1. update the DOM to display the font correctly: add style elements to the editor.Canvas.getDocument()

This is quite easy but here are the things which took me time as I implemented google fonts

  • use google fonts api to select fonts and get their name, variants, weights
  • build the URL of the fonts to load
  • the UI to manage and install fonts

Instruction:

+
Check the plugin README: https://github.com/silexlabs/grapesjs-fonts
Share this item:
Last Update:Aug 11, 2023
Published:Aug 11, 2023
Versions:
0.19.x
0

0 reviews

5
0
4
0
3
0
2
0
1
0

Product Reviews (0)

Sort By :

No Reviews Found

Question and Answers (0)

No question found

Share this item: