# Text Type

> Typewriter text with a gliding bar, block or underscore cursor, per-letter fade, blur or rise, occasional corrected typos and a fixed prefix.

Types one or more sentences character by character, waits, then clears them by backspacing or by highlighting the line like a text selection. The cursor glides to each new position and blinks softly while idle. Pick a preset in the panel, or turn on mistakes to watch wrong keys get noticed and fixed.

<demo-text-type>



</demo-text-type>

## Installation

```bash
npx shadcn-vue@latest add "https://nxui.geoql.in/r/text-type.json"
```

## Usage

```vue
<script setup lang="ts">
  import TextType from '~/components/ui/text-type/TextType.vue';

  function onSentenceComplete(sentence: string, index: number) {
    console.log(index, sentence);
  }
</script>

<template>
  <TextType
    as="h1"
    :text="['interfaces', 'products', 'experiences']"
    prefix="We build "
    prefix-color="#8a8693"
    cursor-style="bar"
    cursor-color="#ff5a36"
    type-effect="rise"
    :mistakes="0.3"
    :variable-speed="{ min: 40, max: 170 }"
    class="text-6xl font-bold"
    @sentence-complete="onSentenceComplete"
  />
</template>
```

## Props

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        text
      </code>
    </td>
    
    <td>
      <code>
        string | string[]
      </code>
    </td>
    
    <td>
      —
    </td>
    
    <td>
      A sentence, or a list of sentences typed one after another
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        as
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'div'
      </code>
    </td>
    
    <td>
      Element to render, such as <code>
        h1
      </code>
      
       or <code>
        span
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        prefix
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Static text before the typed part, such as <code>
        "We build "
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        prefix-color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'currentColor'
      </code>
    </td>
    
    <td>
      Color of the prefix
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        typing-speed
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        50
      </code>
    </td>
    
    <td>
      Delay between typed characters (ms)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        initial-delay
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0
      </code>
    </td>
    
    <td>
      Wait before each sentence starts typing (ms)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pause-duration
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        2000
      </code>
    </td>
    
    <td>
      How long a finished sentence stays before it is cleared (ms)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        deleting-speed
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        30
      </code>
    </td>
    
    <td>
      Delay between deleted characters (ms); in select mode, how fast the highlight grows
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        delete-mode
      </code>
    </td>
    
    <td>
      <code>
        'backspace' | 'select'
      </code>
    </td>
    
    <td>
      <code>
        'backspace'
      </code>
    </td>
    
    <td>
      Erase one character at a time, or highlight the line and remove it at once
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        type-effect
      </code>
    </td>
    
    <td>
      <code>
        'none' | 'fade' | 'blur' | 'rise'
      </code>
    </td>
    
    <td>
      <code>
        'none'
      </code>
    </td>
    
    <td>
      How each character appears as it is typed
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        mistakes
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0
      </code>
    </td>
    
    <td>
      0–1. How often a wrong key is hit, noticed, erased and corrected
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        variable-speed
      </code>
    </td>
    
    <td>
      <code>
        { min: number; max: number }
      </code>
    </td>
    
    <td>
      <code>
        undefined
      </code>
    </td>
    
    <td>
      Random delay between <code>
        min
      </code>
      
       and <code>
        max
      </code>
      
       ms per character
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        loop
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Start over after the last sentence; when off, the last sentence stays
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        show-cursor
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Show the cursor at the typing position
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor-style
      </code>
    </td>
    
    <td>
      <code>
        'character' | 'bar' | 'block' | 'underscore'
      </code>
    </td>
    
    <td>
      <code>
        'character'
      </code>
    </td>
    
    <td>
      Cursor shape; bar, block and underscore are drawn to fit the font
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor-character
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '|'
      </code>
    </td>
    
    <td>
      Character used when <code>
        cursor-style
      </code>
      
       is <code>
        character
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor-color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'currentColor'
      </code>
    </td>
    
    <td>
      Cursor color
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor-blink-duration
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0.5
      </code>
    </td>
    
    <td>
      Half the length of one blink (s); the cursor stays solid while typing
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor-glide
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Glide the cursor to each new position instead of jumping
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hide-cursor-while-typing
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Fade the cursor out while characters are typed or cleared
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor-class
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Extra classes for the cursor
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        text-colors
      </code>
    </td>
    
    <td>
      <code>
        string[]
      </code>
    </td>
    
    <td>
      <code>
        []
      </code>
    </td>
    
    <td>
      Colors for the sentences, used in turn
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        start-on-visible
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Wait until the text scrolls into view before typing
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        reverse-mode
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Reveal each sentence from its last character back to its first
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        class
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Extra classes for the root element
    </td>
  </tr>
</tbody>
</table>

## Events

<table>
<thead>
  <tr>
    <th>
      Event
    </th>
    
    <th>
      Payload
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        sentence-complete
      </code>
    </td>
    
    <td>
      <code>
        (sentence: string, index: number)
      </code>
    </td>
    
    <td>
      Fired each time a sentence has been cleared
    </td>
  </tr>
</tbody>
</table>

## Slots

<table>
<thead>
  <tr>
    <th>
      Slot
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        cursor
      </code>
    </td>
    
    <td>
      Custom cursor content when <code>
        cursor-style
      </code>
      
       is <code>
        character
      </code>
      
       (an icon…)
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The full text (prefix plus every sentence) sits in a visually hidden span, so screen readers read it once instead of every keystroke. The animated copy and the cursor are `aria-hidden`.
- With `prefers-reduced-motion: reduce`, sentences appear and clear at once, typos, letter effects and glide are skipped, and the cursor stops blinking.
- Ported from [React Bits](https://reactbits.dev/text-animations/text-type) by David Haz.
