# File Box

A cardboard file box holding five colourful folders, drawn as one SVG in an oblique projection. Hover or focus a folder and it is pulled up by its tab, leaning a little toward that side. Its front flap falls open a beat later, the three sheets inside trail behind on looser springs, and the neighbouring folders give way. Click it, or press Enter or Space, to tug it up past the hover height. The scene tilts a few degrees with the pointer and the shadow answers it. On a theme change every face and folder cross-fades and the box settles under the new light.

<demo-file-box>



</demo-file-box>

## Installation

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

## Usage

```vue
<script setup lang="ts">
  import { computed } from 'vue';
  import FileBox from '~/components/ui/file-box/FileBox.vue';
  import type { FileBoxPull } from '~/components/ui/file-box/types';

  const colorMode = useColorMode();
  const theme = computed(() => (colorMode.value === 'dark' ? 'dark' : 'light'));

  function onPull(folder: FileBoxPull) {
    console.log(folder.color, folder.position);
  }
</script>

<template>
  <div class="h-100 w-full">
    <FileBox fill :theme="theme" @pull="onPull" />
  </div>
</template>
```

Without `fill` the box is a square that takes the full width of its parent. With `fill` it fills the parent edge to edge, and the scene centres in the largest square that fits.

## Props

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

<tbody>
  <tr>
    <td>
      <code>
        theme
      </code>
    </td>
    
    <td>
      <code>
        'light' | 'dark'
      </code>
    </td>
    
    <td>
      <code>
        'light'
      </code>
    </td>
    
    <td>
      Colour theme. Pass your site's colour mode.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        fill
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Fill the parent edge to edge instead of keeping a square.
    </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>
        pull
      </code>
    </td>
    
    <td>
      <code>
        (folder: FileBoxPull)
      </code>
    </td>
    
    <td>
      Fires when a folder is tugged, with its <code>
        color
      </code>
      
       and its <code>
        position
      </code>
      
       counted from the front (1–5).
    </td>
  </tr>
</tbody>
</table>

## Exposed methods

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Signature
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        hover
      </code>
    </td>
    
    <td>
      <code>
        (position: number | null) => void
      </code>
    </td>
    
    <td>
      Lift the folder at <code>
        position
      </code>
      
       (1 = front), or drop them all.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pull
      </code>
    </td>
    
    <td>
      <code>
        (position: number) => void
      </code>
    </td>
    
    <td>
      Tug the folder at <code>
        position
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        release
      </code>
    </td>
    
    <td>
      <code>
        () => void
      </code>
    </td>
    
    <td>
      Drop a folder lifted through <code>
        hover
      </code>
      
      . A real hover is left alone.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        replay
      </code>
    </td>
    
    <td>
      <code>
        () => void
      </code>
    </td>
    
    <td>
      Play the intro again.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- Each folder is a focusable `role="button"` with a label such as "Pull out the pink folder, middle from the front". Tab moves through the folders from back to front.
- Focus lifts a folder exactly like hover. Enter or Space tugs it. A dashed focus ring outlines the focused folder.
- Press R while a folder has focus to replay the intro.
- The SVG is a labelled `role="group"`. The paper grain is hidden from assistive tech.
- With reduced motion the folders move without springs, the tug and the pointer tilt are off, and the intro is skipped.

Ported from [File Box](https://pinui.xyz/components/file-box) by Pin UI, MIT licence.
