@@ -25,28 +25,67 @@ yarn add react-simple-typewriter
2525## Breaking Changes in v2
2626
2727- Named Imports.
28- - Injected css style.
28+ - Injected ** css** style.
29+
30+ ---
31+
32+ ## Usage
33+
34+ ``` jsx
35+ import { Typewriter , useTypewriter , Cursor } from ' react-simple-typewriter'
36+ ```
37+
38+ ## 1. Component
2939
3040``` jsx
31- // import Typewriter from 'react-simple-typewriter'
32- import { Typewriter } from ' react-simple-typewriter' // use named import
33- // import 'react-simple-typewriter/dist/index.css' // no need to import
41+ import React from ' react'
42+ import { Typewriter } from ' react-simple-typewriter'
43+
44+ const MyComponent = () => {
45+ return (
46+ < div className= ' App' >
47+ < Typewriter {/* Props */ } / >
48+ < / div>
49+ )
50+ }
3451```
3552
36- ## <br />
53+ ### Component Props
54+
55+ | Prop | Type | Options | Description | Default |
56+ | ------------- | :---------------: | -------- | -------------------------------------------------------------------------------------------- | :----------------: |
57+ | ` words ` | Array | Required | Array of strings holding the words | ` ['Hello', '...'] ` |
58+ | ` typeSpeed ` | Number | Optional | Character typing speed in Milliseconds | ` 90 ` |
59+ | ` deleteSpeed ` | Number | Optional | Character deleting speed in Milliseconds | ` 50 ` |
60+ | ` delaySpeed ` | Number | Optional | Delay time between the words in Milliseconds | ` 1500 ` |
61+ | ` loop ` | Number \| Boolean | Optional | Control how many times to run. ` 0 \| false ` to run infinitely | ` 1 ` |
62+ | ` onLoopDone ` | Function | Optional | Callback ` Function ` that is triggered when loops are completed. available if ` loop ` is ` > 0 ` | ` - ` |
63+ | ` onType ` | Function | Optional | Callback ` Function ` that is runs while typing | ` - ` |
64+ | ` cursor ` | Boolean | Optional | Show / Hide a cursor | ` true ` |
65+ | ` cursorStyle ` | String | Optional | Change the cursor style available if ` cursor ` is ` enabled ` | ` \| ` |
66+
67+ ---
3768
38- ## Usage Example (Component)
69+ ### Component Usage Example
3970
4071``` jsx
4172import React from ' react'
4273import { Typewriter } from ' react-simple-typewriter'
4374
4475const MyComponent = () => {
76+
77+ const handleType = (count : number ) => {
78+ // access word count number
79+ console .log (count)}
80+ }
81+
82+ const handleDone = () => {
83+ console .log (` Done after 5 loops!` )
84+ }
85+
4586 return (
4687 < div className= ' App' >
47- < h1
48- style= {{ paddingTop: ' 5rem' , margin: ' auto 0' , fontWeight: ' normal' }}
49- >
88+ < h1 style= {{ paddingTop: ' 5rem' , margin: ' auto 0' , fontWeight: ' normal' }}>
5089 Life is simple{' ' }
5190 < span style= {{ color: ' red' , fontWeight: ' bold' }}>
5291 {/* Style will be inherited from the parent element */ }
@@ -58,7 +97,8 @@ const MyComponent = () => {
5897 typeSpeed= {70 }
5998 deleteSpeed= {50 }
6099 delaySpeed= {1000 }
61- onLoopDone= {() => console .log (` Done after 5 loops!` )}
100+ onLoopDone= {handleDone}
101+ onType= {handleType}
62102 / >
63103 < / span>
64104 < / h1>
@@ -67,49 +107,41 @@ const MyComponent = () => {
67107}
68108```
69109
70- ### Component Props
71-
72- | Prop | Type | Options | Description | Default |
73- | ------------- | :---------------: | -------- | -------------------------------------------------------------------------------------------- | :------------------: |
74- | ` words ` | Array | Required | Array of strings holding the words | ` ['Hello', 'World'] ` |
75- | ` cursor ` | Boolean | Optional | Show / Hide a cursor | ` true ` |
76- | ` cursorStyle ` | String | Optional | Change the cursor style available if ` cursor ` is ` enabled ` | ` \| ` |
77- | ` typeSpeed ` | Integer | Optional | Character typing speed in Milliseconds | ` 100 ` |
78- | ` delaySpeed ` | Integer | Optional | Delay time between the words in Milliseconds | ` 1500 ` |
79- | ` deleteSpeed ` | Integer | Optional | Character deleting speed in Milliseconds | ` 50 ` |
80- | ` loop ` | Number \| Boolean | Optional | Control how many times to run. ` 0 \| false ` to run infinitely | ` 1 ` |
81- | ` onLoopDone ` | Function | Optional | Callback ` Function ` that is triggered when loops are completed. available if ` loop ` is ` > 0 ` | ` - ` |
82-
83- ---
84-
85- ## Hook Usage
110+ ## 2. Hook
86111
87112``` jsx
88113import { useTypewriter } from ' react-simple-typewriter'
89114
90115const MyComponent = () => {
91- const typewritedText = useTypewriter ({
116+ /**
117+ *
118+ * @returns
119+ * text: [string] typed text
120+ * count: [number] typed word count
121+ */
122+ const { text , count } = useTypewriter ({
92123 /* Config */
93124 })
94125
95126 return (
96127 < div className= ' App' >
97- < span> {typewritedText }< / span>
128+ < span> {text }< / span>
98129 < / div>
99130 )
100131}
101132```
102133
103134### Hook Config
104135
105- | Prop | Type | Options | Description | Default |
106- | ------------- | :---------------: | -------- | -------------------------------------------------------------------------------------------- | :------------------: |
107- | ` words ` | Array | Required | Array of strings holding the words | ` ['Hello', 'World'] ` |
108- | ` typeSpeed ` | Integer | Optional | Character typing speed in Milliseconds | ` 100 ` |
109- | ` delaySpeed ` | Integer | Optional | Delay time between the words in Milliseconds | ` 1500 ` |
110- | ` deleteSpeed ` | Integer | Optional | Character deleting speed in Milliseconds | ` 50 ` |
111- | ` loop ` | Number \| Boolean | Optional | Control how many times to run. ` 0 \| false ` to run infinitely | ` 1 ` |
112- | ` onLoopDone ` | Function | Optional | Callback ` Function ` that is triggered when loops are completed. available if ` loop ` is ` > 0 ` | ` - ` |
136+ | Prop | Type | Options | Description | Default |
137+ | ------------- | :---------------: | -------- | -------------------------------------------------------------------------------------------- | :----------------: |
138+ | ` words ` | Array | Required | Array of strings holding the words | ` ['Hello', '...'] ` |
139+ | ` typeSpeed ` | Number | Optional | Character typing speed in Milliseconds | ` 80 ` |
140+ | ` deleteSpeed ` | Number | Optional | Character deleting speed in Milliseconds | ` 50 ` |
141+ | ` delaySpeed ` | Number | Optional | Delay time between the words in Milliseconds | ` 1500 ` |
142+ | ` loop ` | Number \| Boolean | Optional | Control how many times to run. ` 0 \| false ` to run infinitely | ` 1 ` |
143+ | ` onLoopDone ` | Function | Optional | Callback ` Function ` that is triggered when loops are completed. available if ` loop ` is ` > 0 ` | ` - ` |
144+ | ` onType ` | Function | Optional | Callback ` Function ` that is triggered while typing | ` - ` |
113145
114146### Hook Usage Example
115147
@@ -119,7 +151,7 @@ import { useTypewriter} from 'react-simple-typewriter'
119151
120152const MyComponent = () => {
121153
122- const text = useTypewriter ({
154+ const { text } = useTypewriter ({
123155 words: [' Hello' , ' From' , ' Typewriter' , ' Hook!' ],
124156 loop: {0 }, // Infinit
125157 })
@@ -142,7 +174,7 @@ import { useTypewriter, Cursor} from 'react-simple-typewriter'
142174
143175const MyComponent = () => {
144176
145- const text = useTypewriter ({
177+ const { text } = useTypewriter ({
146178 words: [' Hello' , ' From' , ' Typewriter' , ' Hook!' ],
147179 loop: {3 },
148180 onLoopDone : () => console .log (` loop completed after 3 runs.` ),
@@ -168,7 +200,8 @@ const MyComponent = () => {
168200### [ Demo] ( https://react-simple-typewriter.vercel.app/ )
169201
170202<br />
171- [ ![ Edit react-simple-typewriter] ( https://codesandbox.io/static/img/play-codesandbox.svg )] ( https://codesandbox.io/s/broken-wind-uj8ix?fontsize=14&hidenavigation=1&theme=dark )
203+
204+ [ ![ Edit react-simple-typewriter] ( https://codesandbox.io/static/img/play-codesandbox.svg )] ( https://codesandbox.io/s/react-simple-typewriter-uj8ix?fontsize=14&hidenavigation=1&theme=dark )
172205
173206### License
174207
0 commit comments