Code Monkey home page Code Monkey logo

react-colorpickr's Introduction

A colorpicker for React

npm version Build Status

Demo

Install

npm install @mapbox/react-colorpickr

You'll also want to include a copy of colorpickr.css in your code.

<link href='react-colorpickr.css' rel='stylesheet' />

Usage

import React from 'react'
import ColorPicker from '@mapbox/react-colorpickr'

function Example() {
  return (
    <ColorPicker onChange={console.log} />
  )
}

Required properties

onChange (color) => void

Value should be a function and is called whenever a color is updated from the colorpicker. Returns a color object.

Optional properties

theme Object<[key: string]: string>

By default, react-colorpickr depends on Assembly and the CSS located in dist/colorpickr.css. You can however, override it thanks to react-themeable which react-colorpickr uses internally. See the properties used and the class name values in theme.ts.

initialValue string

Accepts any valid css color. If this isn't provided, a default color is used.

colorSpace 'hsl' | 'rgb' | 'hex'

Initializes what should be displaed in the bottom color input. Defaults to hex.

mode 'disc' | 'values'

Initializes which view tab is active. Defaults to disc.

eyedropper boolean

When true, an eyedropper is added to the top-right of the interface. Defaults to true.

reset boolean

When true, a reset button is added that when pressed, reverts to the initialized color. Defaults to true.

alpha boolean

When true, a alpha range slider and input is provided. Defatuls to true.

mounted (ColorPickr) => void

To use internal methods from react-colorpickr, mounted provides access to the components instance. This is helpful for calling methods like overrideValue that can manually set a new color.

const [instance, setInstance] = useState(null);

const override = () => {
  instance.overrideValue('red');
};

render() {
  <>
    <ColorPickr mounted={picker => setInstance(picker)} onChange={console.log} />
    <button onClick={override}>Override</button>
  </>
}

discRadius number

Optional property to provide a different disc radius for selection. Helpful if you are re-themeing the interface. Defaults to 18.

readOnly boolean

If true the colorpicker will render in a readonly state with values clearly shown and selectable, but not editable. Defaults to false.

Developing

npm install & npm start

Then open http://localhost:9966 in browser.

react-colorpickr's People

Contributors

alexanderbelokon avatar andrewharvey avatar cherniavskii avatar conorhastings avatar dafrok avatar davidtheclark avatar dependabot[bot] avatar frankrowe avatar kelvinabrokwa avatar kepta avatar kungfoolabs avatar lacymorrow avatar mcwhittemore avatar pferraris avatar rfoel avatar samanpwbb avatar scothis avatar tmcw avatar tristen avatar vluisa avatar waldyrious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-colorpickr's Issues

Adding "show" props

Wondering if there would be support for adding "show props" here. For example application that does not support alpha transparency can pass in prop to not show the alpha picker, etc... Thanks!

could not complier

react-colorpickr/index.js Line 206: Unexpected token <
You may need an appropriate loader to handle this file type.

return (
/* jshint ignore:start */
<div className='colorpickr' onClick={this._onClick}>
<div className='colorpickr-body'>
<div className='col'>

.babelrc causes issues in other projects

Seeing this error when trying to require the 4.x.x versions of react-colorpickr. My app is using browserify with babelify.

ReferenceError: [BABEL] /Users/saman/work_repos/maki-icons/node_modules/react-colorpickr/dist/colorpickr.js: Unknown option: /Users/saman/work_repos/maki-icons/node_modules/react-colorpickr/.babelrc.presets while parsing file: /Users/saman/work_repos/maki-icons/node_modules/react-colorpickr/dist/colorpickr.js

https://github.com/mapbox/react-colorpickr/blob/mb-pages/.babelrc

If I add the following:

[
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-preset-stage-0": "^6.3.13",
]

as devDependencies in my project, the problem goes away, but that shouldn't' be required to use the colorpickr.

switch to csscolorparser

If we use csscolorparser, react-colorpickr will reuse the application's existing csscolorparser dependency instead of including color-parser alongside it

Display reset color instead of button

Currently if the reset button is enabled, it jumps back to the previous color before.

But it might be more useful if this were a swatch of the original color to measure contrast alongside a changed one:

color-reset

Clicking on the original swatch would reset things. Thoughts @ajashton @nickidlugash ?

Errors when updating color

One thing to notice is that rgb colors and hsv colors are not 1-1 mapping, so hsv -> rgb -> hsv may not return the original hsv value. Thats why i check whether the color should be updated, which seems not quite elegant.

Drag events are generally "sticky" and unreliable

Using Chrome 45 on Ubuntu.

Examples:

  • No matter what I do I can't drag the white circle all the way to the left or bottom of the square. It always gets stuck at a saturation or value of about 1-30.
  • The hue slider will get stuck at 345 or 350 and I can't drag it any further to the right
  • If I'm dragging the hue slider and my cursor leaves the very narrow rainbow track, the slider gets stuck in drag mode and will follow my cursor even after mouseup. I have to click again on the hue slider to stop it.

Provide ES5 version

Is it possible to provide ES5 version for use in browser without transpiling?

Stop using eval under the hood

'unsafe-eval' ('store' via 'react-colorpicker' is being silly, Function('return this')(), could have other eval()/Function())

This is necessary to enable unsafe-eval rule in CSP downstream.

More informative 'Reset color' button

The current/reset colors are identical when first opening up the pane, and it's not clear that one of them is designed to reset to the original value:

image

Consider adding icon or separating the two color squares (bad sketch below)

image

Remove localStorage

Remembering color mode preferences should be an application-level concern, not a component-level one.

S and V mode color field controls are flipped

When S is active I control V:

screen shot 2015-10-27 at 11 24 06 pm

When V is active I control S:
screen shot 2015-10-27 at 11 24 33 pm


Maybe this should be on a different ticket, but I think the mode switch interaction is poorly designed. It doesn't match user intention to change the functionality of the color field based on which input is active. User often wants to use the H version of the color field but manually input an S value. To see an example of a similar UI that is more user-friendly, check out Photoshop: it uses explicit toggles to switch modes. I'd even be in favor of locking the color field in Hue mode always โ€“ it's the most familiar and intuitive way to pick a color.

rotated range input is buggy

the rotated range input sometimes doesn't work or is unresponsive, and covers up other elements on the page. Should un-rotate this guy and place it along the bottom:

screen shot 2015-07-18 at 1 10 07 pm

Don't pass all of this.state to `onChange`

What's received by an onChange listener should be nicely formatted as color values. Right now I'm passing everything which is a little silly and means private things are no longer private.

Move mode switching into it's own input

From #58

User often wants to use the H version of the color field but manually input an S value. To see an example of a similar UI that is more user-friendly, check out Photoshop: it uses explicit toggles to switch modes. I'd even be in favor of locking the color field in Hue mode always โ€“ it's the most familiar and intuitive way to pick a color.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.