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

react-darkroom-tsn

v0.3.9

Published

HTML5 Image upload and edit React Component. Forked from https://github.com/MattMcFarland/react-darkroom.git. Published so deployments run properly.

Downloads

5

Readme

React-Darkroom component

See the live demo: http://blog.mmcfarland.net/react-darkroom/

Inspired by a jquery component called "Darkroom.JS" https://mattketmo.github.io/darkroomjs/

View example

Clone the github project first.

npm install && npm start

Usage

To use, install via npm first.

npm install react-darkroom --save

Once installed, you can access the different parts of react-darkroom as follows:

import { Darkroom, Canvas, History, Toolbar, FilePicker, CropMenu } from 'react-darkroom';

react-darkroom was built using composition, so it can be modified more easily. However this increases the amount of steps necessary to render the component.

A simple example:

Each component that comes with react-darkroom has some settings you can modify:

Canvas

If crop is set to false, then it will not show the crop handles, set crop to true to enable cropping.

source can either be file image or base64 data image.

angle is set to determine rotation of the image.

width and height are used to contrain proportions of an image to a specific rectangle

<Canvas crop={false} source="/myimage.png" angle=0 width=500 height=500>

History

History component uses step and length to determine where user is in history, and looks for children with action prop back or next - it also uses the ifEmpty tag to disable or hide the button if user is at beginning or end of history.

<History step={this.state.step} length={this.state.thread.length-1}>
  <button
    action="back"
    onClick={this.onUndo}
    data-ifEmpty="disable">

    Undo

  </button>
  <button
    action="forward"
    onClick={this.onRedo}
    data-ifEmpty="disable">

    Redo

  </button>
</History>

Toolbar

The toolbar goes over each child node and wraps them in a menu ul li tag

<Toolbar>
  <button id="foo"/>
  <button id="bar"/>
</Toolbar

translates to:

<menu class="darkroom-toolbar">
  <ul>
    <li key=0><button id="foo"/></li>
    <li key=0><button id="bar"/></li>
  </ul>
</menu>

FilePicker

Filepicker can be used to upload files, but not needed, it is used in the kitchensink demo.


<FilePicker hasFile={hasFile} onChange={this.onFileChange}/>

CropMenu

To add crop functionality, you can create a cropmenu, the buttons can be configured to showOnlyWhen a value of croppingIsOff or croppingIsOn. The CropMenu is entirely optional, and you can create your own composition for the crop menu if you choose.

    <CropMenu isCropping={crop}>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOff' onClick={this.onCropStart} data-tipsy="Crop" className="tipsy tipsy--sw">
        <span className="icon icon-crop"/>
      </button>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOn' style={{color: 'cyan'}}>
        <span className="icon icon-crop"/>
      </button>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOn' onClick={this.onCropConfirm} style={{color: 'green'}} data-tipsy="Confirm" className="tipsy tipsy--sw">
        <span className="icon icon-checkmark"/>
      </button>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOn' onClick={this.onCropCancel} style={{color: 'red'}} data-tipsy="Cancel" className="tipsy tipsy--sw">
        <span className="icon icon-cross"/>
      </button>
    </CropMenu>

Example Component


<Darkroom>
  <Toolbar>
    <button onClick={selectFile} data-tipsy="Select Image" className="tipsy tipsy--s">
      <span className="icon icon-image"/>
      <input type="file" ref="fileselect" onChange={this.onFileChange} style={{display: 'none'}}/>
    </button>
    <History step={this.state.step} length={this.state.thread.length-1}>
      <button
        action="back"
        onClick={this.onUndo}
        ifEmpty="disable"
        data-tipsy="Undo"
        className="tipsy tipsy--sw">
        <span className="icon icon-undo2"/>
      </button>
      <button
        action="forward"
        onClick={this.onRedo}
        ifEmpty="disable"
        data-tipsy="Redo"
        className="tipsy tipsy--sw">
        <span className="icon icon-redo2"/>
      </button>
    </History>
    <button disabled={!hasFile} onClick={this.onRotateLeft} data-tipsy="Rotate Left" className="tipsy tipsy--sw">
      <span className="icon icon-undo"/>
    </button>
    <button disabled={!hasFile} onClick={this.onRotateRight} data-tipsy="Rotate Right" className="tipsy tipsy--sw">
      <span className="icon icon-redo"/>
    </button>
    <CropMenu isCropping={crop}>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOff' onClick={this.onCropStart} data-tipsy="Crop" className="tipsy tipsy--sw">
        <span className="icon icon-crop"/>
      </button>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOn' style={{color: 'cyan'}}>
        <span className="icon icon-crop"/>
      </button>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOn' onClick={this.onCropConfirm} style={{color: 'green'}} data-tipsy="Confirm" className="tipsy tipsy--sw">
        <span className="icon icon-checkmark"/>
      </button>
      <button disabled={!hasFile} data-showOnlyWhen='croppingIsOn' onClick={this.onCropCancel} style={{color: 'red'}} data-tipsy="Cancel" className="tipsy tipsy--sw">
        <span className="icon icon-cross"/>
      </button>
    </CropMenu>
    <button disabled={!hasFile} onClick={this.onSave} data-tipsy="Save" className="tipsy tipsy--sw">
      <span className="icon icon-floppy-disk"/>
    </button>
  </Toolbar>
  <Canvas ref="canvasWrapper" crop={crop} source={source} angle={angle} width={canvasWidth} height={canvasHeight}>
    <FilePicker hasFile={hasFile} onChange={this.onFileChange}/>
  </Canvas>
</Darkroom>

State

Component state is managed by you, and each of the different sub-components that react-component comes with are considered "dumb" components, so you have to explicitly define and update each component.

Changelog

0.3

  • Remove gulp
  • Reduce Dependency amount
  • Update all dependencies to latest.
  • Implement CI system

0.2.0-2

  • Expose utils to components list
  • Update build pipeline to transpile es6 to es5
  • add example to cloud9 ide