Giter Site home page Giter Site logo

material-ui-color-picker's Introduction

<ColorPicker> for material-ui

<ColorPicker> example

ColorPicker based on <TextField /> and <ChromePicker /> from react-color and its redux-form field component.

Demo

https://material-ui-color-picker.now.sh/

Installation

For material-ui (v1):

npm install --save material-ui-color-picker

Usage

import React from 'react'
import ColorPicker from 'material-ui-color-picker'

<ColorPicker
  name='color'
  defaultValue='#000'
  // value={this.state.color} - for controlled component
  onChange={color => console.log(color)}

/>

Redux-form field

import React, { Component } from 'react';
import { reduxForm, Field } from 'redux-form';
import { ColorPickerField } from 'material-ui-color-picker';

...
<Field
  name="color"
  component={ColorPickerField}
/>
...

There is not so much properties at this time. The was very quickly designed for my needs. Feel free to submit a PR with new features ;)

License

This library is licensed under the MIT Licence, and sponsored by iGLOO.

material-ui-color-picker's People

Contributors

bchrobot avatar dependabot[bot] avatar jesseflorig avatar khartir avatar kulakowka avatar liorchen avatar loicmahieu avatar motiko avatar orafaelfragoso avatar romannep avatar skoging 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

Watchers

 avatar  avatar  avatar

material-ui-color-picker's Issues

value for controlled component not working

when i pass the in the value, i dont get anything on the text field. not sure if its linked or not and the label just sticks

<ColorPicker fullWidth label='Select Color' value='{newColor}' onChange={color => setNewColor(color)} />

Library needs to be updated to reflect @mui import

Hello @LoicMahieu,

I have tried to use this new color picker with a new Material UI project and failed to get your color picker to work due to references to older versions of MaterialUI Imports.

import TextField from '@material-ui/core/TextField'

Needs to be updated to:

import { TextField } from '@mui/material'

Material Changed its imports from @material-ui to @mui on September 2021.

Thanks!

Installation error

After installing this package and trying to use, I getting the following error.

    ERROR in ./node_modules/material-ui-color-picker/lib/components/ColorPicker.js
    Module not found: Error: Can't resolve '@material-ui/core/TextField' in '/home/jonny/Documents/workspace/amp-wp/node_modules/material-ui-color-picker/lib/components'
     @ ./node_modules/material-ui-color-picker/lib/components/ColorPicker.js 16:40-78
     @ ./node_modules/material-ui-color-picker/lib/index.js
     @ ./assets/src/stories-editor/components/higher-order/with-amp-story-settings.js
     @ ./assets/src/stories-editor/components/index.js
     @ ./assets/src/stories-editor/index.js

Color Picker JSS styles are using the same class name as elements already on my page

The jss styles class name produced by material UI makeStyles on the color picker modal match classes that already exist on my page. Because of this, they are sharing the same css styles which causes visual issues on my page.

Loom video to show a visualization of the issue
https://www.loom.com/share/3136cafd83dd4f8fb0805734337b6ad3

I have seen elsewhere online that this could be caused by versions of either react or material being out of sync. My current versions of my environment are

"@material-ui/core": "^4.11.3",
"react": "^17.0.1",
"material-ui-color": "^1.1.0",

Is there anything I can do to prevent this from happening?

missing material-ui peerDependancy?

Hi,
just stumbled upon your package and im getting ready to use it,
couldn't help but notice that your'e missing a dependency for material-ui.
everything should work, but when someone who isn't using material-ui will try to install it - he will be able to , but the lib won't work.

for your consideration.
thanks,

a vulnerability CVE-2020-15168 is introduced in material-ui-color-picker

Hi, @LoicMahieu, a vulnerability CVE-2020-15168 is introduced in material-ui-color-picker via:
[email protected][email protected][email protected][email protected][email protected]

recompose is a legacy package. It has not been maintained for about 3 years, and is not likely to be updated.
Is it possible to migrate recompose to other package to remediate this vulnerability?

