admin管理员组文章数量:1401281
I am starting to use react-draft-wysiwyg and want to know if I can extend existing elements with styles and classes?
For example, there is a button B (bold) by default and I want to add some styles and classes to it, how can I do that?
My goal is to get something like this <p className = "test"> BOLD TEXT </ p>
and as a result I will get bold text with the class
class EditorContainer extends Component {
constructor(props) {
super(props);
this.state = {
editorState: EditorState.createEmpty(),
};
}
onEditorStateChange = (editorState) => {
this.setState({
editorState,
});
};
render() {
const { editorState } = this.state;
return (
<div className="editor">
<Editor
editorState={editorState}
onEditorStateChange={this.onEditorStateChange}
toolbar={{
options: ["inline", "blockType", "fontSize"],
inline: {
inDropdown: false,
className: "test",
ponent: undefined,
dropdownClassName: undefined,
options: ["bold", "italic", "underline"],
bold: { className: "test", style: { color: "red" } },
italic: { className: undefined },
underline: { className: undefined },
},
}}
/>
<textarea
disabled
// value={draftToHtml(convertToRaw(editorState.getCurrentContent()))}
/>
</div>
);
}
}
Example
Or maybe there is react-wysiwyg another library for this purpose
I am starting to use react-draft-wysiwyg and want to know if I can extend existing elements with styles and classes?
For example, there is a button B (bold) by default and I want to add some styles and classes to it, how can I do that?
My goal is to get something like this <p className = "test"> BOLD TEXT </ p>
and as a result I will get bold text with the class
class EditorContainer extends Component {
constructor(props) {
super(props);
this.state = {
editorState: EditorState.createEmpty(),
};
}
onEditorStateChange = (editorState) => {
this.setState({
editorState,
});
};
render() {
const { editorState } = this.state;
return (
<div className="editor">
<Editor
editorState={editorState}
onEditorStateChange={this.onEditorStateChange}
toolbar={{
options: ["inline", "blockType", "fontSize"],
inline: {
inDropdown: false,
className: "test",
ponent: undefined,
dropdownClassName: undefined,
options: ["bold", "italic", "underline"],
bold: { className: "test", style: { color: "red" } },
italic: { className: undefined },
underline: { className: undefined },
},
}}
/>
<textarea
disabled
// value={draftToHtml(convertToRaw(editorState.getCurrentContent()))}
/>
</div>
);
}
}
Example
Or maybe there is react-wysiwyg another library for this purpose
Share Improve this question edited Jul 21, 2020 at 19:42 Raghul SK 1,3905 gold badges24 silver badges35 bronze badges asked Jul 21, 2020 at 12:59 JuniorrrrrJuniorrrrr 1692 gold badges4 silver badges12 bronze badges3 Answers
Reset to default 2<Editor editorStyle={{ border: "1px solid black" }} />
use customBlockRenderFunc={myBlockStyleFn}
in <Editor/>
ponent instead of blockStyleFn={myBlockStyleFn}
You should be able to apply style to block elements using the blockStyleFn
prop. There's a good example in the docs: https://draftjs/docs/advanced-topics-block-styling#blockstylefn
本文标签: javascriptHow to customize the style for reactdraftwysiwygStack Overflow
版权声明:本文标题:javascript - How to customize the style for react-draft-wysiwyg? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744291150a2599120.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论