
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
draft-js-color-picker
Advanced tools
This package allows you to use dynamic colors on your draft-js editor
npm i --save draft-js-color-picker
inside the constructor initialize the picker functions
this.updateEditorState = editorState => this.setState({ editorState });
this.getEditorState = () => this.state.editorState;
// Step 2: run the colorPickerPlugin function
this.picker = colorPickerPlugin(this.updateEditorState, this.getEditorState);
this.picker
component
import React, { Component } from 'react';
import { Editor } from 'draft-js';
import ColorPicker, { colorPickerPlugin } from 'draft-js-color-picker';
// optionals
import { stateToHTML } from 'draft-js-export-html';
import Raw from 'draft-js-raw-content-state';
// Add preset colors to the picker
const presetColors = [
'#ff00aa',
'#F5A623',
'#F8E71C',
'#8B572A',
'#7ED321',
'#417505',
'#BD10E0',
'#9013FE',
'#4A90E2',
'#50E3C2',
'#B8E986',
'#000000',
'#4A4A4A',
'#9B9B9B',
'#FFFFFF',
];
// Initialize the contentState
class RichEditor extends Component {
constructor(props) {
super(props);
this.state = { editorState: new Raw().addBlock('Hello World', 'header-two').toEditorState() };
// Step 1: Create the functions to get and update the editorState
this.updateEditorState = editorState => this.setState({ editorState });
this.getEditorState = () => this.state.editorState;
// Step 2: run the colorPickerPlugin function
this.picker = colorPickerPlugin(this.updateEditorState, this.getEditorState);
}
render() {
const { editorState } = this.state;
// Optional: you can use an export the color styles if you plan to render html
const inlineStyles = this.picker.exporter(editorState);
const html = stateToHTML(this.state.editorState.getCurrentContent(), { inlineStyles });
return (
<div style={{ display: 'flex', padding: '15px' }}>
<div style={{ flex: '1 0 25%' }}>
{/* Step 4: pass the functions to the color picker */}
<ColorPicker
toggleColor={color => this.picker.addColor(color)}
presetColors={presetColors}
color={this.picker.currentColor(editorState)}
/>
<button onClick={this.picker.removeColor}>clear</button>
</div>
<div style={{ flex: '1 0 25%' }}>
<h2>Draft-JS Editor</h2>
{/* Step 5 pass the customStyleFn */}
<Editor
customStyleFn={this.picker.customStyleFn}
editorState={editorState}
onChange={this.updateEditorState}
placeholder="Tell a story..."
readOnly={this.state.readOnly}
/>
</div>
<div style={{ flex: '1 0 25%' }}>
<h2>Exported HTML</h2>
<div dangerouslySetInnerHTML={{ __html: html }}/>
</div>
</div>
);
}
}
export default RichEditor;
Please open an issue for support.
Please contribute using Github Flow. Create a branch, add commits, and open a pull request.
FAQs
draft-js dynamic color picker
We found that draft-js-color-picker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.