Componentes simples para usar facilmente fontes personalizadas para texto em reação
Atualmente, suporta apenas fontes do Google por enquanto.
npm i react-font
yarn add react-font
<Font /> Aplique fonte em componentes infantis
<Text /> usa <p /> em vez de div
family="Kufam" o nome da fonte que você deseja usar.
weight={700} O peso da fonte, 400 é normal, 700 é em negrito, nem todas as fontes suportam todos os pesos, verifique o Google Fontes.
italic={true} Se a fonte deve ser itálica, nem todas as fontes a suportam, mas o CSS ainda fará com que qualquer fonte seja fascinada.
onLoad: (family: string, style: string) => void chamado quando essa fonte é carregada, analisada e exibida, útil para ocultar o texto até que ele carregue.
onError: (family: string, style: string) => void chamado Se a fonte não conseguir carregar, foi colocado um nome de família da fonte que não existe ou as fontes do Google falharam em responder com a fonte.
onAllLoad: () => void como OnLoad, mas uma vez que todas as fontes tenham carregado. Não funciona no componente <Text /> por algum motivo.
onAllError: () => void como o OnError, mas se todas as fontes não carregarem, por exemplo, se o usuário não tiver Internet e a fonte não estiver em cache.
Aplique qualquer fonte facilmente
import React from 'react'
import Font , { Text } from 'react-font'
const Example = ( ) => {
return (
< Font family = 'Viga' onAllLoad = { ( ) => console . log ( 'all loaded' ) } >
< Font family = 'Ultra' >
< h3 > Easily apply fonts </ h3 >
</ Font >
< Font family = 'Press Start 2P' >
< p > Use any font from google fonts with ease </ p >
< p >
Either wrap a large portion of the app in a Font or just use the font
where you want
</ p >
</ Font >
< p >
No hassle with putting the link in the head tag or importing with css
</ p >
< Text family = 'Monoton' style = { { fontSize : 50 , margin : 0 } } onLoad = { ( ) => console . log ( 'loaded Monoton' ) } >
Super simple :)
</ Text >
</ Font >
)
}
export default Example 
Suporta itálico e peso da fonte
import React from 'react'
import Font , { Text } from 'react-font'
const RobotoExample = ( ) => {
return (
< >
< Font family = 'Roboto' >
< p > Roboto :) </ p >
</ Font >
< Text family = 'Roboto' italic >
Roboto Italic :/
</ Text >
< Font family = 'Roboto' weight = { 700 } >
< p > Roboto Bold :| </ p >
</ Font >
< Text family = 'Roboto' italic weight = { 700 } >
Roboto Italic Bold ;)
</ Text >
</ >
)
}
export default RobotoExample 
MIT © NWYLYNKO