-
-
Save ctjlewis/1a9ee9cac89b8b87fc97c02c28f0f2d0 to your computer and use it in GitHub Desktop.
<GoogleFont> demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FC } from "react"; | |
interface GoogleFontProps { | |
family: string; | |
weights?: (100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900)[]; | |
} | |
/** | |
* Automatically generate <link> elements for the specified Google Fonts. | |
*/ | |
export const GoogleFont: FC<GoogleFontProps> = | |
({ family, weights = [400, 800] }) => { | |
const href = | |
`https://fonts.googleapis.com/css2?family=${ | |
family.replace(/ /g, "+") | |
}${ | |
weights.length | |
? `:wght@${weights.join(";")}` | |
: "" | |
}&display=swap`; | |
return ( | |
<link rel="stylesheet" href={href} /> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment