Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit c0eb47a

Browse files
author
Viktor Pöntinen
committed
release
1 parent 0a619f5 commit c0eb47a

File tree

8 files changed

+3254
-66
lines changed

8 files changed

+3254
-66
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.9.4

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
## VueTinyTyper - a vue component for creating a typing effect element.
22

33
#### Credits
4-
This project is forked from https://github.com/lourenc/tinytyper
4+
This project is forked from https://github.com/lourenc/tinytyper .
55
Some parts of the readme are also originally from above repository.
66

77
#### Why
8-
This project was created because I was missing events in non-vue version.
8+
This project was created because I was missing events in the non-vue version.
99

1010
#### Demo
11+
Full credits to https://github.com/lourenc/tinytyper
1112
<img align="center" src="https://s28.postimg.org/4qva5c1f1/tinytyper2.gif">
1213

1314
#### Installation
1415
Library can be easily installed via either Yarn or NPM:
1516

1617
`npm i vue-tinytyper --save`
17-
OR
18+
19+
or
20+
1821
`yarn add vue-tinytyper`
1922

2023
#### Usage
@@ -24,11 +27,11 @@ Basic setup looks like this:
2427
```js
2528
import VueTinytyper from 'vue-tinytyper';
2629
```
27-
THEN
30+
then
2831
```js
2932
<vue-tinytyper text="Hello, please type this out."></vue-tinytyper>
3033
```
31-
OR
34+
or
3235
```js
3336
<vue-tinytyper>Hello, please type this out.</vue-tinytyper>
3437
```
@@ -40,7 +43,7 @@ Prop | Default | Type | Description
4043
`text` | `` | String | The text to animate
4144
`textSpeed` | `95` | Number | Defines text speed animation
4245
`cursor` | `&#9612;` | String | Defines current cursor symbol
43-
`blinkSpeed` | `0.05` | Number | Defines blink speed of a cursor
46+
`blinkSpeed` | `0.05` | Number | Defines blink speed of the cursor
4447
`containerClass` | 'tiny-typer-container' | String | A CSS class for the container element
4548
`cursorClass` | `tiny-typer-cursor` | String | A CSS class for cursor element
4649
`textClass` | `tiny-typer-text` | String | A CSS class for text element
@@ -57,7 +60,7 @@ Eventname | Trigger | Payload
5760

5861
#### Contributions
5962

60-
Contributions are welcome. Feel free to create [issues](https://github.com/ViktorPontinen/vue-tinytyper/issues) and [PRs](https://github.com/ViktorPontinen/vue-tinytyper/pulls)
63+
Contributions are welcome. Feel free to create [issues](https://github.com/ViktorPontinen/vue-tinytyper/issues)
6164

6265
#### License
6366

dist/vue-tinytyper.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.html

Lines changed: 0 additions & 32 deletions
This file was deleted.

example/styles.css

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/VueTinytyper.vue

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<template>
2+
<div :class="containerClass" ref="containerElement"><slot></slot></div>
3+
</template>
4+
<script>
5+
import blink from './blinker.js'
6+
7+
export default {
8+
name: 'VueTinytyper',
9+
data() {
10+
return {
11+
element: null,
12+
cursorEl: null,
13+
textEl: null,
14+
textString: null,
15+
finishedEventTriggered: false,
16+
}
17+
},
18+
methods: {
19+
init() {
20+
this.element.innerHTML = ''
21+
this.element.innerText = ''
22+
this.element.appendChild(this.textEl)
23+
this.element.appendChild(this.cursorEl)
24+
25+
if(!this.staticCursor) this.blinker = blink(this.cursorEl, this.blinkSpeed)
26+
if(!this.staticText) {
27+
this.animate()
28+
} else {
29+
this.redraw(this.textString)
30+
}
31+
},
32+
animate() {
33+
let symbols = this.textString.split('')
34+
let result = []
35+
let animation = () => setTimeout(tick, this.textSpeed)
36+
let tick = () => {
37+
let character = symbols.shift()
38+
result.push(character)
39+
if(character in this.customEvents) this.$emit(this.customEvents[character])
40+
this.redraw(result.join(''))
41+
if(symbols.length) animation()
42+
else {
43+
if(!this.finishedEventTriggered) this.$emit('animation-finished')
44+
this.finishedEventTriggered = true
45+
}
46+
}
47+
48+
animation()
49+
},
50+
redraw(text) {
51+
this.textEl.innerText = text
52+
}
53+
},
54+
mounted() {
55+
this.element = this.$refs.containerElement
56+
this.cursorEl = document.createElement('span')
57+
this.textEl = document.createElement('span')
58+
59+
this.textString = this.text || this.element.innerText
60+
61+
this.textEl.className = this.textClass
62+
this.cursorEl.className = this.cursorClass
63+
this.cursorEl.innerHTML = this.cursor
64+
65+
this.init()
66+
},
67+
props: {
68+
customEvents: {
69+
type: Object,
70+
required: false,
71+
default() {
72+
return {}
73+
}
74+
},
75+
text: {
76+
type: String,
77+
required: false,
78+
default: ''
79+
},
80+
textSpeed: {
81+
type: Number,
82+
required: false,
83+
default: 95,
84+
},
85+
cursor: {
86+
type: String,
87+
required: false,
88+
default: '&#9612;',
89+
},
90+
blinkSpeed: {
91+
type: Number,
92+
required: false,
93+
default: 0.05,
94+
},
95+
cursorClass: {
96+
type: String,
97+
required: false,
98+
default: 'tiny-typer-cursor',
99+
},
100+
textClass: {
101+
type: String,
102+
required: false,
103+
default: 'tiny-typer-text',
104+
},
105+
containerClass: {
106+
type: String,
107+
required: false,
108+
default: 'tiny-typer-container',
109+
},
110+
staticCursor: {
111+
type: Boolean,
112+
required: false,
113+
default: false,
114+
},
115+
staticText: {
116+
type: Boolean,
117+
required: false,
118+
default: false,
119+
}
120+
},
121+
}
122+
</script>

src/plugin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import VueTinytyper from './VueTinyTyper.vue';
2+
3+
module.exports = {
4+
install: function (Vue, options) {
5+
Vue.component('vue-tinytyper', VueTinytyper);
6+
}
7+
};

0 commit comments

Comments
 (0)