-
Notifications
You must be signed in to change notification settings - Fork 221
/
index.d.ts
189 lines (172 loc) · 4.45 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
type Speed = "natural" | number
declare module "typewriter-effect" {
export interface Options {
/**
* Strings to type out when using autoStart option
*
* @default null
*/
strings?: string | string[]
/**
* String value to use as the cursor.
*
* @default Pipe character
*/
cursor?: string
/**
* The delay between each key when typing.
*
* @default "natural"
*/
delay?: Speed
/**
* The delay between deleting each character.
*
* @default "natural"
*/
deleteSpeed?: Speed
/**
* Whether to keep looping or not.
*
* @default false
*/
loop?: boolean
/**
* Whether to autostart typing strings or not. You are required to provide
* strings option.
*
* @default false
*/
autoStart?: boolean
/**
* Whether or not to display console logs.
*
* @default false
*/
devMode?: boolean
/**
* Skip adding default typewriter css styles.
*
* @default false
*/
skipAddStyles?: boolean
/**
* Class name for the wrapper element.
*
* @default "Typewriter__wrapper"
*/
wrapperClassName?: string
/**
* Class name for the cursor element.
*
* @default "Typewriter__cursor"
*/
cursorClassName?: string
/**
* String splitter function, can be used to split emoji's
*
* @default null
*/
stringSplitter?: (text: string) => string
/**
* Callback function to replace the internal method which
* creates a text node for the character before adding
* it to the DOM. If you return null, then it will
* not add anything to the DOM and so it
* is up to you to handle it
*
* @default null
*/
onCreateTextNode?: (character: string, textNode: Text) => Text | null
/**
* Callback function when a node is about to be removed
*
* @default null
*/
onRemoveNode?: (param: { node: Node | void, charater: string }) => void
}
export interface TypewriterState {
elements: {
container: HTMLDivElement
cursor: HTMLSpanElement
wrapper: HTMLSpanElement
}
}
export class TypewriterClass {
constructor(container: string | HTMLElement, options: Options)
/**
* Start the typewriter effect.
*/
start(): TypewriterClass
/**
* Stop the typewriter effect.
*/
stop(): TypewriterClass
/**
* Pause the typewriter effect.
*/
pause(): TypewriterClass
/**
* Pause for milliseconds
*
* @param ms Time to pause for in milliseconds
*/
pauseFor(ms: number): TypewriterClass
/**
* Type out a string using the typewriter effect.
*
* @param string String to type out, it can contain HTML tags
*/
typeString(string: string): TypewriterClass
/**
* Paste out a string.
*
* @param string String to paste out, it can contain HTML tags
*/
pasteString(string: string, node: HTMLElement | null): TypewriterClass
/**
* Delete everything that is visible inside of the typewriter wrapper
* element.
*
* @param speed Speed to delete all visibles nodes, can be number or
* 'natural'
*/
deleteAll(speed?: Speed): TypewriterClass
/**
* Delete and amount of characters, starting at the end of the visible
* string.
*
* @param amount Number of characters
*/
deleteChars(amount: number): TypewriterClass
/**
* Call a callback function. The first parameter to the callback elements
* which contains all DOM nodes used in the typewriter effect.
*
* @param callback Callback
* @param thisArg this Object to bind to the callback function
*/
callFunction(
callback: (state: TypewriterState) => void,
thisArg?: Record<string, any>,
): TypewriterClass
/**
* The speed at which to delete the characters, lower number is faster.
*
* @param speed Number or 'natural'
*/
changeDeleteSpeed(speed?: Speed): TypewriterClass
/**
* Change the delay when typing out each character
*
* @param delay delay Number or 'natural'
*/
changeDelay(delay?: Speed): TypewriterClass
}
const TypewriterComponent: React.FunctionComponent<{
component?: React.ElementType
onInit?: (typewriter: TypewriterClass) => void
options?: Partial<Options>
}>
export default TypewriterComponent
}