question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: implementing a font picker

See original GitHub issue

Hi,

I currently work on a font picker for our editor, trying to implement it as decoupled from the rest of the editor as possible. It means, font picker shouldn’t care about editor schema, what blocks are there, etc., and individual nodes shouldn’t care about font.

My first thought was, when font is selected, to somehow add a style to the attributes, so every node like this <p {...props.attributes} ... will automatically receive style with custom fontFamily. But I found no way to modify attributes.

Another approach is to use the data property. But it means I will need to change every node from <p {...props.attributes} ... to <p {...props.attributes} style={props.node.data.style} ..., and keep it in mind every time I need to create new custom node. Doesn’t look good.

Another way, is to implement something like CustomFontNode, and use it as a wrapper to apply fonts. So the resulting markup will be not like this <p class="paragraph" style="font-family: Whatever;" ..., but instead, something like <div class="custom-font-node" style="font-family: Whatever;"><p class="paragraph" ... .

The third way looks better for me, but maybe I’m missing something? Is there another way?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Font picker Implementation - php - Stack Overflow
I found a StackOverflow question with a similar problem: Detecting font in Javascript. There I found this solution to list all installed ...
Read more >
Making a font picker - Matt Basta - Medium
I started the project by building a compiler. This compiler downloads the full list of fonts from the Google Fonts API. It filters...
Read more >
How to Use Shopify's New font_picker Settings
In this article, I'll demonstrate how you can use the font_picker setting type in your client's themes, and show you a few ways...
Read more >
Using the Font Picker | Gantry Documentation
Based on Google Fonts, the Font Picker gives you immediate access to over 600 open source fonts. You can find more information about...
Read more >
Manage missing fonts – Figma Help Center
If any text is using a font that you don't have access to, missing font ... using the Figma desktop app, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found