0.3.0 • Published 3 years ago

antd-react-cropper v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

antd-react-cropper

Image cropper using Ant Design and React Cropper

npm npm npm bundle size

Demo

Edit antd-img-crop

Install

yarn add antd-react-cropper

Usage

import React, { useState } from 'react';
import { Upload } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import ImageCropper from 'antd-react-cropper';
import { UploadFile } from 'antd/lib/upload/interface';
import 'antd/dist/antd.css';

const ImageUploadInput = () => {
  const [fileList, setFileList] = useState<UploadFile[]>([]);
  const [file, setFile] = useState<UploadFile>();

  return (
    <>
      <Upload
        multiple={false}
        listType="picture-card"
        accept="image/*"
        showUploadList={{ showPreviewIcon: false }}
        fileList={fileList}
        beforeUpload={() => false}
        onChange={(info) => {
          if (info.fileList.length <= 0) {
            setFileList(info.fileList);
            return;
          }
          const file = info.fileList[info.fileList.length - 1];
          setFile(file);
        }}
      >
        <div>
          <PlusOutlined />
          <div style={{ marginTop: 8 }}>Upload</div>
        </div>
      </Upload>
      {file && (
        <ImageCropper
          file={file}
          aspect={16 / 9}
          onCropped={(file) => {
            setFileList([file]);
          }}
        />
      )}
    </>
  );
};

Props

PropsTypeDefaultDescription
fileUploadFile-antd/lib/upload/UploadFile
aspectnumber-16 / 9
cropperStyleReact.CSSProperties--
cropperClassNamestring--
cropTextstringCrop-
cancelTextstringCancel-
onCropped(file: UploadFile) => void--
onCancel() => void--
previewMaxHeightnumber150-
previewBackgroundstringrgba(212, 212, 216)-
previewClassNamestring--
previewStyleReact.CSSProperties--
titleReact.ReactNode-AntD Modal props
zIndexnumber-AntD Modal props
centeredboolean-AntD Modal props
closableboolean-AntD Modal props
maskClosableboolean-AntD Modal props
widthnumber500AntD Modal props
bodyStyleReact.CSSProperties-AntD Modal props
zoomInButton(onZoom) => React.ReactNode-Custom zoom in button
zoomOutButton(onZoom) => React.ReactNode-Custom zoom out button
rotateLeftButton(onRotate) => React.ReactNode-Custom rotate left button
rotateRightButton(onRotate) => React.ReactNode-Custom rotate right button
customFooter({ onCrop, onCancel }) => React.ReactNode-Custom modal footer
showLoaderbooleantrueshow antd Message.loading
exportFileTypestringimage/jpegCropped image file type
0.3.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago