Kinetic UI
Back to Introduction
Layout

Physics Canvas

A whiteboard wrapper that brings real 2D physics to standard DOM elements.

Quick Actions
CLI Installation
npx kinetic-ui-cli@latest add physics-canvas

The PhysicsCanvas uses the matter.js engine to turn a standard web layout into a physical sandbox. By wrapping your elements in a PhysicsItem, they are automatically registered as rigid bodies with real mass, friction, and bounce.

Users can grab, drag, and throw these DOM elements around the screen naturally, and they will collide with each other and the invisible boundaries of the canvas.

Live Preview

Physics Canvas

Installation

npx kinetic-ui-cli@latest add physics-canvas

[!TIP] Pointer Events: If your PhysicsItem contains images or text that might interfere with the dragging action, make sure to add className="pointer-events-none" to those child elements so the drag event registers cleanly on the wrapper!

Usage Guide

1. Import the Component

Import the component into your React or Next.js page:

import { PhysicsCanvas } from "@/components/creative/physics-canvas";

2. Implementation Example

Render the component and customize its behavior by passing props:

import { PhysicsCanvas } from "@/components/creative/physics-canvas";

export default function Example() {
  return (
    <div className="w-full flex items-center justify-center p-8">
      <PhysicsCanvas
        frictionAir{10}
        gravity{10}
      >
        <div>Content goes here</div>
      </PhysicsCanvas>
    </div>
  );
}
Performance Notes
  • Uses CSS hardware acceleration via GPU transform-binds.
  • Damped interpolation minimizes paint-redraw flashes.
  • Tree-shakable import: only compiles elements requested.
Accessibility Notes
  • Full keyboard focus-ring navigation support (`Tab`/`Shift+Tab`).
  • ARIA roles mapped correctly for assistive screen readers.
  • Respects `prefers-reduced-motion` system toggles.