Skip to content

Commit 9440bb9

Browse files
committed
allow to hide the remove button for stickers
1 parent a739471 commit 9440bb9

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

site/components/SuperheroEditor/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import stickers from './stickers';
99
import StatePreview from '../StatePreview';
1010
import Hashtag from './Hashtag';
1111
import Link from './Link';
12-
import Sticker from './Sticker';
1312

13+
// import Sticker from './Sticker';
14+
// const stickerPluginInstance = stickerPlugin({ stickers, Sticker });
15+
const stickerPluginInstance = stickerPlugin({ stickers, hasRemove: false });
1416
const hashtagPluginInstance = hashtagPlugin({ Hashtag });
1517
const linkifyPluginInstance = linkifyPlugin({ Link });
16-
const stickerPluginInstance = stickerPlugin({ stickers, Sticker });
1718
const { StickerSelect } = stickerPluginInstance;
1819

1920
const plugins = [

src/stickerPlugin/Sticker/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React, { Component } from 'react';
66
import styles from './styles';
77
import { Entity } from 'draft-js';
88

9-
export default (stickers) => {
9+
export default (stickers, hasRemove = true) => {
1010
class Sticker extends Component {
1111

1212
remove = (event) => {
@@ -18,18 +18,22 @@ export default (stickers) => {
1818
};
1919

2020
render() {
21+
const removeButton = (
22+
<span
23+
style={ styles.removeButton }
24+
onClick={ this.remove }
25+
type="button"
26+
>
27+
28+
</span>
29+
);
30+
2131
const { block } = this.props;
2232
const data = Entity.get(block.getEntityAt(0)).getData();
2333
return (
2434
<figure style={ styles.root } contentEditable={ false } data-offset-key={ `${block.get('key')}-0-0` }>
2535
<img style={ styles.image } src={ stickers.getIn(['data', data.id, 'url']) } />
26-
<span
27-
style={ styles.removeButton }
28-
onClick={ this.remove }
29-
type="button"
30-
>
31-
32-
</span>
36+
{ hasRemove ? removeButton : null }
3337
</figure>
3438
);
3539
}

src/stickerPlugin/blockRendererFn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default (config) => (contentBlock, editor) => {
55
const type = contentBlock.getType();
66
if (type === 'sticker') {
77
return {
8-
component: (config.Sticker !== undefined ? config.Sticker : sticker(config.stickers)),
8+
component: (config.Sticker !== undefined ? config.Sticker : sticker(config.stickers, config.hasRemove)),
99
props: {
1010
onRemove: (blockKey) => {
1111
editor.onChange(removeSticker(editor.props.editorState, blockKey));

src/stickerPlugin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const stickerPlugin = (config) => ({
1010
blockRendererFn: blockRendererFn(config), // standard plugin callback
1111
onChange: cleanupEmptyStickers, // standard plugin callback
1212
remove: removeSticker,
13-
Sticker: sticker(config.stickers),
13+
Sticker: sticker(config.stickers, config.hasRemove),
1414
StickerSelect: stickerSelect(config.stickers),
1515
});
1616

0 commit comments

Comments
 (0)