misraj-mushaf-renderer 1.1.20 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +76 -45
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -38,11 +38,11 @@ Make sure to import package styles file which includes css styles and fonts asse
38
38
  import 'misraj-mushaf-renderer/dist/styles';
39
39
  ```
40
40
 
41
- The core of the library is the `MushafPageProvider` and the `Mushaf` component.
41
+ The core of the library is the `MushafReaderProvider` and the `Mushaf` component.
42
42
 
43
- ### 1. `MushafPageProvider`
43
+ ### 1. `MushafReaderProvider`
44
44
 
45
- The `MushafPageProvider` is a React context provider that fetches and manages the state for a specific Mushaf page. You need to wrap any component that will render Mushaf text with it.
45
+ The `MushafReaderProvider` is a React context provider that fetches and manages the state for a specific Mushaf page. You need to wrap any component that will render Mushaf text with it.
46
46
 
47
47
  **Props:**
48
48
 
@@ -52,20 +52,20 @@ The `MushafPageProvider` is a React context provider that fetches and manages th
52
52
  - `initialFontScale` (number, optional): The initial font scale. Defaults to `3`.
53
53
  - `hasBorder` (boolean, optional): Whether to display the page border. Defaults to `true`.
54
54
  - `initialIsTwoPagesView` (boolean, optional): The initial state for two-page view. Defaults to `false`.
55
+ - `themeProps` (object, optional): An object to override default theme styles. See the "Styling and Customization" section.
56
+ - `styleOverride` (object, optional): An object to provide custom CSS classes to components. See the "Styling and Customization" section.
55
57
 
56
58
  ### 2. `useMushafContext` Hook
57
59
 
58
- This hook provides access to the state and actions of the `MushafPageProvider`. It should be used by components that are children of `MushafPageProvider`.
60
+ This hook provides access to the state and actions of the `MushafReaderProvider`. It should be used by components that are children of `MushafReaderProvider`.
59
61
 
60
62
  **State:**
61
63
 
62
64
  - `fontScale` (number): The current font scale.
63
65
  - `selectedVerse` (Ayah | null): The currently selected verse.
64
- - `currentSurah` (Surah | null): The current surah being displayed.
65
66
  - `ayat` (MushafPageDataType | null): The raw data for the current page.
66
67
  - `nextPageAyat` (MushafPageDataType | null): The data for the next page, used in two-page view.
67
68
  - `error` (Error | null): Any error that occurred while fetching data.
68
- - `loading` (boolean): A boolean indicating if the page data is loading.
69
69
  - `pageNumber` (number): The current page number.
70
70
  - `dataId` (DataId): The current narration identifier.
71
71
  - `isTwoPagesView` (boolean): Whether the two-page view is currently active.
@@ -75,34 +75,23 @@ This hook provides access to the state and actions of the `MushafPageProvider`.
75
75
  - `increaseFontScale()`: Increases the font scale.
76
76
  - `decreaseFontScale()`: Decreases the font scale.
77
77
  - `setSelectedVerse(verse: Ayah | null)`: Sets the selected verse.
78
- - `setCurrentSurah(surah: Surah | null)`: Sets the current surah.
79
78
 
80
79
  **Example:**
81
80
 
82
81
  ```tsx
83
- import {
84
- MushafPageProvider,
85
- useMushafContext,
86
- } from '@src/components/MushafReader/contexts/MushafPage/MushafPageProvider';
87
- import Mushaf from '@src/components/MushafReader';
82
+ import { MushafReaderProvider, useMushafContext, Mushaf } from 'misraj-mushaf-renderer';
88
83
 
89
84
  function App() {
90
85
  return (
91
- <MushafPageProvider dataId="quran-hafs" pageNumber={1} initialIsTwoPagesView={true}>
86
+ <MushafReaderProvider dataId="quran-hafs" pageNumber={1} initialIsTwoPagesView={true}>
92
87
  <MushafReader />
93
- </MushafPageProvider>
88
+ </MushafReaderProvider>
94
89
  );
95
90
  }
96
91
 
97
92
  function MushafReader() {
98
- const {
99
- pageNumber,
100
- currentSurah,
101
- fontScale,
102
- increaseFontScale,
103
- decreaseFontScale,
104
- setSelectedVerse,
105
- } = useMushafContext();
93
+ const { pageNumber, fontScale, increaseFontScale, decreaseFontScale, setSelectedVerse } =
94
+ useMushafContext();
106
95
 
107
96
  const handleWordClick = (word) => {
108
97
  // select the verse the word belongs to
@@ -116,9 +105,7 @@ function MushafReader() {
116
105
  return (
117
106
  <div>
118
107
  <header>
119
- <h1>
120
- Page {pageNumber} - Surah {currentSurah?.name}
121
- </h1>
108
+ <h1>Page {pageNumber}</h1>
122
109
  <div>
123
110
  <button onClick={decreaseFontScale}>A-</button>
124
111
  <span>Font size: {fontScale}</span>
@@ -133,15 +120,14 @@ function MushafReader() {
133
120
 
134
121
  ### 3. `Mushaf` Component
135
122
 
136
- This component consumes the data fetched by `MushafPageProvider` and renders the actual Mushaf page(s).
123
+ This component consumes the data fetched by `MushafReaderProvider` and renders the actual Mushaf page(s).
137
124
 
138
- It accepts several optional props to handle user interactions and styling.
125
+ It accepts several optional props to handle user interactions.
139
126
 
140
127
  **Props:**
141
128
 
142
129
  - `onWordClick(word: Word)`: A callback function that triggers when a user clicks on a specific word. The `word` object contains detailed information about the word, including its location, text, and verse key.
143
130
  - `onWordHover(word: Word)`: A callback function that triggers when a user hovers over a word.
144
- - `styleOverride`: An object to override default styles. See the "Overriding Styles" section for more details.
145
131
 
146
132
  ## How It Works: The Rendering Process
147
133
 
@@ -153,7 +139,7 @@ Rendering a Mushaf page is a complex process that this library simplifies into a
153
139
 
154
140
  3. **`MushafWord.tsx`** (`@src/components/dls/MushafWord/MushafWord.tsx`): This is the most granular component, responsible for rendering a single Mushaf word. It attaches the `onClick` and `onMouseEnter` event listeners and applies the specific font-family for the current narration via CSS classes defined in `MushafWord.module.scss`.
155
141
 
156
- ## Styling
142
+ ## Styling and Customization
157
143
 
158
144
  The library's styling is managed through SCSS, offering a high degree of customization.
159
145
 
@@ -162,33 +148,78 @@ The library's styling is managed through SCSS, offering a high degree of customi
162
148
  - **Fonts**: The `@font-face` declarations for all supported narrations are located in `@src/styles/fonts.scss`.
163
149
  - **Responsiveness**: Breakpoints for various screen sizes are defined in `@src/styles/_breakpoints.scss` to ensure the layout is responsive.
164
150
 
165
- ## Overriding Styles
151
+ The library offers two primary ways to customize the appearance of the Mushaf renderer: `themeProps` for global theme adjustments and `styleOverride` for fine-grained component-level style changes. Both are passed as props to the `MushafReaderProvider`.
166
152
 
167
- You can easily override the default component styles by passing a `styleOverride` object to the `Mushaf` component. This object allows you to set specific CSS variables at runtime.
153
+ ### 1. Theming with `themeProps`
154
+
155
+ The `themeProps` object allows you to easily change the overall theme by setting global CSS variables at runtime.
168
156
 
169
157
  **Available Options:**
170
158
 
171
- - `wordHighlightColor` (string): The color of a word when it is hovered or highlighted.
172
- - `chapterHeaderFontSize` (string): The font size for the chapter headers (surah names).
159
+ - `borderColor` ('blue' | 'green' | 'sepia'): Sets the color for the page borders and the default word highlight color.
160
+ - `wordHighlightColor` (string): Overrides the default highlight color for words when they are hovered or selected. Accepts any valid CSS color value.
161
+ - `chapterHeaderFontSize` (string): The font size for the chapter headers (surah names). Accepts any valid CSS font-size value.
173
162
  - `primaryFontColor` (string): The primary color of the Quranic text.
174
- - `borderColor`: ('blue' | 'green' | 'sepia') Supported border colors;
175
163
 
176
164
  **Example:**
177
165
 
178
166
  ```tsx
179
- function MushafReader() {
180
- const styleOverride = {
181
- wordHighlightColor: '#00aaff', // A light blue highlight
182
- chapterHeaderFontSize: '2.5rem',
183
- primaryFontColor: '#333333', // A dark gray for the text
184
- borderColor: 'blue',
185
- };
167
+ const themeProps = {
168
+ borderColor: 'sepia',
169
+ wordHighlightColor: '#D4AF37', // Gold highlight
170
+ chapterHeaderFontSize: '2.5rem',
171
+ primaryFontColor: '#333333', // Dark gray text
172
+ };
173
+
174
+ <MushafReaderProvider dataId="quran-hafs" pageNumber={1} themeProps={themeProps}>
175
+ <Mushaf />
176
+ </MushafReaderProvider>;
177
+ ```
178
+
179
+ ### 2. Component-level styling with `styleOverride`
180
+
181
+ For more specific, dynamic, or one-off styling changes, the `styleOverride` prop allows you to apply a `React.CSSProperties` object directly to the library's internal components.
182
+
183
+ The `styleOverride` object follows this structure:
184
+
185
+ ```ts
186
+ {
187
+ [ComponentName]?: {
188
+ [StyleKey]?: React.CSSProperties; // A CSS style object
189
+ }
190
+ }
191
+ ```
192
+
193
+ - `ComponentName` corresponds to the components you want to style (e.g., `Page`, `MushafWord`, `MushafReader`).
194
+ - `StyleKey` corresponds to a stylable element within that component (e.g., `container`, `highlighted`, `twoPagesRow`).
186
195
 
196
+ You can find all available `ComponentName` and `StyleKey` values in the exported `classnames` object.
197
+
198
+ **Example:**
199
+
200
+ Let's say you want to remove the gap between the two pages in the two-page view. You can do this by passing a style object to the `twoPagesRow` style key of the `MushafReader` component.
201
+
202
+ ```tsx
203
+ import { Mushaf, MushafReaderProvider } from 'misraj-mushaf-renderer';
204
+
205
+ const styleOverride = {
206
+ MushafReader: {
207
+ twoPagesRow: {
208
+ gap: 0,
209
+ },
210
+ },
211
+ };
212
+
213
+ function App() {
187
214
  return (
188
- <div>
189
- {/* ... header and controls ... */}
190
- <Mushaf styleOverride={styleOverride} />
191
- </div>
215
+ <MushafReaderProvider
216
+ dataId="quran-hafs"
217
+ pageNumber={1}
218
+ styleOverride={styleOverride}
219
+ initialIsTwoPagesView={true}
220
+ >
221
+ <Mushaf />
222
+ </MushafReaderProvider>
192
223
  );
193
224
  }
194
225
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "misraj-mushaf-renderer",
3
- "version": "1.1.20",
3
+ "version": "1.2.0",
4
4
  "license": "CC BY-NC 4.0",
5
5
  "description": "A customizable React component for rendering Mushaf pages.",
6
6
  "type": "module",