Gathering detailed insights and metrics for react-colorful
Gathering detailed insights and metrics for react-colorful
Gathering detailed insights and metrics for react-colorful
Gathering detailed insights and metrics for react-colorful
@noya-app/noya-colorpicker
This is derived from: https://github.com/omgovich/react-colorful
@amirhossein92/react-colorful
added gradient component into the react-colorful
@ui-schema/material-colorful
React color pickers as MUI widgets for UI-Schema - using react-colorful.
@armincerf/react-colorful
Fork of react-colorful with action buttons and toggles
🎨 A tiny (2,8 KB) color picker component for React and Preact apps
npm install react-colorful
88.3
Supply Chain
93
Quality
76.1
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3,205 Stars
490 Commits
102 Forks
10 Watching
6 Branches
14 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
TypeScript (58.16%)
JavaScript (38.2%)
CSS (3.64%)
Cumulative downloads
Total Downloads
Last day
-4.8%
877,708
Compared to previous day
Last week
0.9%
4,526,933
Compared to previous week
Last month
0.9%
20,273,010
Compared to previous month
Last year
74.3%
217,935,423
Compared to previous year
30
npm install react-colorful
1import { HexColorPicker } from "react-colorful"; 2 3const YourComponent = () => { 4 const [color, setColor] = useState("#aabbcc"); 5 return <HexColorPicker color={color} onChange={setColor} />; 6};
We provide 12 additional color picker components for different color models, unless your app needs a HEX string as an input/output format.
Import | Value example |
---|---|
{ HexColorPicker } | "#ffffff" |
{ HexAlphaColorPicker } | "#ffffff88" |
{ RgbColorPicker } | { r: 255, g: 255, b: 255 } |
{ RgbaColorPicker } | { r: 255, g: 255, b: 255, a: 1 } |
{ RgbStringColorPicker } | "rgb(255, 255, 255)" |
{ RgbaStringColorPicker } | "rgba(255, 255, 255, 1)" |
{ HslColorPicker } | { h: 0, s: 0, l: 100 } |
{ HslaColorPicker } | { h: 0, s: 0, l: 100, a: 1 } |
{ HslStringColorPicker } | "hsl(0, 0%, 100%)" |
{ HslaStringColorPicker } | "hsla(0, 0%, 100%, 1)" |
{ HsvColorPicker } | { h: 0, s: 0, v: 100 } |
{ HsvaColorPicker } | { h: 0, s: 0, v: 100, a: 1 } |
{ HsvStringColorPicker } | "hsv(0, 0%, 100%)" |
{ HsvaStringColorPicker } | "hsva(0, 0%, 100%, 1)" |
1import { RgbColorPicker } from "react-colorful"; 2 3const YourComponent = () => { 4 const [color, setColor] = useState({ r: 50, g: 100, b: 150 }); 5 return <RgbColorPicker color={color} onChange={setColor} />; 6};
The easiest way to tweak react-colorful is to create another stylesheet to override the default styles.
1.your-component .react-colorful { 2 height: 240px; 3} 4.your-component .react-colorful__saturation { 5 border-radius: 4px 4px 0 0; 6} 7.your-component .react-colorful__hue { 8 height: 40px; 9 border-radius: 0 0 4px 4px; 10} 11.your-component .react-colorful__hue-pointer { 12 width: 12px; 13 height: inherit; 14 border-radius: 0; 15}
As you probably noticed the color picker itself does not include an input field, but do not worry if you need one. react-colorful is a modular library that allows you to build any picker you need. Since v2.1
we provide an additional component that works perfectly in pair with our color picker.
HexColorInput
1import { HexColorPicker, HexColorInput } from "react-colorful"; 2 3const YourComponent = () => { 4 const [color, setColor] = useState("#aabbcc"); 5 return ( 6 <div> 7 <HexColorPicker color={color} onChange={setColor} /> 8 <HexColorInput color={color} onChange={setColor} /> 9 </div> 10 ); 11};
Property | Default | Description |
---|---|---|
alpha | false | Allows #rgba and #rrggbbaa color formats |
prefixed | false | Enables # prefix displaying |
HexColorInput
does not have any default styles, but it also accepts all properties that a regular input
tag does (such as className
, placeholder
and autoFocus
). That means you can place and modify this component as you like. Also, that allows you to combine the color picker and input in different ways:
1<HexColorInput color={color} onChange={setColor} placeholder="Type a color" prefixed alpha />
react-colorful supports TypeScript and ships with types in the library itself; no need for any other install.
While not only typing its own functions and variables, it can also help you type yours. Depending on the component you are using, you can also import the type that is associated with the component. For example, if you are using our HSL color picker component, you can also import the HSL
type.
1import { HslColorPicker, HslColor } from "react-colorful"; 2 3const myHslValue: HslColor = { h: 0, s: 0, l: 0 };
Take a look at Supported Color Models for more information about the types and color formats you may want to use.
react-colorful will work flawlessly with Preact out-of-the-box if you are using WMR, Preact-CLI, NextJS with Preact, or a few other tools/boilerplates thanks to aliasing.
If you are using another solution, please refer to the Aliasing React to Preact section of the Preact documentation.
react-colorful, like all other React + TS projects, can potentially cause issues in a Preact + TS application if you have the @types/react
package installed, either as a direct dependency or a dependency of a dependency. For example, the Preact TS template comes with @types/enzyme
which has @types/react
as a dependency.
To fix this, create a declaration.d.ts
file or add to your existing:
import React from "react";
declare global {
namespace React {
interface ReactElement {
nodeName: any;
attributes: any;
children: any;
}
}
}
This will correct the types and allow you to use react-colorful along with many other React + TS libraries in your Preact + TS application.
It would be an easier task to list all of the browsers and versions that react-colorful does not support! We regularly test against browser versions going all the way back to 2013 and this includes IE11.
react-colorful works out-of-the-box for most browsers, regardless of version, and only requires an Object.assign
polyfill be provided for full IE11 support.
Today each dependency drags more dependencies and increases your project’s bundle size uncontrollably. But size is very important for everything that intends to work in a browser.
react-colorful is a simple color picker for those who care about their bundle size and client-side performance. It is fast and lightweight because:
To show you the problem that react-colorful is trying to solve, we have performed a simple benchmark (using bundlephobia.com) against popular React color picker libraries:
Name | Bundle size | Bundle size (gzip) | Dependencies |
---|---|---|---|
react-colorful | |||
react-color | |||
react-input-color | |||
rc-color-picker |
Not using React or Preact? Not a problem! Check out the list of react-colorful ports adapted to your favourite framework or technology of choice:
vanilla-colorful — a react-colorful reimplementation in vanilla Custom Elements, generously ported by @web-padavan.
angular-colorful — a react-colorful rewritten for use with the Angular framework, lovingly ported by @fil0157.
If your port is not in the list, reach us out via GitHub issues.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 8/18 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
61 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More