|
| 1 | +import { Controller } from '@hotwired/stimulus'; |
| 2 | +import Typed from 'typed.js'; |
| 3 | + |
| 4 | +export default class extends Controller { |
| 5 | + static values = { |
| 6 | + strings: Array, |
| 7 | + typeSpeed: { type: Number, default: 30 }, |
| 8 | + smartBackspace: { type: Boolean, default: true }, |
| 9 | + startDelay: Number, |
| 10 | + backSpeed: Number, |
| 11 | + shuffle: Boolean, |
| 12 | + backDelay: { type: Number, default: 700 }, |
| 13 | + fadeOut: Boolean, |
| 14 | + fadeOutClass: { type: String, default: 'typed-fade-out' }, |
| 15 | + fadeOutDelay: { type: Number, default: 500 }, |
| 16 | + loop: Boolean, |
| 17 | + loopCount: { type: Number, default: Number.POSITIVE_INFINITY }, |
| 18 | + showCursor: { type: Boolean, default: true }, |
| 19 | + cursorChar: { type: String, default: '.' }, |
| 20 | + autoInsertCss: { type: Boolean, default: true }, |
| 21 | + attr: String, |
| 22 | + bindInputFocusEvents: Boolean, |
| 23 | + contentType: { type: String, default: 'html' }, |
| 24 | + }; |
| 25 | + |
| 26 | + connect() { |
| 27 | + const options = { |
| 28 | + strings: this.stringsValue, |
| 29 | + typeSpeed: this.typeSpeedValue, |
| 30 | + smartBackspace: this.smartBackspaceValue, |
| 31 | + startDelay: this.startDelayValue, |
| 32 | + backSpeed: this.backSpeedValue, |
| 33 | + shuffle: this.shuffleValue, |
| 34 | + backDelay: this.backDelayValue, |
| 35 | + fadeOut: this.fadeOutValue, |
| 36 | + fadeOutClass: this.fadeOutClassValue, |
| 37 | + fadeOutDelay: this.fadeOutDelayValue, |
| 38 | + loop: this.loopValue, |
| 39 | + loopCount: this.loopCountValue, |
| 40 | + showCursor: this.showCursorValue, |
| 41 | + cursorChar: this.cursorCharValue, |
| 42 | + autoInsertCss: this.autoInsertCssValue, |
| 43 | + attr: this.attrValue, |
| 44 | + bindInputFocusEvents: this.bindInputFocusEventsValue, |
| 45 | + contentType: this.contentTypeValue, |
| 46 | + }; |
| 47 | + |
| 48 | + this.dispatchEvent('pre-connect', { options }); |
| 49 | + const typed = new Typed(this.element, options); |
| 50 | + this.dispatchEvent('connect', { typed, options }); |
| 51 | + } |
| 52 | + |
| 53 | + dispatchEvent(name, payload) { |
| 54 | + this.dispatch(name, { detail: payload, prefix: 'typed' }); |
| 55 | + } |
| 56 | +} |
0 commit comments