@blazediff/react
React components for high-performance image comparison. Built with TypeScript and optimized for modern React applications.
Installation
npm install @blazediff/react
Features
- React 16.8+ compatible: Works with hooks and modern React features
- TypeScript first: Full type safety and IntelliSense
- Web Components based: Wraps @blazediff/ui components for React
- Performance focused: Built on top of high-performance web components
- Accessible: Proper event handling and React patterns
Quick Start
import { SwipeMode } from '@blazediff/react';
function App() {
return (
<SwipeMode
src1="/before.jpg"
src2="/after.jpg"
onPositionChange={(position) => console.log(position)}
/>
);
}
API Reference
<SwipeMode />
Interactive swipe component for comparing two images with a draggable divider.
Props
Prop | Type | Default | Description |
---|---|---|---|
src1 | string (required) | - | URL of the first image |
src2 | string (required) | - | URL of the second image |
alt1 | string | - | Alt text for the first image |
alt2 | string | - | Alt text for the second image |
className | string | - | CSS class for the root element |
containerClassName | string | - | CSS class for the container |
image1ClassName | string | - | CSS class for the first image |
image2ClassName | string | - | CSS class for the second image |
dividerClassName | string | - | CSS class for the divider |
onPositionChange | (position: number) => void | - | Callback when divider position changes |
<TwoUpMode />
Side-by-side comparison component with dimension information.
Props
Prop | Type | Default | Description |
---|---|---|---|
src1 | string (required) | - | URL of the first image |
src2 | string (required) | - | URL of the second image |
className | string | - | CSS class for the root element |
containerClassName | string | - | CSS class for the main container |
containerInnerClassName | string | - | CSS class for the inner container |
panelClassName | string | - | CSS class for each panel |
imageClassName | string | - | CSS class for images |
dimensionInfoClassName | string | - | CSS class for dimension info text |
onImagesLoaded | (detail: {image1: {width, height}, image2: {width, height}}) => void | - | Callback when images load |
onLoadError | (error: unknown) => void | - | Callback when loading fails |
<OnionSkinMode />
Overlay comparison with opacity control slider.
Props
Prop | Type | Default | Description |
---|---|---|---|
src1 | string (required) | - | URL of the base image |
src2 | string (required) | - | URL of the overlay image |
opacity | number | - | Initial opacity (0-100) |
className | string | - | CSS class for the root element |
containerClassName | string | - | CSS class for the main container |
imageContainerClassName | string | - | CSS class for image container |
imageClassName | string | - | CSS class for images |
sliderContainerClassName | string | - | CSS class for slider container |
sliderClassName | string | - | CSS class for the slider |
sliderLabelClassName | string | - | CSS class for slider label |
sliderLabelText | string | - | Text for the slider label |
onOpacityChange | (opacity: number) => void | - | Callback when opacity changes |
onImagesLoaded | (detail: {image1: {width, height}, image2: {width, height}}) => void | - | Callback when images load |
onLoadError | (error: unknown) => void | - | Callback when loading fails |
<DifferenceMode />
Shows pixel differences using the BlazeDiff comparison algorithm.
Props
Prop | Type | Default | Description |
---|---|---|---|
src1 | string (required) | - | URL of the first image |
src2 | string (required) | - | URL of the second image |
threshold | number | - | Difference threshold (0-1) |
includeAA | boolean | - | Include anti-aliased pixels |
alpha | number | - | Opacity of original image |
className | string | - | CSS class for the root element |
containerClassName | string | - | CSS class for the container |
canvasClassName | string | - | CSS class for the canvas |
onDiffComplete | (detail: {diffCount, totalPixels, percentage}) => void | - | Callback on completion |
onDiffError | (error: unknown) => void | - | Callback on error |
Links
Last updated on