framer-motion
Version:
An open source and production-ready motion library for React on the web
167 lines (166 loc) • 4.08 kB
TypeScript
import { TargetAndTransition } from "../types";
import { Point2D } from "../types/geometry";
import { VariantLabels } from "../motion/types";
import { VisualElement } from "../render/types";
/**
* Passed in to tap event handlers like `onTap` the `TapInfo` object contains
* information about the tap gesture such as it‘s location.
*
* @library
*
* ```jsx
* function onTap(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <Frame onTap={onTap} />
* ```
*
* @motion
*
* ```jsx
* function onTap(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <motion.div onTap={onTap} />
* ```
*
* @public
*/
export interface TapInfo {
/**
* Contains `x` and `y` values for the tap gesture relative to the
* device or page.
*
* @library
*
* ```jsx
* function onTapStart(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <Frame onTapStart={onTapStart} />
* ```
*
* @motion
*
* ```jsx
* function onTapStart(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <motion.div onTapStart={onTapStart} />
* ```
*
* @public
*/
point: Point2D;
}
/**
* @public
*/
export interface TapHandlers {
/**
* Callback when the tap gesture successfully ends on this element.
*
* @library
*
* ```jsx
* function onTap(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <Frame onTap={onTap} />
* ```
*
* @motion
*
* ```jsx
* function onTap(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <motion.div onTap={onTap} />
* ```
*
* @param event - The originating pointer event.
* @param info - An {@link TapInfo} object containing `x` and `y` values for the `point` relative to the device or page.
*/
onTap?(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void;
/**
* Callback when the tap gesture starts on this element.
*
* @library
*
* ```jsx
* function onTapStart(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <Frame onTapStart={onTapStart} />
* ```
*
* @motion
*
* ```jsx
* function onTapStart(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <motion.div onTapStart={onTapStart} />
* ```
*
* @param event - The originating pointer event.
* @param info - An {@link TapInfo} object containing `x` and `y` values for the `point` relative to the device or page.
*/
onTapStart?(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void;
/**
* Callback when the tap gesture ends outside this element.
*
* @library
*
* ```jsx
* function onTapCancel(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <Frame onTapCancel={onTapCancel} />
* ```
*
* @motion
*
* ```jsx
* function onTapCancel(event, info) {
* console.log(info.point.x, info.point.y)
* }
*
* <motion.div onTapCancel={onTapCancel} />
* ```
*
* @param event - The originating pointer event.
* @param info - An {@link TapInfo} object containing `x` and `y` values for the `point` relative to the device or page.
*/
onTapCancel?(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void;
/**
* Properties or variant label to animate to while the component is pressed.
*
* @library
*
* ```jsx
* <Frame whileTap={{ scale: 0.8 }} />
* ```
*
* @motion
*
* ```jsx
* <motion.div whileTap={{ scale: 0.8 }} />
* ```
*/
whileTap?: VariantLabels | TargetAndTransition;
}
/**
* @param handlers -
* @internal
*/
export declare function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap }: TapHandlers, visualElement: VisualElement): void;