react-markdown-typewriter 1.0.1 → 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 +13 -12
- package/dist/components/MarkdownTypewriter.js +1 -1
- package/dist/components/MarkdownTypewriter.mjs +1 -1
- package/dist/components/TypewriterItem.js +1 -1
- package/dist/components/TypewriterItem.mjs +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/functions/markdownComponents.js +1 -1
- package/dist/functions/markdownComponents.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/interfaces/MarkdownTypewriterProps.d.mts +11 -10
- package/dist/interfaces/MarkdownTypewriterProps.d.ts +11 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This library provides a new component, `MarkdownTypewriter`, that combines the Markdown component of [react-markdown](https://www.npmjs.com/package/react-markdown) with the animation of typewriter. The animation was created entirely with [motion](https://www.npmjs.com/package/motion).
|
|
4
4
|
|
|
5
|
-
Live demo: https://codesandbox.io/p/sandbox/react-markdown-typewriter-rgjf6t
|
|
5
|
+
Live demo: <https://codesandbox.io/p/sandbox/react-markdown-typewriter-rgjf6t>
|
|
6
6
|
|
|
7
7
|
## Why?
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@ The component accepts all the props of the `react-markdown` component and adds s
|
|
|
25
25
|
This is a very simple example of how to use the component:
|
|
26
26
|
|
|
27
27
|
```tsx
|
|
28
|
-
import MarkdownTypewriter from "
|
|
28
|
+
import { MarkdownTypewriter } from "react-markdown-typewriter";
|
|
29
29
|
|
|
30
30
|
export default function NarrationScreen() {
|
|
31
31
|
return (
|
|
@@ -42,10 +42,19 @@ This is a more complex example:
|
|
|
42
42
|
import { useRef } from "react";
|
|
43
43
|
import rehypeRaw from "rehype-raw";
|
|
44
44
|
import remarkGfm from "remark-gfm";
|
|
45
|
-
import MarkdownTypewriter from "
|
|
45
|
+
import { MarkdownTypewriter } from "react-markdown-typewriter";
|
|
46
46
|
|
|
47
47
|
export default function NarrationScreen() {
|
|
48
48
|
const paragraphRef = useRef<HTMLDivElement>(null);
|
|
49
|
+
const scrollToEnd = useCallback((ref: { current: HTMLSpanElement | null }) => {
|
|
50
|
+
if (paragraphRef.current && ref.current) {
|
|
51
|
+
let scrollTop = ref.current.offsetTop - paragraphRef.current.clientHeight / 2;
|
|
52
|
+
paragraphRef.current.scrollTo({
|
|
53
|
+
top: scrollTop,
|
|
54
|
+
behavior: "auto",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}, []);
|
|
49
58
|
return (
|
|
50
59
|
<div ref={paragraphRef}>
|
|
51
60
|
<MarkdownTypewriter
|
|
@@ -60,15 +69,7 @@ export default function NarrationScreen() {
|
|
|
60
69
|
hidden: { opacity: 0 },
|
|
61
70
|
visible: { opacity: 1, transition: { opacity: { duration: 0 } } },
|
|
62
71
|
},
|
|
63
|
-
onCharacterAnimationComplete:
|
|
64
|
-
if (paragraphRef.current && ref.current) {
|
|
65
|
-
let scrollTop = ref.current.offsetTop - paragraphRef.current.clientHeight / 2;
|
|
66
|
-
paragraphRef.current.scrollTo({
|
|
67
|
-
top: scrollTop,
|
|
68
|
-
behavior: "auto",
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
+
onCharacterAnimationComplete: scrollToEnd,
|
|
72
73
|
}}
|
|
73
74
|
>
|
|
74
75
|
Hello World
|