RFC: Font Registration #180
Replies: 3 comments 20 replies
-
If the module.exports = {
fonts: [
{ family: 'Roboto', weights: ['400', '500', '600'] }
]
} What does the UI for picking weights look like? What about for italics? Perhaps that can help constraint the API? For example, with Tailwind CSS one just specifies the font family and the browser will pick the proper font file given a font weight or style on a best effort-basis. |
Beta Was this translation helpful? Give feedback.
-
Love it, great job @fikrikarim! Couple questions:
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Background
Makeswift currently supports adding fonts from Google Fonts. This works great for most users, but it has several limitations:
For example, let’s say a user has a custom font called
Metalsmith
, located on thepublic
folder. They are already importing the font with CSS, and they are using it on their Next.js app. When integrating their app with Makeswift, they cannot select theMetalsmith
font in the builder, because Makeswift doesn’t know about the existence of the font.The main goal of this RFC is to propose an API for users to register fonts they already have on the host, so they can select them in the Makeswift builder.
Font registration is the first step in a larger effort to allow Makeswift hosts to expose existing or project-specific resources like colors, typographies, pages, files, and breakpoints in Makeswift.
Proposal
We propose adding a
fonts
field onMakeswiftApiHandler
that will look like this onpages/api/makeswift/[...makeswift].ts
:Once we have that, then we can choose the font family and the variant in the Makeswift
Text
component or in the Style control:The image above shows the font selection in Makeswift. The first three fonts are registered from the host, and the last four fonts are added from Makeswift.
Technical details
makeswift.config.js
instead. But it has the downside of not being able to ability import from a.ts
file. This is a dealbreaker because we want to support@next/font
in the future and we want users to be able to import their@next/font
directly.type: 'google'
andtype: 'custom'
fields on the font so we could load the Google Font directly without needing the users to specify thesrc
. We decided to drop these fields because we could still load the font from Google Fonts based on the family name.family
is the most important part, as it is the value for each item in the dropdown.src
is provided we can load the font and use it in the builder. This is optional, as we can still show the font family on the dropdown without loading the font.src
could be either a relative URL or an absolute URL.Backwards Compatibility
This is a new feature, so it will be backward compatible.
Alternative Approaches
Instead of manually registering the fonts, Makeswift could also automatically register all the fonts using
document.fonts
. But this has several downsides: relying on the DOM, users need to opt out if they don't want to register the font, and feeling like magic (not an explicit behavior).Feedback
We’d love to gather as much feedback as possible on this RFC before we start implementation to make sure that the API covers all the relevant use cases.
Beta Was this translation helpful? Give feedback.
All reactions