react-markdown-typewriter 1.0.0 → 1.0.1
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 +14 -4
- package/dist/components/MarkdownTypewriter.js +1 -1
- package/dist/components/MarkdownTypewriter.mjs +1 -1
- package/dist/components/TypewriterItem.d.mts +4 -4
- package/dist/components/TypewriterItem.d.ts +4 -4
- 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.d.mts +4 -3
- package/dist/functions/markdownComponents.d.ts +4 -3
- 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 +41 -25
- package/dist/interfaces/MarkdownTypewriterProps.d.ts +41 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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,15 +52,23 @@ 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");
|
|
57
58
|
},
|
|
58
|
-
|
|
59
|
+
characterVariants: {
|
|
59
60
|
hidden: { opacity: 0 },
|
|
60
61
|
visible: { opacity: 1, transition: { opacity: { duration: 0 } } },
|
|
61
62
|
},
|
|
63
|
+
onCharacterAnimationComplete: (ref) => {
|
|
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
|
+
},
|
|
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)
|