Last active
August 11, 2018 20:38
-
-
Save Manoz/46ec3f269dec200af195e9b1f9c256e1 to your computer and use it in GitHub Desktop.
React font-face utility
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
/** | |
* FontFace utility function that generates the font-face for you | |
* @param {string} name font-family name | |
* @param {string} src file name | |
* @param {string} fontWeight any font-weight (default: normal) | |
* @param {string} fontStyle any font-style (default: normal) | |
* @return {string} Return the complete css | |
*/ | |
export function fontFace(name, src, fontWeight = 'normal', fontStyle = 'normal') { | |
return ` | |
@font-face{ | |
font-family: "${name}"; | |
src: url(${require(`./fonts/${src}.eot`)}); | |
src: url(${require(`./fonts/${src}.eot`)}?#iefix) format("embedded-opentype"), | |
url(${require(`./fonts/${src}.woff`)}) format("woff"), | |
url(${require(`./fonts/${src}.ttf`)}) format("truetype"), | |
url(${require(`./fonts/${src}.svg`)}#${name}) format("svg"); | |
font-style: ${fontStyle}; | |
font-weight: ${fontWeight}; | |
} | |
`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment