@creativecreate/react-footnotes 1.0.0 → 1.0.2
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.
- package/README.md +59 -3
- package/footnotes.css +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ const messages = messagesData.footnotes;
|
|
|
61
61
|
### 2. Wrap your app with FootnoteProvider and provide messages
|
|
62
62
|
|
|
63
63
|
```tsx
|
|
64
|
+
import { useState, useEffect } from 'react';
|
|
64
65
|
import { FootnoteProvider } from '@creativecreate/react-footnotes';
|
|
65
66
|
import messagesData from './messages.json'; // Your custom messages file from your project
|
|
66
67
|
|
|
@@ -68,11 +69,18 @@ import messagesData from './messages.json'; // Your custom messages file from yo
|
|
|
68
69
|
const messages = messagesData.footnotes;
|
|
69
70
|
|
|
70
71
|
function App() {
|
|
72
|
+
const [pathname, setPathname] = useState('');
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
// Only access window on client-side
|
|
76
|
+
setPathname(`${window.location.pathname}${window.location.search}`);
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
71
79
|
return (
|
|
72
80
|
<FootnoteProvider
|
|
73
81
|
messages={messages}
|
|
74
|
-
// Alternative: see section - using React
|
|
75
|
-
pathname={
|
|
82
|
+
// Alternative: see section - using React Router (recommended for SPAs)
|
|
83
|
+
pathname={pathname}
|
|
76
84
|
>
|
|
77
85
|
{/* Your app content */}
|
|
78
86
|
</FootnoteProvider>
|
|
@@ -114,9 +122,57 @@ function Footer() {
|
|
|
114
122
|
}
|
|
115
123
|
```
|
|
116
124
|
|
|
125
|
+
### 5. Add styling
|
|
126
|
+
|
|
127
|
+
You have two options for styling the footnotes:
|
|
128
|
+
|
|
129
|
+
**Option A: Use the default stylesheet from the package**
|
|
130
|
+
|
|
131
|
+
Import the default stylesheet to get pre-styled footnotes:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import '@creativecreate/react-footnotes/footnotes.css';
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Add this import in your main entry file (e.g., `main.tsx`, `index.tsx`, or `_app.tsx` for Next.js).
|
|
138
|
+
|
|
139
|
+
**Option B: Use your own CSS with the available class names**
|
|
140
|
+
|
|
141
|
+
If you prefer to style the footnotes yourself, you can target the following CSS classes in your own stylesheet:
|
|
142
|
+
|
|
143
|
+
```css
|
|
144
|
+
/* Footnote reference button (the clickable superscript in text) */
|
|
145
|
+
.footnote-ref { }
|
|
146
|
+
|
|
147
|
+
/* Footnote symbol (the number or symbol inside the button) */
|
|
148
|
+
.footnote-symbol { }
|
|
149
|
+
|
|
150
|
+
/* Footnote list (ordered list) */
|
|
151
|
+
.footnote-list { }
|
|
152
|
+
|
|
153
|
+
/* Individual footnote list item */
|
|
154
|
+
.footnote-list-item { }
|
|
155
|
+
|
|
156
|
+
/* Symbol in the list item */
|
|
157
|
+
.footnote-list-item__symbol { }
|
|
158
|
+
|
|
159
|
+
/* Footnote content in the list item */
|
|
160
|
+
.footnote-list-item__content { }
|
|
161
|
+
|
|
162
|
+
/* Back to reference link button */
|
|
163
|
+
.footnote-list-item__back-link { }
|
|
164
|
+
|
|
165
|
+
/* Back link icon */
|
|
166
|
+
.footnote-list-item__back-link-icon { }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
You can also use the `className` props on components to apply your own custom classes (see [Customizing Styles](#customizing-styles) section for details).
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
117
173
|
**Example output:**
|
|
118
174
|
|
|
119
|
-

|
|
120
176
|
|
|
121
177
|
## Advanced Usage
|
|
122
178
|
|
package/footnotes.css
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
cursor: pointer;
|
|
11
11
|
color: inherit;
|
|
12
12
|
text-decoration: none;
|
|
13
|
+
/*
|
|
14
|
+
Add scroll to top gap here if you have a fixed header,
|
|
15
|
+
and you want your footnote reference to scroll to the top
|
|
16
|
+
of the page but still be visible below the fixed header.
|
|
17
|
+
*/
|
|
13
18
|
scroll-margin-top: 1rem;
|
|
14
19
|
}
|
|
15
20
|
|
package/package.json
CHANGED