#Dynamic fontFamily style
56 messages ยท Page 1 of 1 (latest)
import { Box, Title, Text, Container } from '@mantine/core';
import { useTaskVerses, useWordSound } from '../../hooks';
// import { useTaskVerses } from './hooks';
const WBW = () => {
const { pageNumbers, verses } = useTaskVerses();
// console.log(`Mushaf Page ${pageNumbers[0]}`);
const font = verses && `Mushaf Page ${pageNumbers![0]}`;
console.log('the font is', font);
const { playWord } = useWordSound(verses);
if (!verses) return 'loading..';
// const { pageNumbers } = useTaskVerses();
console.log({ pageNumbers });
return (
<Container>
{pageNumbers?.map((page) => (
<style key={page}>
{`
@font-face {
font-family: 'Mushaf Page ${page}';
src: url('fonts/mushaf-woff2/QCF_P${page}.woff2')
}
`}
</style>
))}
<Title>ุงูู
ุทููุจ ุงูููู
ู - ููู
ุฉ ุจููู
ุฉ</Title>
{verses && (
<div
style={{
// fontFamily: font,
fontFamily: 'Mushaf Page 487',
fontSize: '1.8rem',
}}
>
{verses?.map((verse) => (
<Text key={verse.id}>
{verse.words.map((word) => (
<Text
span
key={word.id}
style={{ fontFamily: 'Mushaf Page 487' }}
onClick={() => playWord(word.id)}
>
{word.code_v1}
</Text>
))}
</Text>
))}
</div>
)}
</Container>
);
};
export default WBW;
useTaskVerses definition.
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
const useTaskVerses = () => {
const { data } = useQuery({
queryKey: ['task-verses'],
queryFn: () =>
axios.get(import.meta.env.VITE_SERVER_URL + 'daily-task/wbw'),
});
const verses = data?.data.verses;
console.log({ verses });
const pageNumbers: number[] | undefined =
data &&
([...new Set(verses.map((verse) => verse.page_number))] as
| number[]
| undefined);
return {
verses,
pageNumbers,
};
};
export default useTaskVerses;
You are not using `, instead, you use '
font-family: 'Mushaf Page ${page}';
It does not pick up the page
but rather, just the string ${page}
in this?
{pageNumbers?.map((page) => (
<style key={page}>
{ @font-face { font-family: 'Mushaf Page ${page}'; src: url('fonts/mushaf-woff2/QCF_P${page}.woff2') } }
no, that is not the problem
the font face definition get to the browser successfully
What if you try a different font, because it seems weird that its not applying on a default html element
What if you try Mushaf Page 487 !important
not working..
If you try it on a different page with just a div element, does it work there? (Dont load the fonts, just apply css)
I think the problem is in the font-face definition..
didn't work
So it just doesn't show the fontfamily in element inspect?
yes
weird, for me it adds it to the style but gives a warning that the font is not found
the font-face appears
Can you give me the cdn url
it works when I add the font-family through inspect
{pageNumbers?.map((page) => (
<style key={page}>
{ @font-face { font-family: 'Mushaf Page ${page}'; src: local('./fonts/mushaf-woff2/QCF_P${page}.woff2'), url(https://cdn.rawgit.com/mustafa0x/qpc-fonts/f93bf5f3/mushaf-woff2/QCF_P${page}.woff2) format('woff2'), url(https://cdn.rawgit.com/mustafa0x/qpc-fonts/f93bf5f3/mushaf-woff/QCF_P${page}.woff) format('woff'); } }
Are you using the pages directory or app
Oh okay
I don't like next
so the problem doesn't have to do with mantine
Nope, it has to do with the fontface but give me a sec, I need to pray and then will see how it could be fixed ๐
ok
I fixed it
I found the reason why it did not work
When you have a font family name with spaces, you need to put it in quotes
so "Mushaf Page ${page}"
fontFamily: `"Mushaf Page ${page}"`
@surreal pike
I did not know either haha