-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow fontFace
to accept array of font face rules
#1114
Allow fontFace
to accept array of font face rules
#1114
Conversation
🦋 Changeset detectedLatest commit: 974d278 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/css/src/style.ts
Outdated
If you'd like to define a globally scoped custom font, you can use the "globalFontFace" function instead. | ||
`; | ||
|
||
if (Array.isArray(rule)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could simplify this code by doing
const rules = Array.isArray(rule) ? rule : [rule];
and then just keeping one code path below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm down for that! So we're looking at:
export function fontFace(
rule: FontFaceRule | FontFaceRule[],
debugId?: string,
) {
const fontFamily = `"${cssesc(generateIdentifier(debugId), {
quotes: 'double',
})}"`;
const rules = Array.isArray(rule) ? rule : [rule];
for (const singleRule of rules) {
if ('fontFamily' in singleRule) {
throw new Error(outdent`
This function creates and returns a hashed font-family name, so the "fontFamily" property should not be provided.
If you'd like to define a globally scoped custom font, you can use the "globalFontFace" function instead.
`);
}
appendCss(
{ type: 'fontFace', rule: { ...singleRule, fontFamily } },
getFileScope(),
);
}
return fontFamily;
}
I reverted the error string stuff to keep it from where it was previously.
Co-authored-by: Paul Grau <graup@users.noreply.github.com>
@askoufis I saw you ran some CI checks but they were cancelled, anything I need to do on my end? |
Not sure why one of them was cancelled. The other one failed because the prettier formatting step failed. |
Gah, didn't even see the prettier one failed, my bad. Let's see if this latest commit does the trick |
@taylorfsteele Thanks for the PR bud 🍻 |
This PR adds support to the
fontFace
function to accept an array of font face rules that share the same font family name.Example usage: