PixelShake

Quick horizontal shake animation, ideal for validation errors or attention cues.

  • Configurable duration, distance, repeat count, and easing
  • Trigger on mount, hover, click, focus, in-view, or controlled boolean
  • Respects prefers-reduced-motion automatically
  • Signals the end of its last iteration: onComplete (React), @complete (Vue), (complete) (Angular)
Status
stable
Category
animations
Since
v1.6.0

API

import { PixelShake } from '@pxlkit/ui-kit';
PropTypeDefaultDescription
children (required)React.ReactNode—Content to shake.
durationnumber450Animation duration in milliseconds. Default 450.
distancenumber2Horizontal travel distance in pixels. Default 2.
repeatnumber | 'infinite'1Iteration count: a number or 'infinite'. Default 1.
easingstring'linear'CSS animation-timing-function. Default 'linear'.
trigger'mount' | 'hover' | 'click' | 'focus' | 'inView' | boolean'mount'When the animation should play. Default 'mount'.
onComplete() => void—Fires after the final iteration.
classNamestring—Extra class names applied to the wrapping <div>.

ref points to <div>.

Accessibility

WCAG target: 2.1 AA

  • respects prefers-reduced-motion

Animation is automatically disabled when the user has requested reduced motion.

Usage

import { PixelShake } from '@pxlkit/ui-kit';

export function Default() {
  return (
    <PixelShake>
      <span>Shake on mount</span>
    </PixelShake>
  );
}

Examples

Default

import { PixelShake } from '@pxlkit/ui-kit';

export function Default() {
  return (
    <PixelShake>
      <span>Shake on mount</span>
    </PixelShake>
  );
}

On Hover

import { PixelShake } from '@pxlkit/ui-kit';

export function OnHover() {
  return (
    <PixelShake trigger="hover" repeat="infinite" duration={300}>
      <span>Hover to shake</span>
    </PixelShake>
  );
}

Strong Shake

import { PixelShake } from '@pxlkit/ui-kit';

export function StrongShake() {
  return (
    <PixelShake distance={6} duration={600} repeat={3}>
      <span>Stronger shake</span>
    </PixelShake>
  );
}

Related