1.0.8 • Published 11 months ago

@daveyplate/nextui-crop-image-modal v1.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

@daveyplate/nextui-crop-image-modal

Shows a modal to crop an image.

Installation

You can install the package via npm:

npm install @daveyplate/nextui-crop-image-modal

Basic Usage

Here is an example of how to use the

CropImageModal

component in your React application:

import React, { useState } from 'react';
import CropImageModal from '@daveyplate/nextui-crop-image-modal';

function App() {
  const [imageFile, setImageFile] = useState(null);
  const [croppedImage, setCroppedImage] = useState(null);

  const handleFileChange = (event) => {
    setImageFile(event.target.files[0]);
  };

  const handleConfirm = (file) => {
    setCroppedImage(file);
    setImageFile(null);
  };

  const handleError = (error) => {
    console.error(error);
    setImageFile(null);
  };

  return (
    <div>
      <input type="file" onChange={handleFileChange} />
      {imageFile && (
        <CropImageModal
          imageFile={imageFile}
          setImageFile={setImageFile}
          imageSize={{ width: 300, height: 300 }}
          onConfirm={handleConfirm}
          onError={handleError}
        />
      )}
      {croppedImage && <img src={URL.createObjectURL(croppedImage)} alt="Cropped" />}
    </div>
  );
}

export default App;

Localization

You can customize the text displayed in the modal by providing a

localization

prop to the

CropImageModal

component. The

localization

prop should be an object with the following structure:

/**
 * @typedef {Object} CropModalLocalization
 * @property {string} [header="Crop Image"] - The header text of the modal
 * @property {string} [cancel="Cancel"] - The text of the cancel button
 * @property {string} [confirm="Confirm"] - The text of the confirm button
 */

const localization = {
  header: "Recortar Imagen",
  cancel: "Cancelar",
  confirm: "Confirmar"
};

Example usage with localization:

<CropImageModal
  imageFile={imageFile}
  setImageFile={setImageFile}
  imageSize={{ width: 300, height: 300 }}
  onConfirm={handleConfirm}
  onError={handleError}
  localization={localization}
/>

For more details, please refer to the documentation.

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago