Giter Site home page Giter Site logo

mikbry / material-ui-color Goto Github PK

View Code? Open in Web Editor NEW
141.0 1.0 33.0 11.57 MB

The lightest colorpicker, palette, colorinput, colorbutton ⚡ No dependencies. It uses React hooks, support Typescript theming and more !

Home Page: https://mikbry.github.io/material-ui-color/

License: MIT License

JavaScript 99.91% HTML 0.09%
es6 reactjs material-ui hooks colorpicker color-palette material-ui-color-picker component npm colorinput

material-ui-color's Introduction

material-ui-color picker and other components

Build Status codecov NPM version License minisize dependency status dev dependency status peer dependency status Downloads

Collections of color components for material-ui. No dependencies, small, highly customizable and theming support !

Video of ColorPicker

Contents

Why another ColorPicker ?

  • Fully compatible with Material-UI : theming and low level components
  • Highly customizable ColorPicker : gradient picker, palette, input format, deferred mode
  • Small in size (<30kb) without any direct dependencies
  • Use modern React hook and coding conventions
  • Documentation made with Storybook, using Component Story Format and MDX

Documentation

Full documentation is available here :

https://mikbry.github.io/material-ui-color/

Examples

You can find examples here and here.

Also in codesanbox

Requirements

  • Works on modern browsers supporting ES6+ (Not compatible with IE)
  • React and Material-UI frameworks

Install

yarn add material-ui-color

Or using npm

npm install material-ui-color

Usage

you need to have in your dependencies:

    "@mui/material": "^4.11.2",
    "material-ui-popup-state": "^1.7.1",
    "prop-types": "^15.7.2",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",

material-ui-color bring 5 components.

<ColorPicker/>

A popover component to display a color tool box. It uses ColorBox and material-ui-popup-state.

import { ColorPicker } from 'material-ui-color';

export const Container = () => (
  <div>
    <ColorPicker defaultValue="transparent"/>
  </div>
);

At first it display a button + an input

ColorPicker documentation

<ColorBox />

A component to display a color tool box

import { ColorBox } from 'material-ui-color';

export const Container = () => (
  <div>
    <ColorBox defaultValue="transparent"/>
  </div>
);

ColorBox documentation

<ColorInput />

An input component to display/edit color values in different format (plain, hex, rgb, hsl, hsv).

import { ColorInput } from 'material-ui-color';

export const Container = () => (
  <div>
    <ColorInput defaultValue="red"/>
  </div>
);

ColorInput documentation

<ColorPalette />

A component to display a grid of color buckets.

import { ColorPalette } from 'material-ui-color';

const palette = {
  red: '#ff0000',
  blue: '#0000ff',
  green: '#00ff00',
  yellow: 'yellow',
  cyan: 'cyan',
  lime: 'lime',
  gray: 'gray',
  orange: 'orange',
  purple: 'purple',
  black: 'black',
  white: 'white',
  pink: 'pink',
  darkblue: 'darkblue',
};

export const Container = () => (
  <div>
    <ColorPalette palette={palette} />
  </div>
);

ColorPalette documentation

<ColorButton />

Displays a button filled with a color

import { ColorButton } from 'material-ui-color';

export const Container = () => (
  <div>
    <ColorButton color="red"/>
  </div>
);

ColorButton documentation

Roadmap

  • remove styled-components to have less dependencies and reduce size
  • display wrong color using a red checked box
  • bugs fixes

Contribute

Contributions welcome! Read the contribution guidelines first.

License

Released under MIT License

material-ui-color's People

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

material-ui-color's Issues

ColorPicker support disable 'plain' textfield format

Is your feature request related to a problem? Please describe.

I'm always frustrated when I enter a color using textInput and it transform my value into a text color
example : I want to enter color #000FFF, after typing #000, input text will change to black.

Describe the solution you'd like

I would like a props inside ColorPicker that disabled color automatic renaming.

Describe alternatives you've considered
I think that we can add a condition regarding this line

color.name = Object.keys(cssColors).find(n => cssColors[n] === value) || `color-${hex}`;

otherwise, I can make a custom input and hiding default one. But I think this could be usefull.

hsv gradient position is changed on slider drag

Describe the bug

when a slider (color / alpha) is dragged and the curser moves into the hsv box, the hsv value is changed with the cursor position.

i suspect this ( || event.buttons )to be the reason:

const handleMove = event => {
if (pressed || event.buttons) {
const xy = { x: event.pageX - window.scrollX, y: event.pageY - window.scrollY };
convertMousePosition(xy, ref);
event.preventDefault();
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/material-ui-color-qb4vm?file=/src/App.tsx
  2. open colorpicker
  3. click alpha or hue slider
  4. move mouse in hsv box

Expected behavior

hsv dot should persist

Using a single hex value when the component is controlled causes problems (Typescript)

Describe the bug
Using the full color object (Type Color) provided by onChange immediately resolves this issue but I want to only save the hex value and use this as value for ColorPicker, which is controlled in my case.
The value field excepts a single hex value and displays the correct color just fine. However, the text input for HEX cannot be changed manually and I cannot use the color slider. I can still pick any color and after that the color slider becomes usable aswell.
I tried working around this issue by providing the Color object myself with the hex value inserted but I was not able to construct the object in a clean way since format is dependend on enum ColorFormat which is not exported.

To Reproduce
Steps to reproduce the behavior:

  1. Use the ColorPicker as a controlled component
  2. Pick only the Color.hex from onChange and use this as value
  3. Open the ColorPicker and try using the color slider or changing the HEX text field manually

Expected behavior
The color slider and HEX text field should work when using a hex color as value. If this is not working by design the value field should only accept a Color object.

Screenshots
colorpickerissue

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Browser Google Chrome
  • Version 85

Additional context
Exporting enum ColorFormat would also help since I could construct the Color object on my end.

Fix: 2 index.d.ts and src/type/index.d.ts

Describe the bug
There is 2 index.d.ts one at the root and one in src/type/index.d.ts
src/type/index.d.ts was modified by contributors
But index.d.ts is used for npm package (packito and in package.json)

Expected behavior
Remove index.d.ts at root and use src/type/index.d.ts

fails to render

Describe the bug
ColorPicker throws error on initial render. Dependency versions were carefully compared to manual dependencies list.

To Reproduce
Render the component <ColorPicker defaultValue="red" onChange={() => {}} />.

Expected behavior
The component renders like in the story book

Console log

Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (:9080/[project directory]/node_modules/react/cjs/react.development.js:1465)
    at Object.startsWith [as useRef] (:9080/[project directory]/node_modules/react/cjs/react.development.js:1504)
    at je (:9080/[project directory]/node_modules/src/components/ColorPicker.jsx:36)
    at renderWithHooks (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:14804)
    at mountIndeterminateComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:17483)
    at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:18597)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:189)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:238)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:293)
    at beginWork$1 (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:23204)

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Browser [ chrome ]
  • Version [Version 86.0.4240.111]

Additional context
Project uses electron, mobx-state-tree, typescript

feat: CamPicker

Is your feature request related to a problem? Please describe.
Grab a color using the camera

Add colors to a palette

Colorbox cant handle palette and disableAlpha

Describe the bug
I cannot use the option to disable the alpha slider and the option to add a palette to the colorbox

To Reproduce

using
<Colorbox palette={paletteObj} disableAlpha>
should already throw the error "translate is not a function"

Expected behavior
The palette is displayed while the alphaslider is not

[Typescript] Error in typings

Describe the bug
It seams there is a bug in typings which prevents from successful compilation.

To Reproduce
I have created a test repo

git clone https://github.com/jedrzejowski/my-issue-1
cd my-issue-1/
npm install
npm run tsc

Expected behavior
Code compiles

Screenshots
image

T extends different types here:

