Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-avatar-edit

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-avatar-edit

ReactJS component to upload, crop, and preview avatars

  • 0.5.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.6K
increased by1.93%
Maintainers
1
Weekly downloads
 
Created
Source

react-avatar

👤 Load, crop and preview avatar with ReactJS component

npm version

Demo

Demo website

Usage

import React from 'react'
import ReactDOM from 'react-dom'
import Avatar from 'react-avatar-edit'

class App extends React.Component {

  constructor(props) {
    super(props)
    const src = './example/einshtein.jpg'
    this.state = {
      preview: null,
      src
    }
    this.onCrop = this.onCrop.bind(this)
    this.onClose = this.onClose.bind(this)
  }
  
  onClose() {
    this.setState({preview: null})
  }
  
  onCrop(preview) {
    this.setState({preview})
  }
  
  render () {
    return (
      <div>
        <Avatar
          width={390}
          height={295}
          onCrop={this.onCrop}
          onClose={this.onClose}
          src={this.state.src}
        />
        <img src={this.state.preview} alt="Preview" />
      </div>
    )
  }
}

ReactDOM.render(<App /> , document.getElementById('root'))

Component properties

PropTypeDescription
imgImageThe Image object to display
srcString/Base64The url ot base64 string to load (use urls from your domain to prevent security errors)
widthNumberThe width of the editor
heightNumberThe height of the editor (image will fit to this height)
cropRadiusNumberThe crop area radius in px (default: 100)
cropColorStringThe crop border color (default: white)
lineWidthNumberThe crop border width (default: 4)
minCropRadiusNumberThe min crop area radius in px (default: 30)
backgroundColorStingThe color of the image background (default: white)
closeIconColorStringThe close button color (default: white)
shadingColorStringThe shading color (default: grey)
shadingOpacityNumberThe shading area opacity (default: 0.6)
mimeTypesStringThe mime types used to filter loaded files (default: image/jpeg,image/png)
onImageLoad(image)FunctionInvoked when image based on src prop finish loading
onCrop(image)FunctionInvoked when user drag&drop event stop and return croped image in base64 sting
onFileLoad(file)FunctionInvoked when user upload file with internal file loader
onClose()FunctionInvoked when user clock on close editor button

Contributing

  • To start developer server please use npm run start
  • To build production bundle use npm run build

Keywords

FAQs

Package last updated on 28 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc