مكونات بسيطة لاستخدام الخطوط المخصصة بسهولة للنص في رد الفعل
حاليًا يدعم Google Fonts فقط في الوقت الحالي.
npm i react-font
yarn add react-font
<Font /> تطبيق مكونات من الأطفال
<Text /> يستخدم <p /> بدلاً من div
family="Kufam" اسم الخط الذي تريد استخدامه.
weight={700} وزن الخط ، 400 أمر طبيعي ، 700 جريء ، وليس جميع الخطوط تدعم جميع الأوزان ، تحقق من خطوط Google.
italic={true} إذا كان الخط يجب أن يكون مائلًا ، فلا تدعمه جميع الخطوط ، لكن CSS ستظل تجعل أي خط مائل لتزييفه.
onLoad: (family: string, style: string) => void عندما يتم تحميل هذا الخط ، محسّن وعرض ، مفيد لإخفاء النص حتى يتم تحميله.
onError: (family: string, style: string) => void إذا فشل الخط في التحميل ، إما تم وضع اسم عائلة الخط في أنه غير موجود أو فشل خطوط Google في الاستجابة مع الخط.
onAllLoad: () => void مثل Onload ولكن بمجرد تحميل جميع الخطوط. لا يعمل على مكون <Text /> لسبب ما.
onAllError: () => void مثل onerror ولكن إذا لم يتم تحميل جميع الخطوط ، على سبيل المثال ، إذا لم يكن لدى المستخدم الإنترنت ولم يتم تخزين الخط مؤقتًا.
تطبيق أي خط بسهولة
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 
يدعم مائل ووزن الخط
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