npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lahzenegar/react-drop-n-crop

v0.4.6

Published

A combined implementation of react-dropzone and react-cropper (translated to farsi)

Downloads

15

Readme

@synapsestudios/react-drop-n-crop

A combined implementation of react-dropzone and react-cropper (Cropper.js) for front-end image upload/validation/cropping.

npm version react-drop-n-crop dependencies react-drop-n-crop peer dependencies

Demo

A demo is available at https://synapsestudios.github.io/react-drop-n-crop/

Usage

Installing via CLI

// yarn
yarn add @synapsestudios/react-drop-n-crop

// npm
npm install --save @synapsestudios/react-drop-n-crop

Importing JS

import DropNCrop from '@synapsestudios/react-drop-n-crop';

Importing CSS

// Minified, autoprefixed css
import '@synapsestudios/react-drop-n-crop/lib/react-drop-n-crop.min.css';

// Not-minified, not-autoprefixed css
import '@synapsestudios/react-drop-n-crop/lib/react-drop-n-crop.css';

Using Stylus

If you are using Stylus you can import the .styl file into your build:

@import '@synapsestudios/react-drop-n-crop/lib/react-drop-n-crop.styl';

! See the Stylus Variables section below for variables/details.

Using with an ES6 Class and React Component State

import React, { Component } from 'react';
import DropNCrop from '@synapsestudios/react-drop-n-crop';
import '@synapsestudios/react-drop-n-crop/lib/react-drop-n-crop.min.css';

class SetStateExample extends Component {
  state = {
    result: null,
    filename: null,
    filetype: null,
    src: null,
    error: null,
  };

  onChange = value => {
    this.setState(value);
  };

  render() {
    return <DropNCrop onChange={this.onChange} value={this.state} />;
  }
}

export default SetStateExample;

API

Required Props

DropNCrop is built as a controlled component. The following props must be supplied to the component:

onChange: (required)

onChange is the callback function invoked when an image is dropped or cropped. onChange returns an object (in the shape of value below).

onChange: PropTypes.func.isRequired,

value: (required)

value is the object passed back from the onChange function. It must be in the following shape:

value: PropTypes.shape({
  result: PropTypes.string, // Resulting DataURL from Cropper.js crop box
  filename: PropTypes.string, // Original filename from uploaded file
  filetype: PropTypes.string, // Original MIME type from uploaded file
  src: PropTypes.string, // Original DataURL from the FileReader.result
  error: PropTypes.string, // Error returned from fileSize/fileType validators
}).isRequired,

Optional Props

canvasHeight:

canvasHeight is a string for the container inline style height property.

canvasHeight: PropTypes.string, // default: '360px'

canvasWidth:

canvasWidth is a string for the container inline style width property.

canvasWidth: PropTypes.string, // default: '100%'

className:

className is a string for the outermost container class name.

className: PropTypes.string, // default: ''

cropperOptions:

cropperOptions is an object for customizing the cropper component. Lists of available options can be found here: https://github.com/roadmanfong/react-cropper

cropperOptions: PropTypes.object, // default: {guides: true, viewMode: 0, autoCropArea: 1}

maxFileSize:

maxFileSize is a maximum number (in bytes) for file upload validation.

maxFileSize: PropTypes.object, // default: 3145728

allowedFileTypes:

allowedFileTypes is an array (of strings) of valid MIME types for file upload validation.

allowedFileTypes: PropTypes.array, // default: ['image/jpeg', 'image/jpg', 'image/png']

Stylus Variables

react-drop-n-crop comes with a set of stylus variables that can be overridden to add your own project-specific theming, as shown below:

/* Theming by overriding default stylus variables with your projects colors */

$drop-n-crop--primary-color = $your-project-primary-color;
$drop-n-crop--error-color = $your-project-error-color;

$drop-n-crop--body-color = $your-project-body-color;
$drop-n-crop--heading-color = $your-project-heading-color;

$drop-n-crop--input-background-color = $your-project-background-color;
$drop-n-crop--input-border-color = $your-project-border-color;

@import '@synapsestudios.com/react-drop-n-crop/css/react-drop-n-crop.styl';

Contributing

To run the project on your own computer:

  • Clone this repository
  • yarn install or npm install
  • yarn run storybook or npm run storybook
  • Visit http://localhost:5000/
  • Changes made to files in the src directory should immediately compile and be visible in your browser.