Komponen sederhana untuk dengan mudah menggunakan font khusus untuk teks di React
Saat ini hanya mendukung Google Font untuk saat ini.
npm i react-font
yarn add react-font
<Font /> Terapkan font ke komponen anak
<Text /> menggunakan <p /> bukan div
family="Kufam" Nama font yang ingin Anda gunakan.
weight={700} Berat font, 400 adalah normal, 700 tebal, tidak semua font mendukung semua bobot, periksa Google Fonts.
italic={true} Jika font harus miring, tidak semua font mendukungnya tetapi CSS masih akan membuat font miring untuk memalsukannya.
onLoad: (family: string, style: string) => void dipanggil saat font itu dimuat, diuraikan dan ditampilkan, berguna untuk menyembunyikan teks sampai memuat.
onError: (family: string, style: string) => void Dipanggil Jika font gagal memuat, baik nama keluarga font dimasukkan ke dalam yang tidak ada atau Google font gagal menanggapi font.
onAllLoad: () => void seperti onload tetapi begitu semua font dimuat. Tidak berfungsi pada komponen <Text /> untuk beberapa alasan.
onAllError: () => void seperti onError tetapi jika semua font tidak memuat, misalnya jika pengguna tidak memiliki internet dan font tidak di -cache.
Oleskan font apapun dengan mudah
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 
Mendukung miring dan berat font
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