I noticed several migration records for recompose in other js repos, such as

  1. in react-dnd, version 7.4.1 ➔ 7.4.2, remove recompose via commit
  2. in @nivo/legends, version 0.67.0 ➔ 0.68.0, remove recompose via commit

Are there any efforts planned that would remediate this vulnerability or migrate recompose?

Thanks
; )

onChange handlers get mixed up when using multiple instances

I set up 3 pickers and they behaved pretty inconsistently, sometimes updating as expected, sometimes firing the onChange of one of the other inputs, and sometimes doing nothing at all. Sorry I am not motivated to set up an example because I realized that the actual picker is in react-color and I decided to just write my own wrapper with the UI suggestions I left earlier.

Some Actions

Is it possible to display color code on the ColorPicker TextField? Currently, the ColorPicker textfield does not clear off, is there any way to clear the field? Thank you.

UI suggestions

This is a great little component, I got it up and running in no time and it works wonderfully!

The first time I started using it, I was surprised to find out it was updating my values whenever I changed the color in the dialog. What I was expecting is once I found my color, I could submit the value into the input (or cancel the change of the input altogether).

It would be great if this input could have this kind of "deferred mode" as a boolean prop which would make Ok and Cancel buttons appear inside the dialog.

I've found that the display of the value of the input is not attractive or readable in many cases. I would much prefer to have a little square that was filled by the selected color. I might fork and add the feature, would you take a PR for the feature as a boolean prop?

The PickerDialog disappears when scrolling if the ColorPicker is contained in an element with a scroll bar

I have two cases:

  1. A simplifed "real" case where the ColorPickers are contained in a Drawer with scroll bar (auto). If the PickerDialog is just partly visible when it opens, trying to scroll it into view makes it disappear which makes it impossible to use.

  2. The ColorPickers are contained in a div with scroll bar (auto). This shows the same problem when clicking the scroll bar although in this case the PickerDialog is fully visible before clicking the scroll bar because it "sticks out" below the div (which BTW is not what I want), so there's not the same need to use the scroll bar.

I think the culprit is this line:

style={{ position: 'fixed', top: '0px', right: '0px', bottom: '0px', left: '0px' }}

which seems to place an overlay over the whole document (including the scroll bar) to which a click event is attached that closes the PickerDialog.

I think a solution would be to use "width" instead of "right" and make it as wide as the ColorPicker instead. That works in the debugger at least.

I would be happy to supply such a PR, if that's the intended behavior, but I don't know how to run and test it locally. I'm fairly new to HTML/CSS/Javascript and web development in general and started learning React and Material-UI less than a month ago so I'm still struggling to understand what the code I've copy-and-pasted into my application from different examples actually does. Apologies if I'm using the ColorPicker in the wrong way. Please correct me if I've done something wrong.

Case 1:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import ColorPicker from 'material-ui-color-picker'

const styles = {
  mystyle: {
    width: '250px', // 225px is the picker dialog width
    height: "300px", // less than half the screen height
    overflowY: 'auto',
  },
};

const pickers = [
  'pickerA',
  'pickerB',
  'pickerC',
  'pickerD',
  'pickerE',
  'pickerF',
  'pickerG',
];

class App extends Component {
  render() {
    const { classes } = this.props;
    return (
      <Drawer
          variant="persistent"
          anchor='left'
          open='true'
          classes={{
            paper: classes.mystyle,
          }}
        >
        {pickers.map((picker) =>
            <ColorPicker
              name={picker}
              label={picker}
              key={picker}
              defaultValue='#123456'
              onChange={() => console.log('change')}
            />
          )}
      </Drawer>
    );
  }
}


App.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(App);

Case 2:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import ColorPicker from 'material-ui-color-picker'

const styles = {
  mystyle: {
    width: '250px', // 225px is the picker dialog width
    height: "300px", // less than half the screen height
    overflowY: 'auto',
  },
};

const pickers = [
  'pickerA',
  'pickerB',
  'pickerC',
  'pickerD',
  'pickerE',
  'pickerF',
  'pickerG',
];

