Typewriter
<zn-typewriter>
ZnTypewriter
Types its text out one character at a time, then shows anything slotted after it.
Use a typewriter to reveal a short, freshly generated answer, such as an assistant’s reply. Screen readers receive the full text immediately, and people who prefer reduced motion see it at once.
<zn-typewriter>Here are the articles that cover deep strike and reserves.</zn-typewriter>
Examples
Holding content back until typing finishes
Anything in the after slot appears once the text has been typed, so a reply reads in order.
padded spaces the text like a zn-sp, so flush content can sit beneath it.
<zn-typewriter padded>Two articles cover this. <div slot="after"> <zn-tile caption="Reserves and Strategic Reserves"></zn-tile> <zn-tile caption="Unit Abilities Reference"></zn-tile> </div> </zn-typewriter>
Speed
speed sets the milliseconds per character. Longer text speeds up so it never takes more than
max-duration milliseconds.
<zn-typewriter speed="40" max-duration="4000">A slower, more deliberate reveal.</zn-typewriter>
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/@kubex/zinc@2.0.44/dist/components/typewriter/typewriter.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/@kubex/zinc@2.0.44/dist/components/typewriter/typewriter.js';
To import this component using a bundler:
import '@kubex/zinc/dist/components/typewriter/typewriter.js';
Slots
| Name | Description |
|---|---|
| (default) | The text to type. Read as plain text. |
after
|
Content held back until typing finishes. |
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
speed
|
Milliseconds per character. |
number
|
18
|
|
maxDuration
max-duration
|
Longer text types faster so it never takes more than this many milliseconds. |
number
|
1500
|
|
padded
|
Pads the typed text like a zn-sp, so after-slot content can sit flush beneath it. |
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
| Name | React Event | Description | Event Detail |
|---|---|---|---|
zn-finish |
|
Emitted once the whole text is shown. | - |
Learn more about events.
Parts
| Name | Description |
|---|---|
base |
The typed text wrapper. |
caret |
The blinking caret shown while typing. |
Learn more about customizing CSS parts.