Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
draft-js-color-picker
Advanced tools
Readme
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
The npm package draft-js-color-picker receives a total of 515 weekly downloads. As such, draft-js-color-picker popularity was classified as not popular.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.