You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
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
6
+
5
7
## Why?
6
8
7
9
This library was born during the development of my game engine [pixi-vn](https://www.npmjs.com/package/@drincs/pixi-vn). I needed a component that would display the current dialogue of a character with the "Typewriter" effect and I also wanted to give the developer the possibility to use Markdown to add style to the text.
@@ -50,7 +52,6 @@ export default function NarrationScreen() {
50
52
remarkPlugins={[remarkGfm]}
51
53
rehypePlugins={[rehypeRaw]}
52
54
delay={20}
53
-
scrollRef={paragraphRef}
54
55
motionProps={{
55
56
onAnimationComplete: () => {
56
57
console.log("Typewriter finished");
@@ -59,6 +60,15 @@ export default function NarrationScreen() {
let scrollTop =ref.current.offsetTop-paragraphRef.current.clientHeight/2;
66
+
paragraphRef.current.scrollTo({
67
+
top: scrollTop,
68
+
behavior: "auto",
69
+
});
70
+
}
71
+
},
62
72
}}
63
73
>
64
74
Hello World
@@ -75,7 +85,7 @@ export default function NarrationScreen() {
75
85
In addition to the `react-markdown` component props, the component accepts the following props:
76
86
77
87
*`delay`: The delay in milliseconds between the appearance of one letter and the next. Default: `10`. (Optional)
78
-
*`scrollRef`: The reference to the element that will be scrolled when the text exceeds the height of the container. (Optional)
79
88
*`motionProps` (Optional):
80
89
* The props to pass to the [motion span](https://motion.dev/docs/react-motion-component).
81
90
*`characterVariants`: The motion variants for each individual letter. Default: `{ hidden: { opacity: 0 }, visible: { opacity: 1, transition: { opacity: { duration: 0 } } } }` (Optional).
91
+
*`onCharacterAnimationComplete`: A callback that is called when the animation of a letter is complete. The callback is called with the reference to the letter. (Optional)
0 commit comments