Skip to content

Commit c9b0e8e

Browse files
committed
Add ability to override DefaultPlaceholder component
1 parent 2d1bcbc commit c9b0e8e

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

draft-js-placeholder-plugin/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1-
# DraftJS Divider Plugin
1+
# DraftJS placeholder Plugin
22

33
*This is a plugin for the `draft-js-plugins-editor`.*
4+
5+
## Usage
6+
7+
```js
8+
import createPlaceholderPlugin from 'draft-js-placeholder-plugin';
9+
10+
const placeholderPlugin = createPlaceholderPlugin();
11+
12+
```
13+
14+
## Default Config
15+
16+
```js
17+
{
18+
dataKey = 'placeholder',
19+
component = DefaultPlaceholder,
20+
}
21+
22+
```

draft-js-placeholder-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "draft-js-placeholder-plugin",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Placeholder Plugin for DraftJS",
55
"author": {
66
"name": "Ilkwon Sim",

draft-js-placeholder-plugin/src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { EditorState } from 'draft-js';
22

33
import DefaultPlaceholder from './components/DefaultPlaceholder';
44

5-
const placeholderPlugin = ({ dataKey = 'placeholder' } = {}) => {
5+
const placeholderPlugin = (
6+
{ dataKey = 'placeholder', component = DefaultPlaceholder } = {}
7+
) => {
68
return {
79
blockRendererFn: block => {
810
const placeholder = block.getData().get(dataKey);
911

1012
if (placeholder) {
1113
return {
12-
component: DefaultPlaceholder,
14+
component,
1315
props: {
1416
placeholder,
1517
},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const addPlaceholder = editorState => {
2+
const contentState = editorState.getCurrentContent();
3+
const selectionState = editorState.getSelection();
4+
const currentBlock = getCurrentBlock(editorState);
5+
6+
if (isEmptyBlock(currentBlock)) {
7+
const newContentState = Modifier.setBlockData(
8+
contentState,
9+
selectionState,
10+
{
11+
placeholder: 'This is placeholder',
12+
}
13+
);
14+
15+
setEditorState(
16+
EditorState.push(editorState, newContentState, 'change-block-data')
17+
);
18+
// setEditorState(RichUtils.toggleBlockType(editorState, 'placeholder'));
19+
// setEditorState(
20+
// Modifier.insertText(contentState, selectionState, 'attach youtube')
21+
// );
22+
}
23+
};
24+
25+
export default addPlaceholder;

0 commit comments

Comments
 (0)