class App extends Component {
  render() {
    const { classes } = this.props;
    return (
      <div id="mydiv" className={classes.mystyle}>
        {pickers.map((picker) =>
            <ColorPicker
              name={picker}
              label={picker}
              key={picker}
              defaultValue='#123456'
              onChange={() => console.log('change')}
            />
          )}
      </div>      
    );
  }
}


App.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(App);

bug: unable to set value

Hi,
i have multiple entities which are forms - when selecting an entity im loading it's state into the form
and when the inputs change i gather the inputs
examples:

#componentWillReceiveProps
this.bannerUrl.getInputNode().value = get(nextProps.page, 'bannerUrl', null)

#onInputChanged
const bannerUrl = this.bannerUrl.getValue()

#render
<TextField floatingLabelText="Banner url" ref={input => this.bannerUrl = input}
                     onChange={() => this.onInputChanged()}/>

however when using the color-picker, I can't seem to do so.
tried using setValue , .value on the ref object like so:

<ColorPicker name="color"
                       floatingLabelText="Status bar color"
                       defaultValue="#00000"
                       onChange={ () => this.onInputChanged()}
                       ref={input => this.statusBarColor = input}/>

but it doesn't work,
i also tried setting like this:

<ColorPicker name="color"
                       floatingLabelText="Status bar color"
                       value={color}
                       onChange={ (c) => this.onInputChanged('statusBarColor',c)}

but it doesn't work as well.
any suggestions to how to solve this issue?
thanks

Types package

Hey, can you please register a types package?

I have to make a .d.ts file to use your package in typescript and it would be nice if I didn't have to do this.

Missing decoration file

ERROR in [at-loader] ./node_modules/material-ui-color-picker/lib/index.d.ts:2:28
TS7016: Could not find a declaration file for module './transformers'. 'path/to/project/node_modules/material-ui-color-picker/lib/transformers.js' implicitly has an 'any' type

Deprecation warning for React.createFactory()

I'm receiving the following error and stack trace on my project using React 16.13.1.

Warning: React.createFactory() is deprecated and will be removed in a future major release. Consider using JSX or use React.createElement() directly instead.


printWarning | @ | react.development.js:315
warn | @ | react.development.js:278
createFactoryWithValidation | @ | react.development.js:1827
(anonymous) | @ | withState.js:20
(anonymous) | @ | compose.js:13
./node_modules/material-ui-color-picker/lib/components/ColorPicker.js | @ | ColorPicker.js:105
__webpack_require__ | @ | bootstrap:784
fn | @ | bootstrap:150
./node_modules/material-ui-color-picker/lib/index.js | @ | index.js:8
__webpack_require__ | @ | bootstrap:784
fn | @ | bootstrap:150
./src/components/CreateForm.js | @ | ActionButtons.js:81
__webpack_require__ | @ | bootstrap:784
fn | @ | bootstrap:150
./src/App.js | @ | main.chunk.js:35
__webpack_require__ | @ | bootstrap:784
fn | @ | bootstrap:150
./src/index.js | @ | Welcome.js:95
__webpack_require__ | @ | bootstrap:784
fn | @ | bootstrap:150
1 | @ | utils.js:8
__webpack_require__ | @ | bootstrap:784
checkDeferredModules | @ | bootstrap:45
webpackJsonpCallback | @ | bootstrap:32
(anonymous) | @ | main.chunk.js:1

Add a Button Option for Color Picker

Currently, only a text field can be used as a way to open and pick colors.

An alternative component would have a button allow the user to select for a color.

bug: don't have enough information to build a robust unique id for the TextField component.

I think it should add more properties to the component, otherwise it will display the bug:
Warning: We don't have enough information to build a robust unique id for the TextField component. Please provide an id or a name.
I fixed the bug by adding some properties.
<ColorPicker
name="colorPicker"
hintText="pick your color"
floatingLabelText="pick your color"
id="colorPicker"
defaultValue="#000"
onChange={color => console.log(color)}
/>

Need Some Properties

In this color picker we need some common properties:
ClassName
Style
FullWidth
floatingLabelStyle
floatingLabelFocusStyle
please add asap.

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.