Skip to content

Commit 48b9565

Browse files
committed
feat(ReadingView): add classes to page elements
1 parent 9461697 commit 48b9565

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/components/ReadingView/Line.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CENTERED_PAGES_HORIZONTAL, MEDINA_MUSHAF_CENTERED_LINES } from '../../c
44
import { isSubset } from '../../utils/array'
55
import { LineContainerStyleProps, LineProps } from '../../types'
66
import { useMemo } from 'react'
7+
import { isArabicDigits } from '../../utils/string'
78

89
const LineContainer = styled.div<LineContainerStyleProps>`
910
word-break: keep-all !important;
@@ -40,9 +41,18 @@ export default function Line({ page, words, surahId, lineNumber }: LineProps) {
4041

4142
return (
4243
<LineContainer {...lineContainerStyleProps}>
43-
{words.map((word: { text_uthmani: string }, wordIndex) => (
44-
<QuranText key={`page${page}-line${lineNumber}-word${wordIndex}`} text={word.text_uthmani} />
45-
))}
44+
{words.map((word: { text_uthmani: string }, wordIndex) => {
45+
const isAyahMarker = isArabicDigits(word.text_uthmani)
46+
const charClass = isAyahMarker ? `react-quran_ayah-marker` : 'react-quran_ayah-word'
47+
48+
return (
49+
<QuranText
50+
className={charClass}
51+
key={`page${page}-line${lineNumber}-word${wordIndex}`}
52+
text={word.text_uthmani}
53+
/>
54+
)
55+
})}
4656
</LineContainer>
4757
)
4858
}

src/components/ReadingView/SurahTitle.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export default function SurahTitle({
2929
surahTitleStyles: React.CSSProperties
3030
}) {
3131
return (
32-
<SurahFrame className="surah-title" $linesLength={linesLength} style={surahTitleStyles}>
32+
// class surah-title is old. it might get removed in future updates.
33+
<SurahFrame className="react-quran_surah-title surah-title" $linesLength={linesLength} style={surahTitleStyles}>
3334
{'سورة '.concat(getChapterName(surahNumber))}
3435
</SurahFrame>
3536
)

src/utils/string.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@ export function stringToNumber(string: string | number): number {
66

77
return Number(String(string))
88
}
9+
10+
const arabicDigitsRegex = /^[\u0660-\u0669]+$/
11+
12+
/**
13+
* Check if a string an arabic digit
14+
* @returns
15+
*/
16+
export function isArabicDigits(string: string) {
17+
if (typeof string !== 'string') return
18+
19+
return arabicDigitsRegex.test(string)
20+
}

0 commit comments

Comments
 (0)