# Taxi

A taxi-hailing card that runs the whole ride from one tap. Tap **Taxi!** to hail: the panel narrows and goo bubbles along its edge while it searches, then a driver is found and the ETA counts down from 4 min as the car dot slides along the track. Tap **Get in** when the cab arrives, watch the ride count down from 12 min, then rate it with the stars. The glyph in the corner morphs point for point between a waving person, the cab and a check. Tap the panel while it searches or while the cab is on its way to cancel.

<demo-taxi>



</demo-taxi>

## Installation

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

## Usage

```vue
<script setup lang="ts">
  import { computed } from 'vue';
  import Taxi from '~/components/ui/taxi/Taxi.vue';
  import type { TaxiStateName } from '~/components/ui/taxi/types';

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

  function onRate(stars: number) {
    console.log('rated', stars);
  }

  function onState(state: TaxiStateName) {
    console.log('now', state);
  }
</script>

<template>
  <Taxi
    :width="300"
    :theme="theme"
    sound-base="/sounds/taxi"
    @rate="onRate"
    @state="onState"
  />
</template>
```

A ride moves through `idle` → `searching` → `enroute` → `arrived` → `riding` → `done` → `thanks` and back to `idle`. Searching, the countdowns and the thank-you advance on their own; the taps and the rating move it on. The component also exposes `tap()` and `rate(stars)` through a template ref, so a host can drive a ride.

## Props

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

<tbody>
  <tr>
    <td>
      <code>
        width
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        300
      </code>
    </td>
    
    <td>
      Card width in px. It narrows further on a small screen; everything scales with it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        theme
      </code>
    </td>
    
    <td>
      <code>
        'light' | 'dark'
      </code>
    </td>
    
    <td>
      <code>
        'light'
      </code>
    </td>
    
    <td>
      <code>
        light
      </code>
      
       is ink on a yellow cab. <code>
        dark
      </code>
      
       turns the card to night with the glyph and panel lit in cab yellow. Pass your site's colour mode.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sound
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Plays the ride's cues when <code>
        sound-base
      </code>
      
       points at them. Toggling it mutes or unmutes without restarting the ride.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sound-base
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Folder with the cue files <code>
        tap
      </code>
      
      , <code>
        open
      </code>
      
      , <code>
        cancel
      </code>
      
      , <code>
        ping
      </code>
      
      , <code>
        found
      </code>
      
      , <code>
        tick
      </code>
      
      , <code>
        horn
      </code>
      
      , <code>
        door
      </code>
      
      , <code>
        engine
      </code>
      
      , <code>
        done
      </code>
      
      , <code>
        star
      </code>
      
       and <code>
        thanks
      </code>
      
       (all <code>
        .wav
      </code>
      
      ). Empty means silent.
    </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>
        rate
      </code>
    </td>
    
    <td>
      <code>
        (stars: number)
      </code>
    </td>
    
    <td>
      Fires once a finished ride has been rated.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        state
      </code>
    </td>
    
    <td>
      <code>
        (state: TaxiStateName)
      </code>
    </td>
    
    <td>
      Fires each time the ride moves to a new state.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The panel is one `button` whose `aria-label` follows the ride (for example "Taxi on the way. Tap to cancel"). It is disabled while riding and once the ride is done, when there is nothing to press.
- The status line and the three detail lines are `aria-live="polite"`, so each change of state is announced.
- The rating is a `role="group"` labelled "Rate your ride" of five 44px buttons labelled "1 star" to "5 stars", with `aria-pressed` set on the stars given.
- Focus rings are visible on the panel and on each star.
- With reduced motion the entrance, the letter rolls, the glyph morph, the goo, the wave and the bob are skipped; states switch instantly and the track still fills.

Ported from [Taxi](https://pinui.xyz/components/taxi) by Pin UI, MIT licence.