interface ColorPickerPaletteProps<T extends Record<string, string>> extends ColorPickerProps {

and here:
function ColorPicker<T extends Record<string, string> | null>(

Color box on dark mode has some glitches

I love this package. It's perfect for someone who uses material-ui. This bug is just a small thing but quite annoying.

Describe the bug
Screenshot 2020-10-15 at 16 18 41
The color slider and alpha slider seem transparent. They work, but kind of have opacity 0. This only happens on the dark palette of material-ui.

  • OS: macOS
  • Browser Chrome
  • Version 86

Bug : Material-UI: the `anchorEl` prop provided to the component is invalid.

On Firefox:
The anchor element should be part of the document layout.
Make sure the element is present in the document or that it's not display none.
Error on Chrome:
checkPropTypes.js:20 Warning: Failed prop type: Material-UI: the anchorEl prop provided to the component is invalid.
The anchor element should be part of the document layout.
Make sure the element is present in the document or that it's not display none.
in ForwardRef(Popover) (created by WithStyles(ForwardRef(Popover)))
in WithStyles(ForwardRef(Popover)) (created by ColorPicker)
in div (created by ColorPicker)
in ColorPicker (created by Uncontrolled)
in Uncontrolled
in Unknown
in ThemeProvider (created by ThemeProvider)
in ThemeProvider (created by ThemeProvider)
in StylesProvider (created by ThemeProvider)

feat: ColorPicker when using onChange with defaultValue don't create a controlled component

Is your feature request related to a problem? Please describe.
A lot's of people are doing this:
<ColorPicker defaultValue={color} onChange={handleChange} />
But it doesn't call onChange as it became a controlled component
Instead of
<ColorPicker value={color} onChange={handleChange} />

Describe the solution you'd like
If onChange is set, force as uncontrolled component and use defaultValue as value.
<ColorPicker defaultValue={color} onChange={handleChange} />
should work as
<ColorPicker value={color} onChange={handleChange} />

Describe alternatives you've considered
Or it should throws an error:
Error: ColorPicker can't use onChange in a controlled component, replace property name "defaultValue" by "value"

ColorPicker onChange event not emitted.

ColorPicker is not emitting onChange event.
I am using the code below. I am using similar code for other inputs which output a console log from handleStateChange, but nothing happens with the code below.
<ColorPicker value={state.strokeColor} defaultValue="#000" disableAlpha onChange={value => handleStateChange('strokeColor', value)} />

Environment: Latest Chrome on Windows 10.

ColorPicker support for not rendering textfield

Is your feature request related to a problem? Please describe.
The ColorPicker component should support having the option to not render a text field.

Describe the solution you'd like
Adding a simple prop to the ColorPicker component to decide whether the text field will be rendered.

Describe alternatives you've considered
The first alternative is composing a new component myself using the ColorButton wrapped around a MUI's IconButton and ColorBox to build this functionality. However this also requires keeping track of open/close state and a ref to detect clicks outside the popover.

Other option I tried was hiding the textfield through CSS but that seems hacky and I'm not happy with it.

Additional context
I'm happy to implement this feature if needed.

Bug : the popover component is too tall.

When the window's height is too small:
Material-UI: the popover component is too tall.
Some part of it can not be seen on the screen (32px).
Please consider adding a max-height to improve the user-experience.

Bug : openAtStart=true wrong positionning

Describe the bug
openAtStart=true wrong positionning

To Reproduce
Steps to reproduce the behavior:

  1. Set openAtStart=true for ColorPicker
  2. Run
  3. Close ColorPicker
  4. Open again
  5. Not the same position

Expected behavior
Should be the same position

Bug: ColorPicker pop-up is stuck with black colour

Describe the bug
ColorPicker pop-up doesn't let me pick any colour other than black.

How to reproduce
Access the docs demos (https://mikbry.github.io/material-ui-color/?path=/docs/components-colorpicker--basic#deferred) and try picking a colour. Note: all the demos are having the same issue, except the very first one.

MaterialUiColorPickerIssue

Alternatively, I can reproduce it by just adding PickColor to my react component, like this:
<ColorPicker defaultValue="#987654"/>

System settings

  • Chrome Version 83.0.4103.97 (Official Build) (64-bit) for Windows 10

Expected behaviour
The component should be able to let me pick any colour.

feat: add typescript definition to package

Changes:
1 - filename
src/types/types.d.ts
should be renamed to
src/types/index.d.ts

2- and in package.json add:
"types": "index.d.ts",

3 - In .packito.json add src/types/index.d.tsto copy list

Support for hiding color box in picker

I'm working on a project where the user wants to show the color picker without the large color square at the top. I've successfully hidden it using CSS:

.muicc-colorbox-hsvgradient
height: 0 !important
visibility: hidden

But the issue is that in my picker, I still have palette items that aren't on the color slider(black, grey, white). With the color box hidden I run into an issue where if I choose one of the non-color items and then click a color on the slider the color is not selected. It remains on the [non-color.]

Screen Shot 2021-02-18 at 10 34 57 AM

Steps to reproduce:

  • Create a palette of colors. I've attached the colors I use at the bottom of this issue.
  • Select black, grey or white
  • On the color slider, choose a color
  • See that the color in the square is not changed

Suggested features:

  • Allow the slider to change the color in this situation. And also make hiding the color box an option.

paletteColors = {
"#000000": "#000000",
"#333333": "#333333",
"#4D4D4D": "#4D4D4D",
"#666666": "#666666",
"#808080": "#808080",
"#999999": "#999999",
"#B3B3B3": "#B3B3B3",
"#cccccc": "#cccccc",
"#FFFFFF": "#FFFFFF",
"#9F0500": "#9F0500",
"#D33115": "#D33115",
"#F44E3B": "#F44E3B",
"#C45100": "#C45100",
"#E27300": "#E27300",
"#FE9200": "#FE9200",
"#FB9E00": "#FB9E00",
"#FCC400": "#FCC400",
"#FCDC00": "#FCDC00",
"#808900": "#808900",
"#B0BC00": "#B0BC00",
"#DBDF00": "#DBDF00",
"#194D33": "#194D33",
"#68BC00": "#68BC00",
"#A4DD00": "#A4DD00",
"#0C797D": "#0C797D",
"#16A5A5": "#16A5A5",
"#68CCCA": "#68CCCA",
"#0062B1": "#0062B1",
"#009CE0": "#009CE0",
"#73D8FF": "#73D8FF",
"#653294": "#653294",
"#7B64FF": "#7B64FF",
"#AEA1FF": "#AEA1FF",
"#AB149E": "#AB149E",
"#FA28FF": "#FA28FF",
"#FDA1FF": "#FDA1FF"
}

Peer dependency conflict

Describe the bug

It seems like 0.4.9 updated the react dependency to ^17, but a peer dependency isn't ready yet:

https://github.com/jcoreio/material-ui-popup-state/blob/321c4fdf37001f607f8c1611d48fed4fad4757a6/package.json#L153

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: airg@undefined
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!   peer react@"^17.0.1" from [email protected]
npm ERR!   node_modules/material-ui-color
npm ERR!     material-ui-color@"^0.4.9" from the root project
npm ERR!   2 more (@material-ui/core, react-dom)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^15.0.0 || ^16.0.0" from [email protected]
npm ERR! node_modules/material-ui-popup-state
npm ERR!   peer material-ui-popup-state@"^1.7.1" from [email protected]
npm ERR!   node_modules/material-ui-color
npm ERR!     material-ui-color@"^0.4.9" from the root project

To Reproduce
Steps to reproduce the behavior:

  1. update react to 17.0.1
  2. update material-ui-color to 0.4.9

Desktop (please complete the following information):

linux

dependency-free?

Is your feature request related to a problem? Please describe.
I'm confused about why you say this is a dependency-free library when later you state one needs to have certain libraries installed.

Describe the solution you'd like
Perhaps an explanation as to why these dependencies are not in your package.json dependencies for this project.

Describe alternatives you've considered
N/A

I was using react-color and it wasn't doing what I wanted so I was very happy to find this. Thank you for sharing :)

bug: wrong position for error messages

Describe the bug
Since PR #113
I found a bug in this PR, displaying erroneous color:

Screenshot 2021-03-16 at 16 46 57

To Reproduce
in ColorPicker

  • change hex textfield to 'xxx'
  • the red error is mispositionned

bump version

Is your feature request related to a problem? Please describe.

i'd like to use npm packages and still make use of the fix in #87

Describe the solution you'd like

a version bump to 0.4.7 would help :)

Can't make localisation to work (Typescript)

Hi guys,

Love your package but I'm having some issues to make the localisation to work. I don't quite get the example from the docs.
I've looked through the codebase and it seems that there is no translate prop on any component.

Can somebody help me with this?

Thanks!

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.