Swiperia
Reference

Types

Vector2, SwipeDirection, SwipeConfig and SwipeCallback.

Every type is exported from swiperia-core and re-exported where it is used, so you can import it from whichever package you already depend on.

Vector2

A point or a per-axis pair, as a tuple.

type Vector2 = [number, number];

Used for coordinates (source, target) and for per-axis velocity (vxvy).

SwipeDirection

type SwipeDirection = 'right' | 'left' | 'up' | 'down';

Where a gesture is reported as null rather than a direction, the two points were identical.

SwipeConfig

type SwipeConfig = {
  threshold?: number; // default 10 (px)
  allowedTime?: number; // default 300 (ms)
};

See configuration for how the two are applied.

SwipeCallback

type SwipeCallback = (event: SwipeEvent) => void;

The function passed to listen(), and the type behind every React callback prop.

import type { SwipeCallback } from 'swiperia-core';

const handle: SwipeCallback = (event) => {
  if (event.type === 'end') console.log(event.direction);
};

React types

swiperia-react adds two interfaces for grouping callbacks:

TypeDescription
SwiperiaDirectionCallbacksThe four direction callbacks only.
SwiperiaCallbacksThe direction callbacks plus start, swiping, swiped and cancelled.
SwipeAreaPropsSwiperiaCallbacks plus the props of a div.
UseSwiperiaArgsSwiperiaCallbacks plus config.

On this page