Skip to content

Commit

Permalink
Toggle ayah highlight on click
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed0saber committed May 19, 2024
1 parent b1a62db commit 6e58d6c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
8 changes: 2 additions & 6 deletions app/components/QuranSection/QuranSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useEffect, useState } from 'react';
import normalizeArabic from './arabic-normalizer';
import Ayah from './components/Ayah';
import './style.css';

export default function QuranSection() {
Expand Down Expand Up @@ -82,12 +83,7 @@ export default function QuranSection() {
<div class="surah-name">
<h2>{selectedSurah.name}</h2>
</div>
{selectedSurah.ayahs.map(ayah => (
<>
<span>{ayah.text.replace("\n", "")}</span>
<span class="ayah-number">{ayah.numberInSurah}</span>
</>
))}
{selectedSurah.ayahs.map(ayah => <Ayah ayah={ayah}/>)}
</div>
) : null}
</div>
Expand Down
20 changes: 20 additions & 0 deletions app/components/QuranSection/components/Ayah.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState } from "react"
import "../style.css"

export default function Ayah({ ayah }) {
const [isHighlighted, setIsHighlighted] = useState(false)

const toggleHighlight = () => {
setIsHighlighted(prev => !prev)
}

return (
<>
<span
onClick={toggleHighlight}
className={isHighlighted ? "highlighted" : null}
>{ayah.text.replace("\n", "")}</span>
<span class="ayah-number">{ayah.numberInSurah}</span>
</>
)
}
6 changes: 5 additions & 1 deletion app/components/QuranSection/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

.quran-section-popup .popup-content ::selection {
color: #FEFEFE;
background: green;
background-color: green;
}

.quran-section-popup .popup-content .ayah-number {
Expand All @@ -138,4 +138,8 @@
font-size: larger;
display: flex;
justify-content: center;
}

.highlighted {
background-color: #00800040;
}

0 comments on commit 6e58d6c

Please sign in to comment.