1.0.1 • Published 7 months ago

react-simple-image-preview-1 v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

ImagePreview and ImagePreviewGroup Components

The ImagePreview and ImagePreviewGroup are fully customizable React components for rendering and previewing images. They allow users to view images with features like zooming, rotating, and navigation through grouped images. These components also support dynamic styling and class customization.


Installation

To use these components, copy the ImagePreview and ImagePreviewGroup code into your project or install them from your published package if available.


Components

1. ImagePreview

ImagePreview allows a single image to be displayed with optional features like zooming, rotating, and a full-screen preview.

Basic Example

import React from 'react';
import { ImagePreview } from 'react-simple-image-preview';

const App: React.FC = () => {
  return (
    <div>
      <h1>Image Preview Example</h1>
      <ImagePreview
        src="https://via.placeholder.com/300"
        alt="Sample Image"
        width={300}
        height={200}
      />
    </div>
  );
};

export default App;

2. ImagePreviewGroup

ImagePreviewGroup enables grouping multiple ImagePreview components to provide navigation between them.

Basic Example

import React from 'react';
import { ImagePreviewGroup, ImagePreview } from 'react-simple-image-preview';

const App: React.FC = () => {
  return (
    <div>
      <h1>Image Preview Group Example</h1>
      <ImagePreviewGroup>
        <ImagePreview
          src="https://via.placeholder.com/300"
          alt="Image 1"
          width={300}
          height={200}
        />
        <ImagePreview
          src="https://via.placeholder.com/400"
          alt="Image 2"
          width={300}
          height={200}
        />
        <ImagePreview
          src="https://via.placeholder.com/500"
          alt="Image 3"
          width={300}
          height={200}
        />
      </ImagePreviewGroup>
    </div>
  );
};

export default App;

Advanced Customization

Using Custom Styles, Classes, and Icons

You can pass your own styles, classes, or icons to the images for better control over their appearance.

Example

<ImagePreview
  src="https://via.placeholder.com/300"
  alt="Custom Styled Image"
  width={300}
  height={200}
  style={{
    objectFit: 'cover',
    borderRadius: '8px',
  }}
  className="custom-image-class"
  icon={<MyCustomIcon />}
  iconPosition="topLeft"
  onIconClick={() => alert('Icon clicked!')}
/>

Props

ImagePreview Props

Prop NameTypeDefaultDescription
srcstringundefinedThe source URL of the image.
altstringundefinedAlternative text for the image.
widthnumberundefinedThe width of the image (in pixels).
heightnumberundefinedThe height of the image (in pixels).
previewbooleantrueEnables the preview functionality.
onClickfunctionundefinedCustom callback when the image is clicked.
styleCSSProperties{}Inline styles for the container.
classNamestring''Custom class name for the container.
imgStyleCSSProperties{}Inline styles for the image.
imgClassNamestring''Custom class name for the image.
modalStyleCSSProperties{}Inline styles for the modal.
modalClassNamestring''Custom class name for the modal.
iconReactNodeundefinedIcon to display on the image.
iconPosition'topLeft' \| 'topRight' \| 'bottomLeft' \| 'bottomRight''topRight'Position of the icon.
onIconClickfunctionundefinedCallback when the icon is clicked.

ImagePreviewGroup Props

Prop NameTypeDefaultDescription
childrenReactNodeundefinedImagePreview components to include in the group.
onChangefunctionundefinedCallback when the current image changes in the group.
gapstring'16px'Spacing between grouped images.

Features

  • Zoom and Rotate: Easily zoom in/out or rotate images with intuitive controls.
  • Group Navigation: Navigate between grouped images using ImagePreviewGroup.
  • Dynamic Styling: Fully customizable styles, classes, and inline properties for images and modals.
  • Icons and Actions: Add interactive icons to images and respond to icon clicks with custom callbacks.
  • Lightweight Modal: Images open in an interactive modal for full-screen viewing.
  • Accessibility: Includes ARIA attributes for screen readers and is keyboard-friendly.

Accessibility

These components are designed with accessibility in mind. They include ARIA attributes and ensure a seamless user experience for screen readers.


Contributing

Contributions are welcome! If you find bugs or have feature requests, feel free to open an issue or submit a pull request to the GitHub repository.


License

This component library is open-source and freely available for use.


Enjoy using the ImagePreview and ImagePreviewGroup components! Let us know if you have any feedback or improvements to suggest.

1.0.1

7 months ago