-
Notifications
You must be signed in to change notification settings - Fork 1k
/
index.js
61 lines (56 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import EditorUtils from 'draft-js-plugins-utils';
import AddLinkForm from './AddLinkForm';
export default class LinkButton extends Component {
static propTypes = {
placeholder: PropTypes.string,
store: PropTypes.object.isRequired,
ownTheme: PropTypes.object.isRequired,
onRemoveLinkAtSelection: PropTypes.func.isRequired,
};
onMouseDown = event => {
event.preventDefault();
};
onAddLinkClick = e => {
e.preventDefault();
e.stopPropagation();
const { ownTheme, placeholder, onOverrideContent } = this.props;
const content = props => (
<AddLinkForm {...props} placeholder={placeholder} theme={ownTheme} />
);
onOverrideContent(content);
};
render() {
const { theme, onRemoveLinkAtSelection } = this.props;
const hasLinkSelected = EditorUtils.hasEntity(
this.props.store.getEditorState(),
'LINK'
);
const className = hasLinkSelected
? clsx(theme.button, theme.active)
: theme.button;
return (
<div className={theme.buttonWrapper} onMouseDown={this.onMouseDown}>
<button
className={className}
onClick={
hasLinkSelected ? onRemoveLinkAtSelection : this.onAddLinkClick
}
type="button"
>
<svg
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M0 0h24v24H0z" fill="none" />
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z" />
</svg>
</button>
</div>
);
}
}