Use Press

PreviousNext

The use-press hook.

Docs
animbitslib

Preview

Loading preview…
lib/use-press.ts
import { type MotionProps, type Easing } from "motion/react";

export interface UsePressOptions {
  pressScale?: number;

  duration?: number;

  ease?: Easing | Easing[];

  addRotation?: boolean;

  rotationAmount?: number;
}

export function usePress(options: UsePressOptions = {}): MotionProps {
  const {
    pressScale = 0.95,
    duration = 0.1,
    ease = "easeInOut",
    addRotation = false,
    rotationAmount = 2,
  } = options;

  return {
    whileTap: {
      scale: pressScale,
      rotate: addRotation ? rotationAmount : 0,
    },
    transition: {
      duration,
      ease,
    },
  };
}

Installation

npx shadcn@latest add @animbits/hooks-use-press

Usage

import { HooksUsePress } from "@/lib/hooks-use-press"
HooksUsePress()