|
1 | 1 | # Symfony UX Typed
|
2 | 2 |
|
| 3 | +**Deprecated: This package has been deprecated in 2.x and will be removed in the next major version.** |
| 4 | + |
| 5 | +To keep the same functionality in your Symfony application, you can follow these migration steps: |
| 6 | + |
| 7 | +1. Install the `typed.js` library: |
| 8 | + |
| 9 | +```bash |
| 10 | +# If you are using Symfony AssetMapper: |
| 11 | +php bin/console importmap:require typed.js |
| 12 | + |
| 13 | +# If you are using NPM (e.g.: with Webpack Encore): |
| 14 | +npm install typed.js |
| 15 | +``` |
| 16 | + |
| 17 | +2. Add the following code to your template: |
| 18 | + |
| 19 | +<details><summary><code>assets/controllers/typed_controller.js</code></summary> |
| 20 | + |
| 21 | +```javascript |
| 22 | +import { Controller } from '@hotwired/stimulus'; |
| 23 | +import Typed from 'typed.js'; |
| 24 | + |
| 25 | +export default class extends Controller { |
| 26 | + static values = { |
| 27 | + strings: Array, |
| 28 | + typeSpeed: { type: Number, default: 30 }, |
| 29 | + smartBackspace: { type: Boolean, default: true }, |
| 30 | + startDelay: Number, |
| 31 | + backSpeed: Number, |
| 32 | + shuffle: Boolean, |
| 33 | + backDelay: { type: Number, default: 700 }, |
| 34 | + fadeOut: Boolean, |
| 35 | + fadeOutClass: { type: String, default: 'typed-fade-out' }, |
| 36 | + fadeOutDelay: { type: Number, default: 500 }, |
| 37 | + loop: Boolean, |
| 38 | + loopCount: { type: Number, default: Number.POSITIVE_INFINITY }, |
| 39 | + showCursor: { type: Boolean, default: true }, |
| 40 | + cursorChar: { type: String, default: '.' }, |
| 41 | + autoInsertCss: { type: Boolean, default: true }, |
| 42 | + attr: String, |
| 43 | + bindInputFocusEvents: Boolean, |
| 44 | + contentType: { type: String, default: 'html' }, |
| 45 | + }; |
| 46 | + |
| 47 | + connect() { |
| 48 | + const options = { |
| 49 | + strings: this.stringsValue, |
| 50 | + typeSpeed: this.typeSpeedValue, |
| 51 | + smartBackspace: this.smartBackspaceValue, |
| 52 | + startDelay: this.startDelayValue, |
| 53 | + backSpeed: this.backSpeedValue, |
| 54 | + shuffle: this.shuffleValue, |
| 55 | + backDelay: this.backDelayValue, |
| 56 | + fadeOut: this.fadeOutValue, |
| 57 | + fadeOutClass: this.fadeOutClassValue, |
| 58 | + fadeOutDelay: this.fadeOutDelayValue, |
| 59 | + loop: this.loopValue, |
| 60 | + loopCount: this.loopCountValue, |
| 61 | + showCursor: this.showCursorValue, |
| 62 | + cursorChar: this.cursorCharValue, |
| 63 | + autoInsertCss: this.autoInsertCssValue, |
| 64 | + attr: this.attrValue, |
| 65 | + bindInputFocusEvents: this.bindInputFocusEventsValue, |
| 66 | + contentType: this.contentTypeValue, |
| 67 | + }; |
| 68 | + |
| 69 | + this.dispatchEvent('pre-connect', { options }); |
| 70 | + const typed = new Typed(this.element, options); |
| 71 | + this.dispatchEvent('connect', { typed, options }); |
| 72 | + } |
| 73 | + |
| 74 | + dispatchEvent(name, payload) { |
| 75 | + this.dispatch(name, { detail: payload, prefix: 'typed' }); |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +</details> |
| 81 | + |
| 82 | +3. And finally, replace the `symfony--ux-typed` occurrences in your templates with `typed`, for example: |
| 83 | + |
| 84 | +```diff |
| 85 | +{% set strings = [ |
| 86 | + 'I ❤️ Symfony UX!', |
| 87 | + 'Symfony UX Typed loves to type', |
| 88 | + 'Symfony UX Typed and backspace', |
| 89 | + 'Control the speed', |
| 90 | + 'Control the cursor', |
| 91 | + 'Control your destiny!!!', |
| 92 | + 'Control your destiny... sort of', |
| 93 | +] %} |
| 94 | +<span |
| 95 | +- data-controller="symfony--ux-typed" |
| 96 | +- data-symfony--ux-typed-loop-value="true" |
| 97 | +- data-symfony--ux-typed-show-cursor-value="true" |
| 98 | +- data-symfony--ux-typed-cursor-char-value="✨" |
| 99 | +- data-symfony--ux-typed-strings-value="{{ strings|json_encode|e('html_attr') }}" |
| 100 | ++ data-controller="typed" |
| 101 | ++ data-typed-loop-value="true" |
| 102 | ++ data-typed-show-cursor-value="true" |
| 103 | ++ data-typed-cursor-char-value="✨" |
| 104 | ++ data-typed-strings-value="{{ strings|json_encode|e('html_attr') }}" |
| 105 | +></span> |
| 106 | +``` |
| 107 | +--- |
| 108 | + |
3 | 109 | Symfony UX Typed is a Symfony bundle integrating [Typed](https://github.com/mattboldt/typed.js/blob/master/README.md) in
|
4 | 110 | Symfony applications. It is part of [the Symfony UX initiative](https://ux.symfony.com/).
|
5 | 111 |
|
|
0 commit comments