# Fold Text

Text that unfolds piece by piece, like creased paper opening flat. Each character, word or line swings out from a hinge edge with a shadow along the crease. Pick paper folds, two-slat blinds or a full flip, and play it on mount, on hover, when it scrolls into view, or on a loop. With hover refold on, the letters near the pointer fold partly back up. Try the paper, blinds, flip and swing presets in the panel.

<demo-fold-text>



</demo-fold-text>

## Installation

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

## Usage

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

<template>
  <FoldText
    text="Design unfolds"
    fold-style="blinds"
    trigger="loop"
    stagger-from="center"
    ease="expo.out"
    :duration="1.1"
    :loop-delay="1.6"
    hover-refold
  />
</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
      </code>
    </td>
    
    <td>
      <code>
        'Design unfolds'
      </code>
    </td>
    
    <td>
      The text to unfold. Use <code>
        \n
      </code>
      
       for line breaks.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        split-by
      </code>
    </td>
    
    <td>
      <code>
        'char' | 'word' | 'line'
      </code>
    </td>
    
    <td>
      <code>
        'char'
      </code>
    </td>
    
    <td>
      Fold each character, each word, or each line.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hinge
      </code>
    </td>
    
    <td>
      <code>
        'top' | 'bottom' | 'left' | 'right'
      </code>
    </td>
    
    <td>
      <code>
        'top'
      </code>
    </td>
    
    <td>
      The edge each piece hinges on.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        fold-style
      </code>
    </td>
    
    <td>
      <code>
        'paper' | 'blinds' | 'flip'
      </code>
    </td>
    
    <td>
      <code>
        'paper'
      </code>
    </td>
    
    <td>
      Paper folds from one edge, blinds open as two slats, flip turns a full half-turn.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        duration
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0.65
      </code>
    </td>
    
    <td>
      Seconds each piece takes to unfold.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stagger
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0.045
      </code>
    </td>
    
    <td>
      Seconds between pieces starting.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stagger-from
      </code>
    </td>
    
    <td>
      <code>
        'start' | 'center' | 'end' | 'edges' | 'random'
      </code>
    </td>
    
    <td>
      <code>
        'start'
      </code>
    </td>
    
    <td>
      Where the stagger starts.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        fold-angle
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        92
      </code>
    </td>
    
    <td>
      Angle, in degrees, a piece starts folded at. Flip always uses 180.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ease
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'power3.out'
      </code>
    </td>
    
    <td>
      GSAP-style ease name: <code>
        power1
      </code>
      
      –<code>
        power4
      </code>
      
      , <code>
        sine
      </code>
      
      , <code>
        expo
      </code>
      
      , <code>
        circ
      </code>
      
      , <code>
        back(n)
      </code>
      
      , <code>
        bounce
      </code>
      
       with <code>
        .in
      </code>
      
      , <code>
        .out
      </code>
      
       or <code>
        .inOut
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        perspective
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        700
      </code>
    </td>
    
    <td>
      Perspective distance in pixels.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        crease-shading
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0.55
      </code>
    </td>
    
    <td>
      Strength, 0 to 1, of the shadow along the crease while a piece is folded.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        trigger
      </code>
    </td>
    
    <td>
      <code>
        'mount' | 'hover' | 'scroll' | 'loop'
      </code>
    </td>
    
    <td>
      <code>
        'mount'
      </code>
    </td>
    
    <td>
      When the text unfolds. <code>
        scroll
      </code>
      
       plays once when the top reaches 82% of the viewport.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        loop-delay
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        1.4
      </code>
    </td>
    
    <td>
      Seconds the unfolded text holds before folding back up. Only for <code>
        loop
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hover-refold
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Pieces near the pointer fold partly back.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        refold-radius
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        140
      </code>
    </td>
    
    <td>
      Pointer reach, in pixels, of the refold.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        refold-angle
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        45
      </code>
    </td>
    
    <td>
      Largest refold angle, in degrees.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        font-size
      </code>
    </td>
    
    <td>
      <code>
        string | number
      </code>
    </td>
    
    <td>
      <code>
        80
      </code>
    </td>
    
    <td>
      Font size. Numbers are pixels.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        font-weight
      </code>
    </td>
    
    <td>
      <code>
        string | number
      </code>
    </td>
    
    <td>
      <code>
        800
      </code>
    </td>
    
    <td>
      Font weight.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'currentColor'
      </code>
    </td>
    
    <td>
      Text color.
    </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>

## Accessibility

- The full text sits in a visually hidden span. The folding pieces are `aria-hidden`, so screen readers read the words once.
- With reduced motion, pieces fade in quickly with no fold, no crease shading and no refold.
- Ported from [React Bits](https://reactbits.dev/text-animations/fold-text) by David Haz